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 "chrome/browser/prefs/tracked/pref_hash_store_impl.h" | 5 #include "components/user_prefs/tracked/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/tracked/dictionary_hash_store_contents.h" | 11 #include "components/user_prefs/tracked/dictionary_hash_store_contents.h" |
12 #include "chrome/browser/prefs/tracked/hash_store_contents.h" | 12 #include "components/user_prefs/tracked/hash_store_contents.h" |
13 #include "chrome/browser/prefs/tracked/pref_hash_store_impl.h" | 13 #include "components/user_prefs/tracked/pref_hash_store_impl.h" |
14 #include "chrome/browser/prefs/tracked/pref_hash_store_transaction.h" | 14 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 class PrefHashStoreImplTest : public testing::Test { | 17 class PrefHashStoreImplTest : public testing::Test { |
18 protected: | 18 protected: |
19 scoped_ptr<HashStoreContents> CreateHashStoreContents() { | 19 scoped_ptr<HashStoreContents> CreateHashStoreContents() { |
20 return scoped_ptr<HashStoreContents>( | 20 return scoped_ptr<HashStoreContents>( |
21 new DictionaryHashStoreContents(&pref_store_contents_)); | 21 new DictionaryHashStoreContents(&pref_store_contents_)); |
22 } | 22 } |
23 | 23 |
24 private: | 24 private: |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 | 345 |
346 // Verify old dict no longer matches. | 346 // Verify old dict no longer matches. |
347 EXPECT_EQ(PrefHashStoreTransaction::CHANGED, | 347 EXPECT_EQ(PrefHashStoreTransaction::CHANGED, |
348 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); | 348 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); |
349 std::vector<std::string> expected_invalid_keys2; | 349 std::vector<std::string> expected_invalid_keys2; |
350 expected_invalid_keys2.push_back("a"); | 350 expected_invalid_keys2.push_back("a"); |
351 expected_invalid_keys2.push_back("o"); | 351 expected_invalid_keys2.push_back("o"); |
352 expected_invalid_keys2.push_back("c"); | 352 expected_invalid_keys2.push_back("c"); |
353 EXPECT_EQ(expected_invalid_keys2, invalid_keys); | 353 EXPECT_EQ(expected_invalid_keys2, invalid_keys); |
354 invalid_keys.clear(); | 354 invalid_keys.clear(); |
355 | |
356 } | 355 } |
357 | 356 |
358 { | 357 { |
359 // |pref_hash_store2| should trust its initial hashes dictionary and thus | 358 // |pref_hash_store2| should trust its initial hashes dictionary and thus |
360 // trust new unknown values. | 359 // trust new unknown values. |
361 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true); | 360 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true); |
362 scoped_ptr<PrefHashStoreTransaction> transaction( | 361 scoped_ptr<PrefHashStoreTransaction> transaction( |
363 pref_hash_store2.BeginTransaction(CreateHashStoreContents())); | 362 pref_hash_store2.BeginTransaction(CreateHashStoreContents())); |
364 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, | 363 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, |
365 transaction->CheckSplitValue("new_path", &dict, &invalid_keys)); | 364 transaction->CheckSplitValue("new_path", &dict, &invalid_keys)); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 // Load a new |pref_hash_store2| in which the hashes dictionary is trusted. | 465 // Load a new |pref_hash_store2| in which the hashes dictionary is trusted. |
467 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true); | 466 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true); |
468 scoped_ptr<PrefHashStoreTransaction> transaction( | 467 scoped_ptr<PrefHashStoreTransaction> transaction( |
469 pref_hash_store2.BeginTransaction(CreateHashStoreContents())); | 468 pref_hash_store2.BeginTransaction(CreateHashStoreContents())); |
470 std::vector<std::string> invalid_keys; | 469 std::vector<std::string> invalid_keys; |
471 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, | 470 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, |
472 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); | 471 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); |
473 EXPECT_TRUE(invalid_keys.empty()); | 472 EXPECT_TRUE(invalid_keys.empty()); |
474 } | 473 } |
475 } | 474 } |
OLD | NEW |