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

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

Issue 23528008: Don't use path expansion for profile dictionaries in LocalState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/metrics/histogram.h" 6 #include "base/metrics/histogram.h"
7 #include "base/metrics/statistics_recorder.h" 7 #include "base/metrics/statistics_recorder.h"
8 #include "base/prefs/testing_pref_service.h" 8 #include "base/prefs/testing_pref_service.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/prefs/pref_metrics_service.h" 10 #include "chrome/browser/prefs/pref_metrics_service.h"
11 #include "chrome/browser/prefs/scoped_user_pref_update.h" 11 #include "chrome/browser/prefs/scoped_user_pref_update.h"
12 #include "chrome/test/base/testing_browser_process.h"
12 #include "chrome/test/base/testing_pref_service_syncable.h" 13 #include "chrome/test/base/testing_pref_service_syncable.h"
13 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "chrome/test/base/testing_profile_manager.h"
14 #include "components/user_prefs/pref_registry_syncable.h" 16 #include "components/user_prefs/pref_registry_syncable.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 18
17 namespace { 19 namespace {
18 20
19 // TestingProfile may register some real preferences; to avoid interference, 21 // TestingProfile may register some real preferences; to avoid interference,
20 // define fake preferences for testing. 22 // define fake preferences for testing.
21 const char* kTrackedPrefs[] = { 23 const char* kTrackedPrefs[] = {
22 "pref_metrics_service_test.pref1", 24 "pref_metrics_service_test.pref1",
23 "pref_metrics_service_test.pref2", 25 "pref_metrics_service_test.pref2",
(...skipping 10 matching lines...) Expand all
34 pref2_changed_ = 0; 36 pref2_changed_ = 0;
35 pref1_cleared_ = 0; 37 pref1_cleared_ = 0;
36 pref2_cleared_ = 0; 38 pref2_cleared_ = 0;
37 pref1_initialized_ = 0; 39 pref1_initialized_ = 0;
38 pref2_initialized_ = 0; 40 pref2_initialized_ = 0;
39 pref1_unchanged_ = 0; 41 pref1_unchanged_ = 0;
40 pref2_unchanged_ = 0; 42 pref2_unchanged_ = 0;
41 43
42 base::StatisticsRecorder::Initialize(); 44 base::StatisticsRecorder::Initialize();
43 45
44 prefs_ = profile_.GetTestingPrefService(); 46 // Reset and set up the profile manager.
47 profile_manager_.reset(new TestingProfileManager(
48 TestingBrowserProcess::GetGlobal()));
49 ASSERT_TRUE(profile_manager_->SetUp());
50
51 // Check that PrefMetricsService behaves with a '.' in the profile name.
52 profile_ = profile_manager_->CreateTestingProfile("test@example.com");
53
54 prefs_ = profile_->GetTestingPrefService();
45 55
46 // Register our test-only tracked prefs as string values. 56 // Register our test-only tracked prefs as string values.
47 for (int i = 0; i < kTrackedPrefCount; ++i) { 57 for (int i = 0; i < kTrackedPrefCount; ++i) {
48 prefs_->registry()->RegisterStringPref( 58 prefs_->registry()->RegisterStringPref(
49 kTrackedPrefs[i], 59 kTrackedPrefs[i],
50 "test_default_value", 60 "test_default_value",
51 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 61 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
52 } 62 }
53 63
54 // Initialize pref in local state that holds hashed values. 64 // Initialize pref in local state that holds hashed values.
55 PrefMetricsService::RegisterPrefs(local_state_.registry()); 65 PrefMetricsService::RegisterPrefs(local_state_.registry());
56 66
57 // Update global counts in case another test left stray samples. 67 // Update global counts in case another test left stray samples.
58 UpdateHistogramSamples(); 68 UpdateHistogramSamples();
59 } 69 }
60 70
61 scoped_ptr<PrefMetricsService> CreatePrefMetricsService() { 71 scoped_ptr<PrefMetricsService> CreatePrefMetricsService() {
62 return scoped_ptr<PrefMetricsService>( 72 return scoped_ptr<PrefMetricsService>(
63 new PrefMetricsService(&profile_, 73 new PrefMetricsService(profile_,
64 &local_state_, 74 &local_state_,
65 "test_device_id", 75 "test_device_id",
66 kTrackedPrefs, 76 kTrackedPrefs,
67 kTrackedPrefCount)); 77 kTrackedPrefCount));
68 } 78 }
69 79
70 std::string GetHashedPrefValue(PrefMetricsService* service, 80 std::string GetHashedPrefValue(PrefMetricsService* service,
71 const char* path, base::Value* value) { 81 const char* path, base::Value* value) {
72 return service->GetHashedPrefValue(path, value); 82 return service->GetHashedPrefValue(path, value);
73 } 83 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 pref2_initialized_total = inited2; 118 pref2_initialized_total = inited2;
109 119
110 int unchanged1, unchanged2; 120 int unchanged1, unchanged2;
111 GetSamples("Settings.TrackedPreferenceUnchanged", &unchanged1, &unchanged2); 121 GetSamples("Settings.TrackedPreferenceUnchanged", &unchanged1, &unchanged2);
112 pref1_unchanged_ = unchanged1 - pref1_unchanged_total; 122 pref1_unchanged_ = unchanged1 - pref1_unchanged_total;
113 pref2_unchanged_ = unchanged2 - pref2_unchanged_total; 123 pref2_unchanged_ = unchanged2 - pref2_unchanged_total;
114 pref1_unchanged_total = unchanged1; 124 pref1_unchanged_total = unchanged1;
115 pref2_unchanged_total = unchanged2; 125 pref2_unchanged_total = unchanged2;
116 } 126 }
117 127
118 TestingProfile profile_; 128 TestingProfile* profile_;
129 scoped_ptr<TestingProfileManager> profile_manager_;
119 TestingPrefServiceSyncable* prefs_; 130 TestingPrefServiceSyncable* prefs_;
120 TestingPrefServiceSimple local_state_; 131 TestingPrefServiceSimple local_state_;
121 132
122 // Since histogram samples are recorded by a global StatisticsRecorder, we 133 // Since histogram samples are recorded by a global StatisticsRecorder, we
123 // need to maintain total counts so we can compute deltas for individual 134 // need to maintain total counts so we can compute deltas for individual
124 // tests. 135 // tests.
125 static int pref1_changed_total; 136 static int pref1_changed_total;
126 static int pref2_changed_total; 137 static int pref2_changed_total;
127 static int pref1_cleared_total; 138 static int pref1_cleared_total;
128 static int pref2_cleared_total; 139 static int pref2_cleared_total;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 EXPECT_EQ("C503FB7C65EEFD5C07185F616A0AA67923C069909933F362022B1F187E73E9A2", 276 EXPECT_EQ("C503FB7C65EEFD5C07185F616A0AA67923C069909933F362022B1F187E73E9A2",
266 GetHashedPrefValue(test.get(), "pref.path1", &dict)); 277 GetHashedPrefValue(test.get(), "pref.path1", &dict));
267 278
268 ListValue list; 279 ListValue list;
269 list.Set(0, new base::FundamentalValue(true)); 280 list.Set(0, new base::FundamentalValue(true));
270 list.Set(1, new base::FundamentalValue(100)); 281 list.Set(1, new base::FundamentalValue(100));
271 list.Set(2, new base::FundamentalValue(1.0)); 282 list.Set(2, new base::FundamentalValue(1.0));
272 EXPECT_EQ("3163EC3C96263143AF83EA5C9860DFB960EE2263413C7D7D8A9973FCC00E7692", 283 EXPECT_EQ("3163EC3C96263143AF83EA5C9860DFB960EE2263413C7D7D8A9973FCC00E7692",
273 GetHashedPrefValue(test.get(), "pref.path2", &list)); 284 GetHashedPrefValue(test.get(), "pref.path2", &list));
274 } 285 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_metrics_service.cc ('k') | chrome/browser/profiles/profile_info_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698