Index: chrome/browser/prefs/pref_hash_filter_unittest.cc |
diff --git a/chrome/browser/prefs/pref_hash_filter_unittest.cc b/chrome/browser/prefs/pref_hash_filter_unittest.cc |
index 66f5cc46cf3e3dd9460867c63f0f894fec28eea0..e1793f53678b7c77f42aa7a6a3ce9baee219e5d5 100644 |
--- a/chrome/browser/prefs/pref_hash_filter_unittest.cc |
+++ b/chrome/browser/prefs/pref_hash_filter_unittest.cc |
@@ -10,6 +10,8 @@ |
#include <utility> |
#include "base/basictypes.h" |
+#include "base/bind.h" |
+#include "base/callback_forward.h" |
#include "base/compiler_specific.h" |
#include "base/logging.h" |
#include "base/memory/ref_counted.h" |
@@ -214,7 +216,8 @@ void MockPrefHashStore::RecordStoreHash( |
// |mock_pref_hash_store|. |
scoped_ptr<PrefHashFilter> CreatePrefHashFilter( |
PrefHashFilter::EnforcementLevel enforcement_level, |
- MockPrefHashStore** mock_pref_hash_store) { |
+ MockPrefHashStore** mock_pref_hash_store, |
+ const base::Closure& reset_callback) { |
scoped_ptr<MockPrefHashStore> temp_mock_pref_hash_store( |
new MockPrefHashStore); |
if (mock_pref_hash_store) |
@@ -222,19 +225,26 @@ scoped_ptr<PrefHashFilter> CreatePrefHashFilter( |
return scoped_ptr<PrefHashFilter>( |
new PrefHashFilter(temp_mock_pref_hash_store.PassAs<PrefHashStore>(), |
kTestTrackedPrefs, arraysize(kTestTrackedPrefs), |
- arraysize(kTestTrackedPrefs), |
- enforcement_level)); |
+ arraysize(kTestTrackedPrefs), enforcement_level, |
+ reset_callback)); |
} |
class PrefHashFilterTest |
: public testing::TestWithParam<PrefHashFilter::EnforcementLevel> { |
public: |
- PrefHashFilterTest() : mock_pref_hash_store_(NULL) {} |
+ PrefHashFilterTest() : mock_pref_hash_store_(NULL), reset_event_count_(0) {} |
virtual void SetUp() OVERRIDE { |
// Construct a PrefHashFilter and MockPrefHashStore for the test. |
- pref_hash_filter_ = CreatePrefHashFilter(GetParam(), |
- &mock_pref_hash_store_); |
+ pref_hash_filter_ = CreatePrefHashFilter( |
+ GetParam(), &mock_pref_hash_store_, |
+ base::Bind(&PrefHashFilterTest::HandleResetEvent, |
+ base::Unretained(this))); |
+ reset_event_count_ = 0; |
+ } |
+ |
+ void HandleResetEvent() { |
+ ++reset_event_count_; |
} |
protected: |
@@ -242,6 +252,11 @@ class PrefHashFilterTest |
base::DictionaryValue pref_store_contents_; |
scoped_ptr<PrefHashFilter> pref_hash_filter_; |
+ // The number of times a reset event occurs. A reset event is defined as |
+ // the discovery of a set of one or more changed tracked preferences during |
+ // load time. |
+ int reset_event_count_; |
+ |
DISALLOW_COPY_AND_ASSIGN(PrefHashFilterTest); |
}; |
@@ -258,6 +273,7 @@ TEST_P(PrefHashFilterTest, EmptyAndUnchanged) { |
ASSERT_EQ(NULL, mock_pref_hash_store_->checked_value( |
kTestTrackedPrefs[i].name).first); |
} |
+ ASSERT_EQ(0, reset_event_count_); |
} |
TEST_P(PrefHashFilterTest, FilterTrackedPrefUpdate) { |
@@ -277,6 +293,8 @@ TEST_P(PrefHashFilterTest, FilterTrackedPrefUpdate) { |
mock_pref_hash_store_->stored_value(kAtomicPref); |
ASSERT_EQ(string_value, stored_value.first); |
ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_ATOMIC, stored_value.second); |
+ |
+ ASSERT_EQ(0, reset_event_count_); |
} |
TEST_P(PrefHashFilterTest, FilterSplitPrefUpdate) { |
@@ -298,6 +316,8 @@ TEST_P(PrefHashFilterTest, FilterSplitPrefUpdate) { |
mock_pref_hash_store_->stored_value(kSplitPref); |
ASSERT_EQ(dict_value, stored_value.first); |
ASSERT_EQ(PrefHashFilter::TRACKING_STRATEGY_SPLIT, stored_value.second); |
+ |
+ ASSERT_EQ(0, reset_event_count_); |
} |
TEST_P(PrefHashFilterTest, FilterUntrackedPrefUpdate) { |
@@ -425,6 +445,8 @@ TEST_P(PrefHashFilterTest, InitialValueUnknown) { |
ASSERT_FALSE(pref_store_contents_.Get(kSplitPref, NULL)); |
ASSERT_EQ(NULL, stored_split_value.first); |
+ |
+ ASSERT_EQ(1, reset_event_count_); |
} else { |
// Otherwise the values should have remained intact and the hashes should |
// have been updated to match them. |
@@ -437,6 +459,8 @@ TEST_P(PrefHashFilterTest, InitialValueUnknown) { |
ASSERT_TRUE(pref_store_contents_.Get(kSplitPref, &split_value_in_store)); |
ASSERT_EQ(dict_value, split_value_in_store); |
ASSERT_EQ(dict_value, stored_split_value.first); |
+ |
+ ASSERT_EQ(0, reset_event_count_); |
} |
} |
@@ -534,6 +558,8 @@ TEST_P(PrefHashFilterTest, InitialValueChanged) { |
ASSERT_FALSE(dict_value->HasKey("c")); |
ASSERT_TRUE(dict_value->HasKey("d")); |
ASSERT_EQ(dict_value, stored_split_value.first); |
+ |
+ ASSERT_EQ(1, reset_event_count_); |
} else { |
// Otherwise the value should have remained intact and the hash should have |
// been updated to match it. |
@@ -551,6 +577,8 @@ TEST_P(PrefHashFilterTest, InitialValueChanged) { |
ASSERT_TRUE(dict_value->HasKey("c")); |
ASSERT_TRUE(dict_value->HasKey("d")); |
ASSERT_EQ(dict_value, stored_split_value.first); |
+ |
+ ASSERT_EQ(0, reset_event_count_); |
} |
} |
@@ -606,6 +634,8 @@ TEST_P(PrefHashFilterTest, InitialValueMigrated) { |
// current enforcement level prevents migration. |
ASSERT_FALSE(pref_store_contents_.Get(kAtomicPref, NULL)); |
ASSERT_EQ(NULL, stored_atomic_value.first); |
+ |
+ ASSERT_EQ(1, reset_event_count_); |
} else { |
// Otherwise the value should have remained intact and the hash should have |
// been updated to match it. |
@@ -613,6 +643,8 @@ TEST_P(PrefHashFilterTest, InitialValueMigrated) { |
ASSERT_TRUE(pref_store_contents_.Get(kAtomicPref, &atomic_value_in_store)); |
ASSERT_EQ(list_value, atomic_value_in_store); |
ASSERT_EQ(list_value, stored_atomic_value.first); |
+ |
+ ASSERT_EQ(0, reset_event_count_); |
} |
} |
@@ -661,6 +693,8 @@ TEST_P(PrefHashFilterTest, DontResetReportOnly) { |
ASSERT_FALSE(pref_store_contents_.Get(kAtomicPref2, NULL)); |
ASSERT_EQ(NULL, mock_pref_hash_store_->stored_value(kAtomicPref).first); |
ASSERT_EQ(NULL, mock_pref_hash_store_->stored_value(kAtomicPref2).first); |
+ |
+ ASSERT_EQ(1, reset_event_count_); |
} else { |
const base::Value* value_in_store; |
const base::Value* value_in_store2; |
@@ -672,6 +706,8 @@ TEST_P(PrefHashFilterTest, DontResetReportOnly) { |
ASSERT_EQ(int_value2, value_in_store2); |
ASSERT_EQ(int_value2, |
mock_pref_hash_store_->stored_value(kAtomicPref2).first); |
+ |
+ ASSERT_EQ(0, reset_event_count_); |
} |
} |