Index: chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
diff --git a/chrome/browser/prefs/profile_pref_store_manager_unittest.cc b/chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
index cca594799c2f82e2e6aa4bdfbd05afcac7a59e16..24b39669b83bbbf2b33e1b4eb264db0dcf347b97 100644 |
--- a/chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
+++ b/chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
@@ -22,7 +22,9 @@ |
#include "base/run_loop.h" |
#include "base/strings/string_util.h" |
#include "base/values.h" |
+#include "chrome/browser/prefs/mock_validation_observer.h" |
#include "chrome/browser/prefs/pref_hash_filter.h" |
+#include "chrome/browser/prefs/tracked/tracked_preference_validation_observer.h" |
#include "components/user_prefs/pref_registry_syncable.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -88,7 +90,8 @@ class ProfilePrefStoreManagerTest : public testing::Test { |
: configuration_(kConfiguration, |
kConfiguration + arraysize(kConfiguration)), |
profile_pref_registry_(new user_prefs::PrefRegistrySyncable), |
- registry_verifier_(profile_pref_registry_) {} |
+ registry_verifier_(profile_pref_registry_), |
+ validation_data_(new MockValidationObserver::ValidationData) {} |
virtual void SetUp() OVERRIDE { |
ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); |
@@ -138,14 +141,21 @@ class ProfilePrefStoreManagerTest : public testing::Test { |
} |
void InitializePrefs() { |
+ // Provide a validation observer that collects events for verification. |
+ scoped_ptr<MockValidationObserver> mock_validation_observer( |
+ new MockValidationObserver(validation_data_)); |
+ |
// According to the implementation of ProfilePrefStoreManager, this is |
// actually a SegregatedPrefStore backed by two underlying pref stores. |
scoped_refptr<PersistentPrefStore> pref_store = |
manager_->CreateProfilePrefStore( |
- main_message_loop_.message_loop_proxy()); |
+ main_message_loop_.message_loop_proxy(), |
+ mock_validation_observer |
+ .PassAs<TrackedPreferenceValidationObserver>()); |
InitializePrefStore(pref_store); |
- pref_store = NULL; |
base::RunLoop().RunUntilIdle(); |
+ |
+ pref_store = NULL; |
} |
void DestroyPrefStore() { |
@@ -187,7 +197,8 @@ class ProfilePrefStoreManagerTest : public testing::Test { |
void LoadExistingPrefs() { |
DestroyPrefStore(); |
pref_store_ = manager_->CreateProfilePrefStore( |
- main_message_loop_.message_loop_proxy()); |
+ main_message_loop_.message_loop_proxy(), |
+ scoped_ptr<TrackedPreferenceValidationObserver>()); |
pref_store_->AddObserver(®istry_verifier_); |
pref_store_->ReadPrefs(); |
} |
@@ -221,6 +232,14 @@ class ProfilePrefStoreManagerTest : public testing::Test { |
} |
} |
+ void ExpectValidationObserved(const std::string& pref_path) { |
+ // No validations are expected for platforms that do not support tracking. |
+ if (!ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking) |
+ return; |
+ if (!validation_data_->GetEventForPath(pref_path)) |
+ ADD_FAILURE() << "No validation observed for preference: " << pref_path; |
+ } |
+ |
base::MessageLoop main_message_loop_; |
std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_; |
base::ScopedTempDir profile_dir_; |
@@ -229,6 +248,7 @@ class ProfilePrefStoreManagerTest : public testing::Test { |
RegistryVerifier registry_verifier_; |
scoped_ptr<ProfilePrefStoreManager> manager_; |
scoped_refptr<PersistentPrefStore> pref_store_; |
+ scoped_refptr<MockValidationObserver::ValidationData> validation_data_; |
}; |
TEST_F(ProfilePrefStoreManagerTest, StoreValues) { |
@@ -239,6 +259,8 @@ TEST_F(ProfilePrefStoreManagerTest, StoreValues) { |
ExpectStringValueEquals(kTrackedAtomic, kFoobar); |
ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
EXPECT_FALSE(WasResetRecorded()); |
+ ExpectValidationObserved(kTrackedAtomic); |
+ ExpectValidationObserved(kProtectedAtomic); |
} |
TEST_F(ProfilePrefStoreManagerTest, GetPrefFilePathFromProfilePath) { |
@@ -271,6 +293,9 @@ TEST_F(ProfilePrefStoreManagerTest, ProtectValues) { |
pref_store_->GetValue(kProtectedAtomic, NULL)); |
EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
WasResetRecorded()); |
+ |
+ ExpectValidationObserved(kTrackedAtomic); |
+ ExpectValidationObserved(kProtectedAtomic); |
} |
TEST_F(ProfilePrefStoreManagerTest, ResetPrefHashStore) { |
@@ -288,6 +313,9 @@ TEST_F(ProfilePrefStoreManagerTest, ResetPrefHashStore) { |
pref_store_->GetValue(kProtectedAtomic, NULL)); |
EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
WasResetRecorded()); |
+ |
+ ExpectValidationObserved(kTrackedAtomic); |
+ ExpectValidationObserved(kProtectedAtomic); |
} |
TEST_F(ProfilePrefStoreManagerTest, ResetAllPrefHashStores) { |
@@ -305,6 +333,9 @@ TEST_F(ProfilePrefStoreManagerTest, ResetAllPrefHashStores) { |
pref_store_->GetValue(kProtectedAtomic, NULL)); |
EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
WasResetRecorded()); |
+ |
+ ExpectValidationObserved(kTrackedAtomic); |
+ ExpectValidationObserved(kProtectedAtomic); |
} |
TEST_F(ProfilePrefStoreManagerTest, MigrateFromOneFile) { |
@@ -360,6 +391,10 @@ TEST_F(ProfilePrefStoreManagerTest, InitializePrefsFromMasterPrefs) { |
TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtected) { |
InitializePrefs(); |
+ |
+ ExpectValidationObserved(kTrackedAtomic); |
+ ExpectValidationObserved(kProtectedAtomic); |
+ |
LoadExistingPrefs(); |
ExpectStringValueEquals(kUnprotectedPref, kFoobar); |
@@ -403,6 +438,9 @@ TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtected) { |
TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { |
InitializePrefs(); |
+ ExpectValidationObserved(kTrackedAtomic); |
+ ExpectValidationObserved(kProtectedAtomic); |
+ |
// Now update the configuration to protect it. |
PrefHashFilter::TrackedPreferenceMetadata new_protected = { |
kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD, |
@@ -430,6 +468,10 @@ TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { |
// preference's protection state changes from protected to unprotected. |
TEST_F(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { |
InitializePrefs(); |
+ |
+ ExpectValidationObserved(kTrackedAtomic); |
+ ExpectValidationObserved(kProtectedAtomic); |
+ |
DestroyPrefStore(); |
// Unconfigure protection for kProtectedAtomic |