Fix OmahaRequest unittests in Brillo.
Moved lsb_release related tests to ImagePropertiesTest.
Bug: 26955860
Test: GTEST_FILTER="Omaha*" ./update_engine_unittests
Test: cros_workon_make update_engine --test
Change-Id: I124c9374e7556b04c65bdac80e1b89064dee4008
diff --git a/image_properties_chromeos_unittest.cc b/image_properties_chromeos_unittest.cc
new file mode 100644
index 0000000..12c2039
--- /dev/null
+++ b/image_properties_chromeos_unittest.cc
@@ -0,0 +1,166 @@
+//
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "update_engine/image_properties.h"
+
+#include <string>
+
+#include <base/files/file_util.h>
+#include <base/files/scoped_temp_dir.h>
+#include <gtest/gtest.h>
+
+#include "update_engine/common/constants.h"
+#include "update_engine/common/test_utils.h"
+#include "update_engine/fake_system_state.h"
+
+using chromeos_update_engine::test_utils::WriteFileString;
+using std::string;
+
+namespace chromeos_update_engine {
+
+class ImagePropertiesTest : public ::testing::Test {
+ protected:
+ void SetUp() override {
+ // Create a uniquely named test directory.
+ ASSERT_TRUE(tempdir_.CreateUniqueTempDir());
+ EXPECT_TRUE(base::CreateDirectory(tempdir_.path().Append("etc")));
+ EXPECT_TRUE(base::CreateDirectory(
+ base::FilePath(tempdir_.path().value() + kStatefulPartition + "/etc")));
+ test::SetImagePropertiesRootPrefix(tempdir_.path().value().c_str());
+ SetLockDown(false);
+ }
+
+ void SetLockDown(bool locked_down) {
+ fake_system_state_.fake_hardware()->SetIsOfficialBuild(locked_down);
+ fake_system_state_.fake_hardware()->SetIsNormalBootMode(locked_down);
+ }
+
+ FakeSystemState fake_system_state_;
+
+ base::ScopedTempDir tempdir_;
+};
+
+TEST_F(ImagePropertiesTest, SimpleTest) {
+ ASSERT_TRUE(WriteFileString(tempdir_.path().Append("etc/lsb-release").value(),
+ "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"));
+ ImageProperties props = LoadImageProperties(&fake_system_state_);
+ EXPECT_EQ("arm-generic", props.board);
+ EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", props.product_id);
+ EXPECT_EQ("0.2.2.3", props.version);
+ EXPECT_EQ("dev-channel", props.current_channel);
+ EXPECT_EQ("http://www.google.com", props.omaha_url);
+}
+
+TEST_F(ImagePropertiesTest, AppIDTest) {
+ ASSERT_TRUE(WriteFileString(
+ tempdir_.path().Append("etc/lsb-release").value(),
+ "CHROMEOS_RELEASE_APPID={58c35cef-9d30-476e-9098-ce20377d535d}"));
+ ImageProperties props = LoadImageProperties(&fake_system_state_);
+ EXPECT_EQ("{58c35cef-9d30-476e-9098-ce20377d535d}", props.product_id);
+}
+
+TEST_F(ImagePropertiesTest, ConfusingReleaseTest) {
+ ASSERT_TRUE(
+ WriteFileString(tempdir_.path().Append("etc/lsb-release").value(),
+ "CHROMEOS_RELEASE_FOO=CHROMEOS_RELEASE_VERSION=1.2.3.4\n"
+ "CHROMEOS_RELEASE_VERSION=0.2.2.3"));
+ ImageProperties props = LoadImageProperties(&fake_system_state_);
+ EXPECT_EQ("0.2.2.3", props.version);
+}
+
+TEST_F(ImagePropertiesTest, MissingVersionTest) {
+ ImageProperties props = LoadImageProperties(&fake_system_state_);
+ EXPECT_EQ("", props.version);
+}
+
+TEST_F(ImagePropertiesTest, OverrideTest) {
+ ASSERT_TRUE(WriteFileString(tempdir_.path().Append("etc/lsb-release").value(),
+ "CHROMEOS_RELEASE_BOARD=arm-generic\n"
+ "CHROMEOS_RELEASE_FOO=bar\n"
+ "CHROMEOS_RELEASE_TRACK=dev-channel\n"
+ "CHROMEOS_AUSERVER=http://www.google.com"));
+ ASSERT_TRUE(WriteFileString(
+ tempdir_.path().value() + kStatefulPartition + "/etc/lsb-release",
+ "CHROMEOS_RELEASE_BOARD=x86-generic\n"
+ "CHROMEOS_RELEASE_TRACK=beta-channel\n"
+ "CHROMEOS_AUSERVER=https://www.google.com"));
+ ImageProperties props = LoadImageProperties(&fake_system_state_);
+ EXPECT_EQ("x86-generic", props.board);
+ EXPECT_EQ("dev-channel", props.current_channel);
+ EXPECT_EQ("https://www.google.com", props.omaha_url);
+ MutableImageProperties mutable_props =
+ LoadMutableImageProperties(&fake_system_state_);
+ EXPECT_EQ("beta-channel", mutable_props.target_channel);
+}
+
+TEST_F(ImagePropertiesTest, OverrideLockDownTest) {
+ ASSERT_TRUE(WriteFileString(tempdir_.path().Append("etc/lsb-release").value(),
+ "CHROMEOS_RELEASE_BOARD=arm-generic\n"
+ "CHROMEOS_RELEASE_FOO=bar\n"
+ "CHROMEOS_RELEASE_TRACK=dev-channel\n"
+ "CHROMEOS_AUSERVER=https://www.google.com"));
+ ASSERT_TRUE(WriteFileString(
+ tempdir_.path().value() + kStatefulPartition + "/etc/lsb-release",
+ "CHROMEOS_RELEASE_BOARD=x86-generic\n"
+ "CHROMEOS_RELEASE_TRACK=stable-channel\n"
+ "CHROMEOS_AUSERVER=http://www.google.com"));
+ SetLockDown(true);
+ ImageProperties props = LoadImageProperties(&fake_system_state_);
+ EXPECT_EQ("arm-generic", props.board);
+ EXPECT_EQ("dev-channel", props.current_channel);
+ EXPECT_EQ("https://www.google.com", props.omaha_url);
+ MutableImageProperties mutable_props =
+ LoadMutableImageProperties(&fake_system_state_);
+ EXPECT_EQ("stable-channel", mutable_props.target_channel);
+}
+
+TEST_F(ImagePropertiesTest, BoardAppIdUsedForNonCanaryChannelTest) {
+ ASSERT_TRUE(WriteFileString(tempdir_.path().Append("etc/lsb-release").value(),
+ "CHROMEOS_RELEASE_APPID=r\n"
+ "CHROMEOS_BOARD_APPID=b\n"
+ "CHROMEOS_CANARY_APPID=c\n"
+ "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
+ ImageProperties props = LoadImageProperties(&fake_system_state_);
+ EXPECT_EQ("stable-channel", props.current_channel);
+ EXPECT_EQ("b", props.product_id);
+}
+
+TEST_F(ImagePropertiesTest, CanaryAppIdUsedForCanaryChannelTest) {
+ ASSERT_TRUE(WriteFileString(tempdir_.path().Append("etc/lsb-release").value(),
+ "CHROMEOS_RELEASE_APPID=r\n"
+ "CHROMEOS_BOARD_APPID=b\n"
+ "CHROMEOS_CANARY_APPID=c\n"
+ "CHROMEOS_RELEASE_TRACK=canary-channel\n"));
+ ImageProperties props = LoadImageProperties(&fake_system_state_);
+ EXPECT_EQ("canary-channel", props.current_channel);
+ EXPECT_EQ("c", props.canary_product_id);
+}
+
+TEST_F(ImagePropertiesTest, ReleaseAppIdUsedAsDefaultTest) {
+ ASSERT_TRUE(WriteFileString(tempdir_.path().Append("etc/lsb-release").value(),
+ "CHROMEOS_RELEASE_APPID=r\n"
+ "CHROMEOS_CANARY_APPID=c\n"
+ "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
+ ImageProperties props = LoadImageProperties(&fake_system_state_);
+ EXPECT_EQ("stable-channel", props.current_channel);
+ EXPECT_EQ("r", props.product_id);
+}
+
+} // namespace chromeos_update_engine
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
index 39bc5cd..496143e 100644
--- a/omaha_request_action_unittest.cc
+++ b/omaha_request_action_unittest.cc
@@ -23,6 +23,7 @@
#include <base/bind.h>
#include <base/files/file_util.h>
+#include <base/files/scoped_temp_dir.h>
#include <base/strings/string_number_conversions.h>
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>
@@ -42,7 +43,6 @@
#include "update_engine/common/platform_constants.h"
#include "update_engine/common/prefs.h"
#include "update_engine/common/test_utils.h"
-#include "update_engine/common/utils.h"
#include "update_engine/fake_system_state.h"
#include "update_engine/metrics.h"
#include "update_engine/mock_connection_manager.h"
@@ -1805,30 +1805,17 @@
TEST_F(OmahaRequestActionTest, TestChangingToMoreStableChannel) {
// Create a uniquely named test directory.
- string test_dir;
- ASSERT_TRUE(utils::MakeTempDirectory(
- "omaha_request_action-test-XXXXXX", &test_dir));
+ base::ScopedTempDir tempdir;
+ ASSERT_TRUE(tempdir.CreateUniqueTempDir());
- ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + "/etc"));
- ASSERT_EQ(0, System(string("mkdir -p ") + test_dir +
- kStatefulPartition + "/etc"));
brillo::Blob post_data;
- NiceMock<MockPrefs> prefs;
- fake_system_state_.set_prefs(&prefs);
- ASSERT_TRUE(WriteFileString(
- test_dir + "/etc/lsb-release",
- "CHROMEOS_RELEASE_APPID={11111111-1111-1111-1111-111111111111}\n"
- "CHROMEOS_BOARD_APPID={22222222-2222-2222-2222-222222222222}\n"
- "CHROMEOS_RELEASE_TRACK=canary-channel\n"));
- ASSERT_TRUE(WriteFileString(
- test_dir + kStatefulPartition + "/etc/lsb-release",
- "CHROMEOS_IS_POWERWASH_ALLOWED=true\n"
- "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
- OmahaRequestParams params = request_params_;
- params.set_root(test_dir);
- params.Init("1.2.3.4", "", 0);
- EXPECT_EQ("canary-channel", params.current_channel());
- EXPECT_EQ("stable-channel", params.target_channel());
+ OmahaRequestParams params(&fake_system_state_);
+ params.set_root(tempdir.path().value());
+ params.set_app_id("{22222222-2222-2222-2222-222222222222}");
+ params.set_app_version("1.2.3.4");
+ params.set_current_channel("canary-channel");
+ EXPECT_TRUE(params.SetTargetChannel("stable-channel", true, nullptr));
+ params.UpdateDownloadChannel();
EXPECT_TRUE(params.to_more_stable_channel());
EXPECT_TRUE(params.is_powerwash_allowed());
ASSERT_FALSE(TestUpdateCheck(¶ms,
@@ -1847,35 +1834,21 @@
"appid=\"{22222222-2222-2222-2222-222222222222}\" "
"version=\"0.0.0.0\" from_version=\"1.2.3.4\" "
"track=\"stable-channel\" from_track=\"canary-channel\" "));
-
- ASSERT_TRUE(base::DeleteFile(base::FilePath(test_dir), true));
}
TEST_F(OmahaRequestActionTest, TestChangingToLessStableChannel) {
// Create a uniquely named test directory.
- string test_dir;
- ASSERT_TRUE(utils::MakeTempDirectory(
- "omaha_request_action-test-XXXXXX", &test_dir));
+ base::ScopedTempDir tempdir;
+ ASSERT_TRUE(tempdir.CreateUniqueTempDir());
- ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + "/etc"));
- ASSERT_EQ(0, System(string("mkdir -p ") + test_dir +
- kStatefulPartition + "/etc"));
brillo::Blob post_data;
- NiceMock<MockPrefs> prefs;
- fake_system_state_.set_prefs(&prefs);
- ASSERT_TRUE(WriteFileString(
- test_dir + "/etc/lsb-release",
- "CHROMEOS_RELEASE_APPID={11111111-1111-1111-1111-111111111111}\n"
- "CHROMEOS_BOARD_APPID={22222222-2222-2222-2222-222222222222}\n"
- "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
- ASSERT_TRUE(WriteFileString(
- test_dir + kStatefulPartition + "/etc/lsb-release",
- "CHROMEOS_RELEASE_TRACK=canary-channel\n"));
- OmahaRequestParams params = request_params_;
- params.set_root(test_dir);
- params.Init("5.6.7.8", "", 0);
- EXPECT_EQ("stable-channel", params.current_channel());
- EXPECT_EQ("canary-channel", params.target_channel());
+ OmahaRequestParams params(&fake_system_state_);
+ params.set_root(tempdir.path().value());
+ params.set_app_id("{11111111-1111-1111-1111-111111111111}");
+ params.set_app_version("5.6.7.8");
+ params.set_current_channel("stable-channel");
+ EXPECT_TRUE(params.SetTargetChannel("canary-channel", false, nullptr));
+ params.UpdateDownloadChannel();
EXPECT_FALSE(params.to_more_stable_channel());
EXPECT_FALSE(params.is_powerwash_allowed());
ASSERT_FALSE(TestUpdateCheck(¶ms,
diff --git a/omaha_request_params.h b/omaha_request_params.h
index b4534a1..379563a 100644
--- a/omaha_request_params.h
+++ b/omaha_request_params.h
@@ -106,6 +106,10 @@
inline std::string canary_app_id() const {
return image_props_.canary_product_id;
}
+ inline void set_app_id(const std::string& app_id) {
+ image_props_.product_id = app_id;
+ image_props_.canary_product_id = app_id;
+ }
inline std::string app_lang() const { return app_lang_; }
inline std::string hwid() const { return hwid_; }
inline std::string fw_version() const { return fw_version_; }
@@ -236,9 +240,8 @@
private:
FRIEND_TEST(OmahaRequestParamsTest, IsValidChannelTest);
- FRIEND_TEST(OmahaRequestParamsTest, ShouldLockDownTest);
FRIEND_TEST(OmahaRequestParamsTest, ChannelIndexTest);
- FRIEND_TEST(OmahaRequestParamsTest, LsbPreserveTest);
+ FRIEND_TEST(OmahaRequestParamsTest, ToMoreStableChannelFlagTest);
FRIEND_TEST(OmahaRequestParamsTest, CollectECFWVersionsTest);
// Returns true if |channel| is a valid channel, false otherwise.
diff --git a/omaha_request_params_unittest.cc b/omaha_request_params_unittest.cc
index 33dd6d5..7d4dc2d 100644
--- a/omaha_request_params_unittest.cc
+++ b/omaha_request_params_unittest.cc
@@ -21,14 +21,15 @@
#include <string>
#include <base/files/file_util.h>
+#include <base/files/scoped_temp_dir.h>
#include <gtest/gtest.h>
#include "update_engine/common/constants.h"
+#include "update_engine/common/fake_prefs.h"
#include "update_engine/common/platform_constants.h"
#include "update_engine/common/test_utils.h"
#include "update_engine/common/utils.h"
#include "update_engine/fake_system_state.h"
-#include "update_engine/payload_consumer/install_plan.h"
using chromeos_update_engine::test_utils::WriteFileString;
using std::string;
@@ -40,27 +41,15 @@
OmahaRequestParamsTest() : params_(&fake_system_state_) {}
protected:
- // Return true iff the OmahaRequestParams::Init succeeded. If
- // out is non-null, it's set w/ the generated data.
- bool DoTest(OmahaRequestParams* out, const string& app_version,
- const string& omaha_url);
-
void SetUp() override {
// Create a uniquely named test directory.
- ASSERT_TRUE(utils::MakeTempDirectory(kTestDirTemplate, &test_dir_));
- EXPECT_TRUE(base::CreateDirectory(base::FilePath(test_dir_ + "/etc")));
- EXPECT_TRUE(base::CreateDirectory(
- base::FilePath(test_dir_ + kStatefulPartition + "/etc")));
+ ASSERT_TRUE(tempdir_.CreateUniqueTempDir());
// Create a fresh copy of the params for each test, so there's no
// unintended reuse of state across tests.
- OmahaRequestParams new_params(&fake_system_state_);
- params_ = new_params;
- params_.set_root(test_dir_);
+ params_ = OmahaRequestParams(&fake_system_state_);
+ params_.set_root(tempdir_.path().value());
SetLockDown(false);
- }
-
- void TearDown() override {
- EXPECT_TRUE(base::DeleteFile(base::FilePath(test_dir_), true));
+ fake_system_state_.set_prefs(&fake_prefs_);
}
void SetLockDown(bool locked_down) {
@@ -70,23 +59,11 @@
OmahaRequestParams params_;
FakeSystemState fake_system_state_;
+ FakePrefs fake_prefs_;
- static const char* kTestDirTemplate;
- string test_dir_;
+ base::ScopedTempDir tempdir_;
};
-const char* OmahaRequestParamsTest::kTestDirTemplate =
- "omaha_request_params-test-XXXXXX";
-
-bool OmahaRequestParamsTest::DoTest(OmahaRequestParams* out,
- const string& app_version,
- const string& omaha_url) {
- bool success = params_.Init(app_version, omaha_url, false);
- if (out)
- *out = params_;
- return success;
-}
-
namespace {
string GetMachineType() {
string machine_type;
@@ -100,302 +77,71 @@
}
} // namespace
-TEST_F(OmahaRequestParamsTest, SimpleTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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"));
- OmahaRequestParams out(&fake_system_state_);
- 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.GetAppId());
- EXPECT_EQ("0.2.2.3", out.app_version());
- EXPECT_EQ("en-US", out.app_lang());
- EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
- EXPECT_TRUE(out.delta_okay());
- EXPECT_EQ("dev-channel", out.target_channel());
- EXPECT_EQ("http://www.google.com", out.update_url());
-}
-
-TEST_F(OmahaRequestParamsTest, AppIDTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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_RELEASE_APPID={58c35cef-9d30-476e-9098-ce20377d535d}\n"
- "CHROMEOS_AUSERVER=http://www.google.com"));
- OmahaRequestParams out(&fake_system_state_);
- 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("{58c35cef-9d30-476e-9098-ce20377d535d}", out.GetAppId());
- EXPECT_EQ("0.2.2.3", out.app_version());
- EXPECT_EQ("en-US", out.app_lang());
- EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
- EXPECT_TRUE(out.delta_okay());
- EXPECT_EQ("dev-channel", out.target_channel());
- EXPECT_EQ("http://www.google.com", out.update_url());
-}
-
TEST_F(OmahaRequestParamsTest, MissingChannelTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/etc/lsb-release",
- "CHROMEOS_RELEASE_FOO=bar\n"
- "CHROMEOS_RELEASE_VERSION=0.2.2.3\n"
- "CHROMEOS_RELEASE_TRXCK=dev-channel"));
- OmahaRequestParams out(&fake_system_state_);
- EXPECT_TRUE(DoTest(&out, "", ""));
- 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.GetAppId());
- EXPECT_EQ("0.2.2.3", out.app_version());
- EXPECT_EQ("en-US", out.app_lang());
+ EXPECT_TRUE(params_.Init("", "", false));
// By default, if no channel is set, we should track the stable-channel.
- EXPECT_EQ("stable-channel", out.target_channel());
-}
-
-TEST_F(OmahaRequestParamsTest, ConfusingReleaseTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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=dev-channel"));
- OmahaRequestParams out(&fake_system_state_);
- EXPECT_TRUE(DoTest(&out, "", ""));
- 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.GetAppId());
- EXPECT_EQ("0.2.2.3", out.app_version());
- EXPECT_EQ("en-US", out.app_lang());
- EXPECT_EQ("stable-channel", out.target_channel());
-}
-
-TEST_F(OmahaRequestParamsTest, MissingVersionTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/etc/lsb-release",
- "CHROMEOS_RELEASE_BOARD=arm-generic\n"
- "CHROMEOS_RELEASE_FOO=bar\n"
- "CHROMEOS_RELEASE_TRACK=dev-channel"));
- OmahaRequestParams out(&fake_system_state_);
- EXPECT_TRUE(DoTest(&out, "", ""));
- 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.GetAppId());
- EXPECT_EQ("", out.app_version());
- EXPECT_EQ("en-US", out.app_lang());
- EXPECT_TRUE(out.delta_okay());
- EXPECT_EQ("dev-channel", out.target_channel());
+ EXPECT_EQ("stable-channel", params_.target_channel());
}
TEST_F(OmahaRequestParamsTest, ForceVersionTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/etc/lsb-release",
- "CHROMEOS_RELEASE_BOARD=arm-generic\n"
- "CHROMEOS_RELEASE_FOO=bar\n"
- "CHROMEOS_RELEASE_TRACK=dev-channel"));
- OmahaRequestParams out(&fake_system_state_);
- EXPECT_TRUE(DoTest(&out, "ForcedVersion", ""));
- 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.GetAppId());
- EXPECT_EQ("ForcedVersion", out.app_version());
- EXPECT_EQ("en-US", out.app_lang());
- EXPECT_TRUE(out.delta_okay());
- EXPECT_EQ("dev-channel", out.target_channel());
+ EXPECT_TRUE(params_.Init("ForcedVersion", "", false));
+ EXPECT_EQ(string("ForcedVersion_") + GetMachineType(), params_.os_sp());
+ EXPECT_EQ("ForcedVersion", params_.app_version());
}
TEST_F(OmahaRequestParamsTest, ForcedURLTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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"));
- OmahaRequestParams out(&fake_system_state_);
- EXPECT_TRUE(DoTest(&out, "", "http://forced.google.com"));
- 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.GetAppId());
- EXPECT_EQ("0.2.2.3", out.app_version());
- EXPECT_EQ("en-US", out.app_lang());
- EXPECT_TRUE(out.delta_okay());
- EXPECT_EQ("dev-channel", out.target_channel());
- EXPECT_EQ("http://forced.google.com", out.update_url());
+ EXPECT_TRUE(params_.Init("", "http://forced.google.com", false));
+ EXPECT_EQ("http://forced.google.com", params_.update_url());
}
TEST_F(OmahaRequestParamsTest, MissingURLTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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"));
- OmahaRequestParams out(&fake_system_state_);
- 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.GetAppId());
- EXPECT_EQ("0.2.2.3", out.app_version());
- EXPECT_EQ("en-US", out.app_lang());
- EXPECT_TRUE(out.delta_okay());
- EXPECT_EQ("dev-channel", out.target_channel());
- EXPECT_EQ(constants::kOmahaDefaultProductionURL, out.update_url());
+ EXPECT_TRUE(params_.Init("", "", false));
+ EXPECT_EQ(constants::kOmahaDefaultProductionURL, params_.update_url());
+}
+
+TEST_F(OmahaRequestParamsTest, DeltaOKTest) {
+ EXPECT_TRUE(params_.Init("", "", false));
+ EXPECT_TRUE(params_.delta_okay());
}
TEST_F(OmahaRequestParamsTest, NoDeltasTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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=dev-channel"));
- ASSERT_TRUE(WriteFileString(test_dir_ + "/.nodelta", ""));
- OmahaRequestParams out(&fake_system_state_);
- EXPECT_TRUE(DoTest(&out, "", ""));
- EXPECT_FALSE(out.delta_okay());
-}
-
-TEST_F(OmahaRequestParamsTest, OverrideTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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"));
- ASSERT_TRUE(WriteFileString(
- test_dir_ + kStatefulPartition + "/etc/lsb-release",
- "CHROMEOS_RELEASE_BOARD=x86-generic\n"
- "CHROMEOS_RELEASE_TRACK=beta-channel\n"
- "CHROMEOS_AUSERVER=https://www.google.com"));
- OmahaRequestParams out(&fake_system_state_);
- 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.GetAppId());
- EXPECT_EQ("0.2.2.3", out.app_version());
- EXPECT_EQ("en-US", out.app_lang());
- EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
- EXPECT_FALSE(out.delta_okay());
- EXPECT_EQ("beta-channel", out.target_channel());
- EXPECT_EQ("https://www.google.com", out.update_url());
-}
-
-TEST_F(OmahaRequestParamsTest, OverrideLockDownTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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=https://www.google.com"));
- ASSERT_TRUE(WriteFileString(
- test_dir_ + kStatefulPartition + "/etc/lsb-release",
- "CHROMEOS_RELEASE_BOARD=x86-generic\n"
- "CHROMEOS_RELEASE_TRACK=stable-channel\n"
- "CHROMEOS_AUSERVER=http://www.google.com"));
- SetLockDown(true);
- OmahaRequestParams out(&fake_system_state_);
- EXPECT_TRUE(DoTest(&out, "", ""));
- EXPECT_EQ("arm-generic", out.os_board());
- EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
- EXPECT_EQ("0.2.2.3", out.app_version());
- EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
- EXPECT_FALSE(out.delta_okay());
- EXPECT_EQ("stable-channel", out.target_channel());
- EXPECT_EQ("https://www.google.com", out.update_url());
-}
-
-TEST_F(OmahaRequestParamsTest, OverrideSameChannelTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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"));
- ASSERT_TRUE(WriteFileString(
- test_dir_ + kStatefulPartition + "/etc/lsb-release",
- "CHROMEOS_RELEASE_BOARD=x86-generic\n"
- "CHROMEOS_RELEASE_TRACK=dev-channel"));
- OmahaRequestParams out(&fake_system_state_);
- EXPECT_TRUE(DoTest(&out, "", ""));
- EXPECT_EQ("x86-generic", out.os_board());
- EXPECT_EQ("{87efface-864d-49a5-9bb3-4b050a7c227a}", out.GetAppId());
- EXPECT_EQ("0.2.2.3", out.app_version());
- EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
- EXPECT_TRUE(out.delta_okay());
- EXPECT_EQ("dev-channel", out.target_channel());
- EXPECT_EQ("http://www.google.com", out.update_url());
+ ASSERT_TRUE(WriteFileString(tempdir_.path().Append(".nodelta").value(), ""));
+ EXPECT_TRUE(params_.Init("", "", false));
+ EXPECT_FALSE(params_.delta_okay());
}
TEST_F(OmahaRequestParamsTest, SetTargetChannelTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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"));
{
OmahaRequestParams params(&fake_system_state_);
- params.set_root(test_dir_);
+ params.set_root(tempdir_.path().value());
EXPECT_TRUE(params.Init("", "", false));
- params.SetTargetChannel("canary-channel", false, nullptr);
+ EXPECT_TRUE(params.SetTargetChannel("canary-channel", false, nullptr));
EXPECT_FALSE(params.is_powerwash_allowed());
}
- OmahaRequestParams out(&fake_system_state_);
- out.set_root(test_dir_);
- EXPECT_TRUE(DoTest(&out, "", ""));
- EXPECT_EQ("canary-channel", out.target_channel());
- EXPECT_FALSE(out.is_powerwash_allowed());
+ params_.set_root(tempdir_.path().value());
+ EXPECT_TRUE(params_.Init("", "", false));
+ EXPECT_EQ("canary-channel", params_.target_channel());
+ EXPECT_FALSE(params_.is_powerwash_allowed());
}
TEST_F(OmahaRequestParamsTest, SetIsPowerwashAllowedTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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"));
{
OmahaRequestParams params(&fake_system_state_);
- params.set_root(test_dir_);
+ params.set_root(tempdir_.path().value());
EXPECT_TRUE(params.Init("", "", false));
- params.SetTargetChannel("canary-channel", true, nullptr);
+ EXPECT_TRUE(params.SetTargetChannel("canary-channel", true, nullptr));
EXPECT_TRUE(params.is_powerwash_allowed());
}
- OmahaRequestParams out(&fake_system_state_);
- out.set_root(test_dir_);
- EXPECT_TRUE(DoTest(&out, "", ""));
- EXPECT_EQ("canary-channel", out.target_channel());
- EXPECT_TRUE(out.is_powerwash_allowed());
+ params_.set_root(tempdir_.path().value());
+ EXPECT_TRUE(params_.Init("", "", false));
+ EXPECT_EQ("canary-channel", params_.target_channel());
+ EXPECT_TRUE(params_.is_powerwash_allowed());
}
TEST_F(OmahaRequestParamsTest, SetTargetChannelInvalidTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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"));
{
OmahaRequestParams params(&fake_system_state_);
- params.set_root(test_dir_);
+ params.set_root(tempdir_.path().value());
SetLockDown(true);
EXPECT_TRUE(params.Init("", "", false));
string error_message;
@@ -405,12 +151,10 @@
EXPECT_NE(string::npos, error_message.find("stable-channel"));
EXPECT_FALSE(params.is_powerwash_allowed());
}
- OmahaRequestParams out(&fake_system_state_);
- out.set_root(test_dir_);
- EXPECT_TRUE(DoTest(&out, "", ""));
- EXPECT_EQ("arm-generic", out.os_board());
- EXPECT_EQ("dev-channel", out.target_channel());
- EXPECT_FALSE(out.is_powerwash_allowed());
+ params_.set_root(tempdir_.path().value());
+ EXPECT_TRUE(params_.Init("", "", false));
+ EXPECT_EQ("stable-channel", params_.target_channel());
+ EXPECT_FALSE(params_.is_powerwash_allowed());
}
TEST_F(OmahaRequestParamsTest, IsValidChannelTest) {
@@ -424,69 +168,29 @@
EXPECT_FALSE(params_.IsValidChannel(""));
}
-TEST_F(OmahaRequestParamsTest, ValidChannelTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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"));
- SetLockDown(true);
- OmahaRequestParams out(&fake_system_state_);
- 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.GetAppId());
- EXPECT_EQ("0.2.2.3", out.app_version());
- EXPECT_EQ("en-US", out.app_lang());
- EXPECT_EQ(fake_system_state_.hardware()->GetHardwareClass(), out.hwid());
- EXPECT_TRUE(out.delta_okay());
- EXPECT_EQ("dev-channel", out.target_channel());
- EXPECT_EQ("http://www.google.com", out.update_url());
-}
-
TEST_F(OmahaRequestParamsTest, SetTargetChannelWorks) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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"));
-
- // Check LSB value is used by default when SetTargetChannel is not called.
- params_.Init("", "", false);
+ params_.set_target_channel("dev-channel");
EXPECT_EQ("dev-channel", params_.target_channel());
- // When an invalid value is set, it should be ignored and the
- // value from lsb-release should be used instead.
- params_.Init("", "", false);
+ // When an invalid value is set, it should be ignored.
EXPECT_FALSE(params_.SetTargetChannel("invalid-channel", false, nullptr));
EXPECT_EQ("dev-channel", params_.target_channel());
// When set to a valid value, it should take effect.
- params_.Init("", "", false);
EXPECT_TRUE(params_.SetTargetChannel("beta-channel", true, nullptr));
EXPECT_EQ("beta-channel", params_.target_channel());
// When set to the same value, it should be idempotent.
- params_.Init("", "", false);
EXPECT_TRUE(params_.SetTargetChannel("beta-channel", true, nullptr));
EXPECT_EQ("beta-channel", params_.target_channel());
// When set to a valid value while a change is already pending, it should
// succeed.
- params_.Init("", "", false);
EXPECT_TRUE(params_.SetTargetChannel("stable-channel", true, nullptr));
EXPECT_EQ("stable-channel", params_.target_channel());
- // Set a different channel in stateful LSB release.
- ASSERT_TRUE(WriteFileString(
- test_dir_ + kStatefulPartition + "/etc/lsb-release",
- "CHROMEOS_RELEASE_TRACK=stable-channel\n"
- "CHROMEOS_IS_POWERWASH_ALLOWED=true\n"));
+ // Set a different channel in mutable_image_props_.
+ params_.set_target_channel("stable-channel");
// When set to a valid value while a change is already pending, it should
// succeed.
@@ -520,79 +224,20 @@
}
TEST_F(OmahaRequestParamsTest, ToMoreStableChannelFlagTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/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=canary-channel\n"
- "CHROMEOS_AUSERVER=http://www.google.com"));
- ASSERT_TRUE(WriteFileString(
- test_dir_ + kStatefulPartition + "/etc/lsb-release",
- "CHROMEOS_RELEASE_BOARD=x86-generic\n"
- "CHROMEOS_RELEASE_TRACK=stable-channel\n"
- "CHROMEOS_AUSERVER=https://www.google.com"));
- OmahaRequestParams out(&fake_system_state_);
- EXPECT_TRUE(DoTest(&out, "", ""));
- EXPECT_EQ("https://www.google.com", out.update_url());
- EXPECT_FALSE(out.delta_okay());
- EXPECT_EQ("stable-channel", out.target_channel());
- EXPECT_TRUE(out.to_more_stable_channel());
-}
-
-TEST_F(OmahaRequestParamsTest, BoardAppIdUsedForNonCanaryChannelTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/etc/lsb-release",
- "CHROMEOS_RELEASE_APPID=r\n"
- "CHROMEOS_BOARD_APPID=b\n"
- "CHROMEOS_CANARY_APPID=c\n"
- "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
- OmahaRequestParams out(&fake_system_state_);
- EXPECT_TRUE(DoTest(&out, "", ""));
- EXPECT_EQ("stable-channel", out.download_channel());
- EXPECT_EQ("b", out.GetAppId());
-}
-
-TEST_F(OmahaRequestParamsTest, CanaryAppIdUsedForCanaryChannelTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/etc/lsb-release",
- "CHROMEOS_RELEASE_APPID=r\n"
- "CHROMEOS_BOARD_APPID=b\n"
- "CHROMEOS_CANARY_APPID=c\n"
- "CHROMEOS_RELEASE_TRACK=canary-channel\n"));
- OmahaRequestParams out(&fake_system_state_);
- EXPECT_TRUE(DoTest(&out, "", ""));
- EXPECT_EQ("canary-channel", out.download_channel());
- EXPECT_EQ("c", out.GetAppId());
-}
-
-TEST_F(OmahaRequestParamsTest, ReleaseAppIdUsedAsDefaultTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/etc/lsb-release",
- "CHROMEOS_RELEASE_APPID=r\n"
- "CHROMEOS_CANARY_APPID=c\n"
- "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
- OmahaRequestParams out(&fake_system_state_);
- EXPECT_TRUE(DoTest(&out, "", ""));
- EXPECT_EQ("stable-channel", out.download_channel());
- EXPECT_EQ("r", out.GetAppId());
+ params_.image_props_.current_channel = "canary-channel";
+ params_.download_channel_ = "stable-channel";
+ EXPECT_TRUE(params_.to_more_stable_channel());
}
TEST_F(OmahaRequestParamsTest, CollectECFWVersionsTest) {
- ASSERT_TRUE(WriteFileString(
- test_dir_ + "/etc/lsb-release",
- "CHROMEOS_RELEASE_APPID=r\n"
- "CHROMEOS_CANARY_APPID=c\n"
- "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
- OmahaRequestParams out(&fake_system_state_);
- out.hwid_ = string("STUMPY ALEX 12345");
- EXPECT_FALSE(out.CollectECFWVersions());
+ params_.hwid_ = string("STUMPY ALEX 12345");
+ EXPECT_FALSE(params_.CollectECFWVersions());
- out.hwid_ = string("SNOW 12345");
- EXPECT_TRUE(out.CollectECFWVersions());
+ params_.hwid_ = string("SNOW 12345");
+ EXPECT_TRUE(params_.CollectECFWVersions());
- out.hwid_ = string("SAMS ALEX 12345");
- EXPECT_TRUE(out.CollectECFWVersions());
+ params_.hwid_ = string("SAMS ALEX 12345");
+ EXPECT_TRUE(params_.CollectECFWVersions());
}
} // namespace chromeos_update_engine
diff --git a/omaha_response_handler_action_unittest.cc b/omaha_response_handler_action_unittest.cc
index 4917162..60b139b 100644
--- a/omaha_response_handler_action_unittest.cc
+++ b/omaha_response_handler_action_unittest.cc
@@ -19,6 +19,7 @@
#include <string>
#include <base/files/file_util.h>
+#include <base/files/scoped_temp_dir.h>
#include <gtest/gtest.h>
#include "update_engine/common/constants.h"
@@ -33,6 +34,7 @@
using chromeos_update_engine::test_utils::WriteFileString;
using std::string;
using testing::Return;
+using testing::_;
namespace chromeos_update_engine {
@@ -327,27 +329,22 @@
in.size = 15;
// Create a uniquely named test directory.
- string test_dir;
- ASSERT_TRUE(utils::MakeTempDirectory(
- "omaha_response_handler_action-test-XXXXXX", &test_dir));
-
- ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + "/etc"));
- ASSERT_EQ(0, System(string("mkdir -p ") + test_dir +
- kStatefulPartition + "/etc"));
- ASSERT_TRUE(WriteFileString(
- test_dir + "/etc/lsb-release",
- "CHROMEOS_RELEASE_TRACK=canary-channel\n"));
- ASSERT_TRUE(WriteFileString(
- test_dir + kStatefulPartition + "/etc/lsb-release",
- "CHROMEOS_IS_POWERWASH_ALLOWED=true\n"
- "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
+ base::ScopedTempDir tempdir;
+ ASSERT_TRUE(tempdir.CreateUniqueTempDir());
OmahaRequestParams params(&fake_system_state_);
fake_system_state_.fake_hardware()->SetIsOfficialBuild(false);
- params.set_root(test_dir);
- params.Init("1.2.3.4", "", 0);
- EXPECT_EQ("canary-channel", params.current_channel());
- EXPECT_EQ("stable-channel", params.target_channel());
+ params.set_root(tempdir.path().value());
+ params.set_current_channel("canary-channel");
+ // The ImageProperties in Android uses prefs to store MutableImageProperties.
+#ifdef __ANDROID__
+ EXPECT_CALL(*fake_system_state_.mock_prefs(), SetString(_, "stable-channel"))
+ .WillOnce(Return(true));
+ EXPECT_CALL(*fake_system_state_.mock_prefs(), SetBoolean(_, true))
+ .WillOnce(Return(true));
+#endif // __ANDROID__
+ EXPECT_TRUE(params.SetTargetChannel("stable-channel", true, nullptr));
+ params.UpdateDownloadChannel();
EXPECT_TRUE(params.to_more_stable_channel());
EXPECT_TRUE(params.is_powerwash_allowed());
@@ -355,8 +352,6 @@
InstallPlan install_plan;
EXPECT_TRUE(DoTest(in, "", &install_plan));
EXPECT_TRUE(install_plan.powerwash_required);
-
- ASSERT_TRUE(base::DeleteFile(base::FilePath(test_dir), true));
}
TEST_F(OmahaResponseHandlerActionTest, ChangeToLessStableChannelTest) {
@@ -369,27 +364,22 @@
in.size = 15;
// Create a uniquely named test directory.
- string test_dir;
- ASSERT_TRUE(utils::MakeTempDirectory(
- "omaha_response_handler_action-test-XXXXXX", &test_dir));
-
- ASSERT_EQ(0, System(string("mkdir -p ") + test_dir + "/etc"));
- ASSERT_EQ(0, System(string("mkdir -p ") + test_dir +
- kStatefulPartition + "/etc"));
- ASSERT_TRUE(WriteFileString(
- test_dir + "/etc/lsb-release",
- "CHROMEOS_RELEASE_TRACK=stable-channel\n"));
- ASSERT_TRUE(WriteFileString(
- test_dir + kStatefulPartition + "/etc/lsb-release",
- "CHROMEOS_RELEASE_TRACK=canary-channel\n"));
+ base::ScopedTempDir tempdir;
+ ASSERT_TRUE(tempdir.CreateUniqueTempDir());
OmahaRequestParams params(&fake_system_state_);
fake_system_state_.fake_hardware()->SetIsOfficialBuild(false);
- params.set_root(test_dir);
- params.Init("5.6.7.8", "", 0);
- EXPECT_EQ("stable-channel", params.current_channel());
- params.SetTargetChannel("canary-channel", false, nullptr);
- EXPECT_EQ("canary-channel", params.target_channel());
+ params.set_root(tempdir.path().value());
+ params.set_current_channel("stable-channel");
+ // The ImageProperties in Android uses prefs to store MutableImageProperties.
+#ifdef __ANDROID__
+ EXPECT_CALL(*fake_system_state_.mock_prefs(), SetString(_, "canary-channel"))
+ .WillOnce(Return(true));
+ EXPECT_CALL(*fake_system_state_.mock_prefs(), SetBoolean(_, false))
+ .WillOnce(Return(true));
+#endif // __ANDROID__
+ EXPECT_TRUE(params.SetTargetChannel("canary-channel", false, nullptr));
+ params.UpdateDownloadChannel();
EXPECT_FALSE(params.to_more_stable_channel());
EXPECT_FALSE(params.is_powerwash_allowed());
@@ -397,8 +387,6 @@
InstallPlan install_plan;
EXPECT_TRUE(DoTest(in, "", &install_plan));
EXPECT_FALSE(install_plan.powerwash_required);
-
- ASSERT_TRUE(base::DeleteFile(base::FilePath(test_dir), true));
}
TEST_F(OmahaResponseHandlerActionTest, P2PUrlIsUsedAndHashChecksMandatory) {
diff --git a/update_engine.gyp b/update_engine.gyp
index 40d6314..5f24a83 100644
--- a/update_engine.gyp
+++ b/update_engine.gyp
@@ -506,6 +506,7 @@
'connection_manager_unittest.cc',
'fake_shill_proxy.cc',
'fake_system_state.cc',
+ 'image_properties_chromeos_unittest.cc',
'metrics_utils_unittest.cc',
'omaha_request_action_unittest.cc',
'omaha_request_params_unittest.cc',