OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/user_prefs/tracked/pref_hash_filter.h" | 5 #include "components/user_prefs/tracked/pref_hash_filter.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 381 |
382 // Initializes |pref_hash_filter_| with a PrefHashFilter that uses a | 382 // Initializes |pref_hash_filter_| with a PrefHashFilter that uses a |
383 // MockPrefHashStore. The raw pointer to the MockPrefHashStore (owned by the | 383 // MockPrefHashStore. The raw pointer to the MockPrefHashStore (owned by the |
384 // PrefHashFilter) is stored in |mock_pref_hash_store_|. | 384 // PrefHashFilter) is stored in |mock_pref_hash_store_|. |
385 void InitializePrefHashFilter(const std::vector< | 385 void InitializePrefHashFilter(const std::vector< |
386 PrefHashFilter::TrackedPreferenceMetadata>& configuration) { | 386 PrefHashFilter::TrackedPreferenceMetadata>& configuration) { |
387 scoped_ptr<MockPrefHashStore> temp_mock_pref_hash_store( | 387 scoped_ptr<MockPrefHashStore> temp_mock_pref_hash_store( |
388 new MockPrefHashStore); | 388 new MockPrefHashStore); |
389 mock_pref_hash_store_ = temp_mock_pref_hash_store.get(); | 389 mock_pref_hash_store_ = temp_mock_pref_hash_store.get(); |
390 pref_hash_filter_.reset(new PrefHashFilter( | 390 pref_hash_filter_.reset(new PrefHashFilter( |
391 temp_mock_pref_hash_store.Pass(), configuration, | 391 std::move(temp_mock_pref_hash_store), configuration, |
392 base::Bind(&PrefHashFilterTest::RecordReset, base::Unretained(this)), | 392 base::Bind(&PrefHashFilterTest::RecordReset, base::Unretained(this)), |
393 &mock_validation_delegate_, arraysize(kTestTrackedPrefs), true)); | 393 &mock_validation_delegate_, arraysize(kTestTrackedPrefs), true)); |
394 } | 394 } |
395 | 395 |
396 // Verifies whether a reset was reported by the PrefHashFiler. Also verifies | 396 // Verifies whether a reset was reported by the PrefHashFiler. Also verifies |
397 // that kPreferenceResetTime was set (or not) accordingly. | 397 // that kPreferenceResetTime was set (or not) accordingly. |
398 void VerifyRecordedReset(bool reset_expected) { | 398 void VerifyRecordedReset(bool reset_expected) { |
399 EXPECT_EQ(reset_expected, reset_recorded_); | 399 EXPECT_EQ(reset_expected, reset_recorded_); |
400 EXPECT_EQ(reset_expected, | 400 EXPECT_EQ(reset_expected, |
401 pref_store_contents_->Get( | 401 pref_store_contents_->Get( |
402 user_prefs::kPreferenceResetTime, NULL)); | 402 user_prefs::kPreferenceResetTime, NULL)); |
403 } | 403 } |
404 | 404 |
405 // Calls FilterOnLoad() on |pref_hash_Filter_|. |pref_store_contents_| is | 405 // Calls FilterOnLoad() on |pref_hash_Filter_|. |pref_store_contents_| is |
406 // handed off, but should be given back to us synchronously through | 406 // handed off, but should be given back to us synchronously through |
407 // GetPrefsBack() as there is no FilterOnLoadInterceptor installed on | 407 // GetPrefsBack() as there is no FilterOnLoadInterceptor installed on |
408 // |pref_hash_filter_|. | 408 // |pref_hash_filter_|. |
409 void DoFilterOnLoad(bool expect_prefs_modifications) { | 409 void DoFilterOnLoad(bool expect_prefs_modifications) { |
410 pref_hash_filter_->FilterOnLoad( | 410 pref_hash_filter_->FilterOnLoad( |
411 base::Bind(&PrefHashFilterTest::GetPrefsBack, base::Unretained(this), | 411 base::Bind(&PrefHashFilterTest::GetPrefsBack, base::Unretained(this), |
412 expect_prefs_modifications), | 412 expect_prefs_modifications), |
413 pref_store_contents_.Pass()); | 413 std::move(pref_store_contents_)); |
414 } | 414 } |
415 | 415 |
416 MockPrefHashStore* mock_pref_hash_store_; | 416 MockPrefHashStore* mock_pref_hash_store_; |
417 scoped_ptr<base::DictionaryValue> pref_store_contents_; | 417 scoped_ptr<base::DictionaryValue> pref_store_contents_; |
418 MockValidationDelegate mock_validation_delegate_; | 418 MockValidationDelegate mock_validation_delegate_; |
419 scoped_ptr<PrefHashFilter> pref_hash_filter_; | 419 scoped_ptr<PrefHashFilter> pref_hash_filter_; |
420 | 420 |
421 private: | 421 private: |
422 // Stores |prefs| back in |pref_store_contents| and ensure | 422 // Stores |prefs| back in |pref_store_contents| and ensure |
423 // |expected_schedule_write| matches the reported |schedule_write|. | 423 // |expected_schedule_write| matches the reported |schedule_write|. |
424 void GetPrefsBack(bool expected_schedule_write, | 424 void GetPrefsBack(bool expected_schedule_write, |
425 scoped_ptr<base::DictionaryValue> prefs, | 425 scoped_ptr<base::DictionaryValue> prefs, |
426 bool schedule_write) { | 426 bool schedule_write) { |
427 pref_store_contents_ = prefs.Pass(); | 427 pref_store_contents_ = std::move(prefs); |
428 EXPECT_TRUE(pref_store_contents_); | 428 EXPECT_TRUE(pref_store_contents_); |
429 EXPECT_EQ(expected_schedule_write, schedule_write); | 429 EXPECT_EQ(expected_schedule_write, schedule_write); |
430 } | 430 } |
431 | 431 |
432 void RecordReset() { | 432 void RecordReset() { |
433 // As-is |reset_recorded_| is only designed to remember a single reset, make | 433 // As-is |reset_recorded_| is only designed to remember a single reset, make |
434 // sure none was previously recorded. | 434 // sure none was previously recorded. |
435 EXPECT_FALSE(reset_recorded_); | 435 EXPECT_FALSE(reset_recorded_); |
436 reset_recorded_ = true; | 436 reset_recorded_ = true; |
437 } | 437 } |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 mock_pref_hash_store_->stored_value(kAtomicPref2).first); | 1032 mock_pref_hash_store_->stored_value(kAtomicPref2).first); |
1033 | 1033 |
1034 VerifyRecordedReset(false); | 1034 VerifyRecordedReset(false); |
1035 } | 1035 } |
1036 } | 1036 } |
1037 | 1037 |
1038 INSTANTIATE_TEST_CASE_P(PrefHashFilterTestInstance, | 1038 INSTANTIATE_TEST_CASE_P(PrefHashFilterTestInstance, |
1039 PrefHashFilterTest, | 1039 PrefHashFilterTest, |
1040 testing::Values(PrefHashFilter::NO_ENFORCEMENT, | 1040 testing::Values(PrefHashFilter::NO_ENFORCEMENT, |
1041 PrefHashFilter::ENFORCE_ON_LOAD)); | 1041 PrefHashFilter::ENFORCE_ON_LOAD)); |
OLD | NEW |