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 8e76918f221d4e0e7e21c767b0dc61f2520aaa94..14c4d37d781d7d032496ab5eaafff9c1bf63a7a4 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" |
@@ -293,7 +295,8 @@ void MockPrefHashStore::MockPrefHashStoreTransaction::StoreSplitHash( |
// |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) |
@@ -301,19 +304,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: |
@@ -321,6 +331,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); |
}; |
@@ -337,6 +352,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) { |
@@ -356,6 +372,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) { |
@@ -377,6 +395,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) { |
@@ -508,6 +528,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. |
@@ -520,6 +542,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_); |
} |
} |
@@ -619,6 +643,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. |
@@ -636,6 +662,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_); |
} |
} |
@@ -694,6 +722,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. |
@@ -701,6 +731,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_); |
} |
} |
@@ -751,6 +783,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; |
@@ -762,6 +796,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_); |
} |
} |