blob: 432eb6c31ef49b9ae8453b1f2427637c22ee3c26 [file] [log] [blame]
Darin Petkovf2065b42011-05-17 16:36:27 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
adlr@google.com3defe6a2009-12-04 20:57:17 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <stdio.h>
Darin Petkovfbb40092010-07-29 17:05:50 -07006
adlr@google.com3defe6a2009-12-04 20:57:17 +00007#include <string>
Darin Petkovfbb40092010-07-29 17:05:50 -07008
9#include "base/file_util.h"
10#include "gtest/gtest.h"
Chris Sosabe45bef2013-04-09 18:25:12 -070011#include "update_engine/constants.h"
Gilad Arnold5bb4c902014-04-10 12:32:13 -070012#include "update_engine/fake_system_state.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000013#include "update_engine/install_plan.h"
Darin Petkova4a8a8c2010-07-15 22:21:12 -070014#include "update_engine/omaha_request_params.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000015#include "update_engine/test_utils.h"
16#include "update_engine/utils.h"
17
18using std::string;
19
20namespace chromeos_update_engine {
21
Jay Srinivasanae4697c2013-03-18 17:08:08 -070022class OmahaRequestParamsTest : public ::testing::Test {
23 public:
Gilad Arnold5bb4c902014-04-10 12:32:13 -070024 OmahaRequestParamsTest() : params_(&fake_system_state_) {}
Jay Srinivasanae4697c2013-03-18 17:08:08 -070025
Darin Petkov5a7f5652010-07-22 21:40:09 -070026 protected:
Jay Srinivasanae4697c2013-03-18 17:08:08 -070027 // Return true iff the OmahaRequestParams::Init succeeded. If
Darin Petkova4a8a8c2010-07-15 22:21:12 -070028 // out is non-NULL, it's set w/ the generated data.
Darin Petkov5a7f5652010-07-22 21:40:09 -070029 bool DoTest(OmahaRequestParams* out, const string& app_version,
30 const string& omaha_url);
31
32 virtual void SetUp() {
Gilad Arnoldc9abbec2013-07-01 06:24:42 -070033 // Create a uniquely named test directory.
34 ASSERT_TRUE(utils::MakeTempDirectory(kTestDirTemplate,
35 &test_dir_));
36
37 ASSERT_EQ(0, System(string("mkdir -p ") + test_dir_ + "/etc"));
38 ASSERT_EQ(0, System(string("mkdir -p ") + test_dir_ +
Chris Sosabe45bef2013-04-09 18:25:12 -070039 kStatefulPartition + "/etc"));
Jay Srinivasanae4697c2013-03-18 17:08:08 -070040 // Create a fresh copy of the params for each test, so there's no
41 // unintended reuse of state across tests.
Gilad Arnold5bb4c902014-04-10 12:32:13 -070042 OmahaRequestParams new_params(&fake_system_state_);
Jay Srinivasanae4697c2013-03-18 17:08:08 -070043 params_ = new_params;
Gilad Arnoldd04f8e22014-01-09 13:13:40 -080044 params_.set_root(test_dir_);
Darin Petkov10d02dd2011-01-10 14:57:39 -080045 params_.SetLockDown(false);
Darin Petkov5a7f5652010-07-22 21:40:09 -070046 }
47
48 virtual void TearDown() {
Gilad Arnoldc9abbec2013-07-01 06:24:42 -070049 EXPECT_EQ(0, System(string("rm -rf ") + test_dir_));
Darin Petkov5a7f5652010-07-22 21:40:09 -070050 }
51
Jay Srinivasanae4697c2013-03-18 17:08:08 -070052 OmahaRequestParams params_;
Gilad Arnold5bb4c902014-04-10 12:32:13 -070053 FakeSystemState fake_system_state_;
Darin Petkov49d91322010-10-25 16:34:58 -070054
Gilad Arnoldc9abbec2013-07-01 06:24:42 -070055 static const char* kTestDirTemplate;
56 string test_dir_;
adlr@google.com3defe6a2009-12-04 20:57:17 +000057};
58
Gilad Arnoldc9abbec2013-07-01 06:24:42 -070059const char* OmahaRequestParamsTest::kTestDirTemplate =
60 "omaha_request_params-test-XXXXXX";
adlr@google.com3defe6a2009-12-04 20:57:17 +000061
Jay Srinivasanae4697c2013-03-18 17:08:08 -070062bool OmahaRequestParamsTest::DoTest(OmahaRequestParams* out,
63 const string& app_version,
64 const string& omaha_url) {
65 bool success = params_.Init(app_version, omaha_url, false);
adlr@google.com3defe6a2009-12-04 20:57:17 +000066 if (out)
Darin Petkov49d91322010-10-25 16:34:58 -070067 *out = params_;
Darin Petkova4a8a8c2010-07-15 22:21:12 -070068 return success;
adlr@google.com3defe6a2009-12-04 20:57:17 +000069}
70
71namespace {
adlr@google.com3defe6a2009-12-04 20:57:17 +000072string GetMachineType() {
Gilad Arnold19a45f02012-07-19 12:36:10 -070073 string machine_type;
74 if (!utils::ReadPipe("uname -m", &machine_type))
adlr@google.com3defe6a2009-12-04 20:57:17 +000075 return "";
Gilad Arnold19a45f02012-07-19 12:36:10 -070076 // Strip anything from the first newline char.
77 size_t newline_pos = machine_type.find('\n');
78 if (newline_pos != string::npos)
79 machine_type.erase(newline_pos);
80 return machine_type;
adlr@google.com3defe6a2009-12-04 20:57:17 +000081}
Alex Vakulenkod2779df2014-06-16 13:19:00 -070082} // namespace
adlr@google.com3defe6a2009-12-04 20:57:17 +000083
Jay Srinivasanae4697c2013-03-18 17:08:08 -070084TEST_F(OmahaRequestParamsTest, SimpleTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -070085 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -070086 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -070087 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
88 "CHROMEOS_RELEASE_FOO=bar\n"
89 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -070090 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
Darin Petkov5a7f5652010-07-22 21:40:09 -070091 "CHROMEOS_AUSERVER=http://www.google.com"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -070092 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -070093 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -070094 EXPECT_EQ("Chrome OS", out.os_platform());
95 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp());
96 EXPECT_EQ("arm-generic", out.os_board());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -070097 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -070098 EXPECT_EQ("0.2.2.3", out.app_version());
99 EXPECT_EQ("en-US", out.app_lang());
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700100 EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700101 EXPECT_TRUE(out.delta_okay());
102 EXPECT_EQ("dev-channel", out.target_channel());
103 EXPECT_EQ("http://www.google.com", out.update_url());
adlr@google.com3defe6a2009-12-04 20:57:17 +0000104}
105
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700106TEST_F(OmahaRequestParamsTest, AppIDTest) {
Darin Petkovd315dc72010-11-15 09:52:24 -0800107 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700108 test_dir_ + "/etc/lsb-release",
Darin Petkovd315dc72010-11-15 09:52:24 -0800109 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
110 "CHROMEOS_RELEASE_FOO=bar\n"
111 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700112 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
Darin Petkovd315dc72010-11-15 09:52:24 -0800113 "CHROMEOS_RELEASE_APPID={58c35cef-9d30-476e-9098-ce20377d535d}\n"
114 "CHROMEOS_AUSERVER=http://www.google.com"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700115 OmahaRequestParams out(&fake_system_state_);
Darin Petkovd315dc72010-11-15 09:52:24 -0800116 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700117 EXPECT_EQ("Chrome OS", out.os_platform());
118 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp());
119 EXPECT_EQ("arm-generic", out.os_board());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700120 EXPECT_EQ("{58c35cef-9d30-476e-9098-ce20377d535d}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700121 EXPECT_EQ("0.2.2.3", out.app_version());
122 EXPECT_EQ("en-US", out.app_lang());
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700123 EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700124 EXPECT_TRUE(out.delta_okay());
125 EXPECT_EQ("dev-channel", out.target_channel());
126 EXPECT_EQ("http://www.google.com", out.update_url());
Darin Petkovd315dc72010-11-15 09:52:24 -0800127}
128
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700129TEST_F(OmahaRequestParamsTest, MissingChannelTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -0700130 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700131 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -0700132 "CHROMEOS_RELEASE_FOO=bar\n"
133 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700134 "CHROMEOS_RELEASE_TRXCK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700135 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700136 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700137 EXPECT_EQ("Chrome OS", out.os_platform());
138 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700139 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700140 EXPECT_EQ("0.2.2.3", out.app_version());
141 EXPECT_EQ("en-US", out.app_lang());
142 EXPECT_EQ("", out.target_channel());
adlr@google.com3defe6a2009-12-04 20:57:17 +0000143}
144
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700145TEST_F(OmahaRequestParamsTest, ConfusingReleaseTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -0700146 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700147 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -0700148 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
149 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700150 "CHROMEOS_RELEASE_TRXCK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700151 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700152 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700153 EXPECT_EQ("Chrome OS", out.os_platform());
154 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700155 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700156 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.com3defe6a2009-12-04 20:57:17 +0000159}
160
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700161TEST_F(OmahaRequestParamsTest, MissingVersionTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -0700162 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700163 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -0700164 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
165 "CHROMEOS_RELEASE_FOO=bar\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700166 "CHROMEOS_RELEASE_TRACK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700167 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700168 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700169 EXPECT_EQ("Chrome OS", out.os_platform());
170 EXPECT_EQ(string("_") + GetMachineType(), out.os_sp());
171 EXPECT_EQ("arm-generic", out.os_board());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700172 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700173 EXPECT_EQ("", out.app_version());
174 EXPECT_EQ("en-US", out.app_lang());
175 EXPECT_TRUE(out.delta_okay());
176 EXPECT_EQ("dev-channel", out.target_channel());
Darin Petkov5a7f5652010-07-22 21:40:09 -0700177}
178
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700179TEST_F(OmahaRequestParamsTest, ForceVersionTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -0700180 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700181 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -0700182 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
183 "CHROMEOS_RELEASE_FOO=bar\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700184 "CHROMEOS_RELEASE_TRACK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700185 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700186 EXPECT_TRUE(DoTest(&out, "ForcedVersion", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700187 EXPECT_EQ("Chrome OS", out.os_platform());
188 EXPECT_EQ(string("ForcedVersion_") + GetMachineType(), out.os_sp());
189 EXPECT_EQ("arm-generic", out.os_board());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700190 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700191 EXPECT_EQ("ForcedVersion", out.app_version());
192 EXPECT_EQ("en-US", out.app_lang());
193 EXPECT_TRUE(out.delta_okay());
194 EXPECT_EQ("dev-channel", out.target_channel());
Darin Petkov5a7f5652010-07-22 21:40:09 -0700195}
196
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700197TEST_F(OmahaRequestParamsTest, ForcedURLTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -0700198 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700199 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -0700200 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
201 "CHROMEOS_RELEASE_FOO=bar\n"
202 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700203 "CHROMEOS_RELEASE_TRACK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700204 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700205 EXPECT_TRUE(DoTest(&out, "", "http://forced.google.com"));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700206 EXPECT_EQ("Chrome OS", out.os_platform());
207 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp());
208 EXPECT_EQ("arm-generic", out.os_board());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700209 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700210 EXPECT_EQ("0.2.2.3", out.app_version());
211 EXPECT_EQ("en-US", out.app_lang());
212 EXPECT_TRUE(out.delta_okay());
213 EXPECT_EQ("dev-channel", out.target_channel());
214 EXPECT_EQ("http://forced.google.com", out.update_url());
Darin Petkov5a7f5652010-07-22 21:40:09 -0700215}
216
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700217TEST_F(OmahaRequestParamsTest, MissingURLTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -0700218 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700219 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -0700220 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
221 "CHROMEOS_RELEASE_FOO=bar\n"
222 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700223 "CHROMEOS_RELEASE_TRACK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700224 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700225 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700226 EXPECT_EQ("Chrome OS", out.os_platform());
227 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp());
228 EXPECT_EQ("arm-generic", out.os_board());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700229 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700230 EXPECT_EQ("0.2.2.3", out.app_version());
231 EXPECT_EQ("en-US", out.app_lang());
232 EXPECT_TRUE(out.delta_okay());
233 EXPECT_EQ("dev-channel", out.target_channel());
234 EXPECT_EQ(kProductionOmahaUrl, out.update_url());
Andrew de los Reyes970bb282009-12-09 16:34:04 -0800235}
236
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700237TEST_F(OmahaRequestParamsTest, NoDeltasTest) {
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -0700238 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700239 test_dir_ + "/etc/lsb-release",
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -0700240 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
241 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700242 "CHROMEOS_RELEASE_TRXCK=dev-channel"));
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700243 ASSERT_TRUE(WriteFileString(test_dir_ + "/.nodelta", ""));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700244 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700245 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700246 EXPECT_FALSE(out.delta_okay());
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -0700247}
248
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700249TEST_F(OmahaRequestParamsTest, OverrideTest) {
Darin Petkov49d91322010-10-25 16:34:58 -0700250 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700251 test_dir_ + "/etc/lsb-release",
Darin Petkov49d91322010-10-25 16:34:58 -0700252 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
253 "CHROMEOS_RELEASE_FOO=bar\n"
254 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Darin Petkov10d02dd2011-01-10 14:57:39 -0800255 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
256 "CHROMEOS_AUSERVER=http://www.google.com"));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700257 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700258 test_dir_ + kStatefulPartition + "/etc/lsb-release",
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700259 "CHROMEOS_RELEASE_BOARD=x86-generic\n"
260 "CHROMEOS_RELEASE_TRACK=beta-channel\n"
261 "CHROMEOS_AUSERVER=https://www.google.com"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700262 OmahaRequestParams out(&fake_system_state_);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700263 EXPECT_TRUE(DoTest(&out, "", ""));
264 EXPECT_EQ("Chrome OS", out.os_platform());
265 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp());
266 EXPECT_EQ("x86-generic", out.os_board());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700267 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700268 EXPECT_EQ("0.2.2.3", out.app_version());
269 EXPECT_EQ("en-US", out.app_lang());
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700270 EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700271 EXPECT_FALSE(out.delta_okay());
272 EXPECT_EQ("beta-channel", out.target_channel());
273 EXPECT_EQ("https://www.google.com", out.update_url());
274}
275
276TEST_F(OmahaRequestParamsTest, OverrideLockDownTest) {
277 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700278 test_dir_ + "/etc/lsb-release",
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700279 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
280 "CHROMEOS_RELEASE_FOO=bar\n"
281 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
282 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
283 "CHROMEOS_AUSERVER=https://www.google.com"));
284 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700285 test_dir_ + kStatefulPartition + "/etc/lsb-release",
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700286 "CHROMEOS_RELEASE_BOARD=x86-generic\n"
287 "CHROMEOS_RELEASE_TRACK=stable-channel\n"
288 "CHROMEOS_AUSERVER=http://www.google.com"));
Darin Petkov10d02dd2011-01-10 14:57:39 -0800289 params_.SetLockDown(true);
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700290 OmahaRequestParams out(&fake_system_state_);
Darin Petkov10d02dd2011-01-10 14:57:39 -0800291 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700292 EXPECT_EQ("arm-generic", out.os_board());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700293 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700294 EXPECT_EQ("0.2.2.3", out.app_version());
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700295 EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700296 EXPECT_FALSE(out.delta_okay());
297 EXPECT_EQ("stable-channel", out.target_channel());
298 EXPECT_EQ("https://www.google.com", out.update_url());
Darin Petkov49d91322010-10-25 16:34:58 -0700299}
300
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700301TEST_F(OmahaRequestParamsTest, OverrideSameChannelTest) {
Darin Petkova3df55b2010-11-15 13:33:55 -0800302 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700303 test_dir_ + "/etc/lsb-release",
Darin Petkova3df55b2010-11-15 13:33:55 -0800304 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
305 "CHROMEOS_RELEASE_FOO=bar\n"
306 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700307 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
Darin Petkova3df55b2010-11-15 13:33:55 -0800308 "CHROMEOS_AUSERVER=http://www.google.com"));
309 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700310 test_dir_ + kStatefulPartition + "/etc/lsb-release",
Darin Petkova3df55b2010-11-15 13:33:55 -0800311 "CHROMEOS_RELEASE_BOARD=x86-generic\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700312 "CHROMEOS_RELEASE_TRACK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700313 OmahaRequestParams out(&fake_system_state_);
Darin Petkova3df55b2010-11-15 13:33:55 -0800314 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700315 EXPECT_EQ("x86-generic", out.os_board());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700316 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700317 EXPECT_EQ("0.2.2.3", out.app_version());
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700318 EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700319 EXPECT_TRUE(out.delta_okay());
320 EXPECT_EQ("dev-channel", out.target_channel());
321 EXPECT_EQ("http://www.google.com", out.update_url());
Darin Petkova3df55b2010-11-15 13:33:55 -0800322}
323
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700324TEST_F(OmahaRequestParamsTest, SetTargetChannelTest) {
Darin Petkov49d91322010-10-25 16:34:58 -0700325 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700326 test_dir_ + "/etc/lsb-release",
Darin Petkov49d91322010-10-25 16:34:58 -0700327 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
328 "CHROMEOS_RELEASE_FOO=bar\n"
329 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700330 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
Darin Petkov49d91322010-10-25 16:34:58 -0700331 "CHROMEOS_AUSERVER=http://www.google.com"));
332 {
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700333 OmahaRequestParams params(&fake_system_state_);
Gilad Arnoldd04f8e22014-01-09 13:13:40 -0800334 params.set_root(test_dir_);
Darin Petkov10d02dd2011-01-10 14:57:39 -0800335 params.SetLockDown(false);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700336 EXPECT_TRUE(params.Init("", "", false));
337 params.SetTargetChannel("canary-channel", false);
338 EXPECT_FALSE(params.is_powerwash_allowed());
Darin Petkov49d91322010-10-25 16:34:58 -0700339 }
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700340 OmahaRequestParams out(&fake_system_state_);
Darin Petkov49d91322010-10-25 16:34:58 -0700341 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700342 EXPECT_EQ("canary-channel", out.target_channel());
343 EXPECT_FALSE(out.is_powerwash_allowed());
Darin Petkov49d91322010-10-25 16:34:58 -0700344}
345
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700346TEST_F(OmahaRequestParamsTest, SetIsPowerwashAllowedTest) {
Darin Petkov49d91322010-10-25 16:34:58 -0700347 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700348 test_dir_ + "/etc/lsb-release",
Darin Petkov49d91322010-10-25 16:34:58 -0700349 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
350 "CHROMEOS_RELEASE_FOO=bar\n"
351 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700352 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
Darin Petkov49d91322010-10-25 16:34:58 -0700353 "CHROMEOS_AUSERVER=http://www.google.com"));
Darin Petkov49d91322010-10-25 16:34:58 -0700354 {
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700355 OmahaRequestParams params(&fake_system_state_);
Gilad Arnoldd04f8e22014-01-09 13:13:40 -0800356 params.set_root(test_dir_);
Darin Petkov10d02dd2011-01-10 14:57:39 -0800357 params.SetLockDown(false);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700358 EXPECT_TRUE(params.Init("", "", false));
359 params.SetTargetChannel("canary-channel", true);
360 EXPECT_TRUE(params.is_powerwash_allowed());
Darin Petkov49d91322010-10-25 16:34:58 -0700361 }
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700362 OmahaRequestParams out(&fake_system_state_);
Darin Petkov49d91322010-10-25 16:34:58 -0700363 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700364 EXPECT_EQ("canary-channel", out.target_channel());
365 EXPECT_TRUE(out.is_powerwash_allowed());
Darin Petkov49d91322010-10-25 16:34:58 -0700366}
367
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700368TEST_F(OmahaRequestParamsTest, SetTargetChannelInvalidTest) {
Darin Petkov49d91322010-10-25 16:34:58 -0700369 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700370 test_dir_ + "/etc/lsb-release",
Darin Petkov49d91322010-10-25 16:34:58 -0700371 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
372 "CHROMEOS_RELEASE_FOO=bar\n"
373 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700374 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
Darin Petkov49d91322010-10-25 16:34:58 -0700375 "CHROMEOS_AUSERVER=http://www.google.com"));
376 {
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700377 OmahaRequestParams params(&fake_system_state_);
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700378 params.set_root(string("./") + test_dir_);
Darin Petkov10d02dd2011-01-10 14:57:39 -0800379 params.SetLockDown(true);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700380 EXPECT_TRUE(params.Init("", "", false));
381 params.SetTargetChannel("dogfood-channel", true);
382 EXPECT_FALSE(params.is_powerwash_allowed());
Darin Petkov49d91322010-10-25 16:34:58 -0700383 }
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700384 OmahaRequestParams out(&fake_system_state_);
Darin Petkov49d91322010-10-25 16:34:58 -0700385 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700386 EXPECT_EQ("arm-generic", out.os_board());
387 EXPECT_EQ("dev-channel", out.target_channel());
388 EXPECT_FALSE(out.is_powerwash_allowed());
Darin Petkov49d91322010-10-25 16:34:58 -0700389}
390
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700391TEST_F(OmahaRequestParamsTest, IsValidChannelTest) {
Darin Petkov10d02dd2011-01-10 14:57:39 -0800392 params_.SetLockDown(false);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700393 EXPECT_TRUE(params_.IsValidChannel("canary-channel"));
394 EXPECT_TRUE(params_.IsValidChannel("stable-channel"));
395 EXPECT_TRUE(params_.IsValidChannel("beta-channel"));
396 EXPECT_TRUE(params_.IsValidChannel("dev-channel"));
397 EXPECT_FALSE(params_.IsValidChannel("testimage-channel"));
398 EXPECT_FALSE(params_.IsValidChannel("dogfood-channel"));
399 EXPECT_FALSE(params_.IsValidChannel("some-channel"));
400 EXPECT_FALSE(params_.IsValidChannel(""));
Darin Petkov49d91322010-10-25 16:34:58 -0700401}
402
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700403TEST_F(OmahaRequestParamsTest, ValidChannelTest) {
Darin Petkov49d91322010-10-25 16:34:58 -0700404 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700405 test_dir_ + "/etc/lsb-release",
Darin Petkov49d91322010-10-25 16:34:58 -0700406 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
407 "CHROMEOS_RELEASE_FOO=bar\n"
408 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
409 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
410 "CHROMEOS_AUSERVER=http://www.google.com"));
Darin Petkov10d02dd2011-01-10 14:57:39 -0800411 params_.SetLockDown(true);
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700412 OmahaRequestParams out(&fake_system_state_);
Darin Petkov49d91322010-10-25 16:34:58 -0700413 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700414 EXPECT_EQ("Chrome OS", out.os_platform());
415 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp());
416 EXPECT_EQ("arm-generic", out.os_board());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700417 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700418 EXPECT_EQ("0.2.2.3", out.app_version());
419 EXPECT_EQ("en-US", out.app_lang());
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700420 EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700421 EXPECT_TRUE(out.delta_okay());
422 EXPECT_EQ("dev-channel", out.target_channel());
423 EXPECT_EQ("http://www.google.com", out.update_url());
Darin Petkov49d91322010-10-25 16:34:58 -0700424}
425
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700426TEST_F(OmahaRequestParamsTest, SetTargetChannelWorks) {
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200427 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700428 test_dir_ + "/etc/lsb-release",
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200429 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
430 "CHROMEOS_RELEASE_FOO=bar\n"
431 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
432 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
433 "CHROMEOS_AUSERVER=http://www.google.com"));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700434 params_.SetLockDown(false);
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200435
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700436 // Check LSB value is used by default when SetTargetChannel is not called.
437 params_.Init("", "", false);
438 EXPECT_EQ("dev-channel", params_.target_channel());
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200439
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700440 // When an invalid value is set, it should be ignored and the
441 // value from lsb-release should be used instead.
442 params_.Init("", "", false);
443 EXPECT_FALSE(params_.SetTargetChannel("invalid-channel", false));
444 EXPECT_EQ("dev-channel", params_.target_channel());
445
446 // When set to a valid value, it should take effect.
447 params_.Init("", "", false);
448 EXPECT_TRUE(params_.SetTargetChannel("beta-channel", true));
449 EXPECT_EQ("beta-channel", params_.target_channel());
450
451 // When set to the same value, it should be idempotent.
452 params_.Init("", "", false);
453 EXPECT_TRUE(params_.SetTargetChannel("beta-channel", true));
454 EXPECT_EQ("beta-channel", params_.target_channel());
455
456 // When set to a valid value while a change is already pending, it should
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700457 // succeed.
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700458 params_.Init("", "", false);
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700459 EXPECT_TRUE(params_.SetTargetChannel("stable-channel", true));
460 EXPECT_EQ("stable-channel", params_.target_channel());
461
462 // Set a different channel in stateful LSB release.
463 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700464 test_dir_ + kStatefulPartition + "/etc/lsb-release",
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700465 "CHROMEOS_RELEASE_TRACK=stable-channel\n"
466 "CHROMEOS_IS_POWERWASH_ALLOWED=true\n"));
467
468 // When set to a valid value while a change is already pending, it should
469 // succeed.
470 params_.Init("", "", false);
471 EXPECT_TRUE(params_.SetTargetChannel("beta-channel", true));
472 // The target channel should reflect the change, but the download channel
473 // should continue to retain the old value ...
474 EXPECT_EQ("beta-channel", params_.target_channel());
475 EXPECT_EQ("stable-channel", params_.download_channel());
476
477 // ... until we update the download channel explicitly.
478 params_.UpdateDownloadChannel();
479 EXPECT_EQ("beta-channel", params_.download_channel());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700480 EXPECT_EQ("beta-channel", params_.target_channel());
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200481}
482
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700483TEST_F(OmahaRequestParamsTest, ChannelIndexTest) {
484 int canary = params_.GetChannelIndex("canary-channel");
485 int dev = params_.GetChannelIndex("dev-channel");
486 int beta = params_.GetChannelIndex("beta-channel");
487 int stable = params_.GetChannelIndex("stable-channel");
488 EXPECT_LE(canary, dev);
489 EXPECT_LE(dev, beta);
490 EXPECT_LE(beta, stable);
491
492 // testimage-channel or other names are not recognized, so index will be -1.
493 int testimage = params_.GetChannelIndex("testimage-channel");
494 int bogus = params_.GetChannelIndex("bogus-channel");
495 EXPECT_EQ(-1, testimage);
496 EXPECT_EQ(-1, bogus);
497}
498
499TEST_F(OmahaRequestParamsTest, ToMoreStableChannelFlagTest) {
500 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700501 test_dir_ + "/etc/lsb-release",
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700502 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
503 "CHROMEOS_RELEASE_FOO=bar\n"
504 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
505 "CHROMEOS_RELEASE_TRACK=canary-channel\n"
506 "CHROMEOS_AUSERVER=http://www.google.com"));
507 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700508 test_dir_ + kStatefulPartition + "/etc/lsb-release",
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700509 "CHROMEOS_RELEASE_BOARD=x86-generic\n"
510 "CHROMEOS_RELEASE_TRACK=stable-channel\n"
511 "CHROMEOS_AUSERVER=https://www.google.com"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700512 OmahaRequestParams out(&fake_system_state_);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700513 EXPECT_TRUE(DoTest(&out, "", ""));
514 EXPECT_EQ("https://www.google.com", out.update_url());
515 EXPECT_FALSE(out.delta_okay());
516 EXPECT_EQ("stable-channel", out.target_channel());
517 EXPECT_TRUE(out.to_more_stable_channel());
518}
519
520TEST_F(OmahaRequestParamsTest, ShouldLockDownTest) {
Darin Petkov10d02dd2011-01-10 14:57:39 -0800521 EXPECT_FALSE(params_.ShouldLockDown());
522}
523
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700524TEST_F(OmahaRequestParamsTest, BoardAppIdUsedForNonCanaryChannelTest) {
525 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700526 test_dir_ + "/etc/lsb-release",
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700527 "CHROMEOS_RELEASE_APPID=r\n"
528 "CHROMEOS_BOARD_APPID=b\n"
529 "CHROMEOS_CANARY_APPID=c\n"
530 "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700531 OmahaRequestParams out(&fake_system_state_);
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700532 EXPECT_TRUE(DoTest(&out, "", ""));
533 EXPECT_EQ("stable-channel", out.download_channel());
534 EXPECT_EQ("b", out.GetAppId());
535}
536
537TEST_F(OmahaRequestParamsTest, CanaryAppIdUsedForCanaryChannelTest) {
538 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700539 test_dir_ + "/etc/lsb-release",
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700540 "CHROMEOS_RELEASE_APPID=r\n"
541 "CHROMEOS_BOARD_APPID=b\n"
542 "CHROMEOS_CANARY_APPID=c\n"
543 "CHROMEOS_RELEASE_TRACK=canary-channel\n"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700544 OmahaRequestParams out(&fake_system_state_);
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700545 EXPECT_TRUE(DoTest(&out, "", ""));
546 EXPECT_EQ("canary-channel", out.download_channel());
547 EXPECT_EQ("c", out.GetAppId());
548}
549
550TEST_F(OmahaRequestParamsTest, ReleaseAppIdUsedAsDefaultTest) {
551 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700552 test_dir_ + "/etc/lsb-release",
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700553 "CHROMEOS_RELEASE_APPID=r\n"
554 "CHROMEOS_CANARY_APPID=c\n"
555 "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700556 OmahaRequestParams out(&fake_system_state_);
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700557 EXPECT_TRUE(DoTest(&out, "", ""));
558 EXPECT_EQ("stable-channel", out.download_channel());
559 EXPECT_EQ("r", out.GetAppId());
560}
561
Chris Sosac1972482013-04-30 22:31:10 -0700562TEST_F(OmahaRequestParamsTest, CollectECFWVersionsTest) {
563 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700564 test_dir_ + "/etc/lsb-release",
Chris Sosac1972482013-04-30 22:31:10 -0700565 "CHROMEOS_RELEASE_APPID=r\n"
566 "CHROMEOS_CANARY_APPID=c\n"
567 "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700568 OmahaRequestParams out(&fake_system_state_);
Chris Sosac1972482013-04-30 22:31:10 -0700569 out.hwid_ = string("STUMPY ALEX 12345");
570 EXPECT_FALSE(out.CollectECFWVersions());
571
572 out.hwid_ = string("SNOW 12345");
573 EXPECT_TRUE(out.CollectECFWVersions());
574
575 out.hwid_ = string("SAMS ALEX 12345");
576 EXPECT_TRUE(out.CollectECFWVersions());
577}
578
579
adlr@google.com3defe6a2009-12-04 20:57:17 +0000580} // namespace chromeos_update_engine