Index: omaha_request_params_unittest.cc |
diff --git a/omaha_request_params_unittest.cc b/omaha_request_params_unittest.cc |
index 0150a00292d395ceb9aa8039baca24cdb6eb9f14..c136e06ecabbac31b38206884e3f6474b831223a 100644 |
--- a/omaha_request_params_unittest.cc |
+++ b/omaha_request_params_unittest.cc |
@@ -28,12 +28,16 @@ class OmahaRequestDeviceParamsTest : public ::testing::Test { |
ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); |
ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + |
utils::kStatefulPartition + "/etc")); |
+ params_.set_root(string("./") + kTestDir); |
+ params_.SetBuildTypeOfficial(false); |
} |
virtual void TearDown() { |
EXPECT_EQ(0, System(string("rm -rf ") + kTestDir)); |
} |
+ OmahaRequestDeviceParams params_; |
+ |
static const string kTestDir; |
}; |
@@ -43,11 +47,9 @@ const string OmahaRequestDeviceParamsTest::kTestDir = |
bool OmahaRequestDeviceParamsTest::DoTest(OmahaRequestParams* out, |
const string& app_version, |
const string& omaha_url) { |
- OmahaRequestDeviceParams params; |
- params.set_root(string("./") + kTestDir); |
- bool success = params.Init(app_version, omaha_url); |
+ bool success = params_.Init(app_version, omaha_url); |
if (out) |
- *out = params; |
+ *out = params_; |
return success; |
} |
@@ -227,4 +229,157 @@ TEST_F(OmahaRequestDeviceParamsTest, HardwareClassTest) { |
EXPECT_EQ("sample hardware class", out.hardware_class); |
} |
+TEST_F(OmahaRequestDeviceParamsTest, OverrideTest) { |
+ ASSERT_TRUE(WriteFileString( |
+ kTestDir + "/etc/lsb-release", |
+ "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
+ "CHROMEOS_RELEASE_FOO=bar\n" |
+ "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
+ "CHROMEOS_RELEASE_TRACK=footrack\n" |
+ "CHROMEOS_AUSERVER=http://www.google.com")); |
+ ASSERT_TRUE(WriteFileString( |
+ kTestDir + utils::kStatefulPartition + "/etc/lsb-release", |
+ "CHROMEOS_RELEASE_BOARD=x86-generic\n" |
+ "CHROMEOS_RELEASE_TRACK=bartrack\n" |
+ "CHROMEOS_AUSERVER=http://www.google.com")); |
+ OmahaRequestParams out; |
+ EXPECT_TRUE(DoTest(&out, "", "")); |
+ EXPECT_EQ("Chrome OS", out.os_platform); |
+ EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
+ EXPECT_EQ("x86-generic", out.os_board); |
+ EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
+ EXPECT_EQ("0.2.2.3", out.app_version); |
+ EXPECT_EQ("en-US", out.app_lang); |
+ EXPECT_EQ("", out.hardware_class); |
+ EXPECT_TRUE(out.delta_okay); |
+ EXPECT_EQ("bartrack", out.app_track); |
+ EXPECT_EQ("http://www.google.com", out.update_url); |
+} |
+ |
+TEST_F(OmahaRequestDeviceParamsTest, SetTrackSimpleTest) { |
+ ASSERT_TRUE(WriteFileString( |
+ kTestDir + "/etc/lsb-release", |
+ "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
+ "CHROMEOS_RELEASE_FOO=bar\n" |
+ "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
+ "CHROMEOS_RELEASE_TRACK=footrack\n" |
+ "CHROMEOS_AUSERVER=http://www.google.com")); |
+ { |
+ OmahaRequestDeviceParams params; |
+ params.set_root(string("./") + kTestDir); |
+ params.SetBuildTypeOfficial(false); |
+ EXPECT_TRUE(params.Init("", "")); |
+ params.SetTrack("zootrack"); |
+ } |
+ OmahaRequestParams out; |
+ EXPECT_TRUE(DoTest(&out, "", "")); |
+ EXPECT_EQ("arm-generic", out.os_board); |
+ EXPECT_EQ("zootrack", out.app_track); |
+} |
+ |
+TEST_F(OmahaRequestDeviceParamsTest, SetTrackPreserveTest) { |
+ ASSERT_TRUE(WriteFileString( |
+ kTestDir + "/etc/lsb-release", |
+ "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
+ "CHROMEOS_RELEASE_FOO=bar\n" |
+ "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
+ "CHROMEOS_RELEASE_TRACK=footrack\n" |
+ "CHROMEOS_AUSERVER=http://www.google.com")); |
+ ASSERT_TRUE(WriteFileString( |
+ kTestDir + utils::kStatefulPartition + "/etc/lsb-release", |
+ "CHROMEOS_RELEASE_BOARD=x86-generic\n" |
+ "CHROMEOS_RELEASE_TRACK=bartrack")); |
+ { |
+ OmahaRequestDeviceParams params; |
+ params.set_root(string("./") + kTestDir); |
+ params.SetBuildTypeOfficial(false); |
+ EXPECT_TRUE(params.Init("", "")); |
+ params.SetTrack("zootrack"); |
+ } |
+ OmahaRequestParams out; |
+ EXPECT_TRUE(DoTest(&out, "", "")); |
+ EXPECT_EQ("x86-generic", out.os_board); |
+ EXPECT_EQ("zootrack", out.app_track); |
+} |
+ |
+TEST_F(OmahaRequestDeviceParamsTest, SetTrackInvalidTest) { |
+ ASSERT_TRUE(WriteFileString( |
+ kTestDir + "/etc/lsb-release", |
+ "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
+ "CHROMEOS_RELEASE_FOO=bar\n" |
+ "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
+ "CHROMEOS_RELEASE_TRACK=footrack\n" |
+ "CHROMEOS_AUSERVER=http://www.google.com")); |
+ { |
+ OmahaRequestDeviceParams params; |
+ params.set_root(string("./") + kTestDir); |
+ params.SetBuildTypeOfficial(true); |
+ EXPECT_TRUE(params.Init("", "")); |
+ params.SetTrack("zootrack"); |
+ } |
+ OmahaRequestParams out; |
+ EXPECT_TRUE(DoTest(&out, "", "")); |
+ EXPECT_EQ("arm-generic", out.os_board); |
+ EXPECT_EQ("footrack", out.app_track); |
+} |
+ |
+TEST_F(OmahaRequestDeviceParamsTest, IsValidTrackTest) { |
+ params_.SetBuildTypeOfficial(true); |
+ EXPECT_TRUE(params_.IsValidTrack("beta-channel")); |
+ EXPECT_TRUE(params_.IsValidTrack("dev-channel")); |
+ EXPECT_FALSE(params_.IsValidTrack("some-channel")); |
+ EXPECT_FALSE(params_.IsValidTrack("")); |
+ params_.SetBuildTypeOfficial(false); |
+ EXPECT_TRUE(params_.IsValidTrack("beta-channel")); |
+ EXPECT_TRUE(params_.IsValidTrack("dev-channel")); |
+ EXPECT_TRUE(params_.IsValidTrack("some-channel")); |
+ EXPECT_TRUE(params_.IsValidTrack("")); |
+} |
+ |
+TEST_F(OmahaRequestDeviceParamsTest, InvalidTrackTest) { |
+ ASSERT_TRUE(WriteFileString( |
+ kTestDir + "/etc/lsb-release", |
+ "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
+ "CHROMEOS_RELEASE_FOO=bar\n" |
+ "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
+ "CHROMEOS_RELEASE_TRACK=footrack\n" |
+ "CHROMEOS_AUSERVER=http://www.google.com")); |
+ params_.SetBuildTypeOfficial(true); |
+ OmahaRequestParams out; |
+ EXPECT_TRUE(DoTest(&out, "", "")); |
+ EXPECT_EQ("Chrome OS", out.os_platform); |
+ EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
+ EXPECT_EQ("arm-generic", out.os_board); |
+ EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
+ EXPECT_EQ("0.2.2.3", out.app_version); |
+ EXPECT_EQ("en-US", out.app_lang); |
+ EXPECT_EQ("", out.hardware_class); |
+ EXPECT_TRUE(out.delta_okay); |
+ EXPECT_EQ("", out.app_track); |
+ EXPECT_EQ("http://www.google.com", out.update_url); |
+} |
+ |
+TEST_F(OmahaRequestDeviceParamsTest, ValidTrackTest) { |
+ ASSERT_TRUE(WriteFileString( |
+ kTestDir + "/etc/lsb-release", |
+ "CHROMEOS_RELEASE_BOARD=arm-generic\n" |
+ "CHROMEOS_RELEASE_FOO=bar\n" |
+ "CHROMEOS_RELEASE_VERSION=0.2.2.3\n" |
+ "CHROMEOS_RELEASE_TRACK=dev-channel\n" |
+ "CHROMEOS_AUSERVER=http://www.google.com")); |
+ params_.SetBuildTypeOfficial(true); |
+ OmahaRequestParams out; |
+ EXPECT_TRUE(DoTest(&out, "", "")); |
+ EXPECT_EQ("Chrome OS", out.os_platform); |
+ EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp); |
+ EXPECT_EQ("arm-generic", out.os_board); |
+ EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id); |
+ EXPECT_EQ("0.2.2.3", out.app_version); |
+ EXPECT_EQ("en-US", out.app_lang); |
+ EXPECT_EQ("", out.hardware_class); |
+ EXPECT_TRUE(out.delta_okay); |
+ EXPECT_EQ("dev-channel", out.app_track); |
+ EXPECT_EQ("http://www.google.com", out.update_url); |
+} |
+ |
} // namespace chromeos_update_engine |