Darin Petkov | f2065b4 | 2011-05-17 16:36:27 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <stdio.h> |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 6 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 7 | #include <string> |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 8 | |
| 9 | #include "base/file_util.h" |
| 10 | #include "gtest/gtest.h" |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame^] | 11 | #include "update_engine/constants.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 12 | #include "update_engine/install_plan.h" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 13 | #include "update_engine/mock_system_state.h" |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 14 | #include "update_engine/omaha_request_params.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 15 | #include "update_engine/test_utils.h" |
| 16 | #include "update_engine/utils.h" |
| 17 | |
| 18 | using std::string; |
| 19 | |
| 20 | namespace chromeos_update_engine { |
| 21 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 22 | class OmahaRequestParamsTest : public ::testing::Test { |
| 23 | public: |
| 24 | OmahaRequestParamsTest() : params_(NULL) {} |
| 25 | |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 26 | protected: |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 27 | // Return true iff the OmahaRequestParams::Init succeeded. If |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 28 | // out is non-NULL, it's set w/ the generated data. |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 29 | bool DoTest(OmahaRequestParams* out, const string& app_version, |
| 30 | const string& omaha_url); |
| 31 | |
| 32 | virtual void SetUp() { |
| 33 | ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); |
| 34 | ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame^] | 35 | kStatefulPartition + "/etc")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 36 | // Create a fresh copy of the params for each test, so there's no |
| 37 | // unintended reuse of state across tests. |
| 38 | MockSystemState mock_system_state; |
| 39 | OmahaRequestParams new_params(&mock_system_state); |
| 40 | params_ = new_params; |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 41 | params_.set_root(string("./") + kTestDir); |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 42 | params_.SetLockDown(false); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | virtual void TearDown() { |
| 46 | EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); |
| 47 | } |
| 48 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 49 | OmahaRequestParams params_; |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 50 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 51 | static const string kTestDir; |
| 52 | }; |
| 53 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 54 | const string OmahaRequestParamsTest::kTestDir = |
| 55 | "omaha_request_params-test"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 56 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 57 | bool OmahaRequestParamsTest::DoTest(OmahaRequestParams* out, |
| 58 | const string& app_version, |
| 59 | const string& omaha_url) { |
| 60 | bool success = params_.Init(app_version, omaha_url, false); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 61 | if (out) |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 62 | *out = params_; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 63 | return success; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | namespace { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 67 | string GetMachineType() { |
Gilad Arnold | 19a45f0 | 2012-07-19 12:36:10 -0700 | [diff] [blame] | 68 | string machine_type; |
| 69 | if (!utils::ReadPipe("uname -m", &machine_type)) |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 70 | return ""; |
Gilad Arnold | 19a45f0 | 2012-07-19 12:36:10 -0700 | [diff] [blame] | 71 | // Strip anything from the first newline char. |
| 72 | size_t newline_pos = machine_type.find('\n'); |
| 73 | if (newline_pos != string::npos) |
| 74 | machine_type.erase(newline_pos); |
| 75 | return machine_type; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 76 | } |
| 77 | } // namespace {} |
| 78 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 79 | TEST_F(OmahaRequestParamsTest, SimpleTest) { |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 80 | ASSERT_TRUE(WriteFileString( |
| 81 | kTestDir + "/etc/lsb-release", |
| 82 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 83 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 84 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 85 | "CHROMEOS_RELEASE_TRACK=dev-channel\n" |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 86 | "CHROMEOS_AUSERVER=http://www.google.com")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 87 | MockSystemState mock_system_state; |
| 88 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 89 | EXPECT_TRUE(DoTest(&out, "", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 90 | EXPECT_EQ("Chrome OS", out.os_platform()); |
| 91 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp()); |
| 92 | EXPECT_EQ("arm-generic", out.os_board()); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 93 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 94 | EXPECT_EQ("0.2.2.3", out.app_version()); |
| 95 | EXPECT_EQ("en-US", out.app_lang()); |
| 96 | EXPECT_EQ("", out.hwid()); |
| 97 | EXPECT_TRUE(out.delta_okay()); |
| 98 | EXPECT_EQ("dev-channel", out.target_channel()); |
| 99 | EXPECT_EQ("http://www.google.com", out.update_url()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 102 | TEST_F(OmahaRequestParamsTest, AppIDTest) { |
Darin Petkov | d315dc7 | 2010-11-15 09:52:24 -0800 | [diff] [blame] | 103 | ASSERT_TRUE(WriteFileString( |
| 104 | kTestDir + "/etc/lsb-release", |
| 105 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 106 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 107 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 108 | "CHROMEOS_RELEASE_TRACK=dev-channel\n" |
Darin Petkov | d315dc7 | 2010-11-15 09:52:24 -0800 | [diff] [blame] | 109 | "CHROMEOS_RELEASE_APPID={58c35cef-9d30-476e-9098-ce20377d535d}\n" |
| 110 | "CHROMEOS_AUSERVER=http://www.google.com")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 111 | MockSystemState mock_system_state; |
| 112 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | d315dc7 | 2010-11-15 09:52:24 -0800 | [diff] [blame] | 113 | EXPECT_TRUE(DoTest(&out, "", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 114 | EXPECT_EQ("Chrome OS", out.os_platform()); |
| 115 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp()); |
| 116 | EXPECT_EQ("arm-generic", out.os_board()); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 117 | EXPECT_EQ("{58c35cef-9d30-476e-9098-ce20377d535d}", out.GetAppId()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 118 | EXPECT_EQ("0.2.2.3", out.app_version()); |
| 119 | EXPECT_EQ("en-US", out.app_lang()); |
| 120 | EXPECT_EQ("", out.hwid()); |
| 121 | EXPECT_TRUE(out.delta_okay()); |
| 122 | EXPECT_EQ("dev-channel", out.target_channel()); |
| 123 | EXPECT_EQ("http://www.google.com", out.update_url()); |
Darin Petkov | d315dc7 | 2010-11-15 09:52:24 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 126 | TEST_F(OmahaRequestParamsTest, MissingChannelTest) { |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 127 | ASSERT_TRUE(WriteFileString( |
| 128 | kTestDir + "/etc/lsb-release", |
| 129 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 130 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 131 | "CHROMEOS_RELEASE_TRXCK=dev-channel")); |
| 132 | MockSystemState mock_system_state; |
| 133 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 134 | EXPECT_TRUE(DoTest(&out, "", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 135 | EXPECT_EQ("Chrome OS", out.os_platform()); |
| 136 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp()); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 137 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 138 | EXPECT_EQ("0.2.2.3", out.app_version()); |
| 139 | EXPECT_EQ("en-US", out.app_lang()); |
| 140 | EXPECT_EQ("", out.target_channel()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 143 | TEST_F(OmahaRequestParamsTest, ConfusingReleaseTest) { |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 144 | ASSERT_TRUE(WriteFileString( |
| 145 | kTestDir + "/etc/lsb-release", |
| 146 | "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" |
| 147 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 148 | "CHROMEOS_RELEASE_TRXCK=dev-channel")); |
| 149 | MockSystemState mock_system_state; |
| 150 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 151 | EXPECT_TRUE(DoTest(&out, "", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 152 | EXPECT_EQ("Chrome OS", out.os_platform()); |
| 153 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp()); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 154 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 155 | EXPECT_EQ("0.2.2.3", out.app_version()); |
| 156 | EXPECT_EQ("en-US", out.app_lang()); |
| 157 | EXPECT_EQ("", out.target_channel()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 160 | TEST_F(OmahaRequestParamsTest, MissingVersionTest) { |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 161 | ASSERT_TRUE(WriteFileString( |
| 162 | kTestDir + "/etc/lsb-release", |
| 163 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 164 | "CHROMEOS_RELEASE_FOO=bar\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 165 | "CHROMEOS_RELEASE_TRACK=dev-channel")); |
| 166 | MockSystemState mock_system_state; |
| 167 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 168 | EXPECT_TRUE(DoTest(&out, "", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 169 | EXPECT_EQ("Chrome OS", out.os_platform()); |
| 170 | EXPECT_EQ(string("_") + GetMachineType(), out.os_sp()); |
| 171 | EXPECT_EQ("arm-generic", out.os_board()); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 172 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 173 | EXPECT_EQ("", out.app_version()); |
| 174 | EXPECT_EQ("en-US", out.app_lang()); |
| 175 | EXPECT_TRUE(out.delta_okay()); |
| 176 | EXPECT_EQ("dev-channel", out.target_channel()); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 179 | TEST_F(OmahaRequestParamsTest, ForceVersionTest) { |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 180 | ASSERT_TRUE(WriteFileString( |
| 181 | kTestDir + "/etc/lsb-release", |
| 182 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 183 | "CHROMEOS_RELEASE_FOO=bar\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 184 | "CHROMEOS_RELEASE_TRACK=dev-channel")); |
| 185 | MockSystemState mock_system_state; |
| 186 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 187 | EXPECT_TRUE(DoTest(&out, "ForcedVersion", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 188 | EXPECT_EQ("Chrome OS", out.os_platform()); |
| 189 | EXPECT_EQ(string("ForcedVersion_") + GetMachineType(), out.os_sp()); |
| 190 | EXPECT_EQ("arm-generic", out.os_board()); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 191 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 192 | EXPECT_EQ("ForcedVersion", out.app_version()); |
| 193 | EXPECT_EQ("en-US", out.app_lang()); |
| 194 | EXPECT_TRUE(out.delta_okay()); |
| 195 | EXPECT_EQ("dev-channel", out.target_channel()); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 198 | TEST_F(OmahaRequestParamsTest, ForcedURLTest) { |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 199 | ASSERT_TRUE(WriteFileString( |
| 200 | kTestDir + "/etc/lsb-release", |
| 201 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 202 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 203 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 204 | "CHROMEOS_RELEASE_TRACK=dev-channel")); |
| 205 | MockSystemState mock_system_state; |
| 206 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 207 | EXPECT_TRUE(DoTest(&out, "", "http://forced.google.com")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 208 | EXPECT_EQ("Chrome OS", out.os_platform()); |
| 209 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp()); |
| 210 | EXPECT_EQ("arm-generic", out.os_board()); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 211 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 212 | EXPECT_EQ("0.2.2.3", out.app_version()); |
| 213 | EXPECT_EQ("en-US", out.app_lang()); |
| 214 | EXPECT_TRUE(out.delta_okay()); |
| 215 | EXPECT_EQ("dev-channel", out.target_channel()); |
| 216 | EXPECT_EQ("http://forced.google.com", out.update_url()); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 219 | TEST_F(OmahaRequestParamsTest, MissingURLTest) { |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 220 | ASSERT_TRUE(WriteFileString( |
| 221 | kTestDir + "/etc/lsb-release", |
| 222 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 223 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 224 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 225 | "CHROMEOS_RELEASE_TRACK=dev-channel")); |
| 226 | MockSystemState mock_system_state; |
| 227 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 228 | EXPECT_TRUE(DoTest(&out, "", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 229 | EXPECT_EQ("Chrome OS", out.os_platform()); |
| 230 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp()); |
| 231 | EXPECT_EQ("arm-generic", out.os_board()); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 232 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 233 | EXPECT_EQ("0.2.2.3", out.app_version()); |
| 234 | EXPECT_EQ("en-US", out.app_lang()); |
| 235 | EXPECT_TRUE(out.delta_okay()); |
| 236 | EXPECT_EQ("dev-channel", out.target_channel()); |
| 237 | EXPECT_EQ(kProductionOmahaUrl, out.update_url()); |
Andrew de los Reyes | 970bb28 | 2009-12-09 16:34:04 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 240 | TEST_F(OmahaRequestParamsTest, NoDeltasTest) { |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 241 | ASSERT_TRUE(WriteFileString( |
| 242 | kTestDir + "/etc/lsb-release", |
| 243 | "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" |
| 244 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 245 | "CHROMEOS_RELEASE_TRXCK=dev-channel")); |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 246 | ASSERT_TRUE(WriteFileString(kTestDir + "/.nodelta", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 247 | MockSystemState mock_system_state; |
| 248 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 249 | EXPECT_TRUE(DoTest(&out, "", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 250 | EXPECT_FALSE(out.delta_okay()); |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 253 | TEST_F(OmahaRequestParamsTest, OverrideTest) { |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 254 | ASSERT_TRUE(WriteFileString( |
| 255 | kTestDir + "/etc/lsb-release", |
| 256 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 257 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 258 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 259 | "CHROMEOS_RELEASE_TRACK=dev-channel\n" |
| 260 | "CHROMEOS_AUSERVER=http://www.google.com")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 261 | ASSERT_TRUE(WriteFileString( |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame^] | 262 | kTestDir + kStatefulPartition + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 263 | "CHROMEOS_RELEASE_BOARD=x86-generic\n" |
| 264 | "CHROMEOS_RELEASE_TRACK=beta-channel\n" |
| 265 | "CHROMEOS_AUSERVER=https://www.google.com")); |
| 266 | MockSystemState mock_system_state; |
| 267 | OmahaRequestParams out(&mock_system_state); |
| 268 | EXPECT_TRUE(DoTest(&out, "", "")); |
| 269 | EXPECT_EQ("Chrome OS", out.os_platform()); |
| 270 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp()); |
| 271 | EXPECT_EQ("x86-generic", out.os_board()); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 272 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 273 | EXPECT_EQ("0.2.2.3", out.app_version()); |
| 274 | EXPECT_EQ("en-US", out.app_lang()); |
| 275 | EXPECT_EQ("", out.hwid()); |
| 276 | EXPECT_FALSE(out.delta_okay()); |
| 277 | EXPECT_EQ("beta-channel", out.target_channel()); |
| 278 | EXPECT_EQ("https://www.google.com", out.update_url()); |
| 279 | } |
| 280 | |
| 281 | TEST_F(OmahaRequestParamsTest, OverrideLockDownTest) { |
| 282 | ASSERT_TRUE(WriteFileString( |
| 283 | kTestDir + "/etc/lsb-release", |
| 284 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 285 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 286 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 287 | "CHROMEOS_RELEASE_TRACK=dev-channel\n" |
| 288 | "CHROMEOS_AUSERVER=https://www.google.com")); |
| 289 | ASSERT_TRUE(WriteFileString( |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame^] | 290 | kTestDir + kStatefulPartition + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 291 | "CHROMEOS_RELEASE_BOARD=x86-generic\n" |
| 292 | "CHROMEOS_RELEASE_TRACK=stable-channel\n" |
| 293 | "CHROMEOS_AUSERVER=http://www.google.com")); |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 294 | params_.SetLockDown(true); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 295 | MockSystemState mock_system_state; |
| 296 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 297 | EXPECT_TRUE(DoTest(&out, "", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 298 | EXPECT_EQ("arm-generic", out.os_board()); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 299 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 300 | EXPECT_EQ("0.2.2.3", out.app_version()); |
| 301 | EXPECT_EQ("", out.hwid()); |
| 302 | EXPECT_FALSE(out.delta_okay()); |
| 303 | EXPECT_EQ("stable-channel", out.target_channel()); |
| 304 | EXPECT_EQ("https://www.google.com", out.update_url()); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 307 | TEST_F(OmahaRequestParamsTest, OverrideSameChannelTest) { |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 308 | ASSERT_TRUE(WriteFileString( |
| 309 | kTestDir + "/etc/lsb-release", |
| 310 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 311 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 312 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 313 | "CHROMEOS_RELEASE_TRACK=dev-channel\n" |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 314 | "CHROMEOS_AUSERVER=http://www.google.com")); |
| 315 | ASSERT_TRUE(WriteFileString( |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame^] | 316 | kTestDir + kStatefulPartition + "/etc/lsb-release", |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 317 | "CHROMEOS_RELEASE_BOARD=x86-generic\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 318 | "CHROMEOS_RELEASE_TRACK=dev-channel")); |
| 319 | MockSystemState mock_system_state; |
| 320 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 321 | EXPECT_TRUE(DoTest(&out, "", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 322 | EXPECT_EQ("x86-generic", out.os_board()); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 323 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 324 | EXPECT_EQ("0.2.2.3", out.app_version()); |
| 325 | EXPECT_EQ("", out.hwid()); |
| 326 | EXPECT_TRUE(out.delta_okay()); |
| 327 | EXPECT_EQ("dev-channel", out.target_channel()); |
| 328 | EXPECT_EQ("http://www.google.com", out.update_url()); |
Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 329 | } |
| 330 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 331 | TEST_F(OmahaRequestParamsTest, SetTargetChannelTest) { |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 332 | ASSERT_TRUE(WriteFileString( |
| 333 | kTestDir + "/etc/lsb-release", |
| 334 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 335 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 336 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 337 | "CHROMEOS_RELEASE_TRACK=dev-channel\n" |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 338 | "CHROMEOS_AUSERVER=http://www.google.com")); |
| 339 | { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 340 | MockSystemState mock_system_state; |
| 341 | OmahaRequestParams params(&mock_system_state); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 342 | params.set_root(string("./") + kTestDir); |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 343 | params.SetLockDown(false); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 344 | EXPECT_TRUE(params.Init("", "", false)); |
| 345 | params.SetTargetChannel("canary-channel", false); |
| 346 | EXPECT_FALSE(params.is_powerwash_allowed()); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 347 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 348 | MockSystemState mock_system_state; |
| 349 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 350 | EXPECT_TRUE(DoTest(&out, "", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 351 | EXPECT_EQ("canary-channel", out.target_channel()); |
| 352 | EXPECT_FALSE(out.is_powerwash_allowed()); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 355 | TEST_F(OmahaRequestParamsTest, SetIsPowerwashAllowedTest) { |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 356 | ASSERT_TRUE(WriteFileString( |
| 357 | kTestDir + "/etc/lsb-release", |
| 358 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 359 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 360 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 361 | "CHROMEOS_RELEASE_TRACK=dev-channel\n" |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 362 | "CHROMEOS_AUSERVER=http://www.google.com")); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 363 | { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 364 | MockSystemState mock_system_state; |
| 365 | OmahaRequestParams params(&mock_system_state); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 366 | params.set_root(string("./") + kTestDir); |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 367 | params.SetLockDown(false); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 368 | EXPECT_TRUE(params.Init("", "", false)); |
| 369 | params.SetTargetChannel("canary-channel", true); |
| 370 | EXPECT_TRUE(params.is_powerwash_allowed()); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 371 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 372 | MockSystemState mock_system_state; |
| 373 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 374 | EXPECT_TRUE(DoTest(&out, "", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 375 | EXPECT_EQ("canary-channel", out.target_channel()); |
| 376 | EXPECT_TRUE(out.is_powerwash_allowed()); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 379 | TEST_F(OmahaRequestParamsTest, SetTargetChannelInvalidTest) { |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 380 | ASSERT_TRUE(WriteFileString( |
| 381 | kTestDir + "/etc/lsb-release", |
| 382 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 383 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 384 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 385 | "CHROMEOS_RELEASE_TRACK=dev-channel\n" |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 386 | "CHROMEOS_AUSERVER=http://www.google.com")); |
| 387 | { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 388 | MockSystemState mock_system_state; |
| 389 | OmahaRequestParams params(&mock_system_state); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 390 | params.set_root(string("./") + kTestDir); |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 391 | params.SetLockDown(true); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 392 | EXPECT_TRUE(params.Init("", "", false)); |
| 393 | params.SetTargetChannel("dogfood-channel", true); |
| 394 | EXPECT_FALSE(params.is_powerwash_allowed()); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 395 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 396 | MockSystemState mock_system_state; |
| 397 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 398 | EXPECT_TRUE(DoTest(&out, "", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 399 | EXPECT_EQ("arm-generic", out.os_board()); |
| 400 | EXPECT_EQ("dev-channel", out.target_channel()); |
| 401 | EXPECT_FALSE(out.is_powerwash_allowed()); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 404 | TEST_F(OmahaRequestParamsTest, IsValidChannelTest) { |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 405 | params_.SetLockDown(false); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 406 | EXPECT_TRUE(params_.IsValidChannel("canary-channel")); |
| 407 | EXPECT_TRUE(params_.IsValidChannel("stable-channel")); |
| 408 | EXPECT_TRUE(params_.IsValidChannel("beta-channel")); |
| 409 | EXPECT_TRUE(params_.IsValidChannel("dev-channel")); |
| 410 | EXPECT_FALSE(params_.IsValidChannel("testimage-channel")); |
| 411 | EXPECT_FALSE(params_.IsValidChannel("dogfood-channel")); |
| 412 | EXPECT_FALSE(params_.IsValidChannel("some-channel")); |
| 413 | EXPECT_FALSE(params_.IsValidChannel("")); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 416 | TEST_F(OmahaRequestParamsTest, ValidChannelTest) { |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 417 | ASSERT_TRUE(WriteFileString( |
| 418 | kTestDir + "/etc/lsb-release", |
| 419 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 420 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 421 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 422 | "CHROMEOS_RELEASE_TRACK=dev-channel\n" |
| 423 | "CHROMEOS_AUSERVER=http://www.google.com")); |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 424 | params_.SetLockDown(true); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 425 | MockSystemState mock_system_state; |
| 426 | OmahaRequestParams out(&mock_system_state); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 427 | EXPECT_TRUE(DoTest(&out, "", "")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 428 | EXPECT_EQ("Chrome OS", out.os_platform()); |
| 429 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp()); |
| 430 | EXPECT_EQ("arm-generic", out.os_board()); |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 431 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 432 | EXPECT_EQ("0.2.2.3", out.app_version()); |
| 433 | EXPECT_EQ("en-US", out.app_lang()); |
| 434 | EXPECT_EQ("", out.hwid()); |
| 435 | EXPECT_TRUE(out.delta_okay()); |
| 436 | EXPECT_EQ("dev-channel", out.target_channel()); |
| 437 | EXPECT_EQ("http://www.google.com", out.update_url()); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 440 | TEST_F(OmahaRequestParamsTest, SetTargetChannelWorks) { |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 441 | ASSERT_TRUE(WriteFileString( |
| 442 | kTestDir + "/etc/lsb-release", |
| 443 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 444 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 445 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 446 | "CHROMEOS_RELEASE_TRACK=dev-channel\n" |
| 447 | "CHROMEOS_AUSERVER=http://www.google.com")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 448 | params_.SetLockDown(false); |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 449 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 450 | // Check LSB value is used by default when SetTargetChannel is not called. |
| 451 | params_.Init("", "", false); |
| 452 | EXPECT_EQ("dev-channel", params_.target_channel()); |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 453 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 454 | // When an invalid value is set, it should be ignored and the |
| 455 | // value from lsb-release should be used instead. |
| 456 | params_.Init("", "", false); |
| 457 | EXPECT_FALSE(params_.SetTargetChannel("invalid-channel", false)); |
| 458 | EXPECT_EQ("dev-channel", params_.target_channel()); |
| 459 | |
| 460 | // When set to a valid value, it should take effect. |
| 461 | params_.Init("", "", false); |
| 462 | EXPECT_TRUE(params_.SetTargetChannel("beta-channel", true)); |
| 463 | EXPECT_EQ("beta-channel", params_.target_channel()); |
| 464 | |
| 465 | // When set to the same value, it should be idempotent. |
| 466 | params_.Init("", "", false); |
| 467 | EXPECT_TRUE(params_.SetTargetChannel("beta-channel", true)); |
| 468 | EXPECT_EQ("beta-channel", params_.target_channel()); |
| 469 | |
| 470 | // When set to a valid value while a change is already pending, it should |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 471 | // succeed. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 472 | params_.Init("", "", false); |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 473 | EXPECT_TRUE(params_.SetTargetChannel("stable-channel", true)); |
| 474 | EXPECT_EQ("stable-channel", params_.target_channel()); |
| 475 | |
| 476 | // Set a different channel in stateful LSB release. |
| 477 | ASSERT_TRUE(WriteFileString( |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame^] | 478 | kTestDir + kStatefulPartition + "/etc/lsb-release", |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 479 | "CHROMEOS_RELEASE_TRACK=stable-channel\n" |
| 480 | "CHROMEOS_IS_POWERWASH_ALLOWED=true\n")); |
| 481 | |
| 482 | // When set to a valid value while a change is already pending, it should |
| 483 | // succeed. |
| 484 | params_.Init("", "", false); |
| 485 | EXPECT_TRUE(params_.SetTargetChannel("beta-channel", true)); |
| 486 | // The target channel should reflect the change, but the download channel |
| 487 | // should continue to retain the old value ... |
| 488 | EXPECT_EQ("beta-channel", params_.target_channel()); |
| 489 | EXPECT_EQ("stable-channel", params_.download_channel()); |
| 490 | |
| 491 | // ... until we update the download channel explicitly. |
| 492 | params_.UpdateDownloadChannel(); |
| 493 | EXPECT_EQ("beta-channel", params_.download_channel()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 494 | EXPECT_EQ("beta-channel", params_.target_channel()); |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 495 | } |
| 496 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 497 | TEST_F(OmahaRequestParamsTest, ChannelIndexTest) { |
| 498 | int canary = params_.GetChannelIndex("canary-channel"); |
| 499 | int dev = params_.GetChannelIndex("dev-channel"); |
| 500 | int beta = params_.GetChannelIndex("beta-channel"); |
| 501 | int stable = params_.GetChannelIndex("stable-channel"); |
| 502 | EXPECT_LE(canary, dev); |
| 503 | EXPECT_LE(dev, beta); |
| 504 | EXPECT_LE(beta, stable); |
| 505 | |
| 506 | // testimage-channel or other names are not recognized, so index will be -1. |
| 507 | int testimage = params_.GetChannelIndex("testimage-channel"); |
| 508 | int bogus = params_.GetChannelIndex("bogus-channel"); |
| 509 | EXPECT_EQ(-1, testimage); |
| 510 | EXPECT_EQ(-1, bogus); |
| 511 | } |
| 512 | |
| 513 | TEST_F(OmahaRequestParamsTest, ToMoreStableChannelFlagTest) { |
| 514 | ASSERT_TRUE(WriteFileString( |
| 515 | kTestDir + "/etc/lsb-release", |
| 516 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 517 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 518 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 519 | "CHROMEOS_RELEASE_TRACK=canary-channel\n" |
| 520 | "CHROMEOS_AUSERVER=http://www.google.com")); |
| 521 | ASSERT_TRUE(WriteFileString( |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame^] | 522 | kTestDir + kStatefulPartition + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 523 | "CHROMEOS_RELEASE_BOARD=x86-generic\n" |
| 524 | "CHROMEOS_RELEASE_TRACK=stable-channel\n" |
| 525 | "CHROMEOS_AUSERVER=https://www.google.com")); |
| 526 | MockSystemState mock_system_state; |
| 527 | OmahaRequestParams out(&mock_system_state); |
| 528 | EXPECT_TRUE(DoTest(&out, "", "")); |
| 529 | EXPECT_EQ("https://www.google.com", out.update_url()); |
| 530 | EXPECT_FALSE(out.delta_okay()); |
| 531 | EXPECT_EQ("stable-channel", out.target_channel()); |
| 532 | EXPECT_TRUE(out.to_more_stable_channel()); |
| 533 | } |
| 534 | |
| 535 | TEST_F(OmahaRequestParamsTest, ShouldLockDownTest) { |
Darin Petkov | 10d02dd | 2011-01-10 14:57:39 -0800 | [diff] [blame] | 536 | EXPECT_FALSE(params_.ShouldLockDown()); |
| 537 | } |
| 538 | |
Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 539 | TEST_F(OmahaRequestParamsTest, BoardAppIdUsedForNonCanaryChannelTest) { |
| 540 | ASSERT_TRUE(WriteFileString( |
| 541 | kTestDir + "/etc/lsb-release", |
| 542 | "CHROMEOS_RELEASE_APPID=r\n" |
| 543 | "CHROMEOS_BOARD_APPID=b\n" |
| 544 | "CHROMEOS_CANARY_APPID=c\n" |
| 545 | "CHROMEOS_RELEASE_TRACK=stable-channel\n")); |
| 546 | MockSystemState mock_system_state; |
| 547 | OmahaRequestParams out(&mock_system_state); |
| 548 | EXPECT_TRUE(DoTest(&out, "", "")); |
| 549 | EXPECT_EQ("stable-channel", out.download_channel()); |
| 550 | EXPECT_EQ("b", out.GetAppId()); |
| 551 | } |
| 552 | |
| 553 | TEST_F(OmahaRequestParamsTest, CanaryAppIdUsedForCanaryChannelTest) { |
| 554 | ASSERT_TRUE(WriteFileString( |
| 555 | kTestDir + "/etc/lsb-release", |
| 556 | "CHROMEOS_RELEASE_APPID=r\n" |
| 557 | "CHROMEOS_BOARD_APPID=b\n" |
| 558 | "CHROMEOS_CANARY_APPID=c\n" |
| 559 | "CHROMEOS_RELEASE_TRACK=canary-channel\n")); |
| 560 | MockSystemState mock_system_state; |
| 561 | OmahaRequestParams out(&mock_system_state); |
| 562 | EXPECT_TRUE(DoTest(&out, "", "")); |
| 563 | EXPECT_EQ("canary-channel", out.download_channel()); |
| 564 | EXPECT_EQ("c", out.GetAppId()); |
| 565 | } |
| 566 | |
| 567 | TEST_F(OmahaRequestParamsTest, ReleaseAppIdUsedAsDefaultTest) { |
| 568 | ASSERT_TRUE(WriteFileString( |
| 569 | kTestDir + "/etc/lsb-release", |
| 570 | "CHROMEOS_RELEASE_APPID=r\n" |
| 571 | "CHROMEOS_CANARY_APPID=c\n" |
| 572 | "CHROMEOS_RELEASE_TRACK=stable-channel\n")); |
| 573 | MockSystemState mock_system_state; |
| 574 | OmahaRequestParams out(&mock_system_state); |
| 575 | EXPECT_TRUE(DoTest(&out, "", "")); |
| 576 | EXPECT_EQ("stable-channel", out.download_channel()); |
| 577 | EXPECT_EQ("r", out.GetAppId()); |
| 578 | } |
| 579 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 580 | } // namespace chromeos_update_engine |