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

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

Issue 4876002: Create additional PrefStore for Device Management policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review feedback Created 10 years, 1 month 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
« no previous file with comments | « chrome/browser/prefs/pref_value_store.cc ('k') | chrome/test/testing_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) 2010 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/scoped_ptr.h" 5 #include "base/scoped_ptr.h"
6 #include "base/values.h" 6 #include "base/values.h"
7 #include "chrome/browser/browser_thread.h" 7 #include "chrome/browser/browser_thread.h"
8 #include "chrome/browser/policy/configuration_policy_pref_store.h" 8 #include "chrome/browser/policy/configuration_policy_pref_store.h"
9 #include "chrome/browser/prefs/dummy_pref_store.h" 9 #include "chrome/browser/prefs/dummy_pref_store.h"
10 #include "chrome/browser/prefs/pref_value_store.h" 10 #include "chrome/browser/prefs/pref_value_store.h"
(...skipping 18 matching lines...) Expand all
29 // Names of the preferences used in this test program. 29 // Names of the preferences used in this test program.
30 namespace prefs { 30 namespace prefs {
31 const char kMissingPref[] = "this.pref.does_not_exist"; 31 const char kMissingPref[] = "this.pref.does_not_exist";
32 const char kRecommendedPref[] = "this.pref.recommended_value_only"; 32 const char kRecommendedPref[] = "this.pref.recommended_value_only";
33 const char kSampleDict[] = "sample.dict"; 33 const char kSampleDict[] = "sample.dict";
34 const char kSampleList[] = "sample.list"; 34 const char kSampleList[] = "sample.list";
35 const char kDefaultPref[] = "default.pref"; 35 const char kDefaultPref[] = "default.pref";
36 } 36 }
37 37
38 // Potentially expected values of all preferences used in this test program. 38 // Potentially expected values of all preferences used in this test program.
39 namespace enforced_pref { 39 namespace managed_platform_pref {
40 const std::string kHomepageValue = "http://www.topeka.com"; 40 const std::string kHomepageValue = "http://www.topeka.com";
41 } 41 }
42 42
43 namespace device_management_pref {
44 const std::string kSearchProviderNameValue = "Chromium";
45 const char kHomepageValue[] = "http://www.wandering-around.org";
46 }
47
43 namespace extension_pref { 48 namespace extension_pref {
44 const char kCurrentThemeIDValue[] = "set by extension"; 49 const char kCurrentThemeIDValue[] = "set by extension";
45 const char kHomepageValue[] = "http://www.chromium.org"; 50 const char kHomepageValue[] = "http://www.chromium.org";
51 const std::string kSearchProviderNameValue = "AreYouFeelingALittleLucky";
46 } 52 }
47 53
48 namespace command_line_pref { 54 namespace command_line_pref {
49 const char kApplicationLocaleValue[] = "hi-MOM"; 55 const char kApplicationLocaleValue[] = "hi-MOM";
50 const char kCurrentThemeIDValue[] = "zyxwvut"; 56 const char kCurrentThemeIDValue[] = "zyxwvut";
51 const char kHomepageValue[] = "http://www.ferretcentral.org"; 57 const char kHomepageValue[] = "http://www.ferretcentral.org";
58 const std::string kSearchProviderNameValue = "AreYouFeelingPrettyLucky";
52 } 59 }
53 60
54 // The "user" namespace is defined globally in an ARM system header, so we need 61 // The "user" namespace is defined globally in an ARM system header, so we need
55 // something different here. 62 // something different here.
56 namespace user_pref { 63 namespace user_pref {
57 const int kStabilityLaunchCountValue = 31; 64 const int kStabilityLaunchCountValue = 31;
58 const bool kDeleteCacheValue = true; 65 const bool kDeleteCacheValue = true;
59 const char kCurrentThemeIDValue[] = "abcdefg"; 66 const char kCurrentThemeIDValue[] = "abcdefg";
60 const char kHomepageValue[] = "http://www.google.com"; 67 const char kHomepageValue[] = "http://www.google.com";
61 const char kApplicationLocaleValue[] = "is-WRONG"; 68 const char kApplicationLocaleValue[] = "is-WRONG";
69 const std::string kSearchProviderNameValue = "AreYouFeelingVeryLucky";
62 } 70 }
63 71
64 namespace recommended_pref { 72 namespace recommended_pref {
65 const int kStabilityLaunchCountValue = 10; 73 const int kStabilityLaunchCountValue = 10;
66 const bool kRecommendedPrefValue = true; 74 const bool kRecommendedPrefValue = true;
67 } 75 }
68 76
69 namespace default_pref { 77 namespace default_pref {
70 const int kDefaultValue = 7; 78 const int kDefaultValue = 7;
71 const char kHomepageValue[] = "default homepage"; 79 const char kHomepageValue[] = "default homepage";
80 const std::string kSearchProviderNameValue = "AreYouFeelingExtraLucky";
72 } 81 }
73 82
74 class PrefValueStoreTest : public testing::Test { 83 class PrefValueStoreTest : public testing::Test {
75 protected: 84 protected:
76 virtual void SetUp() { 85 virtual void SetUp() {
77 // Create dummy user preferences. 86 // Create dummy user preferences.
78 enforced_prefs_= CreateEnforcedPrefs(); 87 managed_platform_prefs_= CreateManagedPlatformPrefs();
88 device_management_prefs_ = CreateDeviceManagementPrefs();
79 extension_prefs_ = CreateExtensionPrefs(); 89 extension_prefs_ = CreateExtensionPrefs();
80 command_line_prefs_ = CreateCommandLinePrefs(); 90 command_line_prefs_ = CreateCommandLinePrefs();
81 user_prefs_ = CreateUserPrefs(); 91 user_prefs_ = CreateUserPrefs();
82 recommended_prefs_ = CreateRecommendedPrefs(); 92 recommended_prefs_ = CreateRecommendedPrefs();
83 default_prefs_ = CreateDefaultPrefs(); 93 default_prefs_ = CreateDefaultPrefs();
84 94
95 std::sort(expected_differing_paths_.begin(),
96 expected_differing_paths_.end());
97
85 // Create |DummyPrefStore|s. 98 // Create |DummyPrefStore|s.
86 enforced_pref_store_ = new DummyPrefStore(); 99 managed_platform_pref_store_ = new DummyPrefStore();
87 enforced_pref_store_->set_prefs(enforced_prefs_); 100 managed_platform_pref_store_->set_prefs(managed_platform_prefs_);
101 device_management_pref_store_ = new DummyPrefStore();
102 device_management_pref_store_->set_prefs(device_management_prefs_);
88 extension_pref_store_ = new DummyPrefStore(); 103 extension_pref_store_ = new DummyPrefStore();
89 extension_pref_store_->set_prefs(extension_prefs_); 104 extension_pref_store_->set_prefs(extension_prefs_);
90 command_line_pref_store_ = new DummyPrefStore(); 105 command_line_pref_store_ = new DummyPrefStore();
91 command_line_pref_store_->set_prefs(command_line_prefs_); 106 command_line_pref_store_->set_prefs(command_line_prefs_);
92 user_pref_store_ = new DummyPrefStore(); 107 user_pref_store_ = new DummyPrefStore();
93 user_pref_store_->set_read_only(false); 108 user_pref_store_->set_read_only(false);
94 user_pref_store_->set_prefs(user_prefs_); 109 user_pref_store_->set_prefs(user_prefs_);
95 recommended_pref_store_ = new DummyPrefStore(); 110 recommended_pref_store_ = new DummyPrefStore();
96 recommended_pref_store_->set_prefs(recommended_prefs_); 111 recommended_pref_store_->set_prefs(recommended_prefs_);
97 default_pref_store_ = new DummyPrefStore(); 112 default_pref_store_ = new DummyPrefStore();
98 default_pref_store_->set_prefs(default_prefs_); 113 default_pref_store_->set_prefs(default_prefs_);
99 114
100 // Create a new pref-value-store. 115 // Create a new pref-value-store.
101 pref_value_store_ = new TestingPrefService::TestingPrefValueStore( 116 pref_value_store_ = new TestingPrefService::TestingPrefValueStore(
102 enforced_pref_store_, 117 managed_platform_pref_store_,
118 device_management_pref_store_,
103 extension_pref_store_, 119 extension_pref_store_,
104 command_line_pref_store_, 120 command_line_pref_store_,
105 user_pref_store_, 121 user_pref_store_,
106 recommended_pref_store_, 122 recommended_pref_store_,
107 default_pref_store_); 123 default_pref_store_);
108 124
109 // Register prefs with the PrefValueStore. 125 // Register prefs with the PrefValueStore.
110 pref_value_store_->RegisterPreferenceType(prefs::kApplicationLocale, 126 pref_value_store_->RegisterPreferenceType(prefs::kApplicationLocale,
111 Value::TYPE_STRING); 127 Value::TYPE_STRING);
112 pref_value_store_->RegisterPreferenceType(prefs::kCurrentThemeID, 128 pref_value_store_->RegisterPreferenceType(prefs::kCurrentThemeID,
113 Value::TYPE_STRING); 129 Value::TYPE_STRING);
130 pref_value_store_->RegisterPreferenceType(
131 prefs::kDefaultSearchProviderName,
132 Value::TYPE_STRING);
114 pref_value_store_->RegisterPreferenceType(prefs::kDeleteCache, 133 pref_value_store_->RegisterPreferenceType(prefs::kDeleteCache,
115 Value::TYPE_BOOLEAN); 134 Value::TYPE_BOOLEAN);
116 pref_value_store_->RegisterPreferenceType(prefs::kHomePage, 135 pref_value_store_->RegisterPreferenceType(prefs::kHomePage,
117 Value::TYPE_STRING); 136 Value::TYPE_STRING);
118 pref_value_store_->RegisterPreferenceType(prefs::kStabilityLaunchCount, 137 pref_value_store_->RegisterPreferenceType(prefs::kStabilityLaunchCount,
119 Value::TYPE_INTEGER); 138 Value::TYPE_INTEGER);
120 pref_value_store_->RegisterPreferenceType(prefs::kRecommendedPref, 139 pref_value_store_->RegisterPreferenceType(prefs::kRecommendedPref,
121 Value::TYPE_BOOLEAN); 140 Value::TYPE_BOOLEAN);
122 pref_value_store_->RegisterPreferenceType(prefs::kSampleDict, 141 pref_value_store_->RegisterPreferenceType(prefs::kSampleDict,
123 Value::TYPE_DICTIONARY); 142 Value::TYPE_DICTIONARY);
(...skipping 12 matching lines...) Expand all
136 // in it. 155 // in it.
137 DictionaryValue* CreateUserPrefs() { 156 DictionaryValue* CreateUserPrefs() {
138 DictionaryValue* user_prefs = new DictionaryValue(); 157 DictionaryValue* user_prefs = new DictionaryValue();
139 user_prefs->SetBoolean(prefs::kDeleteCache, user_pref::kDeleteCacheValue); 158 user_prefs->SetBoolean(prefs::kDeleteCache, user_pref::kDeleteCacheValue);
140 user_prefs->SetInteger(prefs::kStabilityLaunchCount, 159 user_prefs->SetInteger(prefs::kStabilityLaunchCount,
141 user_pref::kStabilityLaunchCountValue); 160 user_pref::kStabilityLaunchCountValue);
142 user_prefs->SetString(prefs::kCurrentThemeID, 161 user_prefs->SetString(prefs::kCurrentThemeID,
143 user_pref::kCurrentThemeIDValue); 162 user_pref::kCurrentThemeIDValue);
144 user_prefs->SetString(prefs::kApplicationLocale, 163 user_prefs->SetString(prefs::kApplicationLocale,
145 user_pref::kApplicationLocaleValue); 164 user_pref::kApplicationLocaleValue);
165 user_prefs->SetString(prefs::kDefaultSearchProviderName,
166 user_pref::kSearchProviderNameValue);
146 user_prefs->SetString(prefs::kHomePage, user_pref::kHomepageValue); 167 user_prefs->SetString(prefs::kHomePage, user_pref::kHomepageValue);
147 return user_prefs; 168 return user_prefs;
148 } 169 }
149 170
150 DictionaryValue* CreateEnforcedPrefs() { 171 DictionaryValue* CreateManagedPlatformPrefs() {
151 DictionaryValue* enforced_prefs = new DictionaryValue(); 172 DictionaryValue* managed_platform_prefs = new DictionaryValue();
152 enforced_prefs->SetString(prefs::kHomePage, enforced_pref::kHomepageValue); 173 managed_platform_prefs->SetString(
174 prefs::kHomePage,
175 managed_platform_pref::kHomepageValue);
153 expected_differing_paths_.push_back(prefs::kHomePage); 176 expected_differing_paths_.push_back(prefs::kHomePage);
154 return enforced_prefs; 177 return managed_platform_prefs;
178 }
179
180 DictionaryValue* CreateDeviceManagementPrefs() {
181 DictionaryValue* device_management_prefs = new DictionaryValue();
182 device_management_prefs->SetString(
183 prefs::kDefaultSearchProviderName,
184 device_management_pref::kSearchProviderNameValue);
185 expected_differing_paths_.push_back("default_search_provider");
186 expected_differing_paths_.push_back(prefs::kDefaultSearchProviderName);
187 device_management_prefs->SetString(prefs::kHomePage,
188 device_management_pref::kHomepageValue);
189 return device_management_prefs;
155 } 190 }
156 191
157 DictionaryValue* CreateExtensionPrefs() { 192 DictionaryValue* CreateExtensionPrefs() {
158 DictionaryValue* extension_prefs = new DictionaryValue(); 193 DictionaryValue* extension_prefs = new DictionaryValue();
159 extension_prefs->SetString(prefs::kCurrentThemeID, 194 extension_prefs->SetString(prefs::kCurrentThemeID,
160 extension_pref::kCurrentThemeIDValue); 195 extension_pref::kCurrentThemeIDValue);
161 extension_prefs->SetString(prefs::kHomePage, 196 extension_prefs->SetString(prefs::kHomePage,
162 extension_pref::kHomepageValue); 197 extension_pref::kHomepageValue);
198 extension_prefs->SetString(prefs::kDefaultSearchProviderName,
199 extension_pref::kSearchProviderNameValue);
163 return extension_prefs; 200 return extension_prefs;
164 } 201 }
165 202
166 DictionaryValue* CreateCommandLinePrefs() { 203 DictionaryValue* CreateCommandLinePrefs() {
167 DictionaryValue* command_line_prefs = new DictionaryValue(); 204 DictionaryValue* command_line_prefs = new DictionaryValue();
168 command_line_prefs->SetString(prefs::kCurrentThemeID, 205 command_line_prefs->SetString(prefs::kCurrentThemeID,
169 command_line_pref::kCurrentThemeIDValue); 206 command_line_pref::kCurrentThemeIDValue);
170 command_line_prefs->SetString(prefs::kApplicationLocale, 207 command_line_prefs->SetString(prefs::kApplicationLocale,
171 command_line_pref::kApplicationLocaleValue); 208 command_line_pref::kApplicationLocaleValue);
172 command_line_prefs->SetString(prefs::kHomePage, 209 command_line_prefs->SetString(prefs::kHomePage,
173 command_line_pref::kHomepageValue); 210 command_line_pref::kHomepageValue);
211 command_line_prefs->SetString(
212 prefs::kDefaultSearchProviderName,
213 command_line_pref::kSearchProviderNameValue);
174 return command_line_prefs; 214 return command_line_prefs;
175 } 215 }
176 216
177 DictionaryValue* CreateRecommendedPrefs() { 217 DictionaryValue* CreateRecommendedPrefs() {
178 DictionaryValue* recommended_prefs = new DictionaryValue(); 218 DictionaryValue* recommended_prefs = new DictionaryValue();
179 recommended_prefs->SetInteger(prefs::kStabilityLaunchCount, 219 recommended_prefs->SetInteger(prefs::kStabilityLaunchCount,
180 recommended_pref::kStabilityLaunchCountValue); 220 recommended_pref::kStabilityLaunchCountValue);
181 recommended_prefs->SetBoolean( 221 recommended_prefs->SetBoolean(
182 prefs::kRecommendedPref, 222 prefs::kRecommendedPref,
183 recommended_pref::kRecommendedPrefValue); 223 recommended_pref::kRecommendedPrefValue);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 258
219 virtual void TearDown() { 259 virtual void TearDown() {
220 loop_.RunAllPending(); 260 loop_.RunAllPending();
221 } 261 }
222 262
223 MessageLoop loop_; 263 MessageLoop loop_;
224 264
225 scoped_refptr<TestingPrefService::TestingPrefValueStore> pref_value_store_; 265 scoped_refptr<TestingPrefService::TestingPrefValueStore> pref_value_store_;
226 266
227 // |PrefStore|s are owned by the |PrefValueStore|. 267 // |PrefStore|s are owned by the |PrefValueStore|.
228 DummyPrefStore* enforced_pref_store_; 268 DummyPrefStore* managed_platform_pref_store_;
269 DummyPrefStore* device_management_pref_store_;
229 DummyPrefStore* extension_pref_store_; 270 DummyPrefStore* extension_pref_store_;
230 DummyPrefStore* command_line_pref_store_; 271 DummyPrefStore* command_line_pref_store_;
231 DummyPrefStore* user_pref_store_; 272 DummyPrefStore* user_pref_store_;
232 DummyPrefStore* recommended_pref_store_; 273 DummyPrefStore* recommended_pref_store_;
233 DummyPrefStore* default_pref_store_; 274 DummyPrefStore* default_pref_store_;
234 275
235 // A vector of the preferences paths in the managed and recommended 276 // A vector of the preferences paths in the managed and recommended
236 // PrefStores that are set at the beginning of a test. Can be modified 277 // PrefStores that are set at the beginning of a test. Can be modified
237 // by the test to track changes that it makes to the preferences 278 // by the test to track changes that it makes to the preferences
238 // stored in the managed and recommended PrefStores. 279 // stored in the managed and recommended PrefStores.
239 std::vector<std::string> expected_differing_paths_; 280 std::vector<std::string> expected_differing_paths_;
240 281
241 // Preferences are owned by the individual |DummyPrefStores|. 282 // Preferences are owned by the individual |DummyPrefStores|.
242 DictionaryValue* enforced_prefs_; 283 DictionaryValue* managed_platform_prefs_;
284 DictionaryValue* device_management_prefs_;
243 DictionaryValue* extension_prefs_; 285 DictionaryValue* extension_prefs_;
244 DictionaryValue* command_line_prefs_; 286 DictionaryValue* command_line_prefs_;
245 DictionaryValue* user_prefs_; 287 DictionaryValue* user_prefs_;
246 DictionaryValue* recommended_prefs_; 288 DictionaryValue* recommended_prefs_;
247 DictionaryValue* default_prefs_; 289 DictionaryValue* default_prefs_;
248 290
249 private: 291 private:
250 scoped_ptr<BrowserThread> ui_thread_; 292 scoped_ptr<BrowserThread> ui_thread_;
251 scoped_ptr<BrowserThread> file_thread_; 293 scoped_ptr<BrowserThread> file_thread_;
252 }; 294 };
253 295
254 TEST_F(PrefValueStoreTest, IsReadOnly) { 296 TEST_F(PrefValueStoreTest, IsReadOnly) {
255 enforced_pref_store_->set_read_only(true); 297 managed_platform_pref_store_->set_read_only(true);
256 extension_pref_store_->set_read_only(true); 298 extension_pref_store_->set_read_only(true);
257 command_line_pref_store_->set_read_only(true); 299 command_line_pref_store_->set_read_only(true);
258 user_pref_store_->set_read_only(true); 300 user_pref_store_->set_read_only(true);
259 recommended_pref_store_->set_read_only(true); 301 recommended_pref_store_->set_read_only(true);
260 default_pref_store_->set_read_only(true); 302 default_pref_store_->set_read_only(true);
261 EXPECT_TRUE(pref_value_store_->ReadOnly()); 303 EXPECT_TRUE(pref_value_store_->ReadOnly());
262 304
263 user_pref_store_->set_read_only(false); 305 user_pref_store_->set_read_only(false);
264 EXPECT_FALSE(pref_value_store_->ReadOnly()); 306 EXPECT_FALSE(pref_value_store_->ReadOnly());
265 } 307 }
266 308
267 TEST_F(PrefValueStoreTest, GetValue) { 309 TEST_F(PrefValueStoreTest, GetValue) {
268 Value* value; 310 Value* value;
269 311
270 // Test getting an enforced value overwriting a user-defined and 312 // Test getting a managed platform value overwriting a user-defined and
271 // extension-defined value. 313 // extension-defined value.
272 value = NULL; 314 value = NULL;
273 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &value)); 315 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &value));
274 std::string actual_str_value; 316 std::string actual_str_value;
275 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 317 EXPECT_TRUE(value->GetAsString(&actual_str_value));
276 EXPECT_EQ(enforced_pref::kHomepageValue, actual_str_value); 318 EXPECT_EQ(managed_platform_pref::kHomepageValue, actual_str_value);
319
320 // Test getting a managed platform value overwriting a user-defined value.
321 value = NULL;
322 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDefaultSearchProviderName,
323 &value));
324 EXPECT_TRUE(value->GetAsString(&actual_str_value));
325 EXPECT_EQ(device_management_pref::kSearchProviderNameValue,
326 actual_str_value);
277 327
278 // Test getting an extension value overwriting a user-defined and 328 // Test getting an extension value overwriting a user-defined and
279 // command-line-defined value. 329 // command-line-defined value.
280 value = NULL; 330 value = NULL;
281 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kCurrentThemeID, &value)); 331 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kCurrentThemeID, &value));
282 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 332 EXPECT_TRUE(value->GetAsString(&actual_str_value));
283 EXPECT_EQ(extension_pref::kCurrentThemeIDValue, actual_str_value); 333 EXPECT_EQ(extension_pref::kCurrentThemeIDValue, actual_str_value);
284 334
285 // Test getting a command-line value overwriting a user-defined value. 335 // Test getting a command-line value overwriting a user-defined value.
286 value = NULL; 336 value = NULL;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 Value* value = NULL; 384 Value* value = NULL;
335 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kStabilityLaunchCount, 385 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kStabilityLaunchCount,
336 &value)); 386 &value));
337 ASSERT_TRUE(value != NULL); 387 ASSERT_TRUE(value != NULL);
338 ASSERT_EQ(Value::TYPE_INTEGER, value->GetType()); 388 ASSERT_EQ(Value::TYPE_INTEGER, value->GetType());
339 int actual_int_value = -1; 389 int actual_int_value = -1;
340 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); 390 EXPECT_TRUE(value->GetAsInteger(&actual_int_value));
341 EXPECT_EQ(recommended_pref::kStabilityLaunchCountValue, actual_int_value); 391 EXPECT_EQ(recommended_pref::kStabilityLaunchCountValue, actual_int_value);
342 392
343 // Check falling back multiple times, to a default string. 393 // Check falling back multiple times, to a default string.
344 enforced_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1); 394 managed_platform_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1);
395 device_management_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1);
345 extension_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1); 396 extension_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1);
346 command_line_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1); 397 command_line_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1);
347 user_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1); 398 user_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1);
348 recommended_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1); 399 recommended_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1);
349 default_pref_store_->prefs()->SetString(prefs::kHomePage, 400 default_pref_store_->prefs()->SetString(prefs::kHomePage,
350 default_pref::kHomepageValue); 401 default_pref::kHomepageValue);
351 402
352 value = NULL; 403 value = NULL;
353 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &value)); 404 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &value));
354 ASSERT_TRUE(value != NULL); 405 ASSERT_TRUE(value != NULL);
355 ASSERT_EQ(Value::TYPE_STRING, value->GetType()); 406 ASSERT_EQ(Value::TYPE_STRING, value->GetType());
356 std::string actual_str_value; 407 std::string actual_str_value;
357 EXPECT_TRUE(value->GetAsString(&actual_str_value)); 408 EXPECT_TRUE(value->GetAsString(&actual_str_value));
358 EXPECT_EQ(default_pref::kHomepageValue, actual_str_value); 409 EXPECT_EQ(default_pref::kHomepageValue, actual_str_value);
359 } 410 }
360 411
361 TEST_F(PrefValueStoreTest, HasPrefPath) { 412 TEST_F(PrefValueStoreTest, HasPrefPath) {
362 // Enforced preference 413 // Managed Platform preference
363 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage)); 414 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
415 // Device management preference
416 EXPECT_TRUE(pref_value_store_->HasPrefPath(
417 prefs::kDefaultSearchProviderName));
418 // Extension preference
419 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
364 // User preference 420 // User preference
365 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kDeleteCache)); 421 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kDeleteCache));
366 // Recommended preference 422 // Recommended preference
367 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref)); 423 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
368 // Default preference 424 // Default preference
369 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref)); 425 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref));
370 // Unknown preference 426 // Unknown preference
371 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); 427 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
372 } 428 }
373 429
374 TEST_F(PrefValueStoreTest, PrefHasChanged) { 430 TEST_F(PrefValueStoreTest, PrefHasChanged) {
375 // Setup. 431 // Setup.
376 const char managed_pref_path[] = "managed_pref"; 432 const char managed_platform_pref_path[] = "managed_platform_pref";
377 pref_value_store_->RegisterPreferenceType(managed_pref_path, 433 pref_value_store_->RegisterPreferenceType(managed_platform_pref_path,
378 Value::TYPE_STRING); 434 Value::TYPE_STRING);
379 enforced_pref_store_->prefs()->SetString(managed_pref_path, "managed value"); 435 managed_platform_pref_store_->prefs()->SetString(managed_platform_pref_path,
436 "managed value");
380 const char user_pref_path[] = "user_pref"; 437 const char user_pref_path[] = "user_pref";
381 pref_value_store_->RegisterPreferenceType(user_pref_path, Value::TYPE_STRING); 438 pref_value_store_->RegisterPreferenceType(user_pref_path, Value::TYPE_STRING);
382 user_pref_store_->prefs()->SetString(user_pref_path, "user value"); 439 user_pref_store_->prefs()->SetString(user_pref_path, "user value");
383 const char default_pref_path[] = "default_pref"; 440 const char default_pref_path[] = "default_pref";
384 pref_value_store_->RegisterPreferenceType(default_pref_path, 441 pref_value_store_->RegisterPreferenceType(default_pref_path,
385 Value::TYPE_STRING); 442 Value::TYPE_STRING);
386 default_pref_store_->prefs()->SetString(default_pref_path, "default value"); 443 default_pref_store_->prefs()->SetString(default_pref_path, "default value");
387 444
388 // Check pref controlled by highest-priority store. 445 // Check pref controlled by highest-priority store.
389 EXPECT_TRUE(pref_value_store_->PrefHasChanged(managed_pref_path, 446 EXPECT_TRUE(pref_value_store_->PrefHasChanged(managed_platform_pref_path,
390 static_cast<PrefNotifier::PrefStoreType>(0))); 447 static_cast<PrefNotifier::PrefStoreType>(0)));
391 EXPECT_FALSE(pref_value_store_->PrefHasChanged(managed_pref_path, 448 EXPECT_FALSE(pref_value_store_->PrefHasChanged(managed_platform_pref_path,
392 PrefNotifier::USER_STORE)); 449 PrefNotifier::USER_STORE));
393 450
394 // Check pref controlled by user store. 451 // Check pref controlled by user store.
395 EXPECT_TRUE(pref_value_store_->PrefHasChanged(user_pref_path, 452 EXPECT_TRUE(pref_value_store_->PrefHasChanged(user_pref_path,
396 static_cast<PrefNotifier::PrefStoreType>(0))); 453 static_cast<PrefNotifier::PrefStoreType>(0)));
397 EXPECT_TRUE(pref_value_store_->PrefHasChanged(user_pref_path, 454 EXPECT_TRUE(pref_value_store_->PrefHasChanged(user_pref_path,
398 PrefNotifier::USER_STORE)); 455 PrefNotifier::USER_STORE));
399 EXPECT_FALSE(pref_value_store_->PrefHasChanged(user_pref_path, 456 EXPECT_FALSE(pref_value_store_->PrefHasChanged(user_pref_path,
400 PrefNotifier::PREF_STORE_TYPE_MAX)); 457 PrefNotifier::PREF_STORE_TYPE_MAX));
401 458
(...skipping 16 matching lines...) Expand all
418 TEST_F(PrefValueStoreTest, WritePrefs) { 475 TEST_F(PrefValueStoreTest, WritePrefs) {
419 user_pref_store_->set_prefs_written(false); 476 user_pref_store_->set_prefs_written(false);
420 pref_value_store_->WritePrefs(); 477 pref_value_store_->WritePrefs();
421 ASSERT_TRUE(user_pref_store_->get_prefs_written()); 478 ASSERT_TRUE(user_pref_store_->get_prefs_written());
422 } 479 }
423 480
424 TEST_F(PrefValueStoreTest, SetUserPrefValue) { 481 TEST_F(PrefValueStoreTest, SetUserPrefValue) {
425 Value* new_value = NULL; 482 Value* new_value = NULL;
426 Value* actual_value = NULL; 483 Value* actual_value = NULL;
427 484
428 // Test that enforced values can not be set. 485 // Test that managed platform values can not be set.
429 ASSERT_TRUE(pref_value_store_->PrefValueInManagedStore(prefs::kHomePage)); 486 ASSERT_TRUE(pref_value_store_->PrefValueInManagedPlatformStore(
487 prefs::kHomePage));
430 // The Ownership is tranfered to |PrefValueStore|. 488 // The Ownership is tranfered to |PrefValueStore|.
431 new_value = Value::CreateStringValue("http://www.youtube.com"); 489 new_value = Value::CreateStringValue("http://www.youtube.com");
432 pref_value_store_->SetUserPrefValue(prefs::kHomePage, new_value); 490 pref_value_store_->SetUserPrefValue(prefs::kHomePage, new_value);
433 491
434 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &actual_value)); 492 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &actual_value));
435 std::string value_str; 493 std::string value_str;
436 actual_value->GetAsString(&value_str); 494 actual_value->GetAsString(&value_str);
437 ASSERT_EQ(enforced_pref::kHomepageValue, value_str); 495 ASSERT_EQ(managed_platform_pref::kHomepageValue, value_str);
438 496
439 // User preferences values can be set 497 // User preferences values can be set
440 ASSERT_FALSE(pref_value_store_->PrefValueInManagedStore( 498 ASSERT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore(
441 prefs::kStabilityLaunchCount)); 499 prefs::kStabilityLaunchCount));
442 actual_value = NULL; 500 actual_value = NULL;
443 pref_value_store_->GetValue(prefs::kStabilityLaunchCount, &actual_value); 501 pref_value_store_->GetValue(prefs::kStabilityLaunchCount, &actual_value);
444 int int_value; 502 int int_value;
445 EXPECT_TRUE(actual_value->GetAsInteger(&int_value)); 503 EXPECT_TRUE(actual_value->GetAsInteger(&int_value));
446 EXPECT_EQ(user_pref::kStabilityLaunchCountValue, int_value); 504 EXPECT_EQ(user_pref::kStabilityLaunchCountValue, int_value);
447 505
448 new_value = Value::CreateIntegerValue(1); 506 new_value = Value::CreateIntegerValue(1);
449 pref_value_store_->SetUserPrefValue(prefs::kStabilityLaunchCount, new_value); 507 pref_value_store_->SetUserPrefValue(prefs::kStabilityLaunchCount, new_value);
450 actual_value = NULL; 508 actual_value = NULL;
(...skipping 16 matching lines...) Expand all
467 pref_value_store_->SetUserPrefValue(prefs::kSampleList, expected_list_value); 525 pref_value_store_->SetUserPrefValue(prefs::kSampleList, expected_list_value);
468 526
469 actual_value = NULL; 527 actual_value = NULL;
470 key = prefs::kSampleList; 528 key = prefs::kSampleList;
471 pref_value_store_->GetValue(key, &actual_value); 529 pref_value_store_->GetValue(key, &actual_value);
472 530
473 ASSERT_EQ(expected_list_value, actual_value); 531 ASSERT_EQ(expected_list_value, actual_value);
474 ASSERT_TRUE(expected_list_value->Equals(actual_value)); 532 ASSERT_TRUE(expected_list_value->Equals(actual_value));
475 } 533 }
476 534
477 TEST_F(PrefValueStoreTest, PrefValueInManagedStore) { 535 TEST_F(PrefValueStoreTest, PrefValueInManagedPlatformStore) {
478 // Test an enforced preference. 536 // Test a managed platform preference.
479 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage)); 537 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
480 EXPECT_TRUE(pref_value_store_->PrefValueInManagedStore(prefs::kHomePage)); 538 EXPECT_TRUE(pref_value_store_->PrefValueInManagedPlatformStore(
539 prefs::kHomePage));
540
541 // Test a device management preference.
542 ASSERT_TRUE(pref_value_store_->HasPrefPath(
543 prefs::kDefaultSearchProviderName));
544 EXPECT_TRUE(pref_value_store_->PrefValueInDeviceManagementStore(
545 prefs::kDefaultSearchProviderName));
481 546
482 // Test an extension preference. 547 // Test an extension preference.
483 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID)); 548 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
484 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore( 549 EXPECT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore(
485 prefs::kCurrentThemeID)); 550 prefs::kCurrentThemeID));
486 551
487 // Test a command-line preference. 552 // Test a command-line preference.
488 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale)); 553 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale));
489 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore( 554 EXPECT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore(
490 prefs::kApplicationLocale)); 555 prefs::kApplicationLocale));
491 556
492 // Test a user preference. 557 // Test a user preference.
493 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kStabilityLaunchCount)); 558 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kStabilityLaunchCount));
494 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore( 559 EXPECT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore(
495 prefs::kStabilityLaunchCount)); 560 prefs::kStabilityLaunchCount));
496 561
497 // Test a preference from the recommended pref store. 562 // Test a preference from the recommended pref store.
498 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref)); 563 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref));
499 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore( 564 EXPECT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore(
500 prefs::kRecommendedPref)); 565 prefs::kRecommendedPref));
501 566
502 // Test a preference from the default pref store. 567 // Test a preference from the default pref store.
503 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref)); 568 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref));
504 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore( 569 EXPECT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore(
505 prefs::kDefaultPref)); 570 prefs::kDefaultPref));
506 571
507 // Test a preference for which the PrefValueStore does not contain a value. 572 // Test a preference for which the PrefValueStore does not contain a value.
508 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); 573 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
509 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(prefs::kMissingPref)); 574 EXPECT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore(
575 prefs::kMissingPref));
510 } 576 }
511 577
512 TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) { 578 TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) {
513 // Test an enforced preference. 579 // Test a managed platform preference.
514 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage)); 580 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
515 EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(prefs::kHomePage)); 581 EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(prefs::kHomePage));
516 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore( 582 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
517 prefs::kHomePage)); 583 prefs::kHomePage));
518 584
585 // Test a device management preference.
586 ASSERT_TRUE(pref_value_store_->HasPrefPath(
587 prefs::kDefaultSearchProviderName));
588 EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
589 prefs::kDefaultSearchProviderName));
590 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
591 prefs::kDefaultSearchProviderName));
592
519 // Test an extension preference. 593 // Test an extension preference.
520 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID)); 594 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
521 EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore( 595 EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
522 prefs::kCurrentThemeID)); 596 prefs::kCurrentThemeID));
523 EXPECT_TRUE(pref_value_store_->PrefValueFromExtensionStore( 597 EXPECT_TRUE(pref_value_store_->PrefValueFromExtensionStore(
524 prefs::kCurrentThemeID)); 598 prefs::kCurrentThemeID));
525 599
526 // Test a command-line preference. 600 // Test a command-line preference.
527 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale)); 601 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale));
528 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore( 602 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 } 634 }
561 635
562 TEST_F(PrefValueStoreTest, DetectProxyConfigurationConflict) { 636 TEST_F(PrefValueStoreTest, DetectProxyConfigurationConflict) {
563 // There should be no conflicting proxy prefs in the default 637 // There should be no conflicting proxy prefs in the default
564 // preference stores created for the test. 638 // preference stores created for the test.
565 ASSERT_FALSE(pref_value_store_->HasPolicyConflictingUserProxySettings()); 639 ASSERT_FALSE(pref_value_store_->HasPolicyConflictingUserProxySettings());
566 640
567 // Create conflicting proxy settings in the managed and command-line 641 // Create conflicting proxy settings in the managed and command-line
568 // preference stores. 642 // preference stores.
569 command_line_prefs_->SetBoolean(prefs::kProxyAutoDetect, false); 643 command_line_prefs_->SetBoolean(prefs::kProxyAutoDetect, false);
570 enforced_prefs_->SetBoolean(prefs::kProxyAutoDetect, true); 644 managed_platform_prefs_->SetBoolean(prefs::kProxyAutoDetect, true);
571 ASSERT_TRUE(pref_value_store_->HasPolicyConflictingUserProxySettings()); 645 ASSERT_TRUE(pref_value_store_->HasPolicyConflictingUserProxySettings());
572 } 646 }
573 647
574 TEST_F(PrefValueStoreTest, PrefValueInUserStore) { 648 TEST_F(PrefValueStoreTest, PrefValueInUserStore) {
575 // Test an enforced preference. 649 // Test a managed platform preference.
576 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage)); 650 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
577 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(prefs::kHomePage)); 651 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(prefs::kHomePage));
578 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kHomePage)); 652 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kHomePage));
579 653
654 // Test a device management preference.
655 ASSERT_TRUE(pref_value_store_->HasPrefPath(
656 prefs::kDefaultSearchProviderName));
657 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
658 prefs::kDefaultSearchProviderName));
659 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
660 prefs::kDefaultSearchProviderName));
661
580 // Test an extension preference. 662 // Test an extension preference.
581 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID)); 663 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
582 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore( 664 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
583 prefs::kCurrentThemeID)); 665 prefs::kCurrentThemeID));
584 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore( 666 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
585 prefs::kCurrentThemeID)); 667 prefs::kCurrentThemeID));
586 668
587 // Test a command-line preference. 669 // Test a command-line preference.
588 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale)); 670 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale));
589 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore( 671 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
(...skipping 20 matching lines...) Expand all
610 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(prefs::kDefaultPref)); 692 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(prefs::kDefaultPref));
611 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kDefaultPref)); 693 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kDefaultPref));
612 694
613 // Test a preference for which the PrefValueStore does not contain a value. 695 // Test a preference for which the PrefValueStore does not contain a value.
614 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); 696 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
615 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(prefs::kMissingPref)); 697 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(prefs::kMissingPref));
616 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kMissingPref)); 698 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kMissingPref));
617 } 699 }
618 700
619 TEST_F(PrefValueStoreTest, PrefValueFromDefaultStore) { 701 TEST_F(PrefValueStoreTest, PrefValueFromDefaultStore) {
620 // Test an enforced preference. 702 // Test a managed platform preference.
621 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage)); 703 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage));
622 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(prefs::kHomePage)); 704 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(prefs::kHomePage));
623 705
706 // Test a device management preference.
707 ASSERT_TRUE(pref_value_store_->HasPrefPath(
708 prefs::kDefaultSearchProviderName));
709 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
710 prefs::kDefaultSearchProviderName));
711
624 // Test an extension preference. 712 // Test an extension preference.
625 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID)); 713 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kCurrentThemeID));
626 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore( 714 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
627 prefs::kCurrentThemeID)); 715 prefs::kCurrentThemeID));
628 716
629 // Test a command-line preference. 717 // Test a command-line preference.
630 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale)); 718 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kApplicationLocale));
631 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore( 719 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
632 prefs::kApplicationLocale)); 720 prefs::kApplicationLocale));
633 721
(...skipping 12 matching lines...) Expand all
646 EXPECT_TRUE( 734 EXPECT_TRUE(
647 pref_value_store_->PrefValueFromDefaultStore(prefs::kDefaultPref)); 735 pref_value_store_->PrefValueFromDefaultStore(prefs::kDefaultPref));
648 736
649 // Test a preference for which the PrefValueStore does not contain a value. 737 // Test a preference for which the PrefValueStore does not contain a value.
650 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); 738 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref));
651 EXPECT_FALSE( 739 EXPECT_FALSE(
652 pref_value_store_->PrefValueFromDefaultStore(prefs::kMissingPref)); 740 pref_value_store_->PrefValueFromDefaultStore(prefs::kMissingPref));
653 } 741 }
654 742
655 TEST_F(PrefValueStoreTest, TestPolicyRefresh) { 743 TEST_F(PrefValueStoreTest, TestPolicyRefresh) {
656 // pref_value_store_ is initialized by PrefValueStoreTest to have values 744 // pref_value_store_ is initialized by PrefValueStoreTest to have values in
657 // in both it's managed and recommended store. By replacing them with 745 // the managed platform, device management and recommended stores. By
658 // dummy stores, all of the paths of the prefs originally managed and 746 // replacing them with dummy stores, all of the paths of the prefs originally
659 // recommended stores should change. 747 // in the managed platform, device management and recommended stores should
748 // change.
660 MockPolicyRefreshCallback callback; 749 MockPolicyRefreshCallback callback;
661 EXPECT_CALL(callback, DoCallback(_)).Times(0); 750 EXPECT_CALL(callback, DoCallback(_)).Times(0);
662 BrowserThread::PostTask( 751 BrowserThread::PostTask(
663 BrowserThread::UI, FROM_HERE, 752 BrowserThread::UI, FROM_HERE,
664 NewRunnableMethod( 753 NewRunnableMethod(
665 pref_value_store_.get(), 754 pref_value_store_.get(),
666 &PrefValueStore::RefreshPolicyPrefs, 755 &PrefValueStore::RefreshPolicyPrefs,
667 NewCallback(&callback, 756 NewCallback(&callback,
668 &MockPolicyRefreshCallback::DoCallback))); 757 &MockPolicyRefreshCallback::DoCallback)));
669 Mock::VerifyAndClearExpectations(&callback); 758 Mock::VerifyAndClearExpectations(&callback);
670 EXPECT_CALL(callback, DoCallback(expected_differing_paths_)).Times(1); 759 EXPECT_CALL(callback, DoCallback(expected_differing_paths_)).Times(1);
671 loop_.RunAllPending(); 760 loop_.RunAllPending();
672 } 761 }
673 762
674 TEST_F(PrefValueStoreTest, TestRefreshPolicyPrefsCompletion) { 763 TEST_F(PrefValueStoreTest, TestRefreshPolicyPrefsCompletion) {
675 // Test changed preferences in managed store and removed 764 // Test changed preferences in the managed platform store and removed
676 // preferences in the recommended store. In addition 765 // preferences in the recommended store. In addition to "homepage", the other
677 // to "homepage", the other prefs that are set by default in 766 // prefs that are set by default in the test class are removed by the
678 // the test class are removed by the DummyStore 767 // DummyStore.
679 scoped_ptr<DummyPrefStore> new_managed_store(new DummyPrefStore()); 768 scoped_ptr<DummyPrefStore> new_managed_platform_store(new DummyPrefStore());
680 DictionaryValue* dict = new DictionaryValue(); 769 DictionaryValue* dict = new DictionaryValue();
681 dict->SetString("homepage", "some other changed homepage"); 770 dict->SetString("homepage", "some other changed homepage");
682 new_managed_store->set_prefs(dict); 771 new_managed_platform_store->set_prefs(dict);
683 MockPolicyRefreshCallback callback; 772 MockPolicyRefreshCallback callback;
684 EXPECT_CALL(callback, DoCallback(expected_differing_paths_)).Times(1); 773 EXPECT_CALL(callback, DoCallback(expected_differing_paths_)).Times(1);
685 pref_value_store_->RefreshPolicyPrefsCompletion( 774 pref_value_store_->RefreshPolicyPrefsCompletion(
686 new_managed_store.release(), 775 new_managed_platform_store.release(),
776 new DummyPrefStore(),
687 new DummyPrefStore(), 777 new DummyPrefStore(),
688 NewCallback(&callback, 778 NewCallback(&callback,
689 &MockPolicyRefreshCallback::DoCallback)); 779 &MockPolicyRefreshCallback::DoCallback));
690 780
691 // Test properties that have been removed from the managed store. 781 // Test properties that have been removed from the managed platform store.
692 // Homepage is still set in managed prefs. 782 // Homepage is still set in managed prefs.
693 expected_differing_paths_.clear(); 783 expected_differing_paths_.clear();
694 expected_differing_paths_.push_back(std::string("homepage")); 784 expected_differing_paths_.push_back(std::string("homepage"));
695 MockPolicyRefreshCallback callback2; 785 MockPolicyRefreshCallback callback2;
696 EXPECT_CALL(callback2, DoCallback(expected_differing_paths_)).Times(1); 786 EXPECT_CALL(callback2, DoCallback(expected_differing_paths_)).Times(1);
697 pref_value_store_->RefreshPolicyPrefsCompletion( 787 pref_value_store_->RefreshPolicyPrefsCompletion(
698 new DummyPrefStore(), 788 new DummyPrefStore(),
699 new DummyPrefStore(), 789 new DummyPrefStore(),
790 new DummyPrefStore(),
700 NewCallback(&callback2, 791 NewCallback(&callback2,
701 &MockPolicyRefreshCallback::DoCallback)); 792 &MockPolicyRefreshCallback::DoCallback));
702 793
794 // Test properties that are added to the device management store.
795 expected_differing_paths_.clear();
796 expected_differing_paths_.push_back(std::string("homepage"));
797 scoped_ptr<DummyPrefStore> new_device_management_store(
798 new DummyPrefStore());
799 dict = new DictionaryValue();
800 dict->SetString("homepage", "some other changed homepage");
801 new_device_management_store->set_prefs(dict);
802 MockPolicyRefreshCallback callback3;
803 EXPECT_CALL(callback3, DoCallback(expected_differing_paths_)).Times(1);
804 pref_value_store_->RefreshPolicyPrefsCompletion(
805 new DummyPrefStore(),
806 new_device_management_store.release(),
807 new DummyPrefStore(),
808 NewCallback(&callback3,
809 &MockPolicyRefreshCallback::DoCallback));
810
703 // Test properties that are added to the recommended store. 811 // Test properties that are added to the recommended store.
704 scoped_ptr<DummyPrefStore> new_recommended_store(new DummyPrefStore()); 812 scoped_ptr<DummyPrefStore> new_recommended_store(new DummyPrefStore());
705 dict = new DictionaryValue(); 813 dict = new DictionaryValue();
706 dict->SetString("homepage", "some other changed homepage 2"); 814 dict->SetString("homepage", "some other changed homepage 2");
707 new_recommended_store->set_prefs(dict); 815 new_recommended_store->set_prefs(dict);
708 expected_differing_paths_.clear(); 816 expected_differing_paths_.clear();
709 expected_differing_paths_.push_back(std::string("homepage")); 817 expected_differing_paths_.push_back(std::string("homepage"));
710 MockPolicyRefreshCallback callback3; 818 MockPolicyRefreshCallback callback4;
711 EXPECT_CALL(callback3, DoCallback(expected_differing_paths_)).Times(1); 819 EXPECT_CALL(callback4, DoCallback(expected_differing_paths_)).Times(1);
712 pref_value_store_->RefreshPolicyPrefsCompletion( 820 pref_value_store_->RefreshPolicyPrefsCompletion(
713 new DummyPrefStore(), 821 new DummyPrefStore(),
822 new DummyPrefStore(),
714 new_recommended_store.release(), 823 new_recommended_store.release(),
715 NewCallback(&callback3, 824 NewCallback(&callback4,
716 &MockPolicyRefreshCallback::DoCallback)); 825 &MockPolicyRefreshCallback::DoCallback));
717 826
718 // Test adding a multi-key path. 827 // Test adding a multi-key path.
719 new_managed_store.reset(new DummyPrefStore()); 828 new_managed_platform_store.reset(new DummyPrefStore());
720 dict = new DictionaryValue(); 829 dict = new DictionaryValue();
721 dict->SetString("segment1.segment2", "value"); 830 dict->SetString("segment1.segment2", "value");
722 new_managed_store->set_prefs(dict); 831 new_managed_platform_store->set_prefs(dict);
723 expected_differing_paths_.clear(); 832 expected_differing_paths_.clear();
724 expected_differing_paths_.push_back(std::string("homepage")); 833 expected_differing_paths_.push_back(std::string("homepage"));
725 expected_differing_paths_.push_back(std::string("segment1")); 834 expected_differing_paths_.push_back(std::string("segment1"));
726 expected_differing_paths_.push_back(std::string("segment1.segment2")); 835 expected_differing_paths_.push_back(std::string("segment1.segment2"));
727 MockPolicyRefreshCallback callback4; 836 MockPolicyRefreshCallback callback5;
728 EXPECT_CALL(callback4, DoCallback(expected_differing_paths_)).Times(1); 837 EXPECT_CALL(callback5, DoCallback(expected_differing_paths_)).Times(1);
729 pref_value_store_->RefreshPolicyPrefsCompletion( 838 pref_value_store_->RefreshPolicyPrefsCompletion(
730 new_managed_store.release(), 839 new_managed_platform_store.release(),
731 new DummyPrefStore(), 840 new DummyPrefStore(),
732 NewCallback(&callback4, 841 new DummyPrefStore(),
842 NewCallback(&callback5,
733 &MockPolicyRefreshCallback::DoCallback)); 843 &MockPolicyRefreshCallback::DoCallback));
734 } 844 }
735 845
736 TEST_F(PrefValueStoreTest, TestConcurrentPolicyRefresh) { 846 TEST_F(PrefValueStoreTest, TestConcurrentPolicyRefresh) {
737 MockPolicyRefreshCallback callback1; 847 MockPolicyRefreshCallback callback1;
738 BrowserThread::PostTask( 848 BrowserThread::PostTask(
739 BrowserThread::UI, FROM_HERE, 849 BrowserThread::UI, FROM_HERE,
740 NewRunnableMethod( 850 NewRunnableMethod(
741 pref_value_store_.get(), 851 pref_value_store_.get(),
742 &PrefValueStore::RefreshPolicyPrefs, 852 &PrefValueStore::RefreshPolicyPrefs,
(...skipping 23 matching lines...) Expand all
766 Mock::VerifyAndClearExpectations(&callback1); 876 Mock::VerifyAndClearExpectations(&callback1);
767 Mock::VerifyAndClearExpectations(&callback2); 877 Mock::VerifyAndClearExpectations(&callback2);
768 Mock::VerifyAndClearExpectations(&callback3); 878 Mock::VerifyAndClearExpectations(&callback3);
769 879
770 EXPECT_CALL(callback1, DoCallback(expected_differing_paths_)).Times(1); 880 EXPECT_CALL(callback1, DoCallback(expected_differing_paths_)).Times(1);
771 std::vector<std::string> no_differing_paths; 881 std::vector<std::string> no_differing_paths;
772 EXPECT_CALL(callback2, DoCallback(no_differing_paths)).Times(1); 882 EXPECT_CALL(callback2, DoCallback(no_differing_paths)).Times(1);
773 EXPECT_CALL(callback3, DoCallback(no_differing_paths)).Times(1); 883 EXPECT_CALL(callback3, DoCallback(no_differing_paths)).Times(1);
774 loop_.RunAllPending(); 884 loop_.RunAllPending();
775 } 885 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_value_store.cc ('k') | chrome/test/testing_pref_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698