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