Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1191)

Unified Diff: omaha_request_params_unittest.cc

Issue 3048008: Add support to update_engine_client for -app_version and -omaha_url. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: Don't use ?: shorthand. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « omaha_request_params.cc ('k') | update_attempter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: omaha_request_params_unittest.cc
diff --git a/omaha_request_params_unittest.cc b/omaha_request_params_unittest.cc
index 200b23b4abb672551fc8fc3ca6266a3be5cd4365..07615a235f7fea356c1c8974b6df9c50a18cfa30 100644
--- a/omaha_request_params_unittest.cc
+++ b/omaha_request_params_unittest.cc
@@ -15,20 +15,34 @@ using std::string;
namespace chromeos_update_engine {
class OmahaRequestDeviceParamsTest : public ::testing::Test {
- public:
+ protected:
// Return true iff the OmahaRequestDeviceParams::Init succeeded. If
// out is non-NULL, it's set w/ the generated data.
- bool DoTest(OmahaRequestParams* out);
+ bool DoTest(OmahaRequestParams* out, const string& app_version,
+ const string& omaha_url);
+
+ virtual void SetUp() {
+ ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc"));
+ ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir +
+ utils::kStatefulPartition + "/etc"));
+ }
+
+ virtual void TearDown() {
+ EXPECT_EQ(0, System(string("rm -rf ") + kTestDir));
+ }
+
static const string kTestDir;
};
const string OmahaRequestDeviceParamsTest::kTestDir =
"omaha_request_device_params-test";
-bool OmahaRequestDeviceParamsTest::DoTest(OmahaRequestParams* out) {
+bool OmahaRequestDeviceParamsTest::DoTest(OmahaRequestParams* out,
+ const string& app_version,
+ const string& omaha_url) {
OmahaRequestDeviceParams params;
params.set_root(string("./") + kTestDir);
- bool success = params.Init();
+ bool success = params.Init(app_version, omaha_url);
if (out)
*out = params;
return success;
@@ -77,94 +91,75 @@ string GetMachineType() {
} // namespace {}
TEST_F(OmahaRequestDeviceParamsTest, SimpleTest) {
- ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc"));
- ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir +
- utils::kStatefulPartition + "/etc"));
- {
- 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"));
- OmahaRequestParams out;
- EXPECT_TRUE(DoTest(&out));
- EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id;
- // for now we're just using the machine id here
- EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id;
- 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_TRUE(out.delta_okay);
- EXPECT_EQ("footrack", out.app_track);
- }
- EXPECT_EQ(0, System(string("rm -rf ") + kTestDir));
+ 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"));
+ OmahaRequestParams out;
+ EXPECT_TRUE(DoTest(&out, "", ""));
+ EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id;
+ // for now we're just using the machine id here
+ EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id;
+ 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_TRUE(out.delta_okay);
+ EXPECT_EQ("footrack", out.app_track);
+ EXPECT_EQ("http://www.google.com", out.update_url);
}
TEST_F(OmahaRequestDeviceParamsTest, MissingTrackTest) {
- ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc"));
- ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir +
- utils::kStatefulPartition + "/etc"));
- {
- ASSERT_TRUE(WriteFileString(
- kTestDir + "/etc/lsb-release",
- "CHROMEOS_RELEASE_FOO=bar\n"
- "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
- "CHROMEOS_RELEASE_TRXCK=footrack"));
- OmahaRequestParams out;
- EXPECT_TRUE(DoTest(&out));
- EXPECT_TRUE(IsValidGuid(out.machine_id));
- // for now we're just using the machine id here
- EXPECT_TRUE(IsValidGuid(out.user_id));
- EXPECT_EQ("Chrome OS", out.os_platform);
- EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp);
- 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.app_track);
- }
- EXPECT_EQ(0, System(string("rm -rf ") + kTestDir));
+ ASSERT_TRUE(WriteFileString(
+ kTestDir + "/etc/lsb-release",
+ "CHROMEOS_RELEASE_FOO=bar\n"
+ "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
+ "CHROMEOS_RELEASE_TRXCK=footrack"));
+ OmahaRequestParams out;
+ EXPECT_TRUE(DoTest(&out, "", ""));
+ EXPECT_TRUE(IsValidGuid(out.machine_id));
+ // for now we're just using the machine id here
+ EXPECT_TRUE(IsValidGuid(out.user_id));
+ EXPECT_EQ("Chrome OS", out.os_platform);
+ EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp);
+ 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.app_track);
}
TEST_F(OmahaRequestDeviceParamsTest, ConfusingReleaseTest) {
- ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc"));
- ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir +
- utils::kStatefulPartition + "/etc"));
- {
- ASSERT_TRUE(WriteFileString(
- kTestDir + "/etc/lsb-release",
- "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
- "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
- "CHROMEOS_RELEASE_TRXCK=footrack"));
- OmahaRequestParams out;
- EXPECT_TRUE(DoTest(&out));
- EXPECT_TRUE(IsValidGuid(out.machine_id)) << out.machine_id;
- // for now we're just using the machine id here
- EXPECT_TRUE(IsValidGuid(out.user_id));
- EXPECT_EQ("Chrome OS", out.os_platform);
- EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp);
- 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.app_track);
- }
- EXPECT_EQ(0, System(string("rm -rf ") + kTestDir));
+ ASSERT_TRUE(WriteFileString(
+ kTestDir + "/etc/lsb-release",
+ "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
+ "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
+ "CHROMEOS_RELEASE_TRXCK=footrack"));
+ OmahaRequestParams out;
+ EXPECT_TRUE(DoTest(&out, "", ""));
+ EXPECT_TRUE(IsValidGuid(out.machine_id)) << out.machine_id;
+ // for now we're just using the machine id here
+ EXPECT_TRUE(IsValidGuid(out.user_id));
+ EXPECT_EQ("Chrome OS", out.os_platform);
+ EXPECT_EQ(string("0.2.2.3_") + GetMachineType(), out.os_sp);
+ 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.app_track);
}
TEST_F(OmahaRequestDeviceParamsTest, MachineIdPersistsTest) {
- ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc"));
- ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir +
- utils::kStatefulPartition + "/etc"));
ASSERT_TRUE(WriteFileString(
kTestDir + "/etc/lsb-release",
"CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
"CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
"CHROMEOS_RELEASE_TRXCK=footrack"));
OmahaRequestParams out1;
- EXPECT_TRUE(DoTest(&out1));
+ EXPECT_TRUE(DoTest(&out1, "", ""));
string machine_id;
EXPECT_TRUE(utils::ReadFileToString(
kTestDir +
@@ -172,15 +167,99 @@ TEST_F(OmahaRequestDeviceParamsTest, MachineIdPersistsTest) {
&machine_id));
EXPECT_EQ(machine_id, out1.machine_id);
OmahaRequestParams out2;
- EXPECT_TRUE(DoTest(&out2));
+ EXPECT_TRUE(DoTest(&out2, "", ""));
EXPECT_EQ(machine_id, out2.machine_id);
- EXPECT_EQ(0, System(string("rm -rf ") + kTestDir));
+}
+
+TEST_F(OmahaRequestDeviceParamsTest, MissingVersionTest) {
+ ASSERT_TRUE(WriteFileString(
+ kTestDir + "/etc/lsb-release",
+ "CHROMEOS_RELEASE_BOARD=arm-generic\n"
+ "CHROMEOS_RELEASE_FOO=bar\n"
+ "CHROMEOS_RELEASE_TRACK=footrack"));
+ OmahaRequestParams out;
+ EXPECT_TRUE(DoTest(&out, "", ""));
+ EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id;
+ // for now we're just using the machine id here
+ EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id;
+ EXPECT_EQ("Chrome OS", out.os_platform);
+ EXPECT_EQ(string("_") + GetMachineType(), out.os_sp);
+ EXPECT_EQ("arm-generic", out.os_board);
+ EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id);
+ EXPECT_EQ("", out.app_version);
+ EXPECT_EQ("en-US", out.app_lang);
+ EXPECT_TRUE(out.delta_okay);
+ EXPECT_EQ("footrack", out.app_track);
+}
+
+TEST_F(OmahaRequestDeviceParamsTest, ForceVersionTest) {
+ ASSERT_TRUE(WriteFileString(
+ kTestDir + "/etc/lsb-release",
+ "CHROMEOS_RELEASE_BOARD=arm-generic\n"
+ "CHROMEOS_RELEASE_FOO=bar\n"
+ "CHROMEOS_RELEASE_TRACK=footrack"));
+ OmahaRequestParams out;
+ EXPECT_TRUE(DoTest(&out, "ForcedVersion", ""));
+ EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id;
+ // for now we're just using the machine id here
+ EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id;
+ EXPECT_EQ("Chrome OS", out.os_platform);
+ EXPECT_EQ(string("ForcedVersion_") + GetMachineType(), out.os_sp);
+ EXPECT_EQ("arm-generic", out.os_board);
+ EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.app_id);
+ EXPECT_EQ("ForcedVersion", out.app_version);
+ EXPECT_EQ("en-US", out.app_lang);
+ EXPECT_TRUE(out.delta_okay);
+ EXPECT_EQ("footrack", out.app_track);
+}
+
+TEST_F(OmahaRequestDeviceParamsTest, ForcedURLTest) {
+ 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"));
+ OmahaRequestParams out;
+ EXPECT_TRUE(DoTest(&out, "", "http://forced.google.com"));
+ EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id;
+ // for now we're just using the machine id here
+ EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id;
+ 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_TRUE(out.delta_okay);
+ EXPECT_EQ("footrack", out.app_track);
+ EXPECT_EQ("http://forced.google.com", out.update_url);
+}
+
+TEST_F(OmahaRequestDeviceParamsTest, MissingURLTest) {
+ 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"));
+ OmahaRequestParams out;
+ EXPECT_TRUE(DoTest(&out, "", ""));
+ EXPECT_TRUE(IsValidGuid(out.machine_id)) << "id: " << out.machine_id;
+ // for now we're just using the machine id here
+ EXPECT_TRUE(IsValidGuid(out.user_id)) << "id: " << out.user_id;
+ 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_TRUE(out.delta_okay);
+ EXPECT_EQ("footrack", out.app_track);
+ EXPECT_EQ(OmahaRequestParams::kUpdateUrl, out.update_url);
}
TEST_F(OmahaRequestDeviceParamsTest, NoDeltasTest) {
- ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc"));
- ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir +
- utils::kStatefulPartition + "/etc"));
ASSERT_TRUE(WriteFileString(
kTestDir + "/etc/lsb-release",
"CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
@@ -188,9 +267,8 @@ TEST_F(OmahaRequestDeviceParamsTest, NoDeltasTest) {
"CHROMEOS_RELEASE_TRXCK=footrack"));
ASSERT_TRUE(WriteFileString(kTestDir + "/.nodelta", ""));
OmahaRequestParams out;
- EXPECT_TRUE(DoTest(&out));
+ EXPECT_TRUE(DoTest(&out, "", ""));
EXPECT_FALSE(out.delta_okay);
- EXPECT_EQ(0, System(string("rm -rf ") + kTestDir));
}
} // namespace chromeos_update_engine
« no previous file with comments | « omaha_request_params.cc ('k') | update_attempter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698