blob: 82d74f17a07cf1315acd4a91acd9fb7a9a80478e [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
Alex Deymo8427b4a2014-11-05 14:00:32 -08005#include "update_engine/omaha_request_params.h"
6
adlr@google.com3defe6a2009-12-04 20:57:17 +00007#include <stdio.h>
Darin Petkovfbb40092010-07-29 17:05:50 -07008
adlr@google.com3defe6a2009-12-04 20:57:17 +00009#include <string>
Darin Petkovfbb40092010-07-29 17:05:50 -070010
Alex Deymo8427b4a2014-11-05 14:00:32 -080011#include <base/files/file_util.h>
12#include <gtest/gtest.h>
13
Chris Sosabe45bef2013-04-09 18:25:12 -070014#include "update_engine/constants.h"
Gilad Arnold5bb4c902014-04-10 12:32:13 -070015#include "update_engine/fake_system_state.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000016#include "update_engine/install_plan.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000017#include "update_engine/test_utils.h"
18#include "update_engine/utils.h"
19
Alex Deymo10875d92014-11-10 21:52:57 -080020using chromeos_update_engine::test_utils::System;
21using chromeos_update_engine::test_utils::WriteFileString;
adlr@google.com3defe6a2009-12-04 20:57:17 +000022using std::string;
23
24namespace chromeos_update_engine {
25
Jay Srinivasanae4697c2013-03-18 17:08:08 -070026class OmahaRequestParamsTest : public ::testing::Test {
27 public:
Gilad Arnold5bb4c902014-04-10 12:32:13 -070028 OmahaRequestParamsTest() : params_(&fake_system_state_) {}
Jay Srinivasanae4697c2013-03-18 17:08:08 -070029
Darin Petkov5a7f5652010-07-22 21:40:09 -070030 protected:
Jay Srinivasanae4697c2013-03-18 17:08:08 -070031 // Return true iff the OmahaRequestParams::Init succeeded. If
Alex Vakulenko88b591f2014-08-28 16:48:57 -070032 // out is non-null, it's set w/ the generated data.
Darin Petkov5a7f5652010-07-22 21:40:09 -070033 bool DoTest(OmahaRequestParams* out, const string& app_version,
34 const string& omaha_url);
35
Alex Deymo610277e2014-11-11 21:18:11 -080036 void SetUp() override {
Gilad Arnoldc9abbec2013-07-01 06:24:42 -070037 // 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 Sosabe45bef2013-04-09 18:25:12 -070043 kStatefulPartition + "/etc"));
Jay Srinivasanae4697c2013-03-18 17:08:08 -070044 // Create a fresh copy of the params for each test, so there's no
45 // unintended reuse of state across tests.
Gilad Arnold5bb4c902014-04-10 12:32:13 -070046 OmahaRequestParams new_params(&fake_system_state_);
Jay Srinivasanae4697c2013-03-18 17:08:08 -070047 params_ = new_params;
Gilad Arnoldd04f8e22014-01-09 13:13:40 -080048 params_.set_root(test_dir_);
Darin Petkov10d02dd2011-01-10 14:57:39 -080049 params_.SetLockDown(false);
Darin Petkov5a7f5652010-07-22 21:40:09 -070050 }
51
Alex Deymo610277e2014-11-11 21:18:11 -080052 void TearDown() override {
Gilad Arnoldc9abbec2013-07-01 06:24:42 -070053 EXPECT_EQ(0, System(string("rm -rf ") + test_dir_));
Darin Petkov5a7f5652010-07-22 21:40:09 -070054 }
55
Jay Srinivasanae4697c2013-03-18 17:08:08 -070056 OmahaRequestParams params_;
Gilad Arnold5bb4c902014-04-10 12:32:13 -070057 FakeSystemState fake_system_state_;
Darin Petkov49d91322010-10-25 16:34:58 -070058
Gilad Arnoldc9abbec2013-07-01 06:24:42 -070059 static const char* kTestDirTemplate;
60 string test_dir_;
adlr@google.com3defe6a2009-12-04 20:57:17 +000061};
62
Gilad Arnoldc9abbec2013-07-01 06:24:42 -070063const char* OmahaRequestParamsTest::kTestDirTemplate =
64 "omaha_request_params-test-XXXXXX";
adlr@google.com3defe6a2009-12-04 20:57:17 +000065
Jay Srinivasanae4697c2013-03-18 17:08:08 -070066bool 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.com3defe6a2009-12-04 20:57:17 +000070 if (out)
Darin Petkov49d91322010-10-25 16:34:58 -070071 *out = params_;
Darin Petkova4a8a8c2010-07-15 22:21:12 -070072 return success;
adlr@google.com3defe6a2009-12-04 20:57:17 +000073}
74
75namespace {
adlr@google.com3defe6a2009-12-04 20:57:17 +000076string GetMachineType() {
Gilad Arnold19a45f02012-07-19 12:36:10 -070077 string machine_type;
78 if (!utils::ReadPipe("uname -m", &machine_type))
adlr@google.com3defe6a2009-12-04 20:57:17 +000079 return "";
Gilad Arnold19a45f02012-07-19 12:36:10 -070080 // 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.com3defe6a2009-12-04 20:57:17 +000085}
Alex Vakulenkod2779df2014-06-16 13:19:00 -070086} // namespace
adlr@google.com3defe6a2009-12-04 20:57:17 +000087
Jay Srinivasanae4697c2013-03-18 17:08:08 -070088TEST_F(OmahaRequestParamsTest, SimpleTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -070089 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -070090 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -070091 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
92 "CHROMEOS_RELEASE_FOO=bar\n"
93 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -070094 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
Darin Petkov5a7f5652010-07-22 21:40:09 -070095 "CHROMEOS_AUSERVER=http://www.google.com"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -070096 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -070097 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -070098 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 Srinivasandb0acdf2013-04-02 14:47:45 -0700101 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700102 EXPECT_EQ("0.2.2.3", out.app_version());
103 EXPECT_EQ("en-US", out.app_lang());
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700104 EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700105 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.com3defe6a2009-12-04 20:57:17 +0000108}
109
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700110TEST_F(OmahaRequestParamsTest, AppIDTest) {
Darin Petkovd315dc72010-11-15 09:52:24 -0800111 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700112 test_dir_ + "/etc/lsb-release",
Darin Petkovd315dc72010-11-15 09:52:24 -0800113 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
114 "CHROMEOS_RELEASE_FOO=bar\n"
115 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700116 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
Darin Petkovd315dc72010-11-15 09:52:24 -0800117 "CHROMEOS_RELEASE_APPID={58c35cef-9d30-476e-9098-ce20377d535d}\n"
118 "CHROMEOS_AUSERVER=http://www.google.com"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700119 OmahaRequestParams out(&fake_system_state_);
Darin Petkovd315dc72010-11-15 09:52:24 -0800120 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700121 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 Srinivasandb0acdf2013-04-02 14:47:45 -0700124 EXPECT_EQ("{58c35cef-9d30-476e-9098-ce20377d535d}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700125 EXPECT_EQ("0.2.2.3", out.app_version());
126 EXPECT_EQ("en-US", out.app_lang());
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700127 EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700128 EXPECT_TRUE(out.delta_okay());
129 EXPECT_EQ("dev-channel", out.target_channel());
130 EXPECT_EQ("http://www.google.com", out.update_url());
Darin Petkovd315dc72010-11-15 09:52:24 -0800131}
132
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700133TEST_F(OmahaRequestParamsTest, MissingChannelTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -0700134 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700135 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -0700136 "CHROMEOS_RELEASE_FOO=bar\n"
137 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700138 "CHROMEOS_RELEASE_TRXCK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700139 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700140 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700141 EXPECT_EQ("Chrome OS", out.os_platform());
142 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700143 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700144 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.com3defe6a2009-12-04 20:57:17 +0000147}
148
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700149TEST_F(OmahaRequestParamsTest, ConfusingReleaseTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -0700150 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700151 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -0700152 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
153 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700154 "CHROMEOS_RELEASE_TRXCK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700155 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700156 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700157 EXPECT_EQ("Chrome OS", out.os_platform());
158 EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700159 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700160 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.com3defe6a2009-12-04 20:57:17 +0000163}
164
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700165TEST_F(OmahaRequestParamsTest, MissingVersionTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -0700166 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700167 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -0700168 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
169 "CHROMEOS_RELEASE_FOO=bar\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700170 "CHROMEOS_RELEASE_TRACK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700171 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700172 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700173 EXPECT_EQ("Chrome OS", out.os_platform());
174 EXPECT_EQ(string("_") + GetMachineType(), out.os_sp());
175 EXPECT_EQ("arm-generic", out.os_board());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700176 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700177 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 Petkov5a7f5652010-07-22 21:40:09 -0700181}
182
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700183TEST_F(OmahaRequestParamsTest, ForceVersionTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -0700184 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700185 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -0700186 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
187 "CHROMEOS_RELEASE_FOO=bar\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700188 "CHROMEOS_RELEASE_TRACK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700189 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700190 EXPECT_TRUE(DoTest(&out, "ForcedVersion", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700191 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 Srinivasandb0acdf2013-04-02 14:47:45 -0700194 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700195 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 Petkov5a7f5652010-07-22 21:40:09 -0700199}
200
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700201TEST_F(OmahaRequestParamsTest, ForcedURLTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -0700202 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700203 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -0700204 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
205 "CHROMEOS_RELEASE_FOO=bar\n"
206 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700207 "CHROMEOS_RELEASE_TRACK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700208 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700209 EXPECT_TRUE(DoTest(&out, "", "http://forced.google.com"));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700210 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 Srinivasandb0acdf2013-04-02 14:47:45 -0700213 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700214 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 Petkov5a7f5652010-07-22 21:40:09 -0700219}
220
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700221TEST_F(OmahaRequestParamsTest, MissingURLTest) {
Darin Petkov5a7f5652010-07-22 21:40:09 -0700222 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700223 test_dir_ + "/etc/lsb-release",
Darin Petkov5a7f5652010-07-22 21:40:09 -0700224 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
225 "CHROMEOS_RELEASE_FOO=bar\n"
226 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700227 "CHROMEOS_RELEASE_TRACK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700228 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700229 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700230 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 Srinivasandb0acdf2013-04-02 14:47:45 -0700233 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700234 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 Reyes970bb282009-12-09 16:34:04 -0800239}
240
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700241TEST_F(OmahaRequestParamsTest, NoDeltasTest) {
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -0700242 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700243 test_dir_ + "/etc/lsb-release",
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -0700244 "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
245 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700246 "CHROMEOS_RELEASE_TRXCK=dev-channel"));
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700247 ASSERT_TRUE(WriteFileString(test_dir_ + "/.nodelta", ""));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700248 OmahaRequestParams out(&fake_system_state_);
Darin Petkov5a7f5652010-07-22 21:40:09 -0700249 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700250 EXPECT_FALSE(out.delta_okay());
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -0700251}
252
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700253TEST_F(OmahaRequestParamsTest, OverrideTest) {
Darin Petkov49d91322010-10-25 16:34:58 -0700254 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700255 test_dir_ + "/etc/lsb-release",
Darin Petkov49d91322010-10-25 16:34:58 -0700256 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
257 "CHROMEOS_RELEASE_FOO=bar\n"
258 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Darin Petkov10d02dd2011-01-10 14:57:39 -0800259 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
260 "CHROMEOS_AUSERVER=http://www.google.com"));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700261 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700262 test_dir_ + kStatefulPartition + "/etc/lsb-release",
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700263 "CHROMEOS_RELEASE_BOARD=x86-generic\n"
264 "CHROMEOS_RELEASE_TRACK=beta-channel\n"
265 "CHROMEOS_AUSERVER=https://www.google.com"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700266 OmahaRequestParams out(&fake_system_state_);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700267 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 Srinivasandb0acdf2013-04-02 14:47:45 -0700271 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700272 EXPECT_EQ("0.2.2.3", out.app_version());
273 EXPECT_EQ("en-US", out.app_lang());
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700274 EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700275 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
280TEST_F(OmahaRequestParamsTest, OverrideLockDownTest) {
281 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700282 test_dir_ + "/etc/lsb-release",
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700283 "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 Arnoldc9abbec2013-07-01 06:24:42 -0700289 test_dir_ + kStatefulPartition + "/etc/lsb-release",
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700290 "CHROMEOS_RELEASE_BOARD=x86-generic\n"
291 "CHROMEOS_RELEASE_TRACK=stable-channel\n"
292 "CHROMEOS_AUSERVER=http://www.google.com"));
Darin Petkov10d02dd2011-01-10 14:57:39 -0800293 params_.SetLockDown(true);
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700294 OmahaRequestParams out(&fake_system_state_);
Darin Petkov10d02dd2011-01-10 14:57:39 -0800295 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700296 EXPECT_EQ("arm-generic", out.os_board());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700297 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700298 EXPECT_EQ("0.2.2.3", out.app_version());
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700299 EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700300 EXPECT_FALSE(out.delta_okay());
301 EXPECT_EQ("stable-channel", out.target_channel());
302 EXPECT_EQ("https://www.google.com", out.update_url());
Darin Petkov49d91322010-10-25 16:34:58 -0700303}
304
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700305TEST_F(OmahaRequestParamsTest, OverrideSameChannelTest) {
Darin Petkova3df55b2010-11-15 13:33:55 -0800306 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700307 test_dir_ + "/etc/lsb-release",
Darin Petkova3df55b2010-11-15 13:33:55 -0800308 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
309 "CHROMEOS_RELEASE_FOO=bar\n"
310 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700311 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
Darin Petkova3df55b2010-11-15 13:33:55 -0800312 "CHROMEOS_AUSERVER=http://www.google.com"));
313 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700314 test_dir_ + kStatefulPartition + "/etc/lsb-release",
Darin Petkova3df55b2010-11-15 13:33:55 -0800315 "CHROMEOS_RELEASE_BOARD=x86-generic\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700316 "CHROMEOS_RELEASE_TRACK=dev-channel"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700317 OmahaRequestParams out(&fake_system_state_);
Darin Petkova3df55b2010-11-15 13:33:55 -0800318 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700319 EXPECT_EQ("x86-generic", out.os_board());
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700320 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700321 EXPECT_EQ("0.2.2.3", out.app_version());
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700322 EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700323 EXPECT_TRUE(out.delta_okay());
324 EXPECT_EQ("dev-channel", out.target_channel());
325 EXPECT_EQ("http://www.google.com", out.update_url());
Darin Petkova3df55b2010-11-15 13:33:55 -0800326}
327
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700328TEST_F(OmahaRequestParamsTest, SetTargetChannelTest) {
Darin Petkov49d91322010-10-25 16:34:58 -0700329 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700330 test_dir_ + "/etc/lsb-release",
Darin Petkov49d91322010-10-25 16:34:58 -0700331 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
332 "CHROMEOS_RELEASE_FOO=bar\n"
333 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700334 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
Darin Petkov49d91322010-10-25 16:34:58 -0700335 "CHROMEOS_AUSERVER=http://www.google.com"));
336 {
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700337 OmahaRequestParams params(&fake_system_state_);
Gilad Arnoldd04f8e22014-01-09 13:13:40 -0800338 params.set_root(test_dir_);
Darin Petkov10d02dd2011-01-10 14:57:39 -0800339 params.SetLockDown(false);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700340 EXPECT_TRUE(params.Init("", "", false));
341 params.SetTargetChannel("canary-channel", false);
342 EXPECT_FALSE(params.is_powerwash_allowed());
Darin Petkov49d91322010-10-25 16:34:58 -0700343 }
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700344 OmahaRequestParams out(&fake_system_state_);
Darin Petkov49d91322010-10-25 16:34:58 -0700345 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700346 EXPECT_EQ("canary-channel", out.target_channel());
347 EXPECT_FALSE(out.is_powerwash_allowed());
Darin Petkov49d91322010-10-25 16:34:58 -0700348}
349
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700350TEST_F(OmahaRequestParamsTest, SetIsPowerwashAllowedTest) {
Darin Petkov49d91322010-10-25 16:34:58 -0700351 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700352 test_dir_ + "/etc/lsb-release",
Darin Petkov49d91322010-10-25 16:34:58 -0700353 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
354 "CHROMEOS_RELEASE_FOO=bar\n"
355 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700356 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
Darin Petkov49d91322010-10-25 16:34:58 -0700357 "CHROMEOS_AUSERVER=http://www.google.com"));
Darin Petkov49d91322010-10-25 16:34:58 -0700358 {
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700359 OmahaRequestParams params(&fake_system_state_);
Gilad Arnoldd04f8e22014-01-09 13:13:40 -0800360 params.set_root(test_dir_);
Darin Petkov10d02dd2011-01-10 14:57:39 -0800361 params.SetLockDown(false);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700362 EXPECT_TRUE(params.Init("", "", false));
363 params.SetTargetChannel("canary-channel", true);
364 EXPECT_TRUE(params.is_powerwash_allowed());
Darin Petkov49d91322010-10-25 16:34:58 -0700365 }
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700366 OmahaRequestParams out(&fake_system_state_);
Darin Petkov49d91322010-10-25 16:34:58 -0700367 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700368 EXPECT_EQ("canary-channel", out.target_channel());
369 EXPECT_TRUE(out.is_powerwash_allowed());
Darin Petkov49d91322010-10-25 16:34:58 -0700370}
371
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700372TEST_F(OmahaRequestParamsTest, SetTargetChannelInvalidTest) {
Darin Petkov49d91322010-10-25 16:34:58 -0700373 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700374 test_dir_ + "/etc/lsb-release",
Darin Petkov49d91322010-10-25 16:34:58 -0700375 "CHROMEOS_RELEASE_BOARD=arm-generic\n"
376 "CHROMEOS_RELEASE_FOO=bar\n"
377 "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700378 "CHROMEOS_RELEASE_TRACK=dev-channel\n"
Darin Petkov49d91322010-10-25 16:34:58 -0700379 "CHROMEOS_AUSERVER=http://www.google.com"));
380 {
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700381 OmahaRequestParams params(&fake_system_state_);
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700382 params.set_root(string("./") + test_dir_);
Darin Petkov10d02dd2011-01-10 14:57:39 -0800383 params.SetLockDown(true);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700384 EXPECT_TRUE(params.Init("", "", false));
385 params.SetTargetChannel("dogfood-channel", true);
386 EXPECT_FALSE(params.is_powerwash_allowed());
Darin Petkov49d91322010-10-25 16:34:58 -0700387 }
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700388 OmahaRequestParams out(&fake_system_state_);
Darin Petkov49d91322010-10-25 16:34:58 -0700389 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700390 EXPECT_EQ("arm-generic", out.os_board());
391 EXPECT_EQ("dev-channel", out.target_channel());
392 EXPECT_FALSE(out.is_powerwash_allowed());
Darin Petkov49d91322010-10-25 16:34:58 -0700393}
394
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700395TEST_F(OmahaRequestParamsTest, IsValidChannelTest) {
Darin Petkov10d02dd2011-01-10 14:57:39 -0800396 params_.SetLockDown(false);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700397 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 Petkov49d91322010-10-25 16:34:58 -0700405}
406
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700407TEST_F(OmahaRequestParamsTest, ValidChannelTest) {
Darin Petkov49d91322010-10-25 16:34:58 -0700408 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700409 test_dir_ + "/etc/lsb-release",
Darin Petkov49d91322010-10-25 16:34:58 -0700410 "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 Petkov10d02dd2011-01-10 14:57:39 -0800415 params_.SetLockDown(true);
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700416 OmahaRequestParams out(&fake_system_state_);
Darin Petkov49d91322010-10-25 16:34:58 -0700417 EXPECT_TRUE(DoTest(&out, "", ""));
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700418 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 Srinivasandb0acdf2013-04-02 14:47:45 -0700421 EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700422 EXPECT_EQ("0.2.2.3", out.app_version());
423 EXPECT_EQ("en-US", out.app_lang());
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700424 EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700425 EXPECT_TRUE(out.delta_okay());
426 EXPECT_EQ("dev-channel", out.target_channel());
427 EXPECT_EQ("http://www.google.com", out.update_url());
Darin Petkov49d91322010-10-25 16:34:58 -0700428}
429
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700430TEST_F(OmahaRequestParamsTest, SetTargetChannelWorks) {
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200431 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700432 test_dir_ + "/etc/lsb-release",
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200433 "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 Srinivasanae4697c2013-03-18 17:08:08 -0700438 params_.SetLockDown(false);
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200439
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700440 // 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 Dubroy7fbbe8a2011-08-01 17:28:22 +0200443
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700444 // 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 Srinivasan1c0fe792013-03-28 16:45:25 -0700461 // succeed.
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700462 params_.Init("", "", false);
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700463 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 Arnoldc9abbec2013-07-01 06:24:42 -0700468 test_dir_ + kStatefulPartition + "/etc/lsb-release",
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700469 "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 Srinivasanae4697c2013-03-18 17:08:08 -0700484 EXPECT_EQ("beta-channel", params_.target_channel());
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200485}
486
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700487TEST_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
503TEST_F(OmahaRequestParamsTest, ToMoreStableChannelFlagTest) {
504 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700505 test_dir_ + "/etc/lsb-release",
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700506 "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 Arnoldc9abbec2013-07-01 06:24:42 -0700512 test_dir_ + kStatefulPartition + "/etc/lsb-release",
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700513 "CHROMEOS_RELEASE_BOARD=x86-generic\n"
514 "CHROMEOS_RELEASE_TRACK=stable-channel\n"
515 "CHROMEOS_AUSERVER=https://www.google.com"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700516 OmahaRequestParams out(&fake_system_state_);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700517 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
524TEST_F(OmahaRequestParamsTest, ShouldLockDownTest) {
Darin Petkov10d02dd2011-01-10 14:57:39 -0800525 EXPECT_FALSE(params_.ShouldLockDown());
526}
527
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700528TEST_F(OmahaRequestParamsTest, BoardAppIdUsedForNonCanaryChannelTest) {
529 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700530 test_dir_ + "/etc/lsb-release",
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700531 "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 Arnold5bb4c902014-04-10 12:32:13 -0700535 OmahaRequestParams out(&fake_system_state_);
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700536 EXPECT_TRUE(DoTest(&out, "", ""));
537 EXPECT_EQ("stable-channel", out.download_channel());
538 EXPECT_EQ("b", out.GetAppId());
539}
540
541TEST_F(OmahaRequestParamsTest, CanaryAppIdUsedForCanaryChannelTest) {
542 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700543 test_dir_ + "/etc/lsb-release",
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700544 "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 Arnold5bb4c902014-04-10 12:32:13 -0700548 OmahaRequestParams out(&fake_system_state_);
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700549 EXPECT_TRUE(DoTest(&out, "", ""));
550 EXPECT_EQ("canary-channel", out.download_channel());
551 EXPECT_EQ("c", out.GetAppId());
552}
553
554TEST_F(OmahaRequestParamsTest, ReleaseAppIdUsedAsDefaultTest) {
555 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700556 test_dir_ + "/etc/lsb-release",
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700557 "CHROMEOS_RELEASE_APPID=r\n"
558 "CHROMEOS_CANARY_APPID=c\n"
559 "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700560 OmahaRequestParams out(&fake_system_state_);
Jay Srinivasandb0acdf2013-04-02 14:47:45 -0700561 EXPECT_TRUE(DoTest(&out, "", ""));
562 EXPECT_EQ("stable-channel", out.download_channel());
563 EXPECT_EQ("r", out.GetAppId());
564}
565
Chris Sosac1972482013-04-30 22:31:10 -0700566TEST_F(OmahaRequestParamsTest, CollectECFWVersionsTest) {
567 ASSERT_TRUE(WriteFileString(
Gilad Arnoldc9abbec2013-07-01 06:24:42 -0700568 test_dir_ + "/etc/lsb-release",
Chris Sosac1972482013-04-30 22:31:10 -0700569 "CHROMEOS_RELEASE_APPID=r\n"
570 "CHROMEOS_CANARY_APPID=c\n"
571 "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700572 OmahaRequestParams out(&fake_system_state_);
Chris Sosac1972482013-04-30 22:31:10 -0700573 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.com3defe6a2009-12-04 20:57:17 +0000584} // namespace chromeos_update_engine