Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 1 | // Copyright (c) 2010 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" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 11 | #include "update_engine/install_plan.h" |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 12 | #include "update_engine/omaha_request_params.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 13 | #include "update_engine/test_utils.h" |
| 14 | #include "update_engine/utils.h" |
| 15 | |
| 16 | using std::string; |
| 17 | |
| 18 | namespace chromeos_update_engine { |
| 19 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 20 | class OmahaRequestDeviceParamsTest : public ::testing::Test { |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 21 | protected: |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 22 | // Return true iff the OmahaRequestDeviceParams::Init succeeded. If |
| 23 | // out is non-NULL, it's set w/ the generated data. |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 24 | bool DoTest(OmahaRequestParams* out, const string& app_version, |
| 25 | const string& omaha_url); |
| 26 | |
| 27 | virtual void SetUp() { |
| 28 | ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); |
| 29 | ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + |
| 30 | utils::kStatefulPartition + "/etc")); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 31 | params_.set_root(string("./") + kTestDir); |
| 32 | params_.SetBuildTypeOfficial(false); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | virtual void TearDown() { |
| 36 | EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); |
| 37 | } |
| 38 | |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 39 | OmahaRequestDeviceParams params_; |
| 40 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 41 | static const string kTestDir; |
| 42 | }; |
| 43 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 44 | const string OmahaRequestDeviceParamsTest::kTestDir = |
| 45 | "omaha_request_device_params-test"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 46 | |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 47 | bool OmahaRequestDeviceParamsTest::DoTest(OmahaRequestParams* out, |
| 48 | const string& app_version, |
| 49 | const string& omaha_url) { |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 50 | bool success = params_.Init(app_version, omaha_url); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 51 | if (out) |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 52 | *out = params_; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 53 | return success; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | namespace { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 57 | string GetMachineType() { |
| 58 | FILE* fp = popen("uname -m", "r"); |
| 59 | if (!fp) |
| 60 | return ""; |
| 61 | string ret; |
| 62 | for (;;) { |
| 63 | char buffer[10]; |
| 64 | size_t r = fread(buffer, 1, sizeof(buffer), fp); |
| 65 | if (r == 0) |
| 66 | break; |
| 67 | ret.insert(ret.begin(), buffer, buffer + r); |
| 68 | } |
| 69 | // strip trailing '\n' if it exists |
| 70 | if ((*ret.rbegin()) == '\n') |
| 71 | ret.resize(ret.size() - 1); |
| 72 | fclose(fp); |
| 73 | return ret; |
| 74 | } |
| 75 | } // namespace {} |
| 76 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 77 | TEST_F(OmahaRequestDeviceParamsTest, SimpleTest) { |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 78 | ASSERT_TRUE(WriteFileString( |
| 79 | kTestDir + "/etc/lsb-release", |
| 80 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 81 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 82 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 83 | "CHROMEOS_RELEASE_TRACK=footrack\n" |
| 84 | "CHROMEOS_AUSERVER=http://www.google.com")); |
| 85 | OmahaRequestParams out; |
| 86 | EXPECT_TRUE(DoTest(&out, "", "")); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 87 | EXPECT_EQ("Chrome OS", out.os_platform); |
| 88 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
| 89 | EXPECT_EQ("arm-generic", out.os_board); |
| 90 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 91 | EXPECT_EQ("0.2.2.3", out.app_version); |
| 92 | EXPECT_EQ("en-US", out.app_lang); |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 93 | EXPECT_EQ("", out.hardware_class); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 94 | EXPECT_TRUE(out.delta_okay); |
| 95 | EXPECT_EQ("footrack", out.app_track); |
| 96 | EXPECT_EQ("http://www.google.com", out.update_url); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 99 | TEST_F(OmahaRequestDeviceParamsTest, MissingTrackTest) { |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 100 | ASSERT_TRUE(WriteFileString( |
| 101 | kTestDir + "/etc/lsb-release", |
| 102 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 103 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 104 | "CHROMEOS_RELEASE_TRXCK=footrack")); |
| 105 | OmahaRequestParams out; |
| 106 | EXPECT_TRUE(DoTest(&out, "", "")); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 107 | EXPECT_EQ("Chrome OS", out.os_platform); |
| 108 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
| 109 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 110 | EXPECT_EQ("0.2.2.3", out.app_version); |
| 111 | EXPECT_EQ("en-US", out.app_lang); |
| 112 | EXPECT_EQ("", out.app_track); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 115 | TEST_F(OmahaRequestDeviceParamsTest, ConfusingReleaseTest) { |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 116 | ASSERT_TRUE(WriteFileString( |
| 117 | kTestDir + "/etc/lsb-release", |
| 118 | "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" |
| 119 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 120 | "CHROMEOS_RELEASE_TRXCK=footrack")); |
| 121 | OmahaRequestParams out; |
| 122 | EXPECT_TRUE(DoTest(&out, "", "")); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 123 | EXPECT_EQ("Chrome OS", out.os_platform); |
| 124 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
| 125 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 126 | EXPECT_EQ("0.2.2.3", out.app_version); |
| 127 | EXPECT_EQ("en-US", out.app_lang); |
| 128 | EXPECT_EQ("", out.app_track); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 131 | TEST_F(OmahaRequestDeviceParamsTest, MissingVersionTest) { |
| 132 | ASSERT_TRUE(WriteFileString( |
| 133 | kTestDir + "/etc/lsb-release", |
| 134 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 135 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 136 | "CHROMEOS_RELEASE_TRACK=footrack")); |
| 137 | OmahaRequestParams out; |
| 138 | EXPECT_TRUE(DoTest(&out, "", "")); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 139 | EXPECT_EQ("Chrome OS", out.os_platform); |
| 140 | EXPECT_EQ(string("_") + GetMachineType(), out.os_sp); |
| 141 | EXPECT_EQ("arm-generic", out.os_board); |
| 142 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 143 | EXPECT_EQ("", out.app_version); |
| 144 | EXPECT_EQ("en-US", out.app_lang); |
| 145 | EXPECT_TRUE(out.delta_okay); |
| 146 | EXPECT_EQ("footrack", out.app_track); |
| 147 | } |
| 148 | |
| 149 | TEST_F(OmahaRequestDeviceParamsTest, ForceVersionTest) { |
| 150 | ASSERT_TRUE(WriteFileString( |
| 151 | kTestDir + "/etc/lsb-release", |
| 152 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 153 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 154 | "CHROMEOS_RELEASE_TRACK=footrack")); |
| 155 | OmahaRequestParams out; |
| 156 | EXPECT_TRUE(DoTest(&out, "ForcedVersion", "")); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 157 | EXPECT_EQ("Chrome OS", out.os_platform); |
| 158 | EXPECT_EQ(string("ForcedVersion_") + GetMachineType(), out.os_sp); |
| 159 | EXPECT_EQ("arm-generic", out.os_board); |
| 160 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 161 | EXPECT_EQ("ForcedVersion", out.app_version); |
| 162 | EXPECT_EQ("en-US", out.app_lang); |
| 163 | EXPECT_TRUE(out.delta_okay); |
| 164 | EXPECT_EQ("footrack", out.app_track); |
| 165 | } |
| 166 | |
| 167 | TEST_F(OmahaRequestDeviceParamsTest, ForcedURLTest) { |
| 168 | ASSERT_TRUE(WriteFileString( |
| 169 | kTestDir + "/etc/lsb-release", |
| 170 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 171 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 172 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 173 | "CHROMEOS_RELEASE_TRACK=footrack")); |
| 174 | OmahaRequestParams out; |
| 175 | EXPECT_TRUE(DoTest(&out, "", "http://forced.google.com")); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 176 | EXPECT_EQ("Chrome OS", out.os_platform); |
| 177 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
| 178 | EXPECT_EQ("arm-generic", out.os_board); |
| 179 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 180 | EXPECT_EQ("0.2.2.3", out.app_version); |
| 181 | EXPECT_EQ("en-US", out.app_lang); |
| 182 | EXPECT_TRUE(out.delta_okay); |
| 183 | EXPECT_EQ("footrack", out.app_track); |
| 184 | EXPECT_EQ("http://forced.google.com", out.update_url); |
| 185 | } |
| 186 | |
| 187 | TEST_F(OmahaRequestDeviceParamsTest, MissingURLTest) { |
| 188 | ASSERT_TRUE(WriteFileString( |
| 189 | kTestDir + "/etc/lsb-release", |
| 190 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 191 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 192 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 193 | "CHROMEOS_RELEASE_TRACK=footrack")); |
| 194 | OmahaRequestParams out; |
| 195 | EXPECT_TRUE(DoTest(&out, "", "")); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 196 | EXPECT_EQ("Chrome OS", out.os_platform); |
| 197 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
| 198 | EXPECT_EQ("arm-generic", out.os_board); |
| 199 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 200 | EXPECT_EQ("0.2.2.3", out.app_version); |
| 201 | EXPECT_EQ("en-US", out.app_lang); |
| 202 | EXPECT_TRUE(out.delta_okay); |
| 203 | EXPECT_EQ("footrack", out.app_track); |
| 204 | EXPECT_EQ(OmahaRequestParams::kUpdateUrl, out.update_url); |
Andrew de los Reyes | 970bb28 | 2009-12-09 16:34:04 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 207 | TEST_F(OmahaRequestDeviceParamsTest, NoDeltasTest) { |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 208 | ASSERT_TRUE(WriteFileString( |
| 209 | kTestDir + "/etc/lsb-release", |
| 210 | "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n" |
| 211 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 212 | "CHROMEOS_RELEASE_TRXCK=footrack")); |
| 213 | ASSERT_TRUE(WriteFileString(kTestDir + "/.nodelta", "")); |
| 214 | OmahaRequestParams out; |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 215 | EXPECT_TRUE(DoTest(&out, "", "")); |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 216 | EXPECT_FALSE(out.delta_okay); |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 219 | TEST_F(OmahaRequestDeviceParamsTest, HardwareClassTest) { |
| 220 | string test_class = " \t sample hardware class \n "; |
| 221 | FilePath hwid_path(kTestDir + "/sys/devices/platform/chromeos_acpi/HWID"); |
| 222 | ASSERT_TRUE(file_util::CreateDirectory(hwid_path.DirName())); |
| 223 | ASSERT_EQ(test_class.size(), |
| 224 | file_util::WriteFile(hwid_path, |
| 225 | test_class.data(), |
| 226 | test_class.size())); |
| 227 | OmahaRequestParams out; |
| 228 | EXPECT_TRUE(DoTest(&out, "", "")); |
| 229 | EXPECT_EQ("sample hardware class", out.hardware_class); |
| 230 | } |
| 231 | |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 232 | TEST_F(OmahaRequestDeviceParamsTest, OverrideTest) { |
| 233 | ASSERT_TRUE(WriteFileString( |
| 234 | kTestDir + "/etc/lsb-release", |
| 235 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 236 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 237 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 238 | "CHROMEOS_RELEASE_TRACK=footrack\n" |
| 239 | "CHROMEOS_AUSERVER=http://www.google.com")); |
| 240 | ASSERT_TRUE(WriteFileString( |
| 241 | kTestDir + utils::kStatefulPartition + "/etc/lsb-release", |
| 242 | "CHROMEOS_RELEASE_BOARD=x86-generic\n" |
| 243 | "CHROMEOS_RELEASE_TRACK=bartrack\n" |
| 244 | "CHROMEOS_AUSERVER=http://www.google.com")); |
| 245 | OmahaRequestParams out; |
| 246 | EXPECT_TRUE(DoTest(&out, "", "")); |
| 247 | EXPECT_EQ("Chrome OS", out.os_platform); |
| 248 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
| 249 | EXPECT_EQ("x86-generic", out.os_board); |
| 250 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 251 | EXPECT_EQ("0.2.2.3", out.app_version); |
| 252 | EXPECT_EQ("en-US", out.app_lang); |
| 253 | EXPECT_EQ("", out.hardware_class); |
| 254 | EXPECT_TRUE(out.delta_okay); |
| 255 | EXPECT_EQ("bartrack", out.app_track); |
| 256 | EXPECT_EQ("http://www.google.com", out.update_url); |
| 257 | } |
| 258 | |
| 259 | TEST_F(OmahaRequestDeviceParamsTest, SetTrackSimpleTest) { |
| 260 | ASSERT_TRUE(WriteFileString( |
| 261 | kTestDir + "/etc/lsb-release", |
| 262 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 263 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 264 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 265 | "CHROMEOS_RELEASE_TRACK=footrack\n" |
| 266 | "CHROMEOS_AUSERVER=http://www.google.com")); |
| 267 | { |
| 268 | OmahaRequestDeviceParams params; |
| 269 | params.set_root(string("./") + kTestDir); |
| 270 | params.SetBuildTypeOfficial(false); |
| 271 | EXPECT_TRUE(params.Init("", "")); |
| 272 | params.SetTrack("zootrack"); |
| 273 | } |
| 274 | OmahaRequestParams out; |
| 275 | EXPECT_TRUE(DoTest(&out, "", "")); |
| 276 | EXPECT_EQ("arm-generic", out.os_board); |
| 277 | EXPECT_EQ("zootrack", out.app_track); |
| 278 | } |
| 279 | |
| 280 | TEST_F(OmahaRequestDeviceParamsTest, SetTrackPreserveTest) { |
| 281 | ASSERT_TRUE(WriteFileString( |
| 282 | kTestDir + "/etc/lsb-release", |
| 283 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 284 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 285 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 286 | "CHROMEOS_RELEASE_TRACK=footrack\n" |
| 287 | "CHROMEOS_AUSERVER=http://www.google.com")); |
| 288 | ASSERT_TRUE(WriteFileString( |
| 289 | kTestDir + utils::kStatefulPartition + "/etc/lsb-release", |
| 290 | "CHROMEOS_RELEASE_BOARD=x86-generic\n" |
| 291 | "CHROMEOS_RELEASE_TRACK=bartrack")); |
| 292 | { |
| 293 | OmahaRequestDeviceParams params; |
| 294 | params.set_root(string("./") + kTestDir); |
| 295 | params.SetBuildTypeOfficial(false); |
| 296 | EXPECT_TRUE(params.Init("", "")); |
| 297 | params.SetTrack("zootrack"); |
| 298 | } |
| 299 | OmahaRequestParams out; |
| 300 | EXPECT_TRUE(DoTest(&out, "", "")); |
| 301 | EXPECT_EQ("x86-generic", out.os_board); |
| 302 | EXPECT_EQ("zootrack", out.app_track); |
| 303 | } |
| 304 | |
| 305 | TEST_F(OmahaRequestDeviceParamsTest, SetTrackInvalidTest) { |
| 306 | ASSERT_TRUE(WriteFileString( |
| 307 | kTestDir + "/etc/lsb-release", |
| 308 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 309 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 310 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 311 | "CHROMEOS_RELEASE_TRACK=footrack\n" |
| 312 | "CHROMEOS_AUSERVER=http://www.google.com")); |
| 313 | { |
| 314 | OmahaRequestDeviceParams params; |
| 315 | params.set_root(string("./") + kTestDir); |
| 316 | params.SetBuildTypeOfficial(true); |
| 317 | EXPECT_TRUE(params.Init("", "")); |
| 318 | params.SetTrack("zootrack"); |
| 319 | } |
| 320 | OmahaRequestParams out; |
| 321 | EXPECT_TRUE(DoTest(&out, "", "")); |
| 322 | EXPECT_EQ("arm-generic", out.os_board); |
| 323 | EXPECT_EQ("footrack", out.app_track); |
| 324 | } |
| 325 | |
| 326 | TEST_F(OmahaRequestDeviceParamsTest, IsValidTrackTest) { |
| 327 | params_.SetBuildTypeOfficial(true); |
Darin Petkov | 3f375c7 | 2010-11-05 09:42:26 -0700 | [diff] [blame^] | 328 | EXPECT_TRUE(params_.IsValidTrack("canary-channel")); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 329 | EXPECT_TRUE(params_.IsValidTrack("beta-channel")); |
| 330 | EXPECT_TRUE(params_.IsValidTrack("dev-channel")); |
| 331 | EXPECT_FALSE(params_.IsValidTrack("some-channel")); |
| 332 | EXPECT_FALSE(params_.IsValidTrack("")); |
| 333 | params_.SetBuildTypeOfficial(false); |
Darin Petkov | 3f375c7 | 2010-11-05 09:42:26 -0700 | [diff] [blame^] | 334 | EXPECT_TRUE(params_.IsValidTrack("canary-channel")); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 335 | EXPECT_TRUE(params_.IsValidTrack("beta-channel")); |
| 336 | EXPECT_TRUE(params_.IsValidTrack("dev-channel")); |
| 337 | EXPECT_TRUE(params_.IsValidTrack("some-channel")); |
| 338 | EXPECT_TRUE(params_.IsValidTrack("")); |
| 339 | } |
| 340 | |
| 341 | TEST_F(OmahaRequestDeviceParamsTest, InvalidTrackTest) { |
| 342 | ASSERT_TRUE(WriteFileString( |
| 343 | kTestDir + "/etc/lsb-release", |
| 344 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 345 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 346 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 347 | "CHROMEOS_RELEASE_TRACK=footrack\n" |
| 348 | "CHROMEOS_AUSERVER=http://www.google.com")); |
| 349 | params_.SetBuildTypeOfficial(true); |
| 350 | OmahaRequestParams out; |
| 351 | EXPECT_TRUE(DoTest(&out, "", "")); |
| 352 | EXPECT_EQ("Chrome OS", out.os_platform); |
| 353 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
| 354 | EXPECT_EQ("arm-generic", out.os_board); |
| 355 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 356 | EXPECT_EQ("0.2.2.3", out.app_version); |
| 357 | EXPECT_EQ("en-US", out.app_lang); |
| 358 | EXPECT_EQ("", out.hardware_class); |
| 359 | EXPECT_TRUE(out.delta_okay); |
| 360 | EXPECT_EQ("", out.app_track); |
| 361 | EXPECT_EQ("http://www.google.com", out.update_url); |
| 362 | } |
| 363 | |
| 364 | TEST_F(OmahaRequestDeviceParamsTest, ValidTrackTest) { |
| 365 | ASSERT_TRUE(WriteFileString( |
| 366 | kTestDir + "/etc/lsb-release", |
| 367 | "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
| 368 | "CHROMEOS_RELEASE_FOO=bar\n" |
| 369 | "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
| 370 | "CHROMEOS_RELEASE_TRACK=dev-channel\n" |
| 371 | "CHROMEOS_AUSERVER=http://www.google.com")); |
| 372 | params_.SetBuildTypeOfficial(true); |
| 373 | OmahaRequestParams out; |
| 374 | EXPECT_TRUE(DoTest(&out, "", "")); |
| 375 | EXPECT_EQ("Chrome OS", out.os_platform); |
| 376 | EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
| 377 | EXPECT_EQ("arm-generic", out.os_board); |
| 378 | EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
| 379 | EXPECT_EQ("0.2.2.3", out.app_version); |
| 380 | EXPECT_EQ("en-US", out.app_lang); |
| 381 | EXPECT_EQ("", out.hardware_class); |
| 382 | EXPECT_TRUE(out.delta_okay); |
| 383 | EXPECT_EQ("dev-channel", out.app_track); |
| 384 | EXPECT_EQ("http://www.google.com", out.update_url); |
| 385 | } |
| 386 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 387 | } // namespace chromeos_update_engine |