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

Side by Side Diff: chrome/browser/prefs/pref_hash_store_impl_unittest.cc

Issue 324493002: Move preference MACs to the protected preference stores. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a test for newly tracked prefs when first enabling protection. 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 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 "chrome/browser/prefs/pref_hash_store_impl.h" 5 #include "chrome/browser/prefs/pref_hash_store_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/prefs/pref_hash_store_impl.h" 11 #include "chrome/browser/prefs/pref_hash_store_impl.h"
12 #include "chrome/browser/prefs/pref_hash_store_transaction.h" 12 #include "chrome/browser/prefs/pref_hash_store_transaction.h"
13 #include "chrome/browser/prefs/tracked/dictionary_hash_store_contents.h"
13 #include "chrome/browser/prefs/tracked/hash_store_contents.h" 14 #include "chrome/browser/prefs/tracked/hash_store_contents.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 class MockHashStoreContents : public HashStoreContents {
17 public:
18 // Keep the data separate from the API implementation so that it can be owned
19 // by the test and reused. The API implementation is owned by the
20 // PrefHashStoreImpl.
21 struct Data {
22 Data() : commit_performed(false) {}
23
24 // Returns the current value of |commit_performed| and resets it to false
25 // immediately after.
26 bool GetCommitPerformedAndReset() {
27 bool current_commit_performed = commit_performed;
28 commit_performed = false;
29 return current_commit_performed;
30 }
31
32 scoped_ptr<base::DictionaryValue> contents;
33 std::string super_mac;
34 bool commit_performed;
35 };
36
37 explicit MockHashStoreContents(Data* data) : data_(data) {}
38
39 // HashStoreContents implementation
40 virtual std::string hash_store_id() const OVERRIDE { return "store_id"; }
41
42 virtual void Reset() OVERRIDE {
43 data_->contents.reset();
44 data_->super_mac = "";
45 }
46
47 virtual bool IsInitialized() const OVERRIDE { return data_->contents; }
48
49 virtual const base::DictionaryValue* GetContents() const OVERRIDE {
50 return data_->contents.get();
51 }
52
53 virtual scoped_ptr<MutableDictionary> GetMutableContents() OVERRIDE {
54 return scoped_ptr<MutableDictionary>(new MockMutableDictionary(data_));
55 }
56
57 virtual std::string GetSuperMac() const OVERRIDE { return data_->super_mac; }
58
59 virtual void SetSuperMac(const std::string& super_mac) OVERRIDE {
60 data_->super_mac = super_mac;
61 }
62
63 virtual void CommitPendingWrite() OVERRIDE {
64 EXPECT_FALSE(data_->commit_performed);
65 data_->commit_performed = true;
66 }
67
68 private:
69 class MockMutableDictionary : public MutableDictionary {
70 public:
71 explicit MockMutableDictionary(Data* data) : data_(data) {}
72
73 // MutableDictionary implementation
74 virtual base::DictionaryValue* operator->() OVERRIDE {
75 if (!data_->contents)
76 data_->contents.reset(new base::DictionaryValue);
77 return data_->contents.get();
78 }
79
80 private:
81 Data* data_;
82 DISALLOW_COPY_AND_ASSIGN(MockMutableDictionary);
83 };
84
85 Data* data_;
86
87 DISALLOW_COPY_AND_ASSIGN(MockHashStoreContents);
88 };
89
90 class PrefHashStoreImplTest : public testing::Test { 17 class PrefHashStoreImplTest : public testing::Test {
91 protected: 18 protected:
92 scoped_ptr<HashStoreContents> CreateHashStoreContents() { 19 scoped_ptr<HashStoreContents> CreateHashStoreContents() {
93 return scoped_ptr<HashStoreContents>( 20 return scoped_ptr<HashStoreContents>(
94 new MockHashStoreContents(&hash_store_data_)); 21 new DictionaryHashStoreContents(&pref_store_contents_));
95 } 22 }
96 23
97 MockHashStoreContents::Data hash_store_data_; 24 private:
25 base::DictionaryValue pref_store_contents_;
98 }; 26 };
99 27
100 TEST_F(PrefHashStoreImplTest, AtomicHashStoreAndCheck) { 28 TEST_F(PrefHashStoreImplTest, AtomicHashStoreAndCheck) {
101 base::StringValue string_1("string1"); 29 base::StringValue string_1("string1");
102 base::StringValue string_2("string2"); 30 base::StringValue string_2("string2");
103 31
104 { 32 {
105 // 32 NULL bytes is the seed that was used to generate the legacy hash. 33 // 32 NULL bytes is the seed that was used to generate the legacy hash.
106 PrefHashStoreImpl pref_hash_store( 34 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true);
107 std::string(32, 0), "device_id", CreateHashStoreContents(), true);
108 scoped_ptr<PrefHashStoreTransaction> transaction( 35 scoped_ptr<PrefHashStoreTransaction> transaction(
109 pref_hash_store.BeginTransaction()); 36 pref_hash_store.BeginTransaction(CreateHashStoreContents()));
110 37
111 // Only NULL should be trusted in the absence of a hash. 38 // Only NULL should be trusted in the absence of a hash.
112 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, 39 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE,
113 transaction->CheckValue("path1", &string_1)); 40 transaction->CheckValue("path1", &string_1));
114 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, 41 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE,
115 transaction->CheckValue("path1", NULL)); 42 transaction->CheckValue("path1", NULL));
116 43
117 transaction->StoreHash("path1", &string_1); 44 transaction->StoreHash("path1", &string_1);
118 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, 45 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED,
119 transaction->CheckValue("path1", &string_1)); 46 transaction->CheckValue("path1", &string_1));
(...skipping 14 matching lines...) Expand all
134 // Manually shove in a legacy hash. 61 // Manually shove in a legacy hash.
135 (*CreateHashStoreContents()->GetMutableContents())->SetString( 62 (*CreateHashStoreContents()->GetMutableContents())->SetString(
136 "path1", 63 "path1",
137 "C503FB7C65EEFD5C07185F616A0AA67923C069909933F362022B1F187E73E9A2"); 64 "C503FB7C65EEFD5C07185F616A0AA67923C069909933F362022B1F187E73E9A2");
138 65
139 EXPECT_EQ(PrefHashStoreTransaction::WEAK_LEGACY, 66 EXPECT_EQ(PrefHashStoreTransaction::WEAK_LEGACY,
140 transaction->CheckValue("path1", &dict)); 67 transaction->CheckValue("path1", &dict));
141 transaction->StoreHash("path1", &dict); 68 transaction->StoreHash("path1", &dict);
142 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, 69 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED,
143 transaction->CheckValue("path1", &dict)); 70 transaction->CheckValue("path1", &dict));
144
145 // Test that the |pref_hash_store| flushes its changes on request post
146 // transaction.
147 transaction.reset();
148 pref_hash_store.CommitPendingWrite();
149 EXPECT_TRUE(hash_store_data_.GetCommitPerformedAndReset());
150 } 71 }
151 72
152 ASSERT_FALSE(CreateHashStoreContents()->GetSuperMac().empty()); 73 ASSERT_FALSE(CreateHashStoreContents()->GetSuperMac().empty());
153 74
154 { 75 {
155 // |pref_hash_store2| should trust its initial hashes dictionary and thus 76 // |pref_hash_store2| should trust its initial hashes dictionary and thus
156 // trust new unknown values. 77 // trust new unknown values.
157 PrefHashStoreImpl pref_hash_store2( 78 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true);
158 std::string(32, 0), "device_id", CreateHashStoreContents(), true);
159 scoped_ptr<PrefHashStoreTransaction> transaction( 79 scoped_ptr<PrefHashStoreTransaction> transaction(
160 pref_hash_store2.BeginTransaction()); 80 pref_hash_store2.BeginTransaction(CreateHashStoreContents()));
161 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, 81 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE,
162 transaction->CheckValue("new_path", &string_1)); 82 transaction->CheckValue("new_path", &string_1));
163 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, 83 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE,
164 transaction->CheckValue("new_path", &string_2)); 84 transaction->CheckValue("new_path", &string_2));
165 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, 85 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE,
166 transaction->CheckValue("new_path", NULL)); 86 transaction->CheckValue("new_path", NULL));
167
168 // Test that |pref_hash_store2| doesn't flush its contents to disk when it
169 // didn't change.
170 transaction.reset();
171 pref_hash_store2.CommitPendingWrite();
172 EXPECT_FALSE(hash_store_data_.GetCommitPerformedAndReset());
173 } 87 }
174 88
175 // Manually corrupt the super MAC. 89 // Manually corrupt the super MAC.
176 hash_store_data_.super_mac = std::string(64, 'A'); 90 CreateHashStoreContents()->SetSuperMac(std::string(64, 'A'));
177 91
178 { 92 {
179 // |pref_hash_store3| should no longer trust its initial hashes dictionary 93 // |pref_hash_store3| should no longer trust its initial hashes dictionary
180 // and thus shouldn't trust non-NULL unknown values. 94 // and thus shouldn't trust non-NULL unknown values.
181 PrefHashStoreImpl pref_hash_store3( 95 PrefHashStoreImpl pref_hash_store3(std::string(32, 0), "device_id", true);
182 std::string(32, 0), "device_id", CreateHashStoreContents(), true);
183 scoped_ptr<PrefHashStoreTransaction> transaction( 96 scoped_ptr<PrefHashStoreTransaction> transaction(
184 pref_hash_store3.BeginTransaction()); 97 pref_hash_store3.BeginTransaction(CreateHashStoreContents()));
185 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, 98 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE,
186 transaction->CheckValue("new_path", &string_1)); 99 transaction->CheckValue("new_path", &string_1));
187 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, 100 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE,
188 transaction->CheckValue("new_path", &string_2)); 101 transaction->CheckValue("new_path", &string_2));
189 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, 102 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE,
190 transaction->CheckValue("new_path", NULL)); 103 transaction->CheckValue("new_path", NULL));
191
192 // Test that |pref_hash_store3| doesn't flush its contents to disk when it
193 // didn't change.
194 transaction.reset();
195 pref_hash_store3.CommitPendingWrite();
196 EXPECT_FALSE(hash_store_data_.GetCommitPerformedAndReset());
197 } 104 }
198 } 105 }
199 106
200 TEST_F(PrefHashStoreImplTest, SuperMACDisabled) { 107 TEST_F(PrefHashStoreImplTest, SuperMACDisabled) {
201 base::StringValue string_1("string1"); 108 base::StringValue string_1("string1");
202 base::StringValue string_2("string2"); 109 base::StringValue string_2("string2");
203 110
204 { 111 {
205 // Pass |use_super_mac| => false. 112 // Pass |use_super_mac| => false.
206 PrefHashStoreImpl pref_hash_store( 113 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", false);
207 std::string(32, 0), "device_id", CreateHashStoreContents(), false);
208 scoped_ptr<PrefHashStoreTransaction> transaction( 114 scoped_ptr<PrefHashStoreTransaction> transaction(
209 pref_hash_store.BeginTransaction()); 115 pref_hash_store.BeginTransaction(CreateHashStoreContents()));
210 116
211 transaction->StoreHash("path1", &string_2); 117 transaction->StoreHash("path1", &string_2);
212 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, 118 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED,
213 transaction->CheckValue("path1", &string_2)); 119 transaction->CheckValue("path1", &string_2));
214 } 120 }
215 121
216 ASSERT_TRUE(CreateHashStoreContents()->GetSuperMac().empty()); 122 ASSERT_TRUE(CreateHashStoreContents()->GetSuperMac().empty());
217 123
218 { 124 {
219 PrefHashStoreImpl pref_hash_store2( 125 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", false);
220 std::string(32, 0), "device_id", CreateHashStoreContents(), false);
221 scoped_ptr<PrefHashStoreTransaction> transaction( 126 scoped_ptr<PrefHashStoreTransaction> transaction(
222 pref_hash_store2.BeginTransaction()); 127 pref_hash_store2.BeginTransaction(CreateHashStoreContents()));
223 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, 128 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE,
224 transaction->CheckValue("new_path", &string_1)); 129 transaction->CheckValue("new_path", &string_1));
225 } 130 }
226 } 131 }
227 132
228 TEST_F(PrefHashStoreImplTest, SplitHashStoreAndCheck) { 133 TEST_F(PrefHashStoreImplTest, SplitHashStoreAndCheck) {
229 base::DictionaryValue dict; 134 base::DictionaryValue dict;
230 dict.Set("a", new base::StringValue("to be replaced")); 135 dict.Set("a", new base::StringValue("to be replaced"));
231 dict.Set("b", new base::StringValue("same")); 136 dict.Set("b", new base::StringValue("same"));
232 dict.Set("o", new base::StringValue("old")); 137 dict.Set("o", new base::StringValue("old"));
233 138
234 base::DictionaryValue modified_dict; 139 base::DictionaryValue modified_dict;
235 modified_dict.Set("a", new base::StringValue("replaced")); 140 modified_dict.Set("a", new base::StringValue("replaced"));
236 modified_dict.Set("b", new base::StringValue("same")); 141 modified_dict.Set("b", new base::StringValue("same"));
237 modified_dict.Set("c", new base::StringValue("new")); 142 modified_dict.Set("c", new base::StringValue("new"));
238 143
239 base::DictionaryValue empty_dict; 144 base::DictionaryValue empty_dict;
240 145
241 std::vector<std::string> invalid_keys; 146 std::vector<std::string> invalid_keys;
242 147
243 { 148 {
244 PrefHashStoreImpl pref_hash_store( 149 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true);
245 std::string(32, 0), "device_id", CreateHashStoreContents(), true);
246 scoped_ptr<PrefHashStoreTransaction> transaction( 150 scoped_ptr<PrefHashStoreTransaction> transaction(
247 pref_hash_store.BeginTransaction()); 151 pref_hash_store.BeginTransaction(CreateHashStoreContents()));
248 152
249 // No hashes stored yet and hashes dictionary is empty (and thus not 153 // No hashes stored yet and hashes dictionary is empty (and thus not
250 // trusted). 154 // trusted).
251 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, 155 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE,
252 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); 156 transaction->CheckSplitValue("path1", &dict, &invalid_keys));
253 EXPECT_TRUE(invalid_keys.empty()); 157 EXPECT_TRUE(invalid_keys.empty());
254 158
255 transaction->StoreSplitHash("path1", &dict); 159 transaction->StoreSplitHash("path1", &dict);
256 160
257 // Verify match post storage. 161 // Verify match post storage.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 // Verify old dict no longer matches. 205 // Verify old dict no longer matches.
302 EXPECT_EQ(PrefHashStoreTransaction::CHANGED, 206 EXPECT_EQ(PrefHashStoreTransaction::CHANGED,
303 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); 207 transaction->CheckSplitValue("path1", &dict, &invalid_keys));
304 std::vector<std::string> expected_invalid_keys2; 208 std::vector<std::string> expected_invalid_keys2;
305 expected_invalid_keys2.push_back("a"); 209 expected_invalid_keys2.push_back("a");
306 expected_invalid_keys2.push_back("o"); 210 expected_invalid_keys2.push_back("o");
307 expected_invalid_keys2.push_back("c"); 211 expected_invalid_keys2.push_back("c");
308 EXPECT_EQ(expected_invalid_keys2, invalid_keys); 212 EXPECT_EQ(expected_invalid_keys2, invalid_keys);
309 invalid_keys.clear(); 213 invalid_keys.clear();
310 214
311 // Test that the |pref_hash_store| flushes its changes on request.
312 transaction.reset();
313 pref_hash_store.CommitPendingWrite();
314 EXPECT_TRUE(hash_store_data_.GetCommitPerformedAndReset());
315 } 215 }
316 216
317 { 217 {
318 // |pref_hash_store2| should trust its initial hashes dictionary and thus 218 // |pref_hash_store2| should trust its initial hashes dictionary and thus
319 // trust new unknown values. 219 // trust new unknown values.
320 PrefHashStoreImpl pref_hash_store2( 220 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true);
321 std::string(32, 0), "device_id", CreateHashStoreContents(), true);
322 scoped_ptr<PrefHashStoreTransaction> transaction( 221 scoped_ptr<PrefHashStoreTransaction> transaction(
323 pref_hash_store2.BeginTransaction()); 222 pref_hash_store2.BeginTransaction(CreateHashStoreContents()));
324 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, 223 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE,
325 transaction->CheckSplitValue("new_path", &dict, &invalid_keys)); 224 transaction->CheckSplitValue("new_path", &dict, &invalid_keys));
326 EXPECT_TRUE(invalid_keys.empty()); 225 EXPECT_TRUE(invalid_keys.empty());
327
328 // Test that |pref_hash_store2| doesn't flush its contents to disk when it
329 // didn't change.
330 transaction.reset();
331 pref_hash_store2.CommitPendingWrite();
332 EXPECT_FALSE(hash_store_data_.GetCommitPerformedAndReset());
333 } 226 }
334 227
335 // Manually corrupt the super MAC. 228 // Manually corrupt the super MAC.
336 hash_store_data_.super_mac = std::string(64, 'A'); 229 CreateHashStoreContents()->SetSuperMac(std::string(64, 'A'));
337 230
338 { 231 {
339 // |pref_hash_store3| should no longer trust its initial hashes dictionary 232 // |pref_hash_store3| should no longer trust its initial hashes dictionary
340 // and thus shouldn't trust unknown values. 233 // and thus shouldn't trust unknown values.
341 PrefHashStoreImpl pref_hash_store3( 234 PrefHashStoreImpl pref_hash_store3(std::string(32, 0), "device_id", true);
342 std::string(32, 0), "device_id", CreateHashStoreContents(), true);
343 scoped_ptr<PrefHashStoreTransaction> transaction( 235 scoped_ptr<PrefHashStoreTransaction> transaction(
344 pref_hash_store3.BeginTransaction()); 236 pref_hash_store3.BeginTransaction(CreateHashStoreContents()));
345 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, 237 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE,
346 transaction->CheckSplitValue("new_path", &dict, &invalid_keys)); 238 transaction->CheckSplitValue("new_path", &dict, &invalid_keys));
347 EXPECT_TRUE(invalid_keys.empty()); 239 EXPECT_TRUE(invalid_keys.empty());
348
349 // Test that |pref_hash_store3| doesn't flush its contents to disk when it
350 // didn't change.
351 transaction.reset();
352 pref_hash_store3.CommitPendingWrite();
353 EXPECT_FALSE(hash_store_data_.GetCommitPerformedAndReset());
354 } 240 }
355 } 241 }
356 242
357 TEST_F(PrefHashStoreImplTest, EmptyAndNULLSplitDict) { 243 TEST_F(PrefHashStoreImplTest, EmptyAndNULLSplitDict) {
358 base::DictionaryValue empty_dict; 244 base::DictionaryValue empty_dict;
359 245
360 std::vector<std::string> invalid_keys; 246 std::vector<std::string> invalid_keys;
361 247
362 { 248 {
363 PrefHashStoreImpl pref_hash_store( 249 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true);
364 std::string(32, 0), "device_id", CreateHashStoreContents(), true);
365 scoped_ptr<PrefHashStoreTransaction> transaction( 250 scoped_ptr<PrefHashStoreTransaction> transaction(
366 pref_hash_store.BeginTransaction()); 251 pref_hash_store.BeginTransaction(CreateHashStoreContents()));
367 252
368 // Store hashes for a random dict to be overwritten below. 253 // Store hashes for a random dict to be overwritten below.
369 base::DictionaryValue initial_dict; 254 base::DictionaryValue initial_dict;
370 initial_dict.Set("a", new base::StringValue("foo")); 255 initial_dict.Set("a", new base::StringValue("foo"));
371 transaction->StoreSplitHash("path1", &initial_dict); 256 transaction->StoreSplitHash("path1", &initial_dict);
372 257
373 // Verify stored empty dictionary matches NULL and empty dictionary back. 258 // Verify stored empty dictionary matches NULL and empty dictionary back.
374 transaction->StoreSplitHash("path1", &empty_dict); 259 transaction->StoreSplitHash("path1", &empty_dict);
375 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, 260 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED,
376 transaction->CheckSplitValue("path1", NULL, &invalid_keys)); 261 transaction->CheckSplitValue("path1", NULL, &invalid_keys));
(...skipping 13 matching lines...) Expand all
390 transaction->CheckSplitValue("path1", &empty_dict, &invalid_keys)); 275 transaction->CheckSplitValue("path1", &empty_dict, &invalid_keys));
391 EXPECT_TRUE(invalid_keys.empty()); 276 EXPECT_TRUE(invalid_keys.empty());
392 } 277 }
393 278
394 { 279 {
395 // |pref_hash_store2| should trust its initial hashes dictionary (and thus 280 // |pref_hash_store2| should trust its initial hashes dictionary (and thus
396 // trust new unknown values) even though the last action done was to clear 281 // trust new unknown values) even though the last action done was to clear
397 // the hashes for path1 by setting its value to NULL (this is a regression 282 // the hashes for path1 by setting its value to NULL (this is a regression
398 // test ensuring that the internal action of clearing some hashes does 283 // test ensuring that the internal action of clearing some hashes does
399 // update the stored hash of hashes). 284 // update the stored hash of hashes).
400 PrefHashStoreImpl pref_hash_store2( 285 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true);
401 std::string(32, 0), "device_id", CreateHashStoreContents(), true);
402 scoped_ptr<PrefHashStoreTransaction> transaction( 286 scoped_ptr<PrefHashStoreTransaction> transaction(
403 pref_hash_store2.BeginTransaction()); 287 pref_hash_store2.BeginTransaction(CreateHashStoreContents()));
404 288
405 base::DictionaryValue tested_dict; 289 base::DictionaryValue tested_dict;
406 tested_dict.Set("a", new base::StringValue("foo")); 290 tested_dict.Set("a", new base::StringValue("foo"));
407 tested_dict.Set("b", new base::StringValue("bar")); 291 tested_dict.Set("b", new base::StringValue("bar"));
408 EXPECT_EQ( 292 EXPECT_EQ(
409 PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, 293 PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE,
410 transaction->CheckSplitValue("new_path", &tested_dict, &invalid_keys)); 294 transaction->CheckSplitValue("new_path", &tested_dict, &invalid_keys));
411 EXPECT_TRUE(invalid_keys.empty()); 295 EXPECT_TRUE(invalid_keys.empty());
412 } 296 }
413 } 297 }
414 298
415 // Test that the PrefHashStore returns TRUSTED_UNKNOWN_VALUE when checking for 299 // Test that the PrefHashStore returns TRUSTED_UNKNOWN_VALUE when checking for
416 // a split preference even if there is an existing atomic preference's hash 300 // a split preference even if there is an existing atomic preference's hash
417 // stored. There is no point providing a migration path for preferences 301 // stored. There is no point providing a migration path for preferences
418 // switching strategies after their initial release as split preferences are 302 // switching strategies after their initial release as split preferences are
419 // turned into split preferences specifically because the atomic hash isn't 303 // turned into split preferences specifically because the atomic hash isn't
420 // considered useful. 304 // considered useful.
421 TEST_F(PrefHashStoreImplTest, TrustedUnknownSplitValueFromExistingAtomic) { 305 TEST_F(PrefHashStoreImplTest, TrustedUnknownSplitValueFromExistingAtomic) {
422 base::StringValue string("string1"); 306 base::StringValue string("string1");
423 307
424 base::DictionaryValue dict; 308 base::DictionaryValue dict;
425 dict.Set("a", new base::StringValue("foo")); 309 dict.Set("a", new base::StringValue("foo"));
426 dict.Set("d", new base::StringValue("bad")); 310 dict.Set("d", new base::StringValue("bad"));
427 dict.Set("b", new base::StringValue("bar")); 311 dict.Set("b", new base::StringValue("bar"));
428 dict.Set("c", new base::StringValue("baz")); 312 dict.Set("c", new base::StringValue("baz"));
429 313
430 { 314 {
431 PrefHashStoreImpl pref_hash_store( 315 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true);
432 std::string(32, 0), "device_id", CreateHashStoreContents(), true);
433 scoped_ptr<PrefHashStoreTransaction> transaction( 316 scoped_ptr<PrefHashStoreTransaction> transaction(
434 pref_hash_store.BeginTransaction()); 317 pref_hash_store.BeginTransaction(CreateHashStoreContents()));
435 318
436 transaction->StoreHash("path1", &string); 319 transaction->StoreHash("path1", &string);
437 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, 320 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED,
438 transaction->CheckValue("path1", &string)); 321 transaction->CheckValue("path1", &string));
439 } 322 }
440 323
441 { 324 {
442 // Load a new |pref_hash_store2| in which the hashes dictionary is trusted. 325 // Load a new |pref_hash_store2| in which the hashes dictionary is trusted.
443 PrefHashStoreImpl pref_hash_store2( 326 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true);
444 std::string(32, 0), "device_id", CreateHashStoreContents(), true);
445 scoped_ptr<PrefHashStoreTransaction> transaction( 327 scoped_ptr<PrefHashStoreTransaction> transaction(
446 pref_hash_store2.BeginTransaction()); 328 pref_hash_store2.BeginTransaction(CreateHashStoreContents()));
447 std::vector<std::string> invalid_keys; 329 std::vector<std::string> invalid_keys;
448 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, 330 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE,
449 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); 331 transaction->CheckSplitValue("path1", &dict, &invalid_keys));
450 EXPECT_TRUE(invalid_keys.empty()); 332 EXPECT_TRUE(invalid_keys.empty());
451 } 333 }
452 } 334 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698