Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/prefs/tracked/tracked_preferences_migration_unittest.cc

Issue 324493002: Move preference MACs to the protected preference stores. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self-review. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/prefs/tracked/tracked_preferences_migration.h" 5 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/prefs/testing_pref_service.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "chrome/browser/prefs/interceptable_pref_filter.h" 16 #include "chrome/browser/prefs/interceptable_pref_filter.h"
17 #include "chrome/browser/prefs/pref_hash_store.h"
18 #include "chrome/browser/prefs/pref_hash_store_impl.h"
19 #include "chrome/browser/prefs/profile_pref_store_manager.h"
20 #include "chrome/browser/prefs/tracked/hash_store_contents.h"
21 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h"
16 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" 22 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h"
17 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
18 24
19 namespace { 25 namespace {
20 26
21 // An unprotected pref. 27 // An unprotected pref.
22 const char kUnprotectedPref[] = "unprotected"; 28 const char kUnprotectedPref[] = "unprotected";
23 // A protected pref. 29 // A protected pref.
24 const char kProtectedPref[] = "protected"; 30 const char kProtectedPref[] = "protected";
25 // A protected pref which is initially stored in the unprotected store. 31 // A protected pref which is initially stored in the unprotected store.
26 const char kPreviouslyUnprotectedPref[] = "previously.unprotected"; 32 const char kPreviouslyUnprotectedPref[] = "previously.unprotected";
27 // An unprotected pref which is initially stored in the protected store. 33 // An unprotected pref which is initially stored in the protected store.
28 const char kPreviouslyProtectedPref[] = "previously.protected"; 34 const char kPreviouslyProtectedPref[] = "previously.protected";
29 35
30 const char kUnprotectedPrefValue[] = "unprotected_value"; 36 const char kUnprotectedPrefValue[] = "unprotected_value";
31 const char kProtectedPrefValue[] = "protected_value"; 37 const char kProtectedPrefValue[] = "protected_value";
32 const char kPreviouslyUnprotectedPrefValue[] = "previously_unprotected_value"; 38 const char kPreviouslyUnprotectedPrefValue[] = "previously_unprotected_value";
33 const char kPreviouslyProtectedPrefValue[] = "previously_protected_value"; 39 const char kPreviouslyProtectedPrefValue[] = "previously_protected_value";
34 40
35 // A simple InterceptablePrefFilter which doesn't do anything but hand the prefs 41 // A simple InterceptablePrefFilter which doesn't do anything but hand the prefs
36 // back downstream in FinalizeFilterOnLoad. 42 // back downstream in FinalizeFilterOnLoad.
37 class SimpleInterceptablePrefFilter : public InterceptablePrefFilter { 43 class SimpleInterceptablePrefFilter : public InterceptablePrefFilter {
38 public: 44 public:
39 // PrefFilter remaining implementation. 45 // PrefFilter remaining implementation.
40 virtual void FilterUpdate(const std::string& path) OVERRIDE { 46 virtual void FilterUpdate(const std::string& path) OVERRIDE {
41 ADD_FAILURE(); 47 ADD_FAILURE();
42 } 48 }
43 virtual void FilterSerializeData( 49 virtual void FilterSerializeData(
44 const base::DictionaryValue* pref_store_contents) OVERRIDE { 50 base::DictionaryValue* pref_store_contents) OVERRIDE {
45 ADD_FAILURE(); 51 ADD_FAILURE();
46 } 52 }
47 53
48 private: 54 private:
49 // InterceptablePrefFilter implementation. 55 // InterceptablePrefFilter implementation.
50 virtual void FinalizeFilterOnLoad( 56 virtual void FinalizeFilterOnLoad(
51 const PostFilterOnLoadCallback& post_filter_on_load_callback, 57 const PostFilterOnLoadCallback& post_filter_on_load_callback,
52 scoped_ptr<base::DictionaryValue> pref_store_contents, 58 scoped_ptr<base::DictionaryValue> pref_store_contents,
53 bool prefs_altered) OVERRIDE { 59 bool prefs_altered) OVERRIDE {
54 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); 60 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered);
(...skipping 17 matching lines...) Expand all
72 78
73 TrackedPreferencesMigrationTest() 79 TrackedPreferencesMigrationTest()
74 : unprotected_prefs_(new base::DictionaryValue), 80 : unprotected_prefs_(new base::DictionaryValue),
75 protected_prefs_(new base::DictionaryValue), 81 protected_prefs_(new base::DictionaryValue),
76 migration_modified_unprotected_store_(false), 82 migration_modified_unprotected_store_(false),
77 migration_modified_protected_store_(false), 83 migration_modified_protected_store_(false),
78 unprotected_store_migration_complete_(false), 84 unprotected_store_migration_complete_(false),
79 protected_store_migration_complete_(false) {} 85 protected_store_migration_complete_(false) {}
80 86
81 virtual void SetUp() OVERRIDE { 87 virtual void SetUp() OVERRIDE {
88 const std::string kSeed = "seed";
89 const std::string kDeviceId = "device-id";
90 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry());
82 std::set<std::string> unprotected_pref_names; 91 std::set<std::string> unprotected_pref_names;
83 std::set<std::string> protected_pref_names; 92 std::set<std::string> protected_pref_names;
84 unprotected_pref_names.insert(kUnprotectedPref); 93 unprotected_pref_names.insert(kUnprotectedPref);
85 unprotected_pref_names.insert(kPreviouslyProtectedPref); 94 unprotected_pref_names.insert(kPreviouslyProtectedPref);
86 protected_pref_names.insert(kProtectedPref); 95 protected_pref_names.insert(kProtectedPref);
87 protected_pref_names.insert(kPreviouslyUnprotectedPref); 96 protected_pref_names.insert(kPreviouslyUnprotectedPref);
88 97
89 SetupTrackedPreferencesMigration( 98 SetupTrackedPreferencesMigration(
90 unprotected_pref_names, 99 unprotected_pref_names,
91 protected_pref_names, 100 protected_pref_names,
92 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, 101 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore,
93 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), 102 base::Unretained(this),
103 MOCK_UNPROTECTED_PREF_STORE),
94 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, 104 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore,
95 base::Unretained(this), MOCK_PROTECTED_PREF_STORE), 105 base::Unretained(this),
106 MOCK_PROTECTED_PREF_STORE),
96 base::Bind( 107 base::Bind(
97 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, 108 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure,
98 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), 109 base::Unretained(this),
110 MOCK_UNPROTECTED_PREF_STORE),
99 base::Bind( 111 base::Bind(
100 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, 112 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure,
101 base::Unretained(this), MOCK_PROTECTED_PREF_STORE), 113 base::Unretained(this),
114 MOCK_PROTECTED_PREF_STORE),
115 scoped_ptr<PrefHashStore>(
116 new PrefHashStoreImpl(kSeed, kDeviceId, false)),
117 scoped_ptr<PrefHashStore>(
118 new PrefHashStoreImpl(kSeed, kDeviceId, true)),
119 scoped_ptr<HashStoreContents>(
120 new PrefServiceHashStoreContents("hash-store-id", &local_state_)),
121
102 &mock_unprotected_pref_filter_, 122 &mock_unprotected_pref_filter_,
103 &mock_protected_pref_filter_); 123 &mock_protected_pref_filter_);
104 124
105 // Verify initial expectations are met. 125 // Verify initial expectations are met.
106 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); 126 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE));
107 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); 127 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE));
108 EXPECT_FALSE( 128 EXPECT_FALSE(
109 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); 129 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE));
110 EXPECT_FALSE( 130 EXPECT_FALSE(
111 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); 131 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE));
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 SimpleInterceptablePrefFilter mock_protected_pref_filter_; 315 SimpleInterceptablePrefFilter mock_protected_pref_filter_;
296 316
297 base::Closure unprotected_store_successful_write_callback_; 317 base::Closure unprotected_store_successful_write_callback_;
298 base::Closure protected_store_successful_write_callback_; 318 base::Closure protected_store_successful_write_callback_;
299 319
300 bool migration_modified_unprotected_store_; 320 bool migration_modified_unprotected_store_;
301 bool migration_modified_protected_store_; 321 bool migration_modified_protected_store_;
302 322
303 bool unprotected_store_migration_complete_; 323 bool unprotected_store_migration_complete_;
304 bool protected_store_migration_complete_; 324 bool protected_store_migration_complete_;
325
326 TestingPrefServiceSimple local_state_;
305 }; 327 };
306 328
307 } // namespace 329 } // namespace
308 330
309 TEST_F(TrackedPreferencesMigrationTest, NoMigrationRequired) { 331 TEST_F(TrackedPreferencesMigrationTest, NoMigrationRequired) {
310 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, 332 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref,
311 kUnprotectedPrefValue); 333 kUnprotectedPrefValue);
312 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kProtectedPref, 334 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kProtectedPref,
313 kProtectedPrefValue); 335 kProtectedPrefValue);
314 336
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 expected_unprotected_values); 514 expected_unprotected_values);
493 515
494 std::vector<std::pair<std::string, std::string> > expected_protected_values; 516 std::vector<std::pair<std::string, std::string> > expected_protected_values;
495 expected_protected_values.push_back(std::make_pair( 517 expected_protected_values.push_back(std::make_pair(
496 kProtectedPref, kProtectedPrefValue)); 518 kProtectedPref, kProtectedPrefValue));
497 expected_protected_values.push_back(std::make_pair( 519 expected_protected_values.push_back(std::make_pair(
498 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); 520 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue));
499 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); 521 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values);
500 } 522 }
501 } 523 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698