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

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: Comment typo. 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/pref_hash_store_transaction.h"
20 #include "chrome/browser/prefs/profile_pref_store_manager.h"
21 #include "chrome/browser/prefs/tracked/dictionary_hash_store_contents.h"
22 #include "chrome/browser/prefs/tracked/hash_store_contents.h"
23 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h"
16 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" 24 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h"
17 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
18 26
19 namespace { 27 namespace {
20 28
21 // An unprotected pref. 29 // An unprotected pref.
22 const char kUnprotectedPref[] = "unprotected"; 30 const char kUnprotectedPref[] = "unprotected";
23 // A protected pref. 31 // A protected pref.
24 const char kProtectedPref[] = "protected"; 32 const char kProtectedPref[] = "protected";
25 // A protected pref which is initially stored in the unprotected store. 33 // A protected pref which is initially stored in the unprotected store.
26 const char kPreviouslyUnprotectedPref[] = "previously.unprotected"; 34 const char kPreviouslyUnprotectedPref[] = "previously.unprotected";
27 // An unprotected pref which is initially stored in the protected store. 35 // An unprotected pref which is initially stored in the protected store.
28 const char kPreviouslyProtectedPref[] = "previously.protected"; 36 const char kPreviouslyProtectedPref[] = "previously.protected";
29 37
30 const char kUnprotectedPrefValue[] = "unprotected_value"; 38 const char kUnprotectedPrefValue[] = "unprotected_value";
31 const char kProtectedPrefValue[] = "protected_value"; 39 const char kProtectedPrefValue[] = "protected_value";
32 const char kPreviouslyUnprotectedPrefValue[] = "previously_unprotected_value"; 40 const char kPreviouslyUnprotectedPrefValue[] = "previously_unprotected_value";
33 const char kPreviouslyProtectedPrefValue[] = "previously_protected_value"; 41 const char kPreviouslyProtectedPrefValue[] = "previously_protected_value";
34 42
35 // A simple InterceptablePrefFilter which doesn't do anything but hand the prefs 43 // A simple InterceptablePrefFilter which doesn't do anything but hand the prefs
36 // back downstream in FinalizeFilterOnLoad. 44 // back downstream in FinalizeFilterOnLoad.
37 class SimpleInterceptablePrefFilter : public InterceptablePrefFilter { 45 class SimpleInterceptablePrefFilter : public InterceptablePrefFilter {
38 public: 46 public:
39 // PrefFilter remaining implementation. 47 // PrefFilter remaining implementation.
40 virtual void FilterUpdate(const std::string& path) OVERRIDE { 48 virtual void FilterUpdate(const std::string& path) OVERRIDE {
41 ADD_FAILURE(); 49 ADD_FAILURE();
42 } 50 }
43 virtual void FilterSerializeData( 51 virtual void FilterSerializeData(
44 const base::DictionaryValue* pref_store_contents) OVERRIDE { 52 base::DictionaryValue* pref_store_contents) OVERRIDE {
45 ADD_FAILURE(); 53 ADD_FAILURE();
46 } 54 }
47 55
48 private: 56 private:
49 // InterceptablePrefFilter implementation. 57 // InterceptablePrefFilter implementation.
50 virtual void FinalizeFilterOnLoad( 58 virtual void FinalizeFilterOnLoad(
51 const PostFilterOnLoadCallback& post_filter_on_load_callback, 59 const PostFilterOnLoadCallback& post_filter_on_load_callback,
52 scoped_ptr<base::DictionaryValue> pref_store_contents, 60 scoped_ptr<base::DictionaryValue> pref_store_contents,
53 bool prefs_altered) OVERRIDE { 61 bool prefs_altered) OVERRIDE {
54 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); 62 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered);
55 } 63 }
56 }; 64 };
57 65
58 // A test fixture designed to like this: 66 // A test fixture designed to be used like this:
59 // 1) Set up initial store prefs with PresetStoreValue(). 67 // 1) Set up initial store prefs with PresetStoreValue().
60 // 2) Hand both sets of prefs to the migrator via HandPrefsToMigrator(). 68 // 2) Hand both sets of prefs to the migrator via HandPrefsToMigrator().
61 // 3) Migration completes synchronously when the second store hands its prefs 69 // 3) Migration completes synchronously when the second store hands its prefs
62 // over. 70 // over.
63 // 4) Verifications can be made via various methods of this fixture. 71 // 4) Verifications can be made via various methods of this fixture.
64 // This fixture should not be re-used (i.e., only one migration should be 72 // Call Reset() to perform a second migration.
65 // performed per test).
66 class TrackedPreferencesMigrationTest : public testing::Test { 73 class TrackedPreferencesMigrationTest : public testing::Test {
67 public: 74 public:
68 enum MockPrefStoreID { 75 enum MockPrefStoreID {
69 MOCK_UNPROTECTED_PREF_STORE, 76 MOCK_UNPROTECTED_PREF_STORE,
70 MOCK_PROTECTED_PREF_STORE, 77 MOCK_PROTECTED_PREF_STORE,
71 }; 78 };
72 79
73 TrackedPreferencesMigrationTest() 80 TrackedPreferencesMigrationTest()
74 : unprotected_prefs_(new base::DictionaryValue), 81 : unprotected_prefs_(new base::DictionaryValue),
75 protected_prefs_(new base::DictionaryValue), 82 protected_prefs_(new base::DictionaryValue),
76 migration_modified_unprotected_store_(false), 83 migration_modified_unprotected_store_(false),
77 migration_modified_protected_store_(false), 84 migration_modified_protected_store_(false),
78 unprotected_store_migration_complete_(false), 85 unprotected_store_migration_complete_(false),
79 protected_store_migration_complete_(false) {} 86 protected_store_migration_complete_(false) {}
80 87
81 virtual void SetUp() OVERRIDE { 88 virtual void SetUp() OVERRIDE {
89 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry());
90 Reset();
91 }
92
93 void Reset() {
82 std::set<std::string> unprotected_pref_names; 94 std::set<std::string> unprotected_pref_names;
83 std::set<std::string> protected_pref_names; 95 std::set<std::string> protected_pref_names;
84 unprotected_pref_names.insert(kUnprotectedPref); 96 unprotected_pref_names.insert(kUnprotectedPref);
85 unprotected_pref_names.insert(kPreviouslyProtectedPref); 97 unprotected_pref_names.insert(kPreviouslyProtectedPref);
86 protected_pref_names.insert(kProtectedPref); 98 protected_pref_names.insert(kProtectedPref);
87 protected_pref_names.insert(kPreviouslyUnprotectedPref); 99 protected_pref_names.insert(kPreviouslyUnprotectedPref);
88 100
101 migration_modified_unprotected_store_ = false;
102 migration_modified_protected_store_ = false;
103 unprotected_store_migration_complete_ = false;
104 protected_store_migration_complete_ = false;
105
106 unprotected_store_successful_write_callback_.Reset();
107 protected_store_successful_write_callback_.Reset();
108
89 SetupTrackedPreferencesMigration( 109 SetupTrackedPreferencesMigration(
90 unprotected_pref_names, 110 unprotected_pref_names,
91 protected_pref_names, 111 protected_pref_names,
92 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, 112 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore,
93 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), 113 base::Unretained(this),
114 MOCK_UNPROTECTED_PREF_STORE),
94 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, 115 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore,
95 base::Unretained(this), MOCK_PROTECTED_PREF_STORE), 116 base::Unretained(this),
117 MOCK_PROTECTED_PREF_STORE),
96 base::Bind( 118 base::Bind(
97 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, 119 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure,
98 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), 120 base::Unretained(this),
121 MOCK_UNPROTECTED_PREF_STORE),
99 base::Bind( 122 base::Bind(
100 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, 123 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure,
101 base::Unretained(this), MOCK_PROTECTED_PREF_STORE), 124 base::Unretained(this),
125 MOCK_PROTECTED_PREF_STORE),
126 scoped_ptr<PrefHashStore>(
127 new PrefHashStoreImpl(kSeed, kDeviceId, false)),
128 scoped_ptr<PrefHashStore>(
129 new PrefHashStoreImpl(kSeed, kDeviceId, true)),
130 scoped_ptr<HashStoreContents>(
131 new PrefServiceHashStoreContents("hash-store-id", &local_state_)),
132
102 &mock_unprotected_pref_filter_, 133 &mock_unprotected_pref_filter_,
103 &mock_protected_pref_filter_); 134 &mock_protected_pref_filter_);
104 135
105 // Verify initial expectations are met. 136 // Verify initial expectations are met.
106 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); 137 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE));
107 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); 138 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE));
108 EXPECT_FALSE( 139 EXPECT_FALSE(
109 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); 140 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE));
110 EXPECT_FALSE( 141 EXPECT_FALSE(
111 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); 142 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE));
112
113 std::vector<std::pair<std::string, std::string> > no_prefs_stored;
114 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, no_prefs_stored);
115 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, no_prefs_stored);
116 } 143 }
117 144
118 protected: 145 protected:
119 // Sets |key| to |value| in the test store identified by |store_id| before 146 // Sets |key| to |value| in the test store identified by |store_id| before
120 // migration begins. 147 // migration begins.
121 void PresetStoreValue(MockPrefStoreID store_id, 148 void PresetStoreValue(MockPrefStoreID store_id,
122 const std::string& key, 149 const std::string& key,
123 const std::string value) { 150 const std::string value) {
124 base::DictionaryValue* store = NULL; 151 base::DictionaryValue* store = NULL;
152 scoped_ptr<PrefHashStore> pref_hash_store;
125 switch (store_id) { 153 switch (store_id) {
126 case MOCK_UNPROTECTED_PREF_STORE: 154 case MOCK_UNPROTECTED_PREF_STORE:
127 store = unprotected_prefs_.get(); 155 store = unprotected_prefs_.get();
156 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, false));
128 break; 157 break;
129 case MOCK_PROTECTED_PREF_STORE: 158 case MOCK_PROTECTED_PREF_STORE:
130 store = protected_prefs_.get(); 159 store = protected_prefs_.get();
160 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, true));
131 break; 161 break;
132 } 162 }
133 DCHECK(store); 163 DCHECK(store);
134 164
135 store->SetString(key, value); 165 store->SetString(key, value);
166 base::StringValue string_value(value);
167 pref_hash_store->BeginTransaction(
168 scoped_ptr<HashStoreContents>(
169 new DictionaryHashStoreContents(store)))->StoreHash(
170 key, &string_value);
136 } 171 }
137 172
138 // Returns true if the store opposite to |store_id| is observed for its next 173 // Returns true if the store opposite to |store_id| is observed for its next
139 // successful write. 174 // successful write.
140 bool WasOnSuccessfulWriteCallbackRegistered(MockPrefStoreID store_id) { 175 bool WasOnSuccessfulWriteCallbackRegistered(MockPrefStoreID store_id) {
141 switch (store_id) { 176 switch (store_id) {
142 case MOCK_UNPROTECTED_PREF_STORE: 177 case MOCK_UNPROTECTED_PREF_STORE:
143 return !protected_store_successful_write_callback_.is_null(); 178 return !protected_store_successful_write_callback_.is_null();
144 case MOCK_PROTECTED_PREF_STORE: 179 case MOCK_PROTECTED_PREF_STORE:
145 return !unprotected_store_successful_write_callback_.is_null(); 180 return !unprotected_store_successful_write_callback_.is_null();
(...skipping 21 matching lines...) Expand all
167 202
168 for (std::vector<std::pair<std::string, std::string> >::const_iterator it = 203 for (std::vector<std::pair<std::string, std::string> >::const_iterator it =
169 expected_prefs_in_store.begin(); 204 expected_prefs_in_store.begin();
170 it != expected_prefs_in_store.end(); ++it) { 205 it != expected_prefs_in_store.end(); ++it) {
171 std::string val; 206 std::string val;
172 EXPECT_TRUE(store->GetString(it->first, &val)); 207 EXPECT_TRUE(store->GetString(it->first, &val));
173 EXPECT_EQ(it->second, val); 208 EXPECT_EQ(it->second, val);
174 } 209 }
175 } 210 }
176 211
212 // Determines whether |expected_pref_in_hash_store| has a hash in the hash
213 // store identified by |store_id|.
214 bool ContainsHash(MockPrefStoreID store_id,
215 std::string expected_pref_in_hash_store) {
216 base::DictionaryValue* store = NULL;
217 switch (store_id) {
218 case MOCK_UNPROTECTED_PREF_STORE:
219 store = unprotected_prefs_.get();
220 break;
221 case MOCK_PROTECTED_PREF_STORE:
222 store = protected_prefs_.get();
223 break;
224 }
225 DCHECK(store);
226 return DictionaryHashStoreContents(store).GetContents()->GetString(
227 expected_pref_in_hash_store, static_cast<std::string*>(NULL));
228 }
229
177 // Both stores need to hand their prefs over in order for migration to kick 230 // Both stores need to hand their prefs over in order for migration to kick
178 // in. 231 // in.
179 void HandPrefsToMigrator(MockPrefStoreID store_id) { 232 void HandPrefsToMigrator(MockPrefStoreID store_id) {
180 switch (store_id) { 233 switch (store_id) {
181 case MOCK_UNPROTECTED_PREF_STORE: 234 case MOCK_UNPROTECTED_PREF_STORE:
182 mock_unprotected_pref_filter_.FilterOnLoad( 235 mock_unprotected_pref_filter_.FilterOnLoad(
183 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack, 236 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack,
184 base::Unretained(this), 237 base::Unretained(this),
185 MOCK_UNPROTECTED_PREF_STORE), 238 MOCK_UNPROTECTED_PREF_STORE),
186 unprotected_prefs_.Pass()); 239 unprotected_prefs_.Pass());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 ASSERT_TRUE(unprotected_prefs_); 334 ASSERT_TRUE(unprotected_prefs_);
282 unprotected_prefs_->RemovePath(key, NULL); 335 unprotected_prefs_->RemovePath(key, NULL);
283 break; 336 break;
284 case MOCK_PROTECTED_PREF_STORE: 337 case MOCK_PROTECTED_PREF_STORE:
285 ASSERT_TRUE(protected_prefs_); 338 ASSERT_TRUE(protected_prefs_);
286 protected_prefs_->RemovePath(key, NULL); 339 protected_prefs_->RemovePath(key, NULL);
287 break; 340 break;
288 } 341 }
289 } 342 }
290 343
344 static const char kSeed[];
345 static const char kDeviceId[];
346
291 scoped_ptr<base::DictionaryValue> unprotected_prefs_; 347 scoped_ptr<base::DictionaryValue> unprotected_prefs_;
292 scoped_ptr<base::DictionaryValue> protected_prefs_; 348 scoped_ptr<base::DictionaryValue> protected_prefs_;
293 349
294 SimpleInterceptablePrefFilter mock_unprotected_pref_filter_; 350 SimpleInterceptablePrefFilter mock_unprotected_pref_filter_;
295 SimpleInterceptablePrefFilter mock_protected_pref_filter_; 351 SimpleInterceptablePrefFilter mock_protected_pref_filter_;
296 352
297 base::Closure unprotected_store_successful_write_callback_; 353 base::Closure unprotected_store_successful_write_callback_;
298 base::Closure protected_store_successful_write_callback_; 354 base::Closure protected_store_successful_write_callback_;
299 355
300 bool migration_modified_unprotected_store_; 356 bool migration_modified_unprotected_store_;
301 bool migration_modified_protected_store_; 357 bool migration_modified_protected_store_;
302 358
303 bool unprotected_store_migration_complete_; 359 bool unprotected_store_migration_complete_;
304 bool protected_store_migration_complete_; 360 bool protected_store_migration_complete_;
361
362 TestingPrefServiceSimple local_state_;
305 }; 363 };
306 364
365 // static
366 const char TrackedPreferencesMigrationTest::kSeed[] = "seed";
367
368 // static
369 const char TrackedPreferencesMigrationTest::kDeviceId[] = "device-id";
370
307 } // namespace 371 } // namespace
308 372
309 TEST_F(TrackedPreferencesMigrationTest, NoMigrationRequired) { 373 TEST_F(TrackedPreferencesMigrationTest, NoMigrationRequired) {
310 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, 374 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref,
311 kUnprotectedPrefValue); 375 kUnprotectedPrefValue);
312 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kProtectedPref, 376 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kProtectedPref,
313 kProtectedPrefValue); 377 kProtectedPrefValue);
314 378
379 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref));
380 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref));
381
382 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref));
383 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref));
384
315 // Hand unprotected prefs to the migrator which should wait for the protected 385 // Hand unprotected prefs to the migrator which should wait for the protected
316 // prefs. 386 // prefs.
317 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); 387 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE);
318 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); 388 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE));
319 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); 389 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE));
320 EXPECT_FALSE(MigrationCompleted()); 390 EXPECT_FALSE(MigrationCompleted());
321 391
322 // Hand protected prefs to the migrator which should proceed with the 392 // Hand protected prefs to the migrator which should proceed with the
323 // migration synchronously. 393 // migration synchronously.
324 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); 394 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE);
(...skipping 11 matching lines...) Expand all
336 406
337 std::vector<std::pair<std::string, std::string> > expected_unprotected_values; 407 std::vector<std::pair<std::string, std::string> > expected_unprotected_values;
338 expected_unprotected_values.push_back( 408 expected_unprotected_values.push_back(
339 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); 409 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue));
340 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, expected_unprotected_values); 410 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, expected_unprotected_values);
341 411
342 std::vector<std::pair<std::string, std::string> > expected_protected_values; 412 std::vector<std::pair<std::string, std::string> > expected_protected_values;
343 expected_protected_values.push_back( 413 expected_protected_values.push_back(
344 std::make_pair(kProtectedPref, kProtectedPrefValue)); 414 std::make_pair(kProtectedPref, kProtectedPrefValue));
345 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); 415 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values);
416
417 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref));
418 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref));
419
420 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref));
421 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref));
346 } 422 }
347 423
348 TEST_F(TrackedPreferencesMigrationTest, FullMigration) { 424 TEST_F(TrackedPreferencesMigrationTest, FullMigration) {
349 PresetStoreValue( 425 PresetStoreValue(
350 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); 426 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue);
351 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, 427 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE,
352 kPreviouslyUnprotectedPref, 428 kPreviouslyUnprotectedPref,
353 kPreviouslyUnprotectedPrefValue); 429 kPreviouslyUnprotectedPrefValue);
354 PresetStoreValue( 430 PresetStoreValue(
355 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); 431 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue);
356 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, 432 PresetStoreValue(MOCK_PROTECTED_PREF_STORE,
357 kPreviouslyProtectedPref, 433 kPreviouslyProtectedPref,
358 kPreviouslyProtectedPrefValue); 434 kPreviouslyProtectedPrefValue);
359 435
436 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref));
437 EXPECT_TRUE(
438 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref));
439 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref));
440 EXPECT_FALSE(
441 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref));
442
443 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref));
444 EXPECT_FALSE(
445 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref));
446 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref));
447 EXPECT_TRUE(
448 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref));
449
360 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); 450 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE);
361 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); 451 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE));
362 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); 452 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE));
363 EXPECT_FALSE(MigrationCompleted()); 453 EXPECT_FALSE(MigrationCompleted());
364 454
365 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); 455 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE);
366 EXPECT_TRUE(MigrationCompleted()); 456 EXPECT_TRUE(MigrationCompleted());
367 457
368 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); 458 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE));
369 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); 459 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE));
(...skipping 19 matching lines...) Expand all
389 expected_unprotected_values); 479 expected_unprotected_values);
390 480
391 std::vector<std::pair<std::string, std::string> > expected_protected_values; 481 std::vector<std::pair<std::string, std::string> > expected_protected_values;
392 expected_protected_values.push_back(std::make_pair( 482 expected_protected_values.push_back(std::make_pair(
393 kProtectedPref, kProtectedPrefValue)); 483 kProtectedPref, kProtectedPrefValue));
394 expected_protected_values.push_back(std::make_pair( 484 expected_protected_values.push_back(std::make_pair(
395 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); 485 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue));
396 expected_unprotected_values.push_back(std::make_pair( 486 expected_unprotected_values.push_back(std::make_pair(
397 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); 487 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue));
398 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); 488 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values);
489
490 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref));
491 EXPECT_TRUE(
492 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref));
493 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref));
494 EXPECT_TRUE(
495 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref));
496
497 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref));
498 EXPECT_TRUE(
499 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref));
500 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref));
501 EXPECT_TRUE(
502 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref));
399 } 503 }
400 504
401 // A successful write of the protected pref store should result in a clean up 505 // A successful write of the protected pref store should result in a clean up
402 // of the unprotected store. 506 // of the unprotected store.
403 SimulateSuccessfulWrite(MOCK_PROTECTED_PREF_STORE); 507 SimulateSuccessfulWrite(MOCK_PROTECTED_PREF_STORE);
404 508
405 { 509 {
406 std::vector<std::pair<std::string, std::string> > 510 std::vector<std::pair<std::string, std::string> >
407 expected_unprotected_values; 511 expected_unprotected_values;
408 expected_unprotected_values.push_back(std::make_pair( 512 expected_unprotected_values.push_back(std::make_pair(
(...skipping 25 matching lines...) Expand all
434 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, 538 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE,
435 expected_unprotected_values); 539 expected_unprotected_values);
436 540
437 std::vector<std::pair<std::string, std::string> > expected_protected_values; 541 std::vector<std::pair<std::string, std::string> > expected_protected_values;
438 expected_protected_values.push_back(std::make_pair( 542 expected_protected_values.push_back(std::make_pair(
439 kProtectedPref, kProtectedPrefValue)); 543 kProtectedPref, kProtectedPrefValue));
440 expected_protected_values.push_back(std::make_pair( 544 expected_protected_values.push_back(std::make_pair(
441 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); 545 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue));
442 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); 546 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values);
443 } 547 }
548
549 // Hashes are not cleaned up yet.
550 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref));
551 EXPECT_TRUE(
552 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref));
553 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref));
554 EXPECT_TRUE(
555 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref));
556
557 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref));
558 EXPECT_TRUE(
559 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref));
560 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref));
561 EXPECT_TRUE(
562 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref));
563
564 Reset();
565
566 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE);
567 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE);
568 EXPECT_TRUE(MigrationCompleted());
569
570 // Hashes are cleaned up.
571 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref));
572 EXPECT_FALSE(
573 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref));
574 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref));
575 EXPECT_TRUE(
576 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref));
577
578 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref));
579 EXPECT_TRUE(
580 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref));
581 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref));
582 EXPECT_FALSE(
583 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref));
444 } 584 }
445 585
446 TEST_F(TrackedPreferencesMigrationTest, CleanupOnly) { 586 TEST_F(TrackedPreferencesMigrationTest, CleanupOnly) {
447 // Already migrated; only cleanup needed. 587 // Already migrated; only cleanup needed.
448 PresetStoreValue( 588 PresetStoreValue(
449 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); 589 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue);
450 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, 590 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE,
451 kPreviouslyProtectedPref, 591 kPreviouslyProtectedPref,
452 kPreviouslyProtectedPrefValue); 592 kPreviouslyProtectedPrefValue);
453 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, 593 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 expected_unprotected_values); 632 expected_unprotected_values);
493 633
494 std::vector<std::pair<std::string, std::string> > expected_protected_values; 634 std::vector<std::pair<std::string, std::string> > expected_protected_values;
495 expected_protected_values.push_back(std::make_pair( 635 expected_protected_values.push_back(std::make_pair(
496 kProtectedPref, kProtectedPrefValue)); 636 kProtectedPref, kProtectedPrefValue));
497 expected_protected_values.push_back(std::make_pair( 637 expected_protected_values.push_back(std::make_pair(
498 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); 638 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue));
499 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); 639 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values);
500 } 640 }
501 } 641 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/tracked/tracked_preferences_migration.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698