Add support to update_engine_client for -app_version and -omaha_url.
These options prevent auto-detection of these parameters.
Note that this CL makes the check_for_update DBus method obsolete from
the client's point of view.
BUG=4593
TEST=unit tests, gmerged on device and tried the client with different options.
Review URL: http://codereview.chromium.org/3048008
diff --git a/omaha_request_params_unittest.cc b/omaha_request_params_unittest.cc
index 200b23b..07615a2 100644
--- a/omaha_request_params_unittest.cc
+++ b/omaha_request_params_unittest.cc
@@ -15,20 +15,34 @@
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 @@
} // 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 @@
&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 @@
"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