| 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> | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 24 | #include <base/files/scoped_temp_dir.h> | 
| Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 25 | #include <gtest/gtest.h> | 
 | 26 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 27 | #include "update_engine/common/constants.h" | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 28 | #include "update_engine/common/fake_prefs.h" | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 29 | #include "update_engine/common/platform_constants.h" | 
 | 30 | #include "update_engine/common/test_utils.h" | 
 | 31 | #include "update_engine/common/utils.h" | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 32 | #include "update_engine/fake_system_state.h" | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 33 |  | 
| Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 34 | using chromeos_update_engine::test_utils::WriteFileString; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 35 | using std::string; | 
 | 36 |  | 
 | 37 | namespace chromeos_update_engine { | 
 | 38 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 39 | class OmahaRequestParamsTest : public ::testing::Test { | 
 | 40 |  public: | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 41 |   OmahaRequestParamsTest() : params_(&fake_system_state_) {} | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 42 |  | 
| Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 43 |  protected: | 
| Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 44 |   void SetUp() override { | 
| Gilad Arnold | c9abbec | 2013-07-01 06:24:42 -0700 | [diff] [blame] | 45 |     // Create a uniquely named test directory. | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 46 |     ASSERT_TRUE(tempdir_.CreateUniqueTempDir()); | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 47 |     // Create a fresh copy of the params for each test, so there's no | 
 | 48 |     // unintended reuse of state across tests. | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 49 |     params_ = OmahaRequestParams(&fake_system_state_); | 
 | 50 |     params_.set_root(tempdir_.path().value()); | 
| Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 51 |     SetLockDown(false); | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 52 |     fake_system_state_.set_prefs(&fake_prefs_); | 
| Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 53 |   } | 
 | 54 |  | 
 | 55 |   void SetLockDown(bool locked_down) { | 
 | 56 |     fake_system_state_.fake_hardware()->SetIsOfficialBuild(locked_down); | 
 | 57 |     fake_system_state_.fake_hardware()->SetIsNormalBootMode(locked_down); | 
| Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 58 |   } | 
 | 59 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 60 |   OmahaRequestParams params_; | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 61 |   FakeSystemState fake_system_state_; | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 62 |   FakePrefs fake_prefs_; | 
| Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 63 |  | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 64 |   base::ScopedTempDir tempdir_; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 65 | }; | 
 | 66 |  | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 67 | namespace { | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 68 | string GetMachineType() { | 
| Gilad Arnold | 19a45f0 | 2012-07-19 12:36:10 -0700 | [diff] [blame] | 69 |   string machine_type; | 
 | 70 |   if (!utils::ReadPipe("uname -m", &machine_type)) | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 71 |     return ""; | 
| Gilad Arnold | 19a45f0 | 2012-07-19 12:36:10 -0700 | [diff] [blame] | 72 |   // Strip anything from the first newline char. | 
 | 73 |   size_t newline_pos = machine_type.find('\n'); | 
 | 74 |   if (newline_pos != string::npos) | 
 | 75 |     machine_type.erase(newline_pos); | 
 | 76 |   return machine_type; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 77 | } | 
| Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 78 | }  // namespace | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 79 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 80 | TEST_F(OmahaRequestParamsTest, MissingChannelTest) { | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 81 |   EXPECT_TRUE(params_.Init("", "", false)); | 
| Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 82 |   // By default, if no channel is set, we should track the stable-channel. | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 83 |   EXPECT_EQ("stable-channel", params_.target_channel()); | 
| Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 84 | } | 
 | 85 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 86 | TEST_F(OmahaRequestParamsTest, ForceVersionTest) { | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 87 |   EXPECT_TRUE(params_.Init("ForcedVersion", "", false)); | 
 | 88 |   EXPECT_EQ(string("ForcedVersion_") + GetMachineType(), params_.os_sp()); | 
 | 89 |   EXPECT_EQ("ForcedVersion", params_.app_version()); | 
| Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 90 | } | 
 | 91 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 92 | TEST_F(OmahaRequestParamsTest, ForcedURLTest) { | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 93 |   EXPECT_TRUE(params_.Init("", "http://forced.google.com", false)); | 
 | 94 |   EXPECT_EQ("http://forced.google.com", params_.update_url()); | 
| Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 95 | } | 
 | 96 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 97 | TEST_F(OmahaRequestParamsTest, MissingURLTest) { | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 98 |   EXPECT_TRUE(params_.Init("", "", false)); | 
 | 99 |   EXPECT_EQ(constants::kOmahaDefaultProductionURL, params_.update_url()); | 
 | 100 | } | 
 | 101 |  | 
 | 102 | TEST_F(OmahaRequestParamsTest, DeltaOKTest) { | 
 | 103 |   EXPECT_TRUE(params_.Init("", "", false)); | 
 | 104 |   EXPECT_TRUE(params_.delta_okay()); | 
| Andrew de los Reyes | 970bb28 | 2009-12-09 16:34:04 -0800 | [diff] [blame] | 105 | } | 
 | 106 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 107 | TEST_F(OmahaRequestParamsTest, NoDeltasTest) { | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 108 |   ASSERT_TRUE(WriteFileString(tempdir_.path().Append(".nodelta").value(), "")); | 
 | 109 |   EXPECT_TRUE(params_.Init("", "", false)); | 
 | 110 |   EXPECT_FALSE(params_.delta_okay()); | 
| Darin Petkov | a3df55b | 2010-11-15 13:33:55 -0800 | [diff] [blame] | 111 | } | 
 | 112 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 113 | TEST_F(OmahaRequestParamsTest, SetTargetChannelTest) { | 
| Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 114 |   { | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 115 |     OmahaRequestParams params(&fake_system_state_); | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 116 |     params.set_root(tempdir_.path().value()); | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 117 |     EXPECT_TRUE(params.Init("", "", false)); | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 118 |     EXPECT_TRUE(params.SetTargetChannel("canary-channel", false, nullptr)); | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 119 |     EXPECT_FALSE(params.is_powerwash_allowed()); | 
| Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 120 |   } | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 121 |   params_.set_root(tempdir_.path().value()); | 
 | 122 |   EXPECT_TRUE(params_.Init("", "", false)); | 
 | 123 |   EXPECT_EQ("canary-channel", params_.target_channel()); | 
 | 124 |   EXPECT_FALSE(params_.is_powerwash_allowed()); | 
| Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 125 | } | 
 | 126 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 127 | TEST_F(OmahaRequestParamsTest, SetIsPowerwashAllowedTest) { | 
| Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 128 |   { | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 129 |     OmahaRequestParams params(&fake_system_state_); | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 130 |     params.set_root(tempdir_.path().value()); | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 131 |     EXPECT_TRUE(params.Init("", "", false)); | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 132 |     EXPECT_TRUE(params.SetTargetChannel("canary-channel", true, nullptr)); | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 133 |     EXPECT_TRUE(params.is_powerwash_allowed()); | 
| Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 134 |   } | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 135 |   params_.set_root(tempdir_.path().value()); | 
 | 136 |   EXPECT_TRUE(params_.Init("", "", false)); | 
 | 137 |   EXPECT_EQ("canary-channel", params_.target_channel()); | 
 | 138 |   EXPECT_TRUE(params_.is_powerwash_allowed()); | 
| Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 139 | } | 
 | 140 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 141 | TEST_F(OmahaRequestParamsTest, SetTargetChannelInvalidTest) { | 
| Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 142 |   { | 
| Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 143 |     OmahaRequestParams params(&fake_system_state_); | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 144 |     params.set_root(tempdir_.path().value()); | 
| Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 145 |     SetLockDown(true); | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 146 |     EXPECT_TRUE(params.Init("", "", false)); | 
| Alex Deymo | d942f9d | 2015-11-06 16:11:50 -0800 | [diff] [blame] | 147 |     string error_message; | 
 | 148 |     EXPECT_FALSE( | 
 | 149 |         params.SetTargetChannel("dogfood-channel", true, &error_message)); | 
 | 150 |     // The error message should include a message about the valid channels. | 
 | 151 |     EXPECT_NE(string::npos, error_message.find("stable-channel")); | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 152 |     EXPECT_FALSE(params.is_powerwash_allowed()); | 
| Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 153 |   } | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 154 |   params_.set_root(tempdir_.path().value()); | 
 | 155 |   EXPECT_TRUE(params_.Init("", "", false)); | 
 | 156 |   EXPECT_EQ("stable-channel", params_.target_channel()); | 
 | 157 |   EXPECT_FALSE(params_.is_powerwash_allowed()); | 
| Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 158 | } | 
 | 159 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 160 | TEST_F(OmahaRequestParamsTest, IsValidChannelTest) { | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 161 |   EXPECT_TRUE(params_.IsValidChannel("canary-channel")); | 
 | 162 |   EXPECT_TRUE(params_.IsValidChannel("stable-channel")); | 
 | 163 |   EXPECT_TRUE(params_.IsValidChannel("beta-channel")); | 
 | 164 |   EXPECT_TRUE(params_.IsValidChannel("dev-channel")); | 
 | 165 |   EXPECT_FALSE(params_.IsValidChannel("testimage-channel")); | 
 | 166 |   EXPECT_FALSE(params_.IsValidChannel("dogfood-channel")); | 
 | 167 |   EXPECT_FALSE(params_.IsValidChannel("some-channel")); | 
 | 168 |   EXPECT_FALSE(params_.IsValidChannel("")); | 
| Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 169 | } | 
 | 170 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 171 | TEST_F(OmahaRequestParamsTest, SetTargetChannelWorks) { | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 172 |   params_.set_target_channel("dev-channel"); | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 173 |   EXPECT_EQ("dev-channel", params_.target_channel()); | 
| Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 174 |  | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 175 |   // When an invalid value is set, it should be ignored. | 
| Alex Deymo | d942f9d | 2015-11-06 16:11:50 -0800 | [diff] [blame] | 176 |   EXPECT_FALSE(params_.SetTargetChannel("invalid-channel", false, nullptr)); | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 177 |   EXPECT_EQ("dev-channel", params_.target_channel()); | 
 | 178 |  | 
 | 179 |   // When set to a valid value, it should take effect. | 
| Alex Deymo | d942f9d | 2015-11-06 16:11:50 -0800 | [diff] [blame] | 180 |   EXPECT_TRUE(params_.SetTargetChannel("beta-channel", true, nullptr)); | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 181 |   EXPECT_EQ("beta-channel", params_.target_channel()); | 
 | 182 |  | 
 | 183 |   // When set to the same value, it should be idempotent. | 
| Alex Deymo | d942f9d | 2015-11-06 16:11:50 -0800 | [diff] [blame] | 184 |   EXPECT_TRUE(params_.SetTargetChannel("beta-channel", true, nullptr)); | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 185 |   EXPECT_EQ("beta-channel", params_.target_channel()); | 
 | 186 |  | 
 | 187 |   // 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] | 188 |   // succeed. | 
| Alex Deymo | d942f9d | 2015-11-06 16:11:50 -0800 | [diff] [blame] | 189 |   EXPECT_TRUE(params_.SetTargetChannel("stable-channel", true, nullptr)); | 
| Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 190 |   EXPECT_EQ("stable-channel", params_.target_channel()); | 
 | 191 |  | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 192 |   // Set a different channel in mutable_image_props_. | 
 | 193 |   params_.set_target_channel("stable-channel"); | 
| Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 194 |  | 
 | 195 |   // When set to a valid value while a change is already pending, it should | 
 | 196 |   // succeed. | 
 | 197 |   params_.Init("", "", false); | 
| Alex Deymo | d942f9d | 2015-11-06 16:11:50 -0800 | [diff] [blame] | 198 |   EXPECT_TRUE(params_.SetTargetChannel("beta-channel", true, nullptr)); | 
| Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 199 |   // The target channel should reflect the change, but the download channel | 
 | 200 |   // should continue to retain the old value ... | 
 | 201 |   EXPECT_EQ("beta-channel", params_.target_channel()); | 
 | 202 |   EXPECT_EQ("stable-channel", params_.download_channel()); | 
 | 203 |  | 
 | 204 |   // ... until we update the download channel explicitly. | 
 | 205 |   params_.UpdateDownloadChannel(); | 
 | 206 |   EXPECT_EQ("beta-channel", params_.download_channel()); | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 207 |   EXPECT_EQ("beta-channel", params_.target_channel()); | 
| Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 208 | } | 
 | 209 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 210 | TEST_F(OmahaRequestParamsTest, ChannelIndexTest) { | 
 | 211 |   int canary = params_.GetChannelIndex("canary-channel"); | 
 | 212 |   int dev = params_.GetChannelIndex("dev-channel"); | 
 | 213 |   int beta = params_.GetChannelIndex("beta-channel"); | 
 | 214 |   int stable = params_.GetChannelIndex("stable-channel"); | 
 | 215 |   EXPECT_LE(canary, dev); | 
 | 216 |   EXPECT_LE(dev, beta); | 
 | 217 |   EXPECT_LE(beta, stable); | 
 | 218 |  | 
 | 219 |   // testimage-channel or other names are not recognized, so index will be -1. | 
 | 220 |   int testimage = params_.GetChannelIndex("testimage-channel"); | 
 | 221 |   int bogus = params_.GetChannelIndex("bogus-channel"); | 
 | 222 |   EXPECT_EQ(-1, testimage); | 
 | 223 |   EXPECT_EQ(-1, bogus); | 
 | 224 | } | 
 | 225 |  | 
 | 226 | TEST_F(OmahaRequestParamsTest, ToMoreStableChannelFlagTest) { | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 227 |   params_.image_props_.current_channel = "canary-channel"; | 
 | 228 |   params_.download_channel_ = "stable-channel"; | 
 | 229 |   EXPECT_TRUE(params_.to_more_stable_channel()); | 
| Jay Srinivasan | db0acdf | 2013-04-02 14:47:45 -0700 | [diff] [blame] | 230 | } | 
 | 231 |  | 
| Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 232 | TEST_F(OmahaRequestParamsTest, CollectECFWVersionsTest) { | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 233 |   params_.hwid_ = string("STUMPY ALEX 12345"); | 
 | 234 |   EXPECT_FALSE(params_.CollectECFWVersions()); | 
| Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 235 |  | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 236 |   params_.hwid_ = string("SNOW 12345"); | 
 | 237 |   EXPECT_TRUE(params_.CollectECFWVersions()); | 
| Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 238 |  | 
| Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 239 |   params_.hwid_ = string("SAMS ALEX 12345"); | 
 | 240 |   EXPECT_TRUE(params_.CollectECFWVersions()); | 
| Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 241 | } | 
 | 242 |  | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 243 | }  // namespace chromeos_update_engine |