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

Side by Side Diff: chrome/browser/pref_member_unittest.cc

Issue 3051001: Adjust preference sync code to only sync user modifiable preferences. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: separate out the download_manager_unittest.cc fixes Created 10 years, 5 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
« no previous file with comments | « chrome/browser/managed_prefs_banner_base_unittest.cc ('k') | chrome/browser/pref_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/file_path.h" 5 #include "base/file_path.h"
6 #include "chrome/browser/dummy_pref_store.h" 6 #include "chrome/browser/dummy_pref_store.h"
7 #include "chrome/browser/pref_member.h" 7 #include "chrome/browser/pref_member.h"
8 #include "chrome/browser/pref_service.h"
9 #include "chrome/browser/pref_value_store.h" 8 #include "chrome/browser/pref_value_store.h"
10 #include "chrome/common/notification_service.h" 9 #include "chrome/common/notification_service.h"
10 #include "chrome/test/testing_pref_service.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace { 13 namespace {
14 14
15 static const wchar_t kBoolPref[] = L"bool"; 15 static const wchar_t kBoolPref[] = L"bool";
16 static const wchar_t kIntPref[] = L"int"; 16 static const wchar_t kIntPref[] = L"int";
17 static const wchar_t kRealPref[] = L"real"; 17 static const wchar_t kRealPref[] = L"real";
18 static const wchar_t kStringPref[] = L"string"; 18 static const wchar_t kStringPref[] = L"string";
19 19
20 void RegisterTestPrefs(PrefService* prefs) { 20 void RegisterTestPrefs(PrefService* prefs) {
(...skipping 25 matching lines...) Expand all
46 StringPrefMember str_; 46 StringPrefMember str_;
47 int observe_cnt_; 47 int observe_cnt_;
48 48
49 private: 49 private:
50 PrefService* prefs_; 50 PrefService* prefs_;
51 }; 51 };
52 52
53 } // anonymous namespace 53 } // anonymous namespace
54 54
55 TEST(PrefMemberTest, BasicGetAndSet) { 55 TEST(PrefMemberTest, BasicGetAndSet) {
56 PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(), 56 TestingPrefService prefs;
57 NULL));
58 RegisterTestPrefs(&prefs); 57 RegisterTestPrefs(&prefs);
59 58
60 // Test bool 59 // Test bool
61 BooleanPrefMember boolean; 60 BooleanPrefMember boolean;
62 boolean.Init(kBoolPref, &prefs, NULL); 61 boolean.Init(kBoolPref, &prefs, NULL);
63 62
64 // Check the defaults 63 // Check the defaults
65 EXPECT_FALSE(prefs.GetBoolean(kBoolPref)); 64 EXPECT_FALSE(prefs.GetBoolean(kBoolPref));
66 EXPECT_FALSE(boolean.GetValue()); 65 EXPECT_FALSE(boolean.GetValue());
67 EXPECT_FALSE(*boolean); 66 EXPECT_FALSE(*boolean);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 136
138 // Try changing back through the pref. 137 // Try changing back through the pref.
139 prefs.SetString(kStringPref, "bar"); 138 prefs.SetString(kStringPref, "bar");
140 EXPECT_EQ("bar", prefs.GetString(kStringPref)); 139 EXPECT_EQ("bar", prefs.GetString(kStringPref));
141 EXPECT_EQ("bar", string.GetValue()); 140 EXPECT_EQ("bar", string.GetValue());
142 EXPECT_EQ("bar", *string); 141 EXPECT_EQ("bar", *string);
143 } 142 }
144 143
145 TEST(PrefMemberTest, TwoPrefs) { 144 TEST(PrefMemberTest, TwoPrefs) {
146 // Make sure two RealPrefMembers stay in sync. 145 // Make sure two RealPrefMembers stay in sync.
147 PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(), 146 TestingPrefService prefs;
148 NULL));
149 RegisterTestPrefs(&prefs); 147 RegisterTestPrefs(&prefs);
150 148
151 RealPrefMember pref1; 149 RealPrefMember pref1;
152 pref1.Init(kRealPref, &prefs, NULL); 150 pref1.Init(kRealPref, &prefs, NULL);
153 RealPrefMember pref2; 151 RealPrefMember pref2;
154 pref2.Init(kRealPref, &prefs, NULL); 152 pref2.Init(kRealPref, &prefs, NULL);
155 153
156 pref1.SetValue(2.3); 154 pref1.SetValue(2.3);
157 EXPECT_EQ(2.3, *pref2); 155 EXPECT_EQ(2.3, *pref2);
158 156
159 pref2.SetValue(3.5); 157 pref2.SetValue(3.5);
160 EXPECT_EQ(3.5, *pref1); 158 EXPECT_EQ(3.5, *pref1);
161 159
162 prefs.SetReal(kRealPref, 4.2); 160 prefs.SetReal(kRealPref, 4.2);
163 EXPECT_EQ(4.2, *pref1); 161 EXPECT_EQ(4.2, *pref1);
164 EXPECT_EQ(4.2, *pref2); 162 EXPECT_EQ(4.2, *pref2);
165 } 163 }
166 164
167 TEST(PrefMemberTest, Observer) { 165 TEST(PrefMemberTest, Observer) {
168 PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(), 166 TestingPrefService prefs;
169 NULL));
170 RegisterTestPrefs(&prefs); 167 RegisterTestPrefs(&prefs);
171 168
172 PrefMemberTestClass test_obj(&prefs); 169 PrefMemberTestClass test_obj(&prefs);
173 EXPECT_EQ("default", *test_obj.str_); 170 EXPECT_EQ("default", *test_obj.str_);
174 171
175 // Calling SetValue should not fire the observer. 172 // Calling SetValue should not fire the observer.
176 test_obj.str_.SetValue("hello"); 173 test_obj.str_.SetValue("hello");
177 EXPECT_EQ(0, test_obj.observe_cnt_); 174 EXPECT_EQ(0, test_obj.observe_cnt_);
178 EXPECT_EQ("hello", prefs.GetString(kStringPref)); 175 EXPECT_EQ("hello", prefs.GetString(kStringPref));
179 176
180 // Changing the pref does fire the observer. 177 // Changing the pref does fire the observer.
181 prefs.SetString(kStringPref, "world"); 178 prefs.SetString(kStringPref, "world");
182 EXPECT_EQ(1, test_obj.observe_cnt_); 179 EXPECT_EQ(1, test_obj.observe_cnt_);
183 EXPECT_EQ("world", *(test_obj.str_)); 180 EXPECT_EQ("world", *(test_obj.str_));
184 181
185 // Not changing the value should not fire the observer. 182 // Not changing the value should not fire the observer.
186 prefs.SetString(kStringPref, "world"); 183 prefs.SetString(kStringPref, "world");
187 EXPECT_EQ(1, test_obj.observe_cnt_); 184 EXPECT_EQ(1, test_obj.observe_cnt_);
188 EXPECT_EQ("world", *(test_obj.str_)); 185 EXPECT_EQ("world", *(test_obj.str_));
189 186
190 prefs.SetString(kStringPref, "hello"); 187 prefs.SetString(kStringPref, "hello");
191 EXPECT_EQ(2, test_obj.observe_cnt_); 188 EXPECT_EQ(2, test_obj.observe_cnt_);
192 EXPECT_EQ("hello", prefs.GetString(kStringPref)); 189 EXPECT_EQ("hello", prefs.GetString(kStringPref));
193 } 190 }
194 191
195 TEST(PrefMemberTest, NoInit) { 192 TEST(PrefMemberTest, NoInit) {
196 // Make sure not calling Init on a PrefMember doesn't cause problems. 193 // Make sure not calling Init on a PrefMember doesn't cause problems.
197 IntegerPrefMember pref; 194 IntegerPrefMember pref;
198 } 195 }
OLDNEW
« no previous file with comments | « chrome/browser/managed_prefs_banner_base_unittest.cc ('k') | chrome/browser/pref_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698