blob: b38c4acef1d30a4b9e23b530ee93ab4e399093e8 [file] [log] [blame]
[email protected]4eb4d6ce2012-04-02 14:06:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d8b08c92010-06-07 13:13:282// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]acd78969c2010-12-08 09:49:115#include <string>
6
[email protected]c17427552012-12-27 13:11:557#include "base/bind.h"
[email protected]b6e695a92011-09-29 15:08:338#include "base/memory/ref_counted.h"
[email protected]3b63f8f42011-03-28 01:54:159#include "base/memory/scoped_ptr.h"
[email protected]03b9b4e2012-10-22 20:01:5210#include "base/prefs/pref_notifier.h"
[email protected]3853a4c2013-02-11 17:15:5711#include "base/prefs/pref_value_store.h"
[email protected]03b9b4e2012-10-22 20:01:5212#include "base/prefs/testing_pref_store.h"
[email protected]d8b08c92010-06-07 13:13:2813#include "base/values.h"
[email protected]d8b08c92010-06-07 13:13:2814#include "testing/gmock/include/gmock/gmock.h"
15#include "testing/gtest/include/gtest/gtest.h"
16
[email protected]d8b08c92010-06-07 13:13:2817using testing::Mock;
[email protected]b6e695a92011-09-29 15:08:3318using testing::_;
[email protected]d8b08c92010-06-07 13:13:2819
[email protected]d81288a02010-08-18 07:25:5020namespace {
21
[email protected]acd78969c2010-12-08 09:49:1122// Allows to capture pref notifications through gmock.
23class MockPrefNotifier : public PrefNotifier {
24 public:
25 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&));
[email protected]845b43a82011-05-11 10:14:4326 MOCK_METHOD1(OnInitializationCompleted, void(bool));
[email protected]d81288a02010-08-18 07:25:5027};
28
[email protected]d36f941b2011-05-09 06:19:1629// Allows to capture sync model associator interaction.
[email protected]c17427552012-12-27 13:11:5530class MockPrefModelAssociator {
[email protected]d36f941b2011-05-09 06:19:1631 public:
32 MOCK_METHOD1(ProcessPrefChange, void(const std::string&));
33};
34
[email protected]d81288a02010-08-18 07:25:5035} // namespace
36
[email protected]887288f02011-02-04 22:52:4637// Names of the preferences used in this test.
[email protected]d8b08c92010-06-07 13:13:2838namespace prefs {
[email protected]4eb4d6ce2012-04-02 14:06:5739const char kManagedPref[] = "this.pref.managed";
[email protected]887288f02011-02-04 22:52:4640const char kCommandLinePref[] = "this.pref.command_line";
41const char kExtensionPref[] = "this.pref.extension";
42const char kUserPref[] = "this.pref.user";
[email protected]4eb4d6ce2012-04-02 14:06:5743const char kRecommendedPref[] = "this.pref.recommended";
[email protected]887288f02011-02-04 22:52:4644const char kDefaultPref[] = "this.pref.default";
[email protected]ce1850e92010-10-15 08:40:5845const char kMissingPref[] = "this.pref.does_not_exist";
[email protected]d8b08c92010-06-07 13:13:2846}
47
[email protected]d81288a02010-08-18 07:25:5048// Potentially expected values of all preferences used in this test program.
[email protected]4eb4d6ce2012-04-02 14:06:5749namespace managed_pref {
50const char kManagedValue[] = "managed:managed";
[email protected]be1c6e922010-11-17 12:49:1751}
52
[email protected]9677c902010-07-13 06:56:3253namespace extension_pref {
[email protected]4eb4d6ce2012-04-02 14:06:5754const char kManagedValue[] = "extension:managed";
[email protected]887288f02011-02-04 22:52:4655const char kExtensionValue[] = "extension:extension";
[email protected]db198b22010-07-12 16:48:4956}
57
[email protected]8664dfb2010-07-16 11:48:2158namespace command_line_pref {
[email protected]4eb4d6ce2012-04-02 14:06:5759const char kManagedValue[] = "command_line:managed";
[email protected]887288f02011-02-04 22:52:4660const char kExtensionValue[] = "command_line:extension";
61const char kCommandLineValue[] = "command_line:command_line";
[email protected]8664dfb2010-07-16 11:48:2162}
63
[email protected]99cc9a02010-09-17 07:53:2864namespace user_pref {
[email protected]4eb4d6ce2012-04-02 14:06:5765const char kManagedValue[] = "user:managed";
[email protected]887288f02011-02-04 22:52:4666const char kExtensionValue[] = "user:extension";
67const char kCommandLineValue[] = "user:command_line";
68const char kUserValue[] = "user:user";
[email protected]99cc9a02010-09-17 07:53:2869}
70
[email protected]4eb4d6ce2012-04-02 14:06:5771namespace recommended_pref {
72const char kManagedValue[] = "recommended:managed";
73const char kExtensionValue[] = "recommended:extension";
74const char kCommandLineValue[] = "recommended:command_line";
75const char kUserValue[] = "recommended:user";
76const char kRecommendedValue[] = "recommended:recommended";
[email protected]d8b08c92010-06-07 13:13:2877}
78
[email protected]c3b54f372010-09-14 08:25:0779namespace default_pref {
[email protected]4eb4d6ce2012-04-02 14:06:5780const char kManagedValue[] = "default:managed";
[email protected]887288f02011-02-04 22:52:4681const char kExtensionValue[] = "default:extension";
82const char kCommandLineValue[] = "default:command_line";
83const char kUserValue[] = "default:user";
[email protected]4eb4d6ce2012-04-02 14:06:5784const char kRecommendedValue[] = "default:recommended";
[email protected]887288f02011-02-04 22:52:4685const char kDefaultValue[] = "default:default";
[email protected]c3b54f372010-09-14 08:25:0786}
87
[email protected]d8b08c92010-06-07 13:13:2888class PrefValueStoreTest : public testing::Test {
89 protected:
[email protected]d8b08c92010-06-07 13:13:2890 virtual void SetUp() {
[email protected]acd78969c2010-12-08 09:49:1191 // Create TestingPrefStores.
[email protected]4eb4d6ce2012-04-02 14:06:5792 CreateManagedPrefs();
[email protected]acd78969c2010-12-08 09:49:1193 CreateExtensionPrefs();
94 CreateCommandLinePrefs();
95 CreateUserPrefs();
[email protected]4eb4d6ce2012-04-02 14:06:5796 CreateRecommendedPrefs();
[email protected]acd78969c2010-12-08 09:49:1197 CreateDefaultPrefs();
[email protected]d36f941b2011-05-09 06:19:1698 sync_associator_.reset(new MockPrefModelAssociator());
[email protected]d8b08c92010-06-07 13:13:2899
[email protected]f00768e2010-12-23 12:39:01100 // Create a fresh PrefValueStore.
[email protected]3703e922013-05-31 21:37:53101 pref_value_store_.reset(new PrefValueStore(managed_pref_store_.get(),
102 extension_pref_store_.get(),
103 command_line_pref_store_.get(),
104 user_pref_store_.get(),
105 recommended_pref_store_.get(),
106 default_pref_store_.get(),
107 &pref_notifier_));
[email protected]5b199522012-12-22 17:24:44108
[email protected]c17427552012-12-27 13:11:55109 pref_value_store_->set_callback(
110 base::Bind(&MockPrefModelAssociator::ProcessPrefChange,
111 base::Unretained(sync_associator_.get())));
[email protected]d8b08c92010-06-07 13:13:28112 }
113
[email protected]4eb4d6ce2012-04-02 14:06:57114 void CreateManagedPrefs() {
115 managed_pref_store_ = new TestingPrefStore;
116 managed_pref_store_->SetString(
117 prefs::kManagedPref,
118 managed_pref::kManagedValue);
[email protected]d8b08c92010-06-07 13:13:28119 }
120
[email protected]acd78969c2010-12-08 09:49:11121 void CreateExtensionPrefs() {
122 extension_pref_store_ = new TestingPrefStore;
[email protected]887288f02011-02-04 22:52:46123 extension_pref_store_->SetString(
[email protected]4eb4d6ce2012-04-02 14:06:57124 prefs::kManagedPref,
125 extension_pref::kManagedValue);
[email protected]887288f02011-02-04 22:52:46126 extension_pref_store_->SetString(
127 prefs::kExtensionPref,
128 extension_pref::kExtensionValue);
[email protected]db198b22010-07-12 16:48:49129 }
130
[email protected]acd78969c2010-12-08 09:49:11131 void CreateCommandLinePrefs() {
132 command_line_pref_store_ = new TestingPrefStore;
[email protected]887288f02011-02-04 22:52:46133 command_line_pref_store_->SetString(
[email protected]4eb4d6ce2012-04-02 14:06:57134 prefs::kManagedPref,
135 command_line_pref::kManagedValue);
[email protected]887288f02011-02-04 22:52:46136 command_line_pref_store_->SetString(
137 prefs::kExtensionPref,
138 command_line_pref::kExtensionValue);
139 command_line_pref_store_->SetString(
140 prefs::kCommandLinePref,
141 command_line_pref::kCommandLineValue);
[email protected]8664dfb2010-07-16 11:48:21142 }
143
[email protected]887288f02011-02-04 22:52:46144 void CreateUserPrefs() {
145 user_pref_store_ = new TestingPrefStore;
146 user_pref_store_->SetString(
[email protected]4eb4d6ce2012-04-02 14:06:57147 prefs::kManagedPref,
148 user_pref::kManagedValue);
[email protected]887288f02011-02-04 22:52:46149 user_pref_store_->SetString(
150 prefs::kCommandLinePref,
151 user_pref::kCommandLineValue);
152 user_pref_store_->SetString(
153 prefs::kExtensionPref,
154 user_pref::kExtensionValue);
155 user_pref_store_->SetString(
156 prefs::kUserPref,
157 user_pref::kUserValue);
158 }
159
[email protected]4eb4d6ce2012-04-02 14:06:57160 void CreateRecommendedPrefs() {
161 recommended_pref_store_ = new TestingPrefStore;
162 recommended_pref_store_->SetString(
163 prefs::kManagedPref,
164 recommended_pref::kManagedValue);
165 recommended_pref_store_->SetString(
[email protected]887288f02011-02-04 22:52:46166 prefs::kCommandLinePref,
[email protected]4eb4d6ce2012-04-02 14:06:57167 recommended_pref::kCommandLineValue);
168 recommended_pref_store_->SetString(
[email protected]887288f02011-02-04 22:52:46169 prefs::kExtensionPref,
[email protected]4eb4d6ce2012-04-02 14:06:57170 recommended_pref::kExtensionValue);
171 recommended_pref_store_->SetString(
[email protected]887288f02011-02-04 22:52:46172 prefs::kUserPref,
[email protected]4eb4d6ce2012-04-02 14:06:57173 recommended_pref::kUserValue);
174 recommended_pref_store_->SetString(
175 prefs::kRecommendedPref,
176 recommended_pref::kRecommendedValue);
[email protected]c3b54f372010-09-14 08:25:07177 }
178
[email protected]acd78969c2010-12-08 09:49:11179 void CreateDefaultPrefs() {
180 default_pref_store_ = new TestingPrefStore;
[email protected]887288f02011-02-04 22:52:46181 default_pref_store_->SetString(
[email protected]4eb4d6ce2012-04-02 14:06:57182 prefs::kManagedPref,
183 default_pref::kManagedValue);
[email protected]887288f02011-02-04 22:52:46184 default_pref_store_->SetString(
185 prefs::kCommandLinePref,
186 default_pref::kCommandLineValue);
187 default_pref_store_->SetString(
188 prefs::kExtensionPref,
189 default_pref::kExtensionValue);
190 default_pref_store_->SetString(
191 prefs::kUserPref,
192 default_pref::kUserValue);
193 default_pref_store_->SetString(
[email protected]4eb4d6ce2012-04-02 14:06:57194 prefs::kRecommendedPref,
195 default_pref::kRecommendedValue);
[email protected]887288f02011-02-04 22:52:46196 default_pref_store_->SetString(
197 prefs::kDefaultPref,
198 default_pref::kDefaultValue);
[email protected]d8b08c92010-06-07 13:13:28199 }
200
[email protected]7ca0f362012-07-30 10:14:03201 void ExpectValueChangeNotifications(const char* name) {
202 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(name));
203 EXPECT_CALL(*sync_associator_, ProcessPrefChange(name));
204 }
205
206 void CheckAndClearValueChangeNotifications() {
207 Mock::VerifyAndClearExpectations(&pref_notifier_);
208 Mock::VerifyAndClearExpectations(sync_associator_.get());
209 }
210
[email protected]acd78969c2010-12-08 09:49:11211 MockPrefNotifier pref_notifier_;
[email protected]d36f941b2011-05-09 06:19:16212 scoped_ptr<MockPrefModelAssociator> sync_associator_;
[email protected]a98ce1262011-01-28 13:20:23213 scoped_ptr<PrefValueStore> pref_value_store_;
[email protected]61f972b2010-08-04 15:31:38214
[email protected]4eb4d6ce2012-04-02 14:06:57215 scoped_refptr<TestingPrefStore> managed_pref_store_;
[email protected]9a8c4022011-01-25 14:25:33216 scoped_refptr<TestingPrefStore> extension_pref_store_;
217 scoped_refptr<TestingPrefStore> command_line_pref_store_;
218 scoped_refptr<TestingPrefStore> user_pref_store_;
[email protected]4eb4d6ce2012-04-02 14:06:57219 scoped_refptr<TestingPrefStore> recommended_pref_store_;
[email protected]9a8c4022011-01-25 14:25:33220 scoped_refptr<TestingPrefStore> default_pref_store_;
[email protected]61f972b2010-08-04 15:31:38221};
[email protected]d8b08c92010-06-07 13:13:28222
[email protected]d8b08c92010-06-07 13:13:28223TEST_F(PrefValueStoreTest, GetValue) {
[email protected]a43a667b2013-06-14 17:56:08224 const base::Value* value;
[email protected]d8b08c92010-06-07 13:13:28225
[email protected]887288f02011-02-04 22:52:46226 // The following tests read a value from the PrefService. The preferences are
227 // set in a way such that all lower-priority stores have a value and we can
228 // test whether overrides work correctly.
229
[email protected]4eb4d6ce2012-04-02 14:06:57230 // Test getting a managed value.
[email protected]d8b08c92010-06-07 13:13:28231 value = NULL;
[email protected]4eb4d6ce2012-04-02 14:06:57232 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kManagedPref,
[email protected]a43a667b2013-06-14 17:56:08233 base::Value::TYPE_STRING, &value));
[email protected]57ecc4b2010-08-11 03:02:51234 std::string actual_str_value;
[email protected]d8b08c92010-06-07 13:13:28235 EXPECT_TRUE(value->GetAsString(&actual_str_value));
[email protected]4eb4d6ce2012-04-02 14:06:57236 EXPECT_EQ(managed_pref::kManagedValue, actual_str_value);
[email protected]d8b08c92010-06-07 13:13:28237
[email protected]887288f02011-02-04 22:52:46238 // Test getting an extension value.
[email protected]db198b22010-07-12 16:48:49239 value = NULL;
[email protected]887288f02011-02-04 22:52:46240 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kExtensionPref,
[email protected]a43a667b2013-06-14 17:56:08241 base::Value::TYPE_STRING, &value));
[email protected]db198b22010-07-12 16:48:49242 EXPECT_TRUE(value->GetAsString(&actual_str_value));
[email protected]887288f02011-02-04 22:52:46243 EXPECT_EQ(extension_pref::kExtensionValue, actual_str_value);
[email protected]db198b22010-07-12 16:48:49244
[email protected]887288f02011-02-04 22:52:46245 // Test getting a command-line value.
[email protected]8664dfb2010-07-16 11:48:21246 value = NULL;
[email protected]887288f02011-02-04 22:52:46247 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kCommandLinePref,
[email protected]a43a667b2013-06-14 17:56:08248 base::Value::TYPE_STRING, &value));
[email protected]8664dfb2010-07-16 11:48:21249 EXPECT_TRUE(value->GetAsString(&actual_str_value));
[email protected]887288f02011-02-04 22:52:46250 EXPECT_EQ(command_line_pref::kCommandLineValue, actual_str_value);
[email protected]8664dfb2010-07-16 11:48:21251
[email protected]db198b22010-07-12 16:48:49252 // Test getting a user-set value.
[email protected]d8b08c92010-06-07 13:13:28253 value = NULL;
[email protected]887288f02011-02-04 22:52:46254 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kUserPref,
[email protected]a43a667b2013-06-14 17:56:08255 base::Value::TYPE_STRING, &value));
[email protected]887288f02011-02-04 22:52:46256 EXPECT_TRUE(value->GetAsString(&actual_str_value));
257 EXPECT_EQ(user_pref::kUserValue, actual_str_value);
[email protected]d8b08c92010-06-07 13:13:28258
259 // Test getting a user set value overwriting a recommended value.
260 value = NULL;
[email protected]4eb4d6ce2012-04-02 14:06:57261 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kRecommendedPref,
[email protected]a43a667b2013-06-14 17:56:08262 base::Value::TYPE_STRING, &value));
[email protected]887288f02011-02-04 22:52:46263 EXPECT_TRUE(value->GetAsString(&actual_str_value));
[email protected]4eb4d6ce2012-04-02 14:06:57264 EXPECT_EQ(recommended_pref::kRecommendedValue,
[email protected]887288f02011-02-04 22:52:46265 actual_str_value);
[email protected]d8b08c92010-06-07 13:13:28266
[email protected]c3b54f372010-09-14 08:25:07267 // Test getting a default value.
268 value = NULL;
[email protected]9a8c4022011-01-25 14:25:33269 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kDefaultPref,
[email protected]a43a667b2013-06-14 17:56:08270 base::Value::TYPE_STRING, &value));
[email protected]887288f02011-02-04 22:52:46271 EXPECT_TRUE(value->GetAsString(&actual_str_value));
272 EXPECT_EQ(default_pref::kDefaultValue, actual_str_value);
[email protected]c3b54f372010-09-14 08:25:07273
[email protected]d8b08c92010-06-07 13:13:28274 // Test getting a preference value that the |PrefValueStore|
275 // does not contain.
[email protected]b20c4472011-08-11 16:01:31276 base::FundamentalValue tmp_dummy_value(true);
[email protected]887288f02011-02-04 22:52:46277 value = &tmp_dummy_value;
[email protected]9a8c4022011-01-25 14:25:33278 ASSERT_FALSE(pref_value_store_->GetValue(prefs::kMissingPref,
[email protected]a43a667b2013-06-14 17:56:08279 base::Value::TYPE_STRING, &value));
[email protected]7ca0f362012-07-30 10:14:03280 ASSERT_FALSE(value);
281}
282
283TEST_F(PrefValueStoreTest, GetRecommendedValue) {
[email protected]a43a667b2013-06-14 17:56:08284 const base::Value* value;
[email protected]7ca0f362012-07-30 10:14:03285
286 // The following tests read a value from the PrefService. The preferences are
287 // set in a way such that all lower-priority stores have a value and we can
288 // test whether overrides do not clutter the recommended value.
289
290 // Test getting recommended value when a managed value is present.
291 value = NULL;
292 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
293 prefs::kManagedPref,
[email protected]a43a667b2013-06-14 17:56:08294 base::Value::TYPE_STRING, &value));
[email protected]7ca0f362012-07-30 10:14:03295 std::string actual_str_value;
296 EXPECT_TRUE(value->GetAsString(&actual_str_value));
297 EXPECT_EQ(recommended_pref::kManagedValue, actual_str_value);
298
299 // Test getting recommended value when an extension value is present.
300 value = NULL;
301 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
302 prefs::kExtensionPref,
[email protected]a43a667b2013-06-14 17:56:08303 base::Value::TYPE_STRING, &value));
[email protected]7ca0f362012-07-30 10:14:03304 EXPECT_TRUE(value->GetAsString(&actual_str_value));
305 EXPECT_EQ(recommended_pref::kExtensionValue, actual_str_value);
306
307 // Test getting recommended value when a command-line value is present.
308 value = NULL;
309 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
310 prefs::kCommandLinePref,
[email protected]a43a667b2013-06-14 17:56:08311 base::Value::TYPE_STRING, &value));
[email protected]7ca0f362012-07-30 10:14:03312 EXPECT_TRUE(value->GetAsString(&actual_str_value));
313 EXPECT_EQ(recommended_pref::kCommandLineValue, actual_str_value);
314
315 // Test getting recommended value when a user-set value is present.
316 value = NULL;
317 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
318 prefs::kUserPref,
[email protected]a43a667b2013-06-14 17:56:08319 base::Value::TYPE_STRING, &value));
[email protected]7ca0f362012-07-30 10:14:03320 EXPECT_TRUE(value->GetAsString(&actual_str_value));
321 EXPECT_EQ(recommended_pref::kUserValue, actual_str_value);
322
323 // Test getting recommended value when no higher-priority value is present.
324 value = NULL;
325 ASSERT_TRUE(pref_value_store_->GetRecommendedValue(
326 prefs::kRecommendedPref,
[email protected]a43a667b2013-06-14 17:56:08327 base::Value::TYPE_STRING, &value));
[email protected]7ca0f362012-07-30 10:14:03328 EXPECT_TRUE(value->GetAsString(&actual_str_value));
329 EXPECT_EQ(recommended_pref::kRecommendedValue,
330 actual_str_value);
331
332 // Test getting recommended value when no recommended value is present.
333 base::FundamentalValue tmp_dummy_value(true);
334 value = &tmp_dummy_value;
335 ASSERT_FALSE(pref_value_store_->GetRecommendedValue(
336 prefs::kDefaultPref,
[email protected]a43a667b2013-06-14 17:56:08337 base::Value::TYPE_STRING, &value));
[email protected]7ca0f362012-07-30 10:14:03338 ASSERT_FALSE(value);
339
340 // Test getting a preference value that the |PrefValueStore|
341 // does not contain.
342 value = &tmp_dummy_value;
343 ASSERT_FALSE(pref_value_store_->GetRecommendedValue(
344 prefs::kMissingPref,
[email protected]a43a667b2013-06-14 17:56:08345 base::Value::TYPE_STRING, &value));
[email protected]7ca0f362012-07-30 10:14:03346 ASSERT_FALSE(value);
[email protected]d8b08c92010-06-07 13:13:28347}
348
[email protected]acd78969c2010-12-08 09:49:11349TEST_F(PrefValueStoreTest, PrefChanges) {
[email protected]c3b54f372010-09-14 08:25:07350 // Check pref controlled by highest-priority store.
[email protected]7ca0f362012-07-30 10:14:03351 ExpectValueChangeNotifications(prefs::kManagedPref);
352 managed_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
353 CheckAndClearValueChangeNotifications();
[email protected]acd78969c2010-12-08 09:49:11354
[email protected]7ca0f362012-07-30 10:14:03355 ExpectValueChangeNotifications(prefs::kManagedPref);
356 extension_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
357 CheckAndClearValueChangeNotifications();
358
359 ExpectValueChangeNotifications(prefs::kManagedPref);
360 command_line_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
361 CheckAndClearValueChangeNotifications();
362
363 ExpectValueChangeNotifications(prefs::kManagedPref);
364 user_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
365 CheckAndClearValueChangeNotifications();
366
367 ExpectValueChangeNotifications(prefs::kManagedPref);
368 recommended_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
369 CheckAndClearValueChangeNotifications();
370
371 ExpectValueChangeNotifications(prefs::kManagedPref);
372 default_pref_store_->NotifyPrefValueChanged(prefs::kManagedPref);
373 CheckAndClearValueChangeNotifications();
[email protected]b3247a82010-08-19 09:08:14374
[email protected]c3b54f372010-09-14 08:25:07375 // Check pref controlled by user store.
[email protected]7ca0f362012-07-30 10:14:03376 ExpectValueChangeNotifications(prefs::kUserPref);
[email protected]4eb4d6ce2012-04-02 14:06:57377 managed_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
[email protected]7ca0f362012-07-30 10:14:03378 CheckAndClearValueChangeNotifications();
[email protected]887288f02011-02-04 22:52:46379
[email protected]7ca0f362012-07-30 10:14:03380 ExpectValueChangeNotifications(prefs::kUserPref);
[email protected]887288f02011-02-04 22:52:46381 extension_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
[email protected]7ca0f362012-07-30 10:14:03382 CheckAndClearValueChangeNotifications();
[email protected]887288f02011-02-04 22:52:46383
[email protected]7ca0f362012-07-30 10:14:03384 ExpectValueChangeNotifications(prefs::kUserPref);
[email protected]887288f02011-02-04 22:52:46385 command_line_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
[email protected]7ca0f362012-07-30 10:14:03386 CheckAndClearValueChangeNotifications();
[email protected]887288f02011-02-04 22:52:46387
[email protected]7ca0f362012-07-30 10:14:03388 ExpectValueChangeNotifications(prefs::kUserPref);
[email protected]887288f02011-02-04 22:52:46389 user_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
[email protected]7ca0f362012-07-30 10:14:03390 CheckAndClearValueChangeNotifications();
[email protected]acd78969c2010-12-08 09:49:11391
[email protected]7ca0f362012-07-30 10:14:03392 ExpectValueChangeNotifications(prefs::kUserPref);
393 recommended_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
394 CheckAndClearValueChangeNotifications();
395
396 ExpectValueChangeNotifications(prefs::kUserPref);
397 default_pref_store_->NotifyPrefValueChanged(prefs::kUserPref);
398 CheckAndClearValueChangeNotifications();
[email protected]b3247a82010-08-19 09:08:14399
[email protected]c3b54f372010-09-14 08:25:07400 // Check pref controlled by default-pref store.
[email protected]7ca0f362012-07-30 10:14:03401 ExpectValueChangeNotifications(prefs::kDefaultPref);
[email protected]4eb4d6ce2012-04-02 14:06:57402 managed_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
[email protected]7ca0f362012-07-30 10:14:03403 CheckAndClearValueChangeNotifications();
[email protected]887288f02011-02-04 22:52:46404
[email protected]7ca0f362012-07-30 10:14:03405 ExpectValueChangeNotifications(prefs::kDefaultPref);
[email protected]887288f02011-02-04 22:52:46406 extension_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
[email protected]7ca0f362012-07-30 10:14:03407 CheckAndClearValueChangeNotifications();
[email protected]887288f02011-02-04 22:52:46408
[email protected]7ca0f362012-07-30 10:14:03409 ExpectValueChangeNotifications(prefs::kDefaultPref);
[email protected]887288f02011-02-04 22:52:46410 command_line_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
[email protected]7ca0f362012-07-30 10:14:03411 CheckAndClearValueChangeNotifications();
[email protected]887288f02011-02-04 22:52:46412
[email protected]7ca0f362012-07-30 10:14:03413 ExpectValueChangeNotifications(prefs::kDefaultPref);
[email protected]887288f02011-02-04 22:52:46414 user_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
[email protected]7ca0f362012-07-30 10:14:03415 CheckAndClearValueChangeNotifications();
[email protected]887288f02011-02-04 22:52:46416
[email protected]7ca0f362012-07-30 10:14:03417 ExpectValueChangeNotifications(prefs::kDefaultPref);
[email protected]4eb4d6ce2012-04-02 14:06:57418 recommended_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
[email protected]7ca0f362012-07-30 10:14:03419 CheckAndClearValueChangeNotifications();
[email protected]887288f02011-02-04 22:52:46420
[email protected]7ca0f362012-07-30 10:14:03421 ExpectValueChangeNotifications(prefs::kDefaultPref);
[email protected]887288f02011-02-04 22:52:46422 default_pref_store_->NotifyPrefValueChanged(prefs::kDefaultPref);
[email protected]7ca0f362012-07-30 10:14:03423 CheckAndClearValueChangeNotifications();
[email protected]acd78969c2010-12-08 09:49:11424}
425
426TEST_F(PrefValueStoreTest, OnInitializationCompleted) {
[email protected]845b43a82011-05-11 10:14:43427 EXPECT_CALL(pref_notifier_, OnInitializationCompleted(true)).Times(0);
[email protected]4eb4d6ce2012-04-02 14:06:57428 managed_pref_store_->SetInitializationCompleted();
[email protected]acd78969c2010-12-08 09:49:11429 extension_pref_store_->SetInitializationCompleted();
430 command_line_pref_store_->SetInitializationCompleted();
[email protected]4eb4d6ce2012-04-02 14:06:57431 recommended_pref_store_->SetInitializationCompleted();
[email protected]acd78969c2010-12-08 09:49:11432 default_pref_store_->SetInitializationCompleted();
433 Mock::VerifyAndClearExpectations(&pref_notifier_);
434
435 // The notification should only be triggered after the last store is done.
[email protected]845b43a82011-05-11 10:14:43436 EXPECT_CALL(pref_notifier_, OnInitializationCompleted(true)).Times(1);
[email protected]acd78969c2010-12-08 09:49:11437 user_pref_store_->SetInitializationCompleted();
438 Mock::VerifyAndClearExpectations(&pref_notifier_);
[email protected]d81288a02010-08-18 07:25:50439}
440
[email protected]887288f02011-02-04 22:52:46441TEST_F(PrefValueStoreTest, PrefValueInManagedStore) {
442 EXPECT_TRUE(pref_value_store_->PrefValueInManagedStore(
[email protected]4eb4d6ce2012-04-02 14:06:57443 prefs::kManagedPref));
[email protected]887288f02011-02-04 22:52:46444 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
445 prefs::kExtensionPref));
446 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
447 prefs::kCommandLinePref));
448 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
449 prefs::kUserPref));
450 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
[email protected]4eb4d6ce2012-04-02 14:06:57451 prefs::kRecommendedPref));
[email protected]887288f02011-02-04 22:52:46452 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
[email protected]c3b54f372010-09-14 08:25:07453 prefs::kDefaultPref));
[email protected]887288f02011-02-04 22:52:46454 EXPECT_FALSE(pref_value_store_->PrefValueInManagedStore(
[email protected]be1c6e922010-11-17 12:49:17455 prefs::kMissingPref));
[email protected]d8b08c92010-06-07 13:13:28456}
457
[email protected]d7449e82010-07-14 11:42:35458TEST_F(PrefValueStoreTest, PrefValueInExtensionStore) {
[email protected]be1c6e922010-11-17 12:49:17459 EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
[email protected]4eb4d6ce2012-04-02 14:06:57460 prefs::kManagedPref));
[email protected]887288f02011-02-04 22:52:46461 EXPECT_TRUE(pref_value_store_->PrefValueInExtensionStore(
462 prefs::kExtensionPref));
[email protected]8664dfb2010-07-16 11:48:21463 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
[email protected]887288f02011-02-04 22:52:46464 prefs::kCommandLinePref));
[email protected]ce1850e92010-10-15 08:40:58465 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
[email protected]887288f02011-02-04 22:52:46466 prefs::kUserPref));
[email protected]d7449e82010-07-14 11:42:35467 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
[email protected]4eb4d6ce2012-04-02 14:06:57468 prefs::kRecommendedPref));
[email protected]c3b54f372010-09-14 08:25:07469 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
470 prefs::kDefaultPref));
[email protected]d7449e82010-07-14 11:42:35471 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore(
472 prefs::kMissingPref));
[email protected]d7449e82010-07-14 11:42:35473}
474
475TEST_F(PrefValueStoreTest, PrefValueInUserStore) {
[email protected]be1c6e922010-11-17 12:49:17476 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
[email protected]4eb4d6ce2012-04-02 14:06:57477 prefs::kManagedPref));
[email protected]8664dfb2010-07-16 11:48:21478 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
[email protected]887288f02011-02-04 22:52:46479 prefs::kExtensionPref));
[email protected]ce1850e92010-10-15 08:40:58480 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
[email protected]887288f02011-02-04 22:52:46481 prefs::kCommandLinePref));
482 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(
483 prefs::kUserPref));
[email protected]d7449e82010-07-14 11:42:35484 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
[email protected]4eb4d6ce2012-04-02 14:06:57485 prefs::kRecommendedPref));
[email protected]887288f02011-02-04 22:52:46486 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
487 prefs::kDefaultPref));
488 EXPECT_FALSE(pref_value_store_->PrefValueInUserStore(
489 prefs::kMissingPref));
490}
491
492TEST_F(PrefValueStoreTest, PrefValueFromExtensionStore) {
493 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
[email protected]4eb4d6ce2012-04-02 14:06:57494 prefs::kManagedPref));
[email protected]887288f02011-02-04 22:52:46495 EXPECT_TRUE(pref_value_store_->PrefValueFromExtensionStore(
496 prefs::kExtensionPref));
497 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
498 prefs::kCommandLinePref));
499 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
500 prefs::kUserPref));
501 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
[email protected]4eb4d6ce2012-04-02 14:06:57502 prefs::kRecommendedPref));
[email protected]887288f02011-02-04 22:52:46503 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
504 prefs::kDefaultPref));
505 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore(
506 prefs::kMissingPref));
507}
508
509TEST_F(PrefValueStoreTest, PrefValueFromUserStore) {
[email protected]d7449e82010-07-14 11:42:35510 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
[email protected]4eb4d6ce2012-04-02 14:06:57511 prefs::kManagedPref));
[email protected]887288f02011-02-04 22:52:46512 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
513 prefs::kExtensionPref));
514 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
515 prefs::kCommandLinePref));
516 EXPECT_TRUE(pref_value_store_->PrefValueFromUserStore(
517 prefs::kUserPref));
518 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
[email protected]4eb4d6ce2012-04-02 14:06:57519 prefs::kRecommendedPref));
[email protected]887288f02011-02-04 22:52:46520 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
521 prefs::kDefaultPref));
522 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(
523 prefs::kMissingPref));
[email protected]d7449e82010-07-14 11:42:35524}
[email protected]61f972b2010-08-04 15:31:38525
[email protected]a5437282011-12-12 12:33:21526TEST_F(PrefValueStoreTest, PrefValueFromRecommendedStore) {
527 EXPECT_FALSE(pref_value_store_->PrefValueFromRecommendedStore(
[email protected]4eb4d6ce2012-04-02 14:06:57528 prefs::kManagedPref));
[email protected]a5437282011-12-12 12:33:21529 EXPECT_FALSE(pref_value_store_->PrefValueFromRecommendedStore(
530 prefs::kExtensionPref));
531 EXPECT_FALSE(pref_value_store_->PrefValueFromRecommendedStore(
532 prefs::kCommandLinePref));
533 EXPECT_FALSE(pref_value_store_->PrefValueFromRecommendedStore(
534 prefs::kUserPref));
535 EXPECT_TRUE(pref_value_store_->PrefValueFromRecommendedStore(
[email protected]4eb4d6ce2012-04-02 14:06:57536 prefs::kRecommendedPref));
[email protected]a5437282011-12-12 12:33:21537 EXPECT_FALSE(pref_value_store_->PrefValueFromRecommendedStore(
538 prefs::kDefaultPref));
539 EXPECT_FALSE(pref_value_store_->PrefValueFromRecommendedStore(
540 prefs::kMissingPref));
541}
542
[email protected]c3b54f372010-09-14 08:25:07543TEST_F(PrefValueStoreTest, PrefValueFromDefaultStore) {
[email protected]be1c6e922010-11-17 12:49:17544 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
[email protected]4eb4d6ce2012-04-02 14:06:57545 prefs::kManagedPref));
[email protected]c3b54f372010-09-14 08:25:07546 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
[email protected]887288f02011-02-04 22:52:46547 prefs::kExtensionPref));
[email protected]ce1850e92010-10-15 08:40:58548 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
[email protected]887288f02011-02-04 22:52:46549 prefs::kCommandLinePref));
[email protected]c3b54f372010-09-14 08:25:07550 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
[email protected]887288f02011-02-04 22:52:46551 prefs::kUserPref));
552 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
[email protected]4eb4d6ce2012-04-02 14:06:57553 prefs::kRecommendedPref));
[email protected]887288f02011-02-04 22:52:46554 EXPECT_TRUE(pref_value_store_->PrefValueFromDefaultStore(
555 prefs::kDefaultPref));
556 EXPECT_FALSE(pref_value_store_->PrefValueFromDefaultStore(
557 prefs::kMissingPref));
558}
[email protected]c3b54f372010-09-14 08:25:07559
[email protected]887288f02011-02-04 22:52:46560TEST_F(PrefValueStoreTest, PrefValueUserModifiable) {
561 EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
[email protected]4eb4d6ce2012-04-02 14:06:57562 prefs::kManagedPref));
[email protected]887288f02011-02-04 22:52:46563 EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
564 prefs::kExtensionPref));
565 EXPECT_FALSE(pref_value_store_->PrefValueUserModifiable(
566 prefs::kCommandLinePref));
567 EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
568 prefs::kUserPref));
569 EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
[email protected]4eb4d6ce2012-04-02 14:06:57570 prefs::kRecommendedPref));
[email protected]887288f02011-02-04 22:52:46571 EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
572 prefs::kDefaultPref));
573 EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable(
574 prefs::kMissingPref));
[email protected]c3b54f372010-09-14 08:25:07575}
[email protected]9a28f132011-02-24 21:15:16576
577TEST_F(PrefValueStoreTest, PrefValueExtensionModifiable) {
578 EXPECT_FALSE(pref_value_store_->PrefValueExtensionModifiable(
[email protected]4eb4d6ce2012-04-02 14:06:57579 prefs::kManagedPref));
[email protected]9a28f132011-02-24 21:15:16580 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
581 prefs::kExtensionPref));
582 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
583 prefs::kCommandLinePref));
584 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
585 prefs::kUserPref));
586 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
[email protected]4eb4d6ce2012-04-02 14:06:57587 prefs::kRecommendedPref));
[email protected]9a28f132011-02-24 21:15:16588 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
589 prefs::kDefaultPref));
590 EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable(
591 prefs::kMissingPref));
592}