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

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

Issue 90563003: Fix a race condition in preference metric reporting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Also filter 'empty loads' as in new run or corrupted pref file scenarios. Created 6 years, 12 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/prefs/pref_hash_store_impl.h"
6
7 #include <string>
8
9 #include "base/prefs/pref_service.h"
10 #include "base/prefs/scoped_user_pref_update.h"
11 #include "base/prefs/testing_pref_service.h"
12 #include "base/values.h"
13 #include "chrome/browser/prefs/pref_hash_store.h"
14 #include "chrome/common/pref_names.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 TEST(PrefHashStoreImplTest, TestCase) {
18 base::StringValue string_1("string1");
19 base::StringValue string_2("string2");
20
21 TestingPrefServiceSimple local_state;
22 PrefHashStoreImpl::RegisterPrefs(local_state.registry());
23
24 // 32 NULL bytes is the seed that was used to generate the legacy hash.
25 PrefHashStoreImpl pref_hash_store(
26 "store_id", std::string(32,0), "device_id", &local_state);
27
28 ASSERT_EQ(PrefHashStore::UNKNOWN_VALUE,
29 pref_hash_store.CheckValue("path1", &string_1));
30 pref_hash_store.StoreHash("path1", &string_1);
31 ASSERT_EQ(PrefHashStore::UNCHANGED,
32 pref_hash_store.CheckValue("path1", &string_1));
33 ASSERT_EQ(PrefHashStore::CLEARED, pref_hash_store.CheckValue("path1", NULL));
34 pref_hash_store.StoreHash("path1", NULL);
35 ASSERT_EQ(PrefHashStore::UNCHANGED,
36 pref_hash_store.CheckValue("path1", NULL));
37 ASSERT_EQ(PrefHashStore::CHANGED,
38 pref_hash_store.CheckValue("path1", &string_2));
39
40 DictionaryValue dict;
41 dict.Set("a", new StringValue("foo"));
42 dict.Set("d", new StringValue("bad"));
43 dict.Set("b", new StringValue("bar"));
44 dict.Set("c", new StringValue("baz"));
45
46 // Manually shove in a legacy hash.
47 DictionaryPrefUpdate update(&local_state, prefs::kProfilePreferenceHashes);
48 DictionaryValue* child_dictionary = NULL;
49 ASSERT_TRUE(update->GetDictionary("store_id", &child_dictionary));
50 child_dictionary->SetString(
51 "path1",
52 "C503FB7C65EEFD5C07185F616A0AA67923C069909933F362022B1F187E73E9A2");
53
54 ASSERT_EQ(PrefHashStore::MIGRATED,
55 pref_hash_store.CheckValue("path1", &dict));
56 pref_hash_store.StoreHash("path1", &dict);
57 ASSERT_EQ(PrefHashStore::UNCHANGED,
58 pref_hash_store.CheckValue("path1", &dict));
59 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_hash_store_impl.cc ('k') | chrome/browser/prefs/pref_metrics_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698