Fix non-critical updates on boards without an OOBE flow.
A recent change in the policy made update_engine to ignore available
updates if the OOBE flow is not completed and the update is not
critical. Nevertheless, some custom boards don't have a OOBE flow as
Chromebooks do and set is_oobe_enabled=false in the policy manager.
These board were not getting regular updates because the OOBE flow is
considered not completed in those cases.
This patch moves the is_oobe_enabled flag to the HardwareInterface class
together with the IsOOBEComplete() method and updates the callers to
check the IsOOBEEnabled() value before.
Bug: 28460247
Bug: 28553821
TEST=Added unittest for the disabled and not complete case.
Change-Id: Ifd3ac2dc5e7a43f6c24eb014b7e3eacad22e3ab3
diff --git a/Android.mk b/Android.mk
index 93c6c87..ca8087c 100644
--- a/Android.mk
+++ b/Android.mk
@@ -942,7 +942,6 @@
update_manager/evaluation_context_unittest.cc \
update_manager/generic_variables_unittest.cc \
update_manager/prng_unittest.cc \
- update_manager/real_config_provider_unittest.cc \
update_manager/real_device_policy_provider_unittest.cc \
update_manager/real_random_provider_unittest.cc \
update_manager/real_shill_provider_unittest.cc \
diff --git a/common/fake_hardware.h b/common/fake_hardware.h
index 449787b..4558c8c 100644
--- a/common/fake_hardware.h
+++ b/common/fake_hardware.h
@@ -34,21 +34,15 @@
// false.
static const int kPowerwashCountNotSet = -1;
- FakeHardware()
- : is_official_build_(true),
- is_normal_boot_mode_(true),
- is_oobe_complete_(true),
- oobe_timestamp_(base::Time::FromTimeT(1169280000)), // Jan 20, 2007
- hardware_class_("Fake HWID BLAH-1234"),
- firmware_version_("Fake Firmware v1.0.1"),
- ec_version_("Fake EC v1.0a"),
- powerwash_count_(kPowerwashCountNotSet) {}
+ FakeHardware() = default;
// HardwareInterface methods.
bool IsOfficialBuild() const override { return is_official_build_; }
bool IsNormalBootMode() const override { return is_normal_boot_mode_; }
+ bool IsOOBEEnabled() const override { return is_oobe_enabled_; }
+
bool IsOOBEComplete(base::Time* out_time_of_oobe) const override {
if (out_time_of_oobe != nullptr)
*out_time_of_oobe = oobe_timestamp_;
@@ -80,13 +74,17 @@
is_normal_boot_mode_ = is_normal_boot_mode;
}
+ // Sets the SetIsOOBEEnabled to |is_oobe_enabled|.
+ void SetIsOOBEEnabled(bool is_oobe_enabled) {
+ is_oobe_enabled_ = is_oobe_enabled;
+ }
+
// Sets the IsOOBEComplete to True with the given timestamp.
void SetIsOOBEComplete(base::Time oobe_timestamp) {
is_oobe_complete_ = true;
oobe_timestamp_ = oobe_timestamp;
}
- // Sets the IsOOBEComplete to False.
void UnsetIsOOBEComplete() {
is_oobe_complete_ = false;
}
@@ -108,14 +106,15 @@
}
private:
- bool is_official_build_;
- bool is_normal_boot_mode_;
- bool is_oobe_complete_;
- base::Time oobe_timestamp_;
- std::string hardware_class_;
- std::string firmware_version_;
- std::string ec_version_;
- int powerwash_count_;
+ bool is_official_build_{true};
+ bool is_normal_boot_mode_{true};
+ bool is_oobe_enabled_{true};
+ bool is_oobe_complete_{true};
+ base::Time oobe_timestamp_{base::Time::FromTimeT(1169280000)}; // Jan 20, 2007
+ std::string hardware_class_{"Fake HWID BLAH-1234"};
+ std::string firmware_version_{"Fake Firmware v1.0.1"};
+ std::string ec_version_{"Fake EC v1.0a"};
+ int powerwash_count_{kPowerwashCountNotSet};
DISALLOW_COPY_AND_ASSIGN(FakeHardware);
};
diff --git a/common/hardware_interface.h b/common/hardware_interface.h
index 17ce694..e434cc9 100644
--- a/common/hardware_interface.h
+++ b/common/hardware_interface.h
@@ -44,6 +44,11 @@
// features.
virtual bool IsNormalBootMode() const = 0;
+ // Returns whether the device has an OOBE flow that the user must go through
+ // before getting non-critical updates. Use IsOOBEComplete() to determine if
+ // that flow is complete.
+ virtual bool IsOOBEEnabled() const = 0;
+
// Returns true if the OOBE process has been completed and EULA accepted,
// False otherwise. If True is returned, and |out_time_of_oobe| isn't null,
// the time-stamp of when OOBE happened is stored at |out_time_of_oobe|.
diff --git a/common/libcurl_http_fetcher.cc b/common/libcurl_http_fetcher.cc
index 5b61263..9e40eeb 100644
--- a/common/libcurl_http_fetcher.cc
+++ b/common/libcurl_http_fetcher.cc
@@ -51,7 +51,7 @@
// be waiting on the dev server to build an image.
if (!hardware_->IsOfficialBuild())
low_speed_time_seconds_ = kDownloadDevModeLowSpeedTimeSeconds;
- if (!hardware_->IsOOBEComplete(nullptr))
+ if (hardware_->IsOOBEEnabled() && !hardware_->IsOOBEComplete(nullptr))
max_retry_count_ = kDownloadMaxRetryCountOobeNotComplete;
}
diff --git a/common/mock_hardware.h b/common/mock_hardware.h
index 451af91..826b3b3 100644
--- a/common/mock_hardware.h
+++ b/common/mock_hardware.h
@@ -36,6 +36,9 @@
ON_CALL(*this, IsNormalBootMode())
.WillByDefault(testing::Invoke(&fake_,
&FakeHardware::IsNormalBootMode));
+ ON_CALL(*this, IsOOBEEnabled())
+ .WillByDefault(testing::Invoke(&fake_,
+ &FakeHardware::IsOOBEEnabled));
ON_CALL(*this, IsOOBEComplete(testing::_))
.WillByDefault(testing::Invoke(&fake_,
&FakeHardware::IsOOBEComplete));
@@ -64,6 +67,7 @@
// Hardware overrides.
MOCK_CONST_METHOD0(IsOfficialBuild, bool());
MOCK_CONST_METHOD0(IsNormalBootMode, bool());
+ MOCK_CONST_METHOD0(IsOOBEEnabled, bool());
MOCK_CONST_METHOD1(IsOOBEComplete, bool(base::Time* out_time_of_oobe));
MOCK_CONST_METHOD0(GetHardwareClass, std::string());
MOCK_CONST_METHOD0(GetFirmwareVersion, std::string());
diff --git a/hardware_android.cc b/hardware_android.cc
index a20fe6f..60e26f2 100644
--- a/hardware_android.cc
+++ b/hardware_android.cc
@@ -68,8 +68,13 @@
return property_get_bool("ro.debuggable", 0) != 1;
}
+bool HardwareAndroid::IsOOBEEnabled() const {
+ // No OOBE flow blocking updates for Android-based boards.
+ return false;
+}
+
bool HardwareAndroid::IsOOBEComplete(base::Time* out_time_of_oobe) const {
- LOG(WARNING) << "STUB: Assuming OOBE is complete.";
+ LOG(WARNING) << "OOBE is not enabled but IsOOBEComplete() called.";
if (out_time_of_oobe)
*out_time_of_oobe = base::Time();
return true;
diff --git a/hardware_android.h b/hardware_android.h
index 1b03661..9aa729c 100644
--- a/hardware_android.h
+++ b/hardware_android.h
@@ -36,6 +36,7 @@
// HardwareInterface methods.
bool IsOfficialBuild() const override;
bool IsNormalBootMode() const override;
+ bool IsOOBEEnabled() const override;
bool IsOOBEComplete(base::Time* out_time_of_oobe) const override;
std::string GetHardwareClass() const override;
std::string GetFirmwareVersion() const override;
diff --git a/hardware_chromeos.cc b/hardware_chromeos.cc
index ccb3978..57583a1 100644
--- a/hardware_chromeos.cc
+++ b/hardware_chromeos.cc
@@ -16,10 +16,12 @@
#include "update_engine/hardware_chromeos.h"
+#include <base/files/file_path.h>
#include <base/files/file_util.h>
#include <base/logging.h>
#include <base/strings/string_number_conversions.h>
#include <base/strings/string_util.h>
+#include <brillo/key_value_store.h>
#include <brillo/make_unique_ptr.h>
#include <vboot/crossystem.h>
@@ -27,6 +29,7 @@
#include "vboot/vboot_host.h"
}
+#include "update_engine/common/constants.h"
#include "update_engine/common/hardware.h"
#include "update_engine/common/hwid_override.h"
#include "update_engine/common/platform_constants.h"
@@ -50,6 +53,12 @@
// a powerwash is performed.
const char kPowerwashCountMarker[] = "powerwash_count";
+// UpdateManager config path.
+const char* kConfigFilePath = "/etc/update_manager.conf";
+
+// UpdateManager config options:
+const char* kConfigOptsIsOOBEEnabled = "is_oobe_enabled";
+
} // namespace
namespace chromeos_update_engine {
@@ -58,11 +67,17 @@
// Factory defined in hardware.h.
std::unique_ptr<HardwareInterface> CreateHardware() {
- return brillo::make_unique_ptr(new HardwareChromeOS());
+ std::unique_ptr<HardwareChromeOS> hardware(new HardwareChromeOS());
+ hardware->Init();
+ return std::move(hardware);
}
} // namespace hardware
+void HardwareChromeOS::Init() {
+ LoadConfig("" /* root_prefix */, IsNormalBootMode());
+}
+
bool HardwareChromeOS::IsOfficialBuild() const {
return VbGetSystemPropertyInt("debug_build") == 0;
}
@@ -72,7 +87,14 @@
return !dev_mode;
}
+bool HardwareChromeOS::IsOOBEEnabled() const {
+ return is_oobe_enabled_;
+}
+
bool HardwareChromeOS::IsOOBEComplete(base::Time* out_time_of_oobe) const {
+ if (!is_oobe_enabled_) {
+ LOG(WARNING) << "OOBE is not enabled but IsOOBEComplete() was called";
+ }
struct stat statbuf;
if (stat(kOOBECompletedMarker, &statbuf) != 0) {
if (errno != ENOENT) {
@@ -150,4 +172,22 @@
return true;
}
+void HardwareChromeOS::LoadConfig(const string& root_prefix, bool normal_mode) {
+ brillo::KeyValueStore store;
+
+ if (normal_mode) {
+ store.Load(base::FilePath(root_prefix + kConfigFilePath));
+ } else {
+ if (store.Load(base::FilePath(root_prefix + kStatefulPartition +
+ kConfigFilePath))) {
+ LOG(INFO) << "UpdateManager Config loaded from stateful partition.";
+ } else {
+ store.Load(base::FilePath(root_prefix + kConfigFilePath));
+ }
+ }
+
+ if (!store.GetBoolean(kConfigOptsIsOOBEEnabled, &is_oobe_enabled_))
+ is_oobe_enabled_ = true; // Default value.
+}
+
} // namespace chromeos_update_engine
diff --git a/hardware_chromeos.h b/hardware_chromeos.h
index 80888ab..d9a73f8 100644
--- a/hardware_chromeos.h
+++ b/hardware_chromeos.h
@@ -34,9 +34,12 @@
HardwareChromeOS() = default;
~HardwareChromeOS() override = default;
+ void Init();
+
// HardwareInterface methods.
bool IsOfficialBuild() const override;
bool IsNormalBootMode() const override;
+ bool IsOOBEEnabled() const override;
bool IsOOBEComplete(base::Time* out_time_of_oobe) const override;
std::string GetHardwareClass() const override;
std::string GetFirmwareVersion() const override;
@@ -46,6 +49,15 @@
bool GetPowerwashSafeDirectory(base::FilePath* path) const override;
private:
+ friend class HardwareChromeOSTest;
+
+ // Load the update manager config flags (is_oobe_enabled flag) from the
+ // appropriate location based on whether we are in a normal mode boot (as
+ // passed in |normal_mode|) prefixing the paths with |root_prefix|.
+ void LoadConfig(const std::string& root_prefix, bool normal_mode);
+
+ bool is_oobe_enabled_;
+
DISALLOW_COPY_AND_ASSIGN(HardwareChromeOS);
};
diff --git a/hardware_chromeos_unittest.cc b/hardware_chromeos_unittest.cc
new file mode 100644
index 0000000..a6bad54
--- /dev/null
+++ b/hardware_chromeos_unittest.cc
@@ -0,0 +1,89 @@
+//
+// 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/hardware_chromeos.h"
+
+#include <memory>
+
+#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_hardware.h"
+#include "update_engine/common/test_utils.h"
+#include "update_engine/update_manager/umtest_utils.h"
+
+using chromeos_update_engine::test_utils::WriteFileString;
+using std::string;
+
+namespace chromeos_update_engine {
+
+class HardwareChromeOSTest : public ::testing::Test {
+ protected:
+ void SetUp() override { ASSERT_TRUE(root_dir_.CreateUniqueTempDir()); }
+
+ void WriteStatefulConfig(const string& config) {
+ base::FilePath kFile(root_dir_.path().value() + kStatefulPartition +
+ "/etc/update_manager.conf");
+ ASSERT_TRUE(base::CreateDirectory(kFile.DirName()));
+ ASSERT_TRUE(WriteFileString(kFile.value(), config));
+ }
+
+ void WriteRootfsConfig(const string& config) {
+ base::FilePath kFile(root_dir_.path().value() + "/etc/update_manager.conf");
+ ASSERT_TRUE(base::CreateDirectory(kFile.DirName()));
+ ASSERT_TRUE(WriteFileString(kFile.value(), config));
+ }
+
+ // Helper method to call HardwareChromeOS::LoadConfig with the test directory.
+ void CallLoadConfig(bool normal_mode) {
+ hardware_.LoadConfig(root_dir_.path().value(), normal_mode);
+ }
+
+ HardwareChromeOS hardware_;
+ base::ScopedTempDir root_dir_;
+};
+
+TEST_F(HardwareChromeOSTest, NoFileFoundReturnsDefault) {
+ CallLoadConfig(true /* normal_mode */);
+ EXPECT_TRUE(hardware_.IsOOBEEnabled());
+}
+
+TEST_F(HardwareChromeOSTest, DontReadStatefulInNormalMode) {
+ WriteStatefulConfig("is_oobe_enabled=false");
+
+ CallLoadConfig(true /* normal_mode */);
+ EXPECT_TRUE(hardware_.IsOOBEEnabled());
+}
+
+TEST_F(HardwareChromeOSTest, ReadStatefulInDevMode) {
+ WriteRootfsConfig("is_oobe_enabled=true");
+ // Since the stateful is present, we should read that one.
+ WriteStatefulConfig("is_oobe_enabled=false");
+
+ CallLoadConfig(false /* normal_mode */);
+ EXPECT_FALSE(hardware_.IsOOBEEnabled());
+}
+
+TEST_F(HardwareChromeOSTest, ReadRootfsIfStatefulNotFound) {
+ WriteRootfsConfig("is_oobe_enabled=false");
+
+ CallLoadConfig(false /* normal_mode */);
+ EXPECT_FALSE(hardware_.IsOOBEEnabled());
+}
+
+} // namespace chromeos_update_engine
diff --git a/omaha_request_action.cc b/omaha_request_action.cc
index 16338a8..173d387 100644
--- a/omaha_request_action.cc
+++ b/omaha_request_action.cc
@@ -605,9 +605,10 @@
// inspecting the timestamp of when OOBE happened.
Time time_of_oobe;
- if (!system_state->hardware()->IsOOBEComplete(&time_of_oobe)) {
+ if (!system_state->hardware()->IsOOBEEnabled() ||
+ !system_state->hardware()->IsOOBEComplete(&time_of_oobe)) {
LOG(INFO) << "Not generating Omaha InstallData as we have "
- << "no prefs file and OOBE is not complete.";
+ << "no prefs file and OOBE is not complete or not enabled.";
return -1;
}
@@ -1037,7 +1038,8 @@
OmahaResponse& output_object = const_cast<OmahaResponse&>(GetOutputObject());
PayloadStateInterface* payload_state = system_state_->payload_state();
- if (!system_state_->hardware()->IsOOBEComplete(nullptr) &&
+ if (system_state_->hardware()->IsOOBEEnabled() &&
+ !system_state_->hardware()->IsOOBEComplete(nullptr) &&
output_object.deadline.empty() &&
params_->app_version() != "ForcedUpdate") {
output_object.update_exists = false;
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
index a7abdec..d4b166f 100644
--- a/omaha_request_action_unittest.cc
+++ b/omaha_request_action_unittest.cc
@@ -531,6 +531,22 @@
nullptr));
EXPECT_FALSE(response.update_exists);
+ // The IsOOBEComplete() value is ignored when the OOBE flow is not enabled.
+ fake_system_state_.fake_hardware()->SetIsOOBEEnabled(false);
+ ASSERT_TRUE(TestUpdateCheck(nullptr, // request_params
+ fake_update_response_.GetUpdateResponse(),
+ -1,
+ false, // ping_only
+ ErrorCode::kSuccess,
+ metrics::CheckResult::kUpdateAvailable,
+ metrics::CheckReaction::kUpdating,
+ metrics::DownloadErrorCode::kUnset,
+ &response,
+ nullptr));
+ EXPECT_TRUE(response.update_exists);
+ fake_system_state_.fake_hardware()->SetIsOOBEEnabled(true);
+
+ // The payload is applied when a deadline was set in the response.
fake_update_response_.deadline = "20101020";
ASSERT_TRUE(
TestUpdateCheck(nullptr, // request_params
diff --git a/update_attempter.cc b/update_attempter.cc
index 6dd1483..8f19f51 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -479,8 +479,10 @@
LOG(INFO) << "Scattering disabled since scatter factor is set to 0";
} else if (interactive) {
LOG(INFO) << "Scattering disabled as this is an interactive update check";
- } else if (!system_state_->hardware()->IsOOBEComplete(nullptr)) {
- LOG(INFO) << "Scattering disabled since OOBE is not complete yet";
+ } else if (system_state_->hardware()->IsOOBEEnabled() &&
+ !system_state_->hardware()->IsOOBEComplete(nullptr)) {
+ LOG(INFO) << "Scattering disabled since OOBE is enabled but not complete "
+ "yet";
} else {
is_scatter_enabled = true;
LOG(INFO) << "Scattering is enabled";
diff --git a/update_engine.gyp b/update_engine.gyp
index b8eccdc..2f27dd4 100644
--- a/update_engine.gyp
+++ b/update_engine.gyp
@@ -508,6 +508,7 @@
'connection_manager_unittest.cc',
'fake_shill_proxy.cc',
'fake_system_state.cc',
+ 'hardware_chromeos_unittest.cc',
'image_properties_chromeos_unittest.cc',
'metrics_utils_unittest.cc',
'omaha_request_action_unittest.cc',
@@ -549,7 +550,6 @@
'update_manager/evaluation_context_unittest.cc',
'update_manager/generic_variables_unittest.cc',
'update_manager/prng_unittest.cc',
- 'update_manager/real_config_provider_unittest.cc',
'update_manager/real_device_policy_provider_unittest.cc',
'update_manager/real_random_provider_unittest.cc',
'update_manager/real_shill_provider_unittest.cc',
diff --git a/update_manager/real_config_provider.cc b/update_manager/real_config_provider.cc
index 2d17a7f..97e624e 100644
--- a/update_manager/real_config_provider.cc
+++ b/update_manager/real_config_provider.cc
@@ -16,47 +16,13 @@
#include "update_engine/update_manager/real_config_provider.h"
-#include <base/files/file_path.h>
-#include <base/logging.h>
-#include <brillo/key_value_store.h>
-
-#include "update_engine/common/constants.h"
-#include "update_engine/common/utils.h"
#include "update_engine/update_manager/generic_variables.h"
-using brillo::KeyValueStore;
-
-namespace {
-
-const char* kConfigFilePath = "/etc/update_manager.conf";
-
-// Config options:
-const char* kConfigOptsIsOOBEEnabled = "is_oobe_enabled";
-
-} // namespace
-
namespace chromeos_update_manager {
bool RealConfigProvider::Init() {
- KeyValueStore store;
-
- if (hardware_->IsNormalBootMode()) {
- store.Load(base::FilePath(root_prefix_ + kConfigFilePath));
- } else {
- if (store.Load(base::FilePath(root_prefix_ +
- chromeos_update_engine::kStatefulPartition +
- kConfigFilePath))) {
- LOG(INFO) << "UpdateManager Config loaded from stateful partition.";
- } else {
- store.Load(base::FilePath(root_prefix_ + kConfigFilePath));
- }
- }
-
- bool is_oobe_enabled;
- if (!store.GetBoolean(kConfigOptsIsOOBEEnabled, &is_oobe_enabled))
- is_oobe_enabled = true; // Default value.
- var_is_oobe_enabled_.reset(
- new ConstCopyVariable<bool>(kConfigOptsIsOOBEEnabled, is_oobe_enabled));
+ var_is_oobe_enabled_.reset(new ConstCopyVariable<bool>(
+ "is_oobe_enabled", hardware_->IsOOBEEnabled()));
return true;
}
diff --git a/update_manager/real_config_provider.h b/update_manager/real_config_provider.h
index 4de910c..e79ae60 100644
--- a/update_manager/real_config_provider.h
+++ b/update_manager/real_config_provider.h
@@ -18,7 +18,6 @@
#define UPDATE_ENGINE_UPDATE_MANAGER_REAL_CONFIG_PROVIDER_H_
#include <memory>
-#include <string>
#include "update_engine/common/hardware_interface.h"
#include "update_engine/update_manager/config_provider.h"
@@ -41,22 +40,10 @@
}
private:
- friend class UmRealConfigProviderTest;
-
- // Used for testing. Sets the root prefix, which is by default "". Call this
- // method before calling Init() in order to mock out the place where the files
- // are being read from.
- void SetRootPrefix(const std::string& prefix) {
- root_prefix_ = prefix;
- }
-
std::unique_ptr<ConstCopyVariable<bool>> var_is_oobe_enabled_;
chromeos_update_engine::HardwareInterface* hardware_;
- // Prefix to prepend to the file paths. Useful for testing.
- std::string root_prefix_;
-
DISALLOW_COPY_AND_ASSIGN(RealConfigProvider);
};
diff --git a/update_manager/real_config_provider_unittest.cc b/update_manager/real_config_provider_unittest.cc
deleted file mode 100644
index 2d7dc0d..0000000
--- a/update_manager/real_config_provider_unittest.cc
+++ /dev/null
@@ -1,102 +0,0 @@
-//
-// Copyright (C) 2014 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/update_manager/real_config_provider.h"
-
-#include <memory>
-
-#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_hardware.h"
-#include "update_engine/common/test_utils.h"
-#include "update_engine/update_manager/umtest_utils.h"
-
-using base::TimeDelta;
-using chromeos_update_engine::test_utils::WriteFileString;
-using std::string;
-using std::unique_ptr;
-
-namespace chromeos_update_manager {
-
-class UmRealConfigProviderTest : public ::testing::Test {
- protected:
- void SetUp() override {
- ASSERT_TRUE(root_dir_.CreateUniqueTempDir());
- provider_.reset(new RealConfigProvider(&fake_hardware_));
- provider_->SetRootPrefix(root_dir_.path().value());
- }
-
- void WriteStatefulConfig(const string& config) {
- base::FilePath kFile(root_dir_.path().value()
- + chromeos_update_engine::kStatefulPartition
- + "/etc/update_manager.conf");
- ASSERT_TRUE(base::CreateDirectory(kFile.DirName()));
- ASSERT_TRUE(WriteFileString(kFile.value(), config));
- }
-
- void WriteRootfsConfig(const string& config) {
- base::FilePath kFile(root_dir_.path().value()
- + "/etc/update_manager.conf");
- ASSERT_TRUE(base::CreateDirectory(kFile.DirName()));
- ASSERT_TRUE(WriteFileString(kFile.value(), config));
- }
-
- unique_ptr<RealConfigProvider> provider_;
- chromeos_update_engine::FakeHardware fake_hardware_;
- TimeDelta default_timeout_ = TimeDelta::FromSeconds(1);
- base::ScopedTempDir root_dir_;
-};
-
-TEST_F(UmRealConfigProviderTest, InitTest) {
- EXPECT_TRUE(provider_->Init());
- EXPECT_NE(nullptr, provider_->var_is_oobe_enabled());
-}
-
-TEST_F(UmRealConfigProviderTest, NoFileFoundReturnsDefault) {
- EXPECT_TRUE(provider_->Init());
- UmTestUtils::ExpectVariableHasValue(true, provider_->var_is_oobe_enabled());
-}
-
-TEST_F(UmRealConfigProviderTest, DontReadStatefulInNormalMode) {
- fake_hardware_.SetIsNormalBootMode(true);
- WriteStatefulConfig("is_oobe_enabled=false");
-
- EXPECT_TRUE(provider_->Init());
- UmTestUtils::ExpectVariableHasValue(true, provider_->var_is_oobe_enabled());
-}
-
-TEST_F(UmRealConfigProviderTest, ReadStatefulInDevMode) {
- fake_hardware_.SetIsNormalBootMode(false);
- WriteRootfsConfig("is_oobe_enabled=true");
- // Since the stateful is present, this should read that one.
- WriteStatefulConfig("is_oobe_enabled=false");
-
- EXPECT_TRUE(provider_->Init());
- UmTestUtils::ExpectVariableHasValue(false, provider_->var_is_oobe_enabled());
-}
-
-TEST_F(UmRealConfigProviderTest, ReadRootfsIfStatefulNotFound) {
- fake_hardware_.SetIsNormalBootMode(false);
- WriteRootfsConfig("is_oobe_enabled=false");
-
- EXPECT_TRUE(provider_->Init());
- UmTestUtils::ExpectVariableHasValue(false, provider_->var_is_oobe_enabled());
-}
-
-} // namespace chromeos_update_manager