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

Side by Side Diff: base/prefs/pref_value_store_unittest.cc

Issue 1645073005: Revert of Move base/prefs to components/prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 | « base/prefs/pref_value_store.cc ('k') | base/prefs/scoped_user_pref_update.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 <string>
6
7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_notifier.h"
11 #include "base/prefs/pref_value_store.h"
12 #include "base/prefs/testing_pref_store.h"
13 #include "base/values.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 using testing::Mock;
18 using testing::_;
19
20 namespace {
21
22 // Allows to capture pref notifications through gmock.
23 class MockPrefNotifier : public PrefNotifier {
24 public:
25 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&));
26 MOCK_METHOD1(OnInitializationCompleted, void(bool));
27 };
28
29 // Allows to capture sync model associator interaction.
30 class MockPrefModelAssociator {
31 public:
32 MOCK_METHOD1(ProcessPrefChange, void(const std::string&));
33 };
34
35 } // namespace
36
37 // Names of the preferences used in this test.
38 namespace prefs {
39 const char kManagedPref[] = "this.pref.managed";
40 const char kSupervisedUserPref[] = "this.pref.supervised_user";
41 const char kCommandLinePref[] = "this.pref.command_line";
42 const char kExtensionPref[] = "this.pref.extension";
43 const char kUserPref[] = "this.pref.user";
44 const char kRecommendedPref[] = "this.pref.recommended";
45 const char kDefaultPref[] = "this.pref.default";
46 const char kMissingPref[] = "this.pref.does_not_exist";
47 }
48
49 // Potentially expected values of all preferences used in this test program.
50 namespace managed_pref {
51 const char kManagedValue[] = "managed:managed";
52 }
53
54 namespace supervised_user_pref {
55 const char kManagedValue[] = "supervised_user:managed";
56 const char kSupervisedUserValue[] = "supervised_user:supervised_user";
57 }
58
59 namespace extension_pref {
60 const char kManagedValue[] = "extension:managed";
61 const char kSupervisedUserValue[] = "extension:supervised_user";
62 const char kExtensionValue[] = "extension:extension";
63 }
64
65 namespace command_line_pref {
66 const char kManagedValue[] = "command_line:managed";
67 const char kSupervisedUserValue[] = "command_line:supervised_user";
68 const char kExtensionValue[] = "command_line:extension";
69 const char kCommandLineValue[] = "command_line:command_line";
70 }
71
72 namespace user_pref {
73 const char kManagedValue[] = "user:managed";
74 const char kSupervisedUserValue[] = "supervised_user:supervised_user";
75 const char kExtensionValue[] = "user:extension";
76 const char kCommandLineValue[] = "user:command_line";
77 const char kUserValue[] = "user:user";
78 }
79
80 namespace recommended_pref {
81 const char kManagedValue[] = "recommended:managed";
82 const char kSupervisedUserValue[] = "recommended:supervised_user";
83 const char kExtensionValue[] = "recommended:extension";
84 const char kCommandLineValue[] = "recommended:command_line";
85 const char kUserValue[] = "recommended:user";
86 const char kRecommendedValue[] = "recommended:recommended";
87 }
88
89 namespace default_pref {
90 const char kManagedValue[] = "default:managed";
91 const char kSupervisedUserValue[] = "default:supervised_user";
92 const char kExtensionValue[] = "default:extension";
93 const char kCommandLineValue[] = "default:command_line";
94 const char kUserValue[] = "default:user";
95 const char kRecommendedValue[] = "default:recommended";
96 const char kDefaultValue[] = "default:default";
97 }
98
99 class PrefValueStoreTest : public testing::Test {
100 protected:
101 void SetUp() override {
102 // Create TestingPrefStores.
103 CreateManagedPrefs();
104 CreateSupervisedUserPrefs();
105 CreateExtensionPrefs();
106 CreateCommandLinePrefs();
107 CreateUserPrefs();
108 CreateRecommendedPrefs();
109 CreateDefaultPrefs();
110 sync_associator_.reset(new MockPrefModelAssociator());
111
112 // Create a fresh PrefValueStore.
113 pref_value_store_.reset(
114 new PrefValueStore(managed_pref_store_.get(),
115 supervised_user_pref_store_.get(),
116 extension_pref_store_.get(),
117 command_line_pref_store_.get(),
118 user_pref_store_.get(),
119 recommended_pref_store_.get(),
120 default_pref_store_.get(),
121 &pref_notifier_));
122
123 pref_value_store_->set_callback(
124 base::Bind(&MockPrefModelAssociator::ProcessPrefChange,
125 base::Unretained(sync_associator_.get())));
126 }
127
128 void CreateManagedPrefs() {
129 managed_pref_store_ = new TestingPrefStore;
130 managed_pref_store_->SetString(
131 prefs::kManagedPref,
132 managed_pref::kManagedValue);
133 }
134
135 void CreateSupervisedUserPrefs() {
136 supervised_user_pref_store_ = new TestingPrefStore;
137 supervised_user_pref_store_->SetString(
138 prefs::kManagedPref,
139 supervised_user_pref::kManagedValue);
140 supervised_user_pref_store_->SetString(
141 prefs::kSupervisedUserPref,
142 supervised_user_pref::kSupervisedUserValue);
143 }
144
145 void CreateExtensionPrefs() {
146 extension_pref_store_ = new TestingPrefStore;
147 extension_pref_store_->SetString(
148 prefs::kManagedPref,
149 extension_pref::kManagedValue);
150 extension_pref_store_->SetString(
151 prefs::kSupervisedUserPref,
152 extension_pref::kSupervisedUserValue);
153 extension_pref_store_->SetString(
154 prefs::kExtensionPref,
155 extension_pref::kExtensionValue);
156 }
157
158 void CreateCommandLinePrefs() {
159 command_line_pref_store_ = new TestingPrefStore;
160 command_line_pref_store_->SetString(
161 prefs::kManagedPref,
162 command_line_pref::kManagedValue);
163 command_line_pref_store_->SetString(
164 prefs::kSupervisedUserPref,
165 command_line_pref::kSupervisedUserValue);
166 command_line_pref_store_->SetString(
167 prefs::kExtensionPref,
168 command_line_pref::kExtensionValue);
169 command_line_pref_store_->SetString(
170 prefs::kCommandLinePref,
171 command_line_pref::kCommandLineValue);
172 }
173
174 void CreateUserPrefs() {
175 user_pref_store_ = new TestingPrefStore;
176 user_pref_store_->SetString(
177 prefs::kManagedPref,
178 user_pref::kManagedValue);
179 user_pref_store_->SetString(
180 prefs::kSupervisedUserPref,
181 user_pref::kSupervisedUserValue);
182 user_pref_store_->SetString(
183 prefs::kCommandLinePref,
184 user_pref::kCommandLineValue);
185 user_pref_store_->SetString(
186 prefs::kExtensionPref,
187 user_pref::kExtensionValue);
188 user_pref_store_->SetString(
189 prefs::kUserPref,
190 user_pref::kUserValue);
191 }
192
193 void CreateRecommendedPrefs() {
194 recommended_pref_store_ = new TestingPrefStore;
195 recommended_pref_store_->SetString(
196 prefs::kManagedPref,
197 recommended_pref::kManagedValue);
198 recommended_pref_store_->SetString(
199 prefs::kSupervisedUserPref,
200 recommended_pref::kSupervisedUserValue);
201 recommended_pref_store_->SetString(
202 prefs::kCommandLinePref,
203 recommended_pref::kCommandLineValue);
204 recommended_pref_store_->SetString(
205 prefs::kExtensionPref,
206 recommended_pref::kExtensionValue);
207 recommended_pref_store_->SetString(
208 prefs::kUserPref,
209 recommended_pref::kUserValue);
210 recommended_pref_store_->SetString(
211 prefs::kRecommendedPref,
212 recommended_pref::kRecommendedValue);
213 }
214
215 void CreateDefaultPrefs() {
216 default_pref_store_ = new TestingPrefStore;
217 default_pref_store_->SetString(
218 prefs::kSupervisedUserPref,
219 default_pref::kSupervisedUserValue);
220 default_pref_store_->SetString(
221 prefs::kManagedPref,
222 default_pref::kManagedValue);
223 default_pref_store_->SetString(
224 prefs::kCommandLinePref,
225 default_pref::kCommandLineValue);
226 default_pref_store_->SetString(
227 prefs::kExtensionPref,
228 default_pref::kExtensionValue);
229 default_pref_store_->SetString(
230 prefs::kUserPref,
231 default_pref::kUserValue);
232 default_pref_store_->SetString(
233 prefs::kRecommendedPref,
234 default_pref::kRecommendedValue);
235 default_pref_store_->SetString(
236 prefs::kDefaultPref,
237 default_pref::kDefaultValue);
238 }
239
240 void ExpectValueChangeNotifications(const std::string& name) {
241 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(name));
242 EXPECT_CALL(*sync_associator_, ProcessPrefChange(name));
243 }
244
245 void CheckAndClearValueChangeNotifications() {
246 Mock::VerifyAndClearExpectations(&pref_notifier_);
247 Mock::VerifyAndClearExpectations(sync_associator_.get());
248 }
249
250 MockPrefNotifier pref_notifier_;
251 scoped_ptr<MockPrefModelAssociator> sync_associator_;
252 scoped_ptr<PrefValueStore> pref_value_store_;
253
254 scoped_refptr<TestingPrefStore> managed_pref_store_;
255 scoped_refptr<TestingPrefStore> supervised_user_pref_store_;
256 scoped_refptr<TestingPrefStore> extension_pref_store_;
257 scoped_refptr<TestingPrefStore> command_line_pref_store_;
258 scoped_refptr<TestingPrefStore> user_pref_store_;
259 scoped_refptr<TestingPrefStore> recommended_pref_store_;
260 scoped_refptr<TestingPrefStore> default_pref_store_;
261 };
262
263 TEST_F(PrefValueStoreTest, GetValue) {
264 const base::Value* value;
265
266 // The following tests read a value from the PrefService. The preferences are
267 // set in a way such that all lower-priority stores have a value and we can
268 // test whether overrides work correctly.
269
270 // Test getting a managed value.
271 value = NULL;
272 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kManagedPref,
273 base::Value::TYPE_STRING, &value));
274 std::string actual_str_value;
275 EXPECT_TRUE(value->GetAsString(&actual_str_value));
276 EXPECT_EQ(managed_pref::kManagedValue, actual_str_value);
277
278 // Test getting a supervised user value.
279 value = NULL;
280 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kSupervisedUserPref,
281 base::Value::TYPE_STRING, &value));
282 EXPECT_TRUE(value->GetAsString(&actual_str_value));
283 EXPECT_EQ(supervised_user_pref::kSupervisedUserValue, actual_str_value);
284
285 // Test getting an extension value.
286 value = NULL;
287 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kExtensionPref,
288 base::Value::TYPE_STRING, &value));
289 EXPECT_TRUE(value->GetAsString(&actual_str_value));
290 EXPECT_EQ(extension_pref::kExtensionValue, actual_str_value);
291
292 // Test getting a command-line value.
293 value = NULL;
294 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kCommandLinePref,
295 base::Value::TYPE_STRING, &value));
296 EXPECT_TRUE(value->GetAsString(&actual_str_value));
297 EXPECT_EQ(command_line_pref::kCommandLineValue, actual_str_value);
298
299 // Test getting a user-set value.
300 value = NULL;
301 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kUserPref,
302 base::Value::TYPE_STRING, &value));
303 EXPECT_TRUE(value->GetAsString(&actual_str_value));
304 EXPECT_EQ(user_pref::kUserValue, actual_str_value);
305
306 // Test getting a user set value overwriting a recommended value.
307 value = NULL;
308 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kRecommendedPref,
309 base::Value::TYPE_STRING, &value));
310 EXPECT_TRUE(value->GetAsString(&actual_str_value));
311 EXPECT_EQ(recommended_pref::kRecommendedValue,
312 actual_str_value);
313
314 // Test getting a default value.
315 value = NULL;
316 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDefaultPref,
317 base::Value::TYPE_STRING, &value));
318 EXPECT_TRUE(value->GetAsString(&actual_str_value));
319 EXPECT_EQ(default_pref::kDefaultValue, actual_str_value);
320
321 // Test getting a preference value that the |PrefValueStore|
322 // does not contain.
323 base::FundamentalValue tmp_dummy_value(true);
324 value = &tmp_dummy_value;
325 ASSERT_FALSE(pref_value_store_->GetValue(prefs::kMissingPref,
326 base::Value::TYPE_STRING, &value));
327 ASSERT_FALSE(value);
328 }
329
330 TEST_F(PrefValueStoreTest, GetRecommendedValue) {
331 const base::Value* value;
332
333 // The following tests read a value from the PrefService. The preferences are
334 // set in a way such that all lower-priority stores have a value and we can
335 // test whether overrides do not clutter the recommended value.
336
337 // Test getting recommended value when a managed value is present.
338 value = NULL;
339 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
340 prefs::kManagedPref,
341 base::Value::TYPE_STRING, &value));
342 std::string actual_str_value;
343 EXPECT_TRUE(value->GetAsString(&actual_str_value));
344 EXPECT_EQ(recommended_pref::kManagedValue, actual_str_value);
345
346 // Test getting recommended value when a supervised user value is present.
347 value = NULL;
348 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
349 prefs::kSupervisedUserPref,
350 base::Value::TYPE_STRING, &value));
351 EXPECT_TRUE(value->GetAsString(&actual_str_value));
352 EXPECT_EQ(recommended_pref::kSupervisedUserValue, actual_str_value);
353
354 // Test getting recommended value when an extension value is present.
355 value = NULL;
356 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
357 prefs::kExtensionPref,
358 base::Value::TYPE_STRING, &value));
359 EXPECT_TRUE(value->GetAsString(&actual_str_value));
360 EXPECT_EQ(recommended_pref::kExtensionValue, actual_str_value);
361
362 // Test getting recommended value when a command-line value is present.
363 value = NULL;
364 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
365 prefs::kCommandLinePref,
366 base::Value::TYPE_STRING, &value));
367 EXPECT_TRUE(value->GetAsString(&actual_str_value));
368 EXPECT_EQ(recommended_pref::kCommandLineValue, actual_str_value);
369
370 // Test getting recommended value when a user-set value is present.
371 value = NULL;
372 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
373 prefs::kUserPref,
374 base::Value::TYPE_STRING, &value));
375 EXPECT_TRUE(value->GetAsString(&actual_str_value));
376 EXPECT_EQ(recommended_pref::kUserValue, actual_str_value);
377
378 // Test getting recommended value when no higher-priority value is present.
379 value = NULL;
380 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
381 prefs::kRecommendedPref,
382 base::Value::TYPE_STRING, &value));
383 EXPECT_TRUE(value->GetAsString(&actual_str_value));
384 EXPECT_EQ(recommended_pref::kRecommendedValue,
385 actual_str_value);
386
387 // Test getting recommended value when no recommended value is present.
388 base::FundamentalValue tmp_dummy_value(true);
389 value = &tmp_dummy_value;
390 ASSERT_FALSE(pref_value_store_->GetRecommendedValue(
391 prefs::kDefaultPref,
392 base::Value::TYPE_STRING, &value));
393 ASSERT_FALSE(value);
394
395 // Test getting a preference value that the |PrefValueStore|
396 // does not contain.
397 value = &tmp_dummy_value;
398 ASSERT_FALSE(pref_value_store_->GetRecommendedValue(
399 prefs::kMissingPref,
400 base::Value::TYPE_STRING, &value));
401 ASSERT_FALSE(value);
402 }
403
404 TEST_F(PrefValueStoreTest, PrefChanges) {
405 // Check pref controlled by highest-priority store.
406 ExpectValueChangeNotifications(prefs::kManagedPref);
407 managed_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
408 CheckAndClearValueChangeNotifications();
409
410 ExpectValueChangeNotifications(prefs::kManagedPref);
411 supervised_user_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
412 CheckAndClearValueChangeNotifications();
413
414 ExpectValueChangeNotifications(prefs::kManagedPref);
415 extension_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
416 CheckAndClearValueChangeNotifications();
417
418 ExpectValueChangeNotifications(prefs::kManagedPref);
419 command_line_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
420 CheckAndClearValueChangeNotifications();
421
422 ExpectValueChangeNotifications(prefs::kManagedPref);
423 user_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
424 CheckAndClearValueChangeNotifications();
425
426 ExpectValueChangeNotifications(prefs::kManagedPref);
427 recommended_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
428 CheckAndClearValueChangeNotifications();
429
430 ExpectValueChangeNotifications(prefs::kManagedPref);
431 default_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
432 CheckAndClearValueChangeNotifications();
433
434 // Check pref controlled by user store.
435 ExpectValueChangeNotifications(prefs::kUserPref);
436 managed_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
437 CheckAndClearValueChangeNotifications();
438
439 ExpectValueChangeNotifications(prefs::kUserPref);
440 extension_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
441 CheckAndClearValueChangeNotifications();
442
443 ExpectValueChangeNotifications(prefs::kUserPref);
444 command_line_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
445 CheckAndClearValueChangeNotifications();
446
447 ExpectValueChangeNotifications(prefs::kUserPref);
448 user_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
449 CheckAndClearValueChangeNotifications();
450
451 ExpectValueChangeNotifications(prefs::kUserPref);
452 recommended_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
453 CheckAndClearValueChangeNotifications();
454
455 ExpectValueChangeNotifications(prefs::kUserPref);
456 default_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
457 CheckAndClearValueChangeNotifications();
458
459 // Check pref controlled by default-pref store.
460 ExpectValueChangeNotifications(prefs::kDefaultPref);
461 managed_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
462 CheckAndClearValueChangeNotifications();
463
464 ExpectValueChangeNotifications(prefs::kDefaultPref);
465 extension_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
466 CheckAndClearValueChangeNotifications();
467
468 ExpectValueChangeNotifications(prefs::kDefaultPref);
469 command_line_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
470 CheckAndClearValueChangeNotifications();
471
472 ExpectValueChangeNotifications(prefs::kDefaultPref);
473 user_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
474 CheckAndClearValueChangeNotifications();
475
476 ExpectValueChangeNotifications(prefs::kDefaultPref);
477 recommended_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
478 CheckAndClearValueChangeNotifications();
479
480 ExpectValueChangeNotifications(prefs::kDefaultPref);
481 default_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
482 CheckAndClearValueChangeNotifications();
483 }
484
485 TEST_F(PrefValueStoreTest, OnInitializationCompleted) {
486 EXPECT_CALL(pref_notifier_, OnInitializationCompleted(true)).Times(0);
487 managed_pref_store_->SetInitializationCompleted();
488 supervised_user_pref_store_->SetInitializationCompleted();
489 extension_pref_store_->SetInitializationCompleted();
490 command_line_pref_store_->SetInitializationCompleted();
491 recommended_pref_store_->SetInitializationCompleted();
492 default_pref_store_->SetInitializationCompleted();
493 Mock::VerifyAndClearExpectations(&pref_notifier_);
494
495 // The notification should only be triggered after the last store is done.
496 EXPECT_CALL(pref_notifier_, OnInitializationCompleted(true)).Times(1);
497 user_pref_store_->SetInitializationCompleted();
498 Mock::VerifyAndClearExpectations(&pref_notifier_);
499 }
500
501 TEST_F(PrefValueStoreTest, PrefValueInManagedStore) {
502 EXPECT_TRUE(pref_value_store_->PrefValueInManagedStore(
503 prefs::kManagedPref));
504 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
505 prefs::kSupervisedUserPref));
506 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
507 prefs::kExtensionPref));
508 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
509 prefs::kCommandLinePref));
510 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
511 prefs::kUserPref));
512 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
513 prefs::kRecommendedPref));
514 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
515 prefs::kDefaultPref));
516 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
517 prefs::kMissingPref));
518 }
519
520 TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) {
521 EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
522 prefs::kManagedPref));
523 EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
524 prefs::kSupervisedUserPref));
525 EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
526 prefs::kExtensionPref));
527 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
528 prefs::kCommandLinePref));
529 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
530 prefs::kUserPref));
531 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
532 prefs::kRecommendedPref));
533 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
534 prefs::kDefaultPref));
535 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
536 prefs::kMissingPref));
537 }
538
539 TEST_F(PrefValueStoreTest, PrefValueInUserStore) {
540 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
541 prefs::kManagedPref));
542 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
543 prefs::kSupervisedUserPref));
544 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
545 prefs::kExtensionPref));
546 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
547 prefs::kCommandLinePref));
548 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
549 prefs::kUserPref));
550 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
551 prefs::kRecommendedPref));
552 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
553 prefs::kDefaultPref));
554 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
555 prefs::kMissingPref));
556 }
557
558 TEST_F(PrefValueStoreTest, PrefValueFromExtensionStore) {
559 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
560 prefs::kManagedPref));
561 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
562 prefs::kSupervisedUserPref));
563 EXPECT_TRUE(pref_value_store_->PrefValueFromExtensionStore(
564 prefs::kExtensionPref));
565 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
566 prefs::kCommandLinePref));
567 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
568 prefs::kUserPref));
569 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
570 prefs::kRecommendedPref));
571 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
572 prefs::kDefaultPref));
573 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
574 prefs::kMissingPref));
575 }
576
577 TEST_F(PrefValueStoreTest, PrefValueFromUserStore) {
578 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
579 prefs::kManagedPref));
580 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
581 prefs::kSupervisedUserPref));
582 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
583 prefs::kExtensionPref));
584 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
585 prefs::kCommandLinePref));
586 EXPECT_TRUE(pref_value_store_->PrefValueFromUserStore(
587 prefs::kUserPref));
588 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
589 prefs::kRecommendedPref));
590 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
591 prefs::kDefaultPref));
592 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
593 prefs::kMissingPref));
594 }
595
596 TEST_F(PrefValueStoreTest, PrefValueFromRecommendedStore) {
597 EXPECT_FALSE(pref_value_store_->PrefValueFromRecommendedStore(
598 prefs::kManagedPref));
599 EXPECT_FALSE(pref_value_store_->PrefValueFromRecommendedStore(
600 prefs::kSupervisedUserPref));
601 EXPECT_FALSE(pref_value_store_->PrefValueFromRecommendedStore(
602 prefs::kExtensionPref));
603 EXPECT_FALSE(pref_value_store_->PrefValueFromRecommendedStore(
604 prefs::kCommandLinePref));
605 EXPECT_FALSE(pref_value_store_->PrefValueFromRecommendedStore(
606 prefs::kUserPref));
607 EXPECT_TRUE(pref_value_store_->PrefValueFromRecommendedStore(
608 prefs::kRecommendedPref));
609 EXPECT_FALSE(pref_value_store_->PrefValueFromRecommendedStore(
610 prefs::kDefaultPref));
611 EXPECT_FALSE(pref_value_store_->PrefValueFromRecommendedStore(
612 prefs::kMissingPref));
613 }
614
615 TEST_F(PrefValueStoreTest, PrefValueFromDefaultStore) {
616 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
617 prefs::kManagedPref));
618 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
619 prefs::kSupervisedUserPref));
620 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
621 prefs::kExtensionPref));
622 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
623 prefs::kCommandLinePref));
624 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
625 prefs::kUserPref));
626 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
627 prefs::kRecommendedPref));
628 EXPECT_TRUE(pref_value_store_->PrefValueFromDefaultStore(
629 prefs::kDefaultPref));
630 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
631 prefs::kMissingPref));
632 }
633
634 TEST_F(PrefValueStoreTest, PrefValueUserModifiable) {
635 EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
636 prefs::kManagedPref));
637 EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
638 prefs::kSupervisedUserPref));
639 EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
640 prefs::kExtensionPref));
641 EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
642 prefs::kCommandLinePref));
643 EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
644 prefs::kUserPref));
645 EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
646 prefs::kRecommendedPref));
647 EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
648 prefs::kDefaultPref));
649 EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
650 prefs::kMissingPref));
651 }
652
653 TEST_F(PrefValueStoreTest, PrefValueExtensionModifiable) {
654 EXPECT_FALSE(pref_value_store_->PrefValueExtensionModifiable(
655 prefs::kManagedPref));
656 EXPECT_FALSE(pref_value_store_->PrefValueExtensionModifiable(
657 prefs::kSupervisedUserPref));
658 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
659 prefs::kExtensionPref));
660 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
661 prefs::kCommandLinePref));
662 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
663 prefs::kUserPref));
664 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
665 prefs::kRecommendedPref));
666 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
667 prefs::kDefaultPref));
668 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
669 prefs::kMissingPref));
670 }
OLDNEW
« no previous file with comments | « base/prefs/pref_value_store.cc ('k') | base/prefs/scoped_user_pref_update.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698