Index: chrome/browser/safe_browsing/incident_reporting/state_store_unittest.cc |
diff --git a/chrome/browser/safe_browsing/incident_reporting/state_store_unittest.cc b/chrome/browser/safe_browsing/incident_reporting/state_store_unittest.cc |
index 5ec58bf226aaf9e725964c076a783c86e7c3f4af..f3e11b9bd14e577e5f5e7d2c16ce0d362a0f22b4 100644 |
--- a/chrome/browser/safe_browsing/incident_reporting/state_store_unittest.cc |
+++ b/chrome/browser/safe_browsing/incident_reporting/state_store_unittest.cc |
@@ -23,11 +23,41 @@ |
#include "components/pref_registry/pref_registry_syncable.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#if defined(OS_WIN) |
+#include "base/test/test_reg_util_win.h" |
+#endif |
+ |
namespace safe_browsing { |
+#if defined(OS_WIN) |
+ |
+// A base test fixture that redirects HKCU for testing the platform state store |
+// backed by the Windows registry to prevent interference with existing Chrome |
+// installs or other tests. |
+class PlatformStateStoreTestBase : public ::testing::Test { |
+ protected: |
+ PlatformStateStoreTestBase() {} |
+ |
+ void SetUp() override { |
+ ::testing::Test::SetUp(); |
+ registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER); |
+ } |
+ |
+ private: |
+ registry_util::RegistryOverrideManager registry_override_manager_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PlatformStateStoreTestBase); |
+}; |
+ |
+#else // OS_WIN |
+ |
+using PlatformStateStoreTestBase = ::testing::Test; |
+ |
+#endif // !OS_WIN |
+ |
// A test fixture with a testing profile that writes its user prefs to a json |
// file. |
-class StateStoreTest : public ::testing::Test { |
+class StateStoreTest : public PlatformStateStoreTestBase { |
protected: |
struct TestData { |
IncidentType type; |
@@ -42,7 +72,7 @@ class StateStoreTest : public ::testing::Test { |
profile_manager_(TestingBrowserProcess::GetGlobal()) {} |
void SetUp() override { |
- testing::Test::SetUp(); |
+ PlatformStateStoreTestBase::SetUp(); |
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
ASSERT_TRUE(profile_manager_.SetUp()); |
CreateProfile(); |
@@ -199,10 +229,10 @@ TEST_F(StateStoreTest, PersistenceWithStoreDelete) { |
// Recreate the profile. |
CreateProfile(); |
- // Verify that the state did not survive. |
+ // Verify that the state survived. |
StateStore state_store(profile_); |
for (const auto& data : kTestData_) |
- ASSERT_FALSE(state_store.HasBeenReported(data.type, data.key, data.digest)); |
+ ASSERT_TRUE(state_store.HasBeenReported(data.type, data.key, data.digest)); |
} |
} // namespace safe_browsing |