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