Commit f6d7da24 authored by grt's avatar grt Committed by Commit bot

Fail tests fast if overriding the Windows registry fails.

All calls to RegistryOverrideManager::OverrideRegistry are now wrapped
in ASSERT_NO_FATAL_FAILURE, as are a few helper functions in
RegistryOverrideManagerTest that should have been.

BUG=688878
TBR=brettw@chromium.org

Review-Url: https://codereview.chromium.org/2692843002
Cr-Commit-Position: refs/heads/master@{#450288}
parent 0deaad5f
......@@ -70,18 +70,13 @@ base::string16 GenerateTempKeyPath(const base::string16& test_key_root,
RegistryOverrideManager::ScopedRegistryKeyOverride::ScopedRegistryKeyOverride(
HKEY override,
const base::string16& key_path)
: override_(override) {
EXPECT_EQ(
ERROR_SUCCESS,
temp_key_.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_ALL_ACCESS));
EXPECT_EQ(ERROR_SUCCESS,
::RegOverridePredefKey(override_, temp_key_.Handle()));
}
: override_(override), key_path_(key_path) {}
RegistryOverrideManager::
ScopedRegistryKeyOverride::~ScopedRegistryKeyOverride() {
::RegOverridePredefKey(override_, NULL);
temp_key_.DeleteKey(L"");
base::win::RegKey(HKEY_CURRENT_USER, L"", KEY_QUERY_VALUE)
.DeleteKey(key_path_.c_str());
}
RegistryOverrideManager::RegistryOverrideManager()
......@@ -105,6 +100,12 @@ void RegistryOverrideManager::OverrideRegistry(HKEY override) {
void RegistryOverrideManager::OverrideRegistry(HKEY override,
base::string16* override_path) {
base::string16 key_path = GenerateTempKeyPath(test_key_root_, timestamp_);
base::win::RegKey temp_key;
ASSERT_EQ(ERROR_SUCCESS, temp_key.Create(HKEY_CURRENT_USER, key_path.c_str(),
KEY_ALL_ACCESS));
ASSERT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(override, temp_key.Handle()));
overrides_.push_back(
base::MakeUnique<ScopedRegistryKeyOverride>(override, key_path));
if (override_path)
......
......@@ -39,6 +39,8 @@ class RegistryOverrideManager {
// Multiple overrides to the same hive are not supported and lead to undefined
// behavior.
// Optional return of the registry override path.
// Calls to these functions must be wrapped in ASSERT_NO_FATAL_FAILURE to
// ensure that tests do not proceeed in case of failure to override.
void OverrideRegistry(HKEY override);
void OverrideRegistry(HKEY override, base::string16* override_path);
......@@ -53,7 +55,7 @@ class RegistryOverrideManager {
private:
HKEY override_;
base::win::RegKey temp_key_;
base::string16 key_path_;
DISALLOW_COPY_AND_ASSIGN(ScopedRegistryKeyOverride);
};
......
......@@ -55,7 +55,7 @@ class RegistryOverrideManagerTest : public testing::Test {
void CreateKey(const base::string16& key_path) {
base::win::RegKey key;
EXPECT_EQ(ERROR_SUCCESS,
ASSERT_EQ(ERROR_SUCCESS,
key.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_ALL_ACCESS));
}
......@@ -74,7 +74,7 @@ class RegistryOverrideManagerTest : public testing::Test {
};
TEST_F(RegistryOverrideManagerTest, Basic) {
CreateManager(base::Time::Now());
ASSERT_NO_FATAL_FAILURE(CreateManager(base::Time::Now()));
base::win::RegKey create_key;
EXPECT_EQ(ERROR_SUCCESS,
......@@ -83,7 +83,7 @@ TEST_F(RegistryOverrideManagerTest, Basic) {
EXPECT_EQ(ERROR_SUCCESS, create_key.WriteValue(kTestValueName, 42));
create_key.Close();
AssertKeyExists(kTestKeyPath);
ASSERT_NO_FATAL_FAILURE(AssertKeyExists(kTestKeyPath));
DWORD value;
base::win::RegKey read_key;
......@@ -96,7 +96,7 @@ TEST_F(RegistryOverrideManagerTest, Basic) {
manager_.reset();
AssertKeyAbsent(kTestKeyPath);
ASSERT_NO_FATAL_FAILURE(AssertKeyAbsent(kTestKeyPath));
}
TEST_F(RegistryOverrideManagerTest, DeleteStaleKeys) {
......@@ -114,20 +114,20 @@ TEST_F(RegistryOverrideManagerTest, DeleteStaleKeys) {
base::string16 path_future =
FakeOverrideManagerPath(kTestTime + base::TimeDelta::FromMinutes(1));
CreateKey(path_garbage);
CreateKey(path_very_stale);
CreateKey(path_stale);
CreateKey(path_current);
CreateKey(path_future);
ASSERT_NO_FATAL_FAILURE(CreateKey(path_garbage));
ASSERT_NO_FATAL_FAILURE(CreateKey(path_very_stale));
ASSERT_NO_FATAL_FAILURE(CreateKey(path_stale));
ASSERT_NO_FATAL_FAILURE(CreateKey(path_current));
ASSERT_NO_FATAL_FAILURE(CreateKey(path_future));
CreateManager(kTestTime);
ASSERT_NO_FATAL_FAILURE(CreateManager(kTestTime));
manager_.reset();
AssertKeyAbsent(path_garbage);
AssertKeyAbsent(path_very_stale);
AssertKeyAbsent(path_stale);
AssertKeyExists(path_current);
AssertKeyExists(path_future);
ASSERT_NO_FATAL_FAILURE(AssertKeyAbsent(path_garbage));
ASSERT_NO_FATAL_FAILURE(AssertKeyAbsent(path_very_stale));
ASSERT_NO_FATAL_FAILURE(AssertKeyAbsent(path_stale));
ASSERT_NO_FATAL_FAILURE(AssertKeyExists(path_current));
ASSERT_NO_FATAL_FAILURE(AssertKeyExists(path_future));
}
} // namespace registry_util
......@@ -24,7 +24,7 @@ class UserDataDowngradeBrowserTestBase : public InProcessBrowserTest {
// content::BrowserTestBase:
void SetUpInProcessBrowserTestFixture() override {
HKEY root = HKEY_CURRENT_USER;
registry_override_manager_.OverrideRegistry(root);
ASSERT_NO_FATAL_FAILURE(registry_override_manager_.OverrideRegistry(root));
key_.Create(root,
BrowserDistribution::GetDistribution()->GetStateKey().c_str(),
KEY_SET_VALUE | KEY_WOW64_32KEY);
......
......@@ -77,7 +77,7 @@ void ScopedTestNativeMessagingHost::RegisterTestHost(bool user_level) {
#if defined(OS_WIN)
HKEY root_key = user_level ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
registry_override_.OverrideRegistry(root_key);
ASSERT_NO_FATAL_FAILURE(registry_override_.OverrideRegistry(root_key));
#else
path_override_.reset(new base::ScopedPathOverride(
user_level ? chrome::DIR_USER_NATIVE_MESSAGING
......
......@@ -560,8 +560,10 @@ class GoogleUpdateWinTest : public ::testing::TestWithParam<bool> {
new base::ScopedPathOverride(base::DIR_LOCAL_APP_DATA, temp));
// Override the registry so that tests can freely push state to it.
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE);
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE));
// Chrome is installed.
const HKEY root =
......
......@@ -193,7 +193,8 @@ void EnsureMediaDirectoriesExists::Init() {
local_app_data_override_.reset(new base::ScopedPathOverride(
base::DIR_LOCAL_APP_DATA, GetFakeLocalAppDataPath()));
// Picasa also looks in the registry for an alternate path.
registry_override_.OverrideRegistry(HKEY_CURRENT_USER);
ASSERT_NO_FATAL_FAILURE(
registry_override_.OverrideRegistry(HKEY_CURRENT_USER));
#endif // OS_WIN
#if defined(OS_MACOSX)
......
......@@ -27,7 +27,8 @@ using base::win::RegKey;
class TriggeredProfileResetterTest : public testing::Test {
protected:
void SetUp() override {
override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
ASSERT_NO_FATAL_FAILURE(
override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
// Activate the triggered reset field trial for these tests.
field_trial_list_.reset(
......
......@@ -183,7 +183,7 @@ TEST(SafeBrowsingEnvironmentDataCollectionWinTest, CollectRegistryData) {
// Ensure that all values and subkeys from the specified registry keys are
// correctly stored in the report.
registry_util::RegistryOverrideManager override_manager;
override_manager.OverrideRegistry(HKEY_CURRENT_USER);
ASSERT_NO_FATAL_FAILURE(override_manager.OverrideRegistry(HKEY_CURRENT_USER));
const wchar_t kRootKey[] = L"Software\\TestKey";
const RegistryKeyInfo kRegKeysToCollect[] = {
......
......@@ -212,7 +212,8 @@ class IncidentReportingServiceTest : public testing::Test {
#if defined(OS_WIN)
// Redirect HKCU so that the platform state store used by the test doesn't
// collide with existing Chrome installs or other tests running in parallel.
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
#endif
ASSERT_TRUE(profile_manager_.SetUp());
}
......
......@@ -42,7 +42,8 @@ class PlatformStateStoreWinTest : public ::testing::Test {
void SetUp() override {
::testing::Test::SetUp();
base::MessageLoop::current()->SetTaskRunner(task_runner_);
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
ASSERT_TRUE(profile_manager_.SetUp());
}
......
......@@ -46,7 +46,8 @@ class PlatformStateStoreTestBase : public ::testing::Test {
void SetUp() override {
::testing::Test::SetUp();
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
}
private:
......
......@@ -30,7 +30,8 @@ class ChromeBlacklistTrialTest : public testing::Test {
void SetUp() override {
testing::Test::SetUp();
override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
ASSERT_NO_FATAL_FAILURE(
override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
blacklist_registry_key_.reset(
new base::win::RegKey(HKEY_CURRENT_USER,
......
......@@ -273,20 +273,20 @@ class InstallStaticUtilTest
scoped_install_details_(system_level_, std::get<0>(GetParam())),
mode_(&InstallDetails::Get().mode()),
root_key_(system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER),
nt_root_key_(system_level_ ? nt::HKLM : nt::HKCU) {
nt_root_key_(system_level_ ? nt::HKLM : nt::HKCU) {}
void SetUp() override {
ASSERT_TRUE(!system_level_ || mode_->supports_system_level);
base::string16 path;
override_manager_.OverrideRegistry(root_key_, &path);
ASSERT_NO_FATAL_FAILURE(
override_manager_.OverrideRegistry(root_key_, &path));
nt::SetTestingOverride(nt_root_key_, path);
}
~InstallStaticUtilTest() {
void TearDown() override {
nt::SetTestingOverride(nt_root_key_, base::string16());
}
void SetUp() override {
ASSERT_TRUE(!system_level_ || mode_->supports_system_level);
}
bool system_level() const { return system_level_; }
const wchar_t* default_channel() const { return mode_->default_channel_name; }
......
......@@ -173,15 +173,19 @@ class MakeProductDetailsTest : public testing::TestWithParam<TestData> {
root_key_(test_data_.system_level ? HKEY_LOCAL_MACHINE
: HKEY_CURRENT_USER),
nt_root_key_(test_data_.system_level ? nt::HKLM : nt::HKCU) {
base::string16 path;
override_manager_.OverrideRegistry(root_key_, &path);
nt::SetTestingOverride(nt_root_key_, path);
}
~MakeProductDetailsTest() {
nt::SetTestingOverride(nt_root_key_, base::string16());
}
void SetUp() override {
base::string16 path;
ASSERT_NO_FATAL_FAILURE(
override_manager_.OverrideRegistry(root_key_, &path));
nt::SetTestingOverride(nt_root_key_, path);
}
const TestData& test_data() const { return test_data_; }
void SetAp(const wchar_t* value) {
......
......@@ -71,7 +71,8 @@ TEST(UserDataDir, RegistrySettingsInHKLMOverrides) {
// precedence over the command line in both implementations.
registry_util::RegistryOverrideManager override_manager;
base::string16 temp;
override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp);
ASSERT_NO_FATAL_FAILURE(
override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp));
ScopedNTRegistryTestingOverride nt_override(nt::HKLM, temp);
base::win::RegKey key(HKEY_LOCAL_MACHINE, kPolicyRegistryKey, KEY_WRITE);
......@@ -92,7 +93,8 @@ TEST(UserDataDir, RegistrySettingsInHKCUOverrides) {
// precedence over the command line in both implementations.
registry_util::RegistryOverrideManager override_manager;
base::string16 temp;
override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp);
ASSERT_NO_FATAL_FAILURE(
override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp));
ScopedNTRegistryTestingOverride nt_override(nt::HKCU, temp);
base::win::RegKey key(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE);
......@@ -113,14 +115,16 @@ TEST(UserDataDir, RegistrySettingsInHKLMTakesPrecedenceOverHKCU) {
// precedence.
registry_util::RegistryOverrideManager override_manager;
base::string16 temp;
override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp);
ASSERT_NO_FATAL_FAILURE(
override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE, &temp));
ScopedNTRegistryTestingOverride nt_override(nt::HKLM, temp);
LONG rv;
base::win::RegKey key1(HKEY_LOCAL_MACHINE, kPolicyRegistryKey, KEY_WRITE);
rv = key1.WriteValue(kUserDataDirRegistryKey, L"111");
ASSERT_EQ(rv, ERROR_SUCCESS);
override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp);
ASSERT_NO_FATAL_FAILURE(
override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp));
ScopedNTRegistryTestingOverride nt_override2(nt::HKCU, temp);
base::win::RegKey key2(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE);
rv = key2.WriteValue(kUserDataDirRegistryKey, L"222");
......@@ -138,7 +142,8 @@ TEST(UserDataDir, RegistrySettingWithPathExpansionHKCU) {
registry_util::RegistryOverrideManager override_manager;
base::string16 temp;
override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp);
ASSERT_NO_FATAL_FAILURE(
override_manager.OverrideRegistry(HKEY_CURRENT_USER, &temp));
ScopedNTRegistryTestingOverride nt_override(nt::HKCU, temp);
base::win::RegKey key(HKEY_CURRENT_USER, kPolicyRegistryKey, KEY_WRITE);
LONG rv = key.WriteValue(kUserDataDirRegistryKey, L"${windows}");
......
......@@ -66,8 +66,6 @@ test("gcapi_test") {
"gcapi_reactivation_test.cc",
"gcapi_test.cc",
"gcapi_test.rc",
"gcapi_test_registry_overrider.cc",
"gcapi_test_registry_overrider.h",
"resource.h",
]
......
......@@ -26,7 +26,8 @@ class GCAPILastRunTest : public ::testing::Test {
protected:
void SetUp() override {
// Override keys - this is undone during destruction.
override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
ASSERT_NO_FATAL_FAILURE(
override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
// Create the client state key in the right places.
std::wstring reg_path(google_update::kRegPathClientState);
......
......@@ -7,8 +7,8 @@
#include <stdint.h>
#include "base/strings/utf_string_conversions.h"
#include "base/test/test_reg_util_win.h"
#include "chrome/installer/gcapi/gcapi.h"
#include "chrome/installer/gcapi/gcapi_test_registry_overrider.h"
#include "chrome/installer/util/google_update_constants.h"
#include "chrome/installer/util/google_update_settings.h"
#include "components/variations/variations_experiment_util.h"
......@@ -35,6 +35,13 @@ class GCAPIOmahaExperimentTest : public ::testing::Test {
kBrand, gcapi_internals::kRelaunchLabel)) {
}
void SetUp() override {
ASSERT_NO_FATAL_FAILURE(
override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
ASSERT_NO_FATAL_FAILURE(
override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE));
}
void VerifyExperimentLabels(const base::string16& expected_labels) {
base::string16 actual_labels;
EXPECT_TRUE(GoogleUpdateSettings::ReadExperimentLabels(false,
......@@ -42,11 +49,10 @@ class GCAPIOmahaExperimentTest : public ::testing::Test {
EXPECT_EQ(expected_labels, actual_labels);
}
registry_util::RegistryOverrideManager override_manager_;
base::string16 brand_;
base::string16 reactivation_label_;
base::string16 relaunch_label_;
const GCAPITestRegistryOverrider gcapi_test_registry_overrider_;
};
TEST_F(GCAPIOmahaExperimentTest, SetReactivationLabelFromEmptyExperiments) {
......
......@@ -7,12 +7,12 @@
#include <string>
#include "base/strings/string_number_conversions.h"
#include "base/test/test_reg_util_win.h"
#include "base/time/time.h"
#include "base/win/registry.h"
#include "chrome/installer/gcapi/gcapi.h"
#include "chrome/installer/gcapi/gcapi_omaha_experiment.h"
#include "chrome/installer/gcapi/gcapi_reactivation.h"
#include "chrome/installer/gcapi/gcapi_test_registry_overrider.h"
#include "chrome/installer/util/google_update_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -24,6 +24,13 @@ class GCAPIReactivationTest : public ::testing::Test {
protected:
GCAPIReactivationTest() {}
void SetUp() override {
ASSERT_NO_FATAL_FAILURE(
override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
ASSERT_NO_FATAL_FAILURE(
override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE));
}
bool SetChromeInstallMarker(HKEY hive) {
// Create the client state keys in the right places.
std::wstring reg_path(google_update::kRegPathClients);
......@@ -91,7 +98,7 @@ class GCAPIReactivationTest : public ::testing::Test {
return L"ERROR";
}
const GCAPITestRegistryOverrider gcapi_test_registry_overrider_;
registry_util::RegistryOverrideManager override_manager_;
};
TEST_F(GCAPIReactivationTest, CheckSetReactivationBrandCode) {
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/installer/gcapi/gcapi_test_registry_overrider.h"
#include "base/guid.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
GCAPITestRegistryOverrider::GCAPITestRegistryOverrider() {
// Override keys - this is undone during destruction.
override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE);
}
GCAPITestRegistryOverrider::~GCAPITestRegistryOverrider() {
}
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_INSTALLER_GCAPI_GCAPI_TEST_REGISTRY_OVERRIDER_H_
#define CHROME_INSTALLER_GCAPI_GCAPI_TEST_REGISTRY_OVERRIDER_H_
#include "base/macros.h"
#include "base/test/test_reg_util_win.h"
// Overrides the registry throughout its lifetime; used by GCAPI tests
// overriding the registry.
class GCAPITestRegistryOverrider {
public:
GCAPITestRegistryOverrider();
~GCAPITestRegistryOverrider();
private:
registry_util::RegistryOverrideManager override_manager_;
DISALLOW_COPY_AND_ASSIGN(GCAPITestRegistryOverrider);
};
#endif // CHROME_INSTALLER_GCAPI_GCAPI_TEST_REGISTRY_OVERRIDER_H_
......@@ -52,9 +52,13 @@ class TestConfiguration : public Configuration {
class MiniInstallerConfigurationTest : public ::testing::Test {
protected:
MiniInstallerConfigurationTest() {
registry_overrides_.OverrideRegistry(HKEY_CURRENT_USER);
registry_overrides_.OverrideRegistry(HKEY_LOCAL_MACHINE);
MiniInstallerConfigurationTest() = default;
void SetUp() override {
ASSERT_NO_FATAL_FAILURE(
registry_overrides_.OverrideRegistry(HKEY_CURRENT_USER));
ASSERT_NO_FATAL_FAILURE(
registry_overrides_.OverrideRegistry(HKEY_LOCAL_MACHINE));
}
// Adds sufficient state in the registry for Configuration to think that
......
......@@ -87,7 +87,7 @@ TEST_F(InstallerStateTest, WithProduct) {
{
RegistryOverrideManager override_manager;
override_manager.OverrideRegistry(root);
ASSERT_NO_FATAL_FAILURE(override_manager.OverrideRegistry(root));
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS);
EXPECT_TRUE(chrome_key.Valid());
......@@ -123,7 +123,7 @@ TEST_F(InstallerStateTest, InstallerResult) {
};
for (const wchar_t* command_line : kCommandLines) {
RegistryOverrideManager override_manager;
override_manager.OverrideRegistry(root);
ASSERT_NO_FATAL_FAILURE(override_manager.OverrideRegistry(root));
base::CommandLine cmd_line = base::CommandLine::FromString(command_line);
const MasterPreferences prefs(cmd_line);
InstallationState machine_state;
......@@ -164,8 +164,9 @@ TEST_F(InstallerStateTest, InitializeTwice) {
base::ScopedPathOverride local_app_data_override(base::DIR_LOCAL_APP_DATA,
temp);
registry_util::RegistryOverrideManager override_manager;
override_manager.OverrideRegistry(HKEY_CURRENT_USER);
override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE);
ASSERT_NO_FATAL_FAILURE(override_manager.OverrideRegistry(HKEY_CURRENT_USER));
ASSERT_NO_FATAL_FAILURE(
override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE));
InstallationState machine_state;
machine_state.Initialize();
......
......@@ -197,7 +197,8 @@ TEST(SetupUtilTest, GuidToSquid) {
TEST(SetupUtilTest, RegisterEventLogProvider) {
registry_util::RegistryOverrideManager registry_override_manager;
registry_override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE);
ASSERT_NO_FATAL_FAILURE(
registry_override_manager.OverrideRegistry(HKEY_LOCAL_MACHINE));
const base::Version version("1.2.3.4");
const base::FilePath install_directory(
......@@ -374,8 +375,10 @@ class FindArchiveToPatchTest : public testing::Test {
void SetUp() override {
ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE);
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE));
product_version_ = base::Version("30.0.1559.0");
max_version_ = base::Version("47.0.1559.0");
......@@ -530,7 +533,7 @@ class DeleteRegistryKeyPartialTest : public ::testing::Test {
using RegKey = base::win::RegKey;
void SetUp() override {
_registry_override_manager.OverrideRegistry(root_);
ASSERT_NO_FATAL_FAILURE(_registry_override_manager.OverrideRegistry(root_));
to_preserve_.push_back(L"preSERve1");
to_preserve_.push_back(L"1evRESerp");
}
......@@ -641,7 +644,8 @@ class LegacyCleanupsTest : public ::testing::Test {
LegacyCleanupsTest() = default;
void SetUp() override {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
installer_state_ =
base::MakeUnique<FakeInstallerState>(temp_dir_.GetPath());
// Create the state to be cleared.
......
......@@ -80,7 +80,8 @@ class UpdateActiveSetupVersionWorkItemTest
UpdateActiveSetupVersionWorkItemTest() {}
void SetUp() override {
registry_override_manager_.OverrideRegistry(kActiveSetupRoot);
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(kActiveSetupRoot));
}
private:
......
......@@ -41,10 +41,14 @@ class BeaconTest : public ::testing::TestWithParam<
beacon_type_,
beacon_scope_,
system_install_,
app_registration_data_) {
app_registration_data_) {}
void SetUp() override {
// Override the registry so that tests can freely push state to it.
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE);
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE));
}
TestAppRegistrationData app_registration_data_;
......@@ -177,8 +181,10 @@ class DefaultBrowserBeaconTest
}
// Override the registry so that tests can freely push state to it.
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE);
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE));
// Ensure that IsPerUserInstall returns the proper value.
ASSERT_EQ(!system_install_, InstallUtil::IsPerUserInstall(chrome_exe_));
......
......@@ -28,7 +28,8 @@ class DeleteRegValueWorkItemTest : public testing::Test {
DeleteRegValueWorkItemTest() {}
void SetUp() override {
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
}
private:
......
......@@ -52,9 +52,13 @@ class GoogleUpdateSettingsTest : public testing::Test {
GoogleUpdateSettingsTest()
: program_files_override_(base::DIR_PROGRAM_FILES),
program_files_x86_override_(base::DIR_PROGRAM_FILESX86) {
registry_overrides_.OverrideRegistry(HKEY_LOCAL_MACHINE);
registry_overrides_.OverrideRegistry(HKEY_CURRENT_USER);
program_files_x86_override_(base::DIR_PROGRAM_FILESX86) {}
void SetUp() override {
ASSERT_NO_FATAL_FAILURE(
registry_overrides_.OverrideRegistry(HKEY_LOCAL_MACHINE));
ASSERT_NO_FATAL_FAILURE(
registry_overrides_.OverrideRegistry(HKEY_CURRENT_USER));
}
void SetApField(SystemUserInstall is_system, const wchar_t* value) {
......@@ -1203,8 +1207,10 @@ void CollectStatsConsent::TearDownTestCase() {
// Install the registry override and apply the settings to the registry.
void CollectStatsConsent::SetUp() {
// Override both HKLM and HKCU as tests may touch either/both.
override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE);
override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
ASSERT_NO_FATAL_FAILURE(
override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE));
ASSERT_NO_FATAL_FAILURE(
override_manager_.OverrideRegistry(HKEY_CURRENT_USER));
const StatsState& stats_state = GetParam();
const HKEY root_key = stats_state.root_key();
......
......@@ -47,15 +47,15 @@ class InstallUtilTest : public testing::Test {
protected:
InstallUtilTest() {}
void SetUp() override {
ResetRegistryOverrides();
}
void SetUp() override { ASSERT_NO_FATAL_FAILURE(ResetRegistryOverrides()); }
void ResetRegistryOverrides() {
registry_override_manager_.reset(
new registry_util::RegistryOverrideManager);
registry_override_manager_->OverrideRegistry(HKEY_CURRENT_USER);
registry_override_manager_->OverrideRegistry(HKEY_LOCAL_MACHINE);
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_->OverrideRegistry(HKEY_CURRENT_USER));
ASSERT_NO_FATAL_FAILURE(
registry_override_manager_->OverrideRegistry(HKEY_LOCAL_MACHINE));
}
private:
......@@ -207,7 +207,7 @@ TEST_F(InstallUtilTest, DeleteRegistryValueIf) {
const wchar_t value[] = L"hi mom";
{
ResetRegistryOverrides();
ASSERT_NO_FATAL_FAILURE(ResetRegistryOverrides());
// Nothing to delete if the key isn't even there.
{
MockRegistryValuePredicate pred;
......@@ -270,7 +270,7 @@ TEST_F(InstallUtilTest, DeleteRegistryValueIf) {
}
{
ResetRegistryOverrides();
ASSERT_NO_FATAL_FAILURE(ResetRegistryOverrides());
// Default value matches: delete using empty string.
{
MockRegistryValuePredicate pred;
......@@ -290,7 +290,7 @@ TEST_F(InstallUtilTest, DeleteRegistryValueIf) {
}
{
ResetRegistryOverrides();
ASSERT_NO_FATAL_FAILURE(ResetRegistryOverrides());
// Default value matches: delete using NULL.
{
MockRegistryValuePredicate pred;
......
......@@ -19,6 +19,8 @@ class ProductStateTest : public testing::TestWithParam<bool> {
protected:
ProductStateTest();
void SetUp() override;
void ApplyUninstallCommand(const wchar_t* exe_path, const wchar_t* args);
void MinimallyInstallProduct(const wchar_t* version);
......@@ -31,14 +33,17 @@ class ProductStateTest : public testing::TestWithParam<bool> {
ProductStateTest::ProductStateTest()
: system_install_(GetParam()),