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