OLD | NEW |
---|---|
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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
11 #include "chrome/browser/policy/dummy_configuration_policy_provider.h" | |
danno
2010/12/08 13:08:45
alphabetize
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Done.
| |
11 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 12 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
12 #include "chrome/browser/prefs/pref_notifier.h" | 13 #include "chrome/browser/prefs/pref_notifier.h" |
13 #include "chrome/browser/prefs/pref_value_store.h" | 14 #include "chrome/browser/prefs/pref_value_store.h" |
14 #include "chrome/browser/prefs/testing_pref_store.h" | 15 #include "chrome/browser/prefs/testing_pref_store.h" |
15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 using testing::_; | 20 using testing::_; |
20 using testing::AnyNumber; | 21 using testing::AnyNumber; |
21 using testing::Mock; | 22 using testing::Mock; |
22 using testing::Invoke; | 23 using testing::Invoke; |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 // Records preference changes. | |
27 class PrefChangeRecorder { | |
28 public: | |
29 void Record(const std::string& pref_name) { | |
30 changed_prefs_.insert(pref_name); | |
31 } | |
32 | |
33 void Clear() { | |
34 changed_prefs_.clear(); | |
35 } | |
36 | |
37 const std::set<std::string>& changed_prefs() { return changed_prefs_; } | |
38 | |
39 private: | |
40 std::set<std::string> changed_prefs_; | |
41 }; | |
42 | |
43 // Allows to capture pref notifications through gmock. | 27 // Allows to capture pref notifications through gmock. |
44 class MockPrefNotifier : public PrefNotifier { | 28 class MockPrefNotifier : public PrefNotifier { |
45 public: | 29 public: |
46 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&)); | 30 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&)); |
47 MOCK_METHOD0(OnInitializationCompleted, void()); | 31 MOCK_METHOD0(OnInitializationCompleted, void()); |
48 }; | 32 }; |
49 | 33 |
50 } // namespace | 34 } // namespace |
51 | 35 |
52 // Names of the preferences used in this test program. | 36 // Names of the preferences used in this test program. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 pref_value_store_->RegisterPreferenceType(prefs::kRecommendedPref, | 128 pref_value_store_->RegisterPreferenceType(prefs::kRecommendedPref, |
145 Value::TYPE_BOOLEAN); | 129 Value::TYPE_BOOLEAN); |
146 pref_value_store_->RegisterPreferenceType(prefs::kSampleDict, | 130 pref_value_store_->RegisterPreferenceType(prefs::kSampleDict, |
147 Value::TYPE_DICTIONARY); | 131 Value::TYPE_DICTIONARY); |
148 pref_value_store_->RegisterPreferenceType(prefs::kSampleList, | 132 pref_value_store_->RegisterPreferenceType(prefs::kSampleList, |
149 Value::TYPE_LIST); | 133 Value::TYPE_LIST); |
150 pref_value_store_->RegisterPreferenceType(prefs::kDefaultPref, | 134 pref_value_store_->RegisterPreferenceType(prefs::kDefaultPref, |
151 Value::TYPE_INTEGER); | 135 Value::TYPE_INTEGER); |
152 pref_value_store_->RegisterPreferenceType(prefs::kProxyAutoDetect, | 136 pref_value_store_->RegisterPreferenceType(prefs::kProxyAutoDetect, |
153 Value::TYPE_BOOLEAN); | 137 Value::TYPE_BOOLEAN); |
154 | |
155 ui_thread_.reset(new BrowserThread(BrowserThread::UI, &loop_)); | |
156 file_thread_.reset(new BrowserThread(BrowserThread::FILE, &loop_)); | |
157 } | 138 } |
158 | 139 |
159 // Creates a new dictionary and stores some sample user preferences | 140 // Creates a new dictionary and stores some sample user preferences |
160 // in it. | 141 // in it. |
161 void CreateUserPrefs() { | 142 void CreateUserPrefs() { |
162 user_pref_store_ = new TestingPrefStore; | 143 user_pref_store_ = new TestingPrefStore; |
163 user_pref_store_->prefs()->SetBoolean(prefs::kDeleteCache, | 144 user_pref_store_->SetBoolean(prefs::kDeleteCache, |
164 user_pref::kDeleteCacheValue); | 145 user_pref::kDeleteCacheValue); |
165 user_pref_store_->prefs()->SetInteger(prefs::kStabilityLaunchCount, | 146 user_pref_store_->SetInteger(prefs::kStabilityLaunchCount, |
166 user_pref::kStabilityLaunchCountValue); | 147 user_pref::kStabilityLaunchCountValue); |
167 user_pref_store_->prefs()->SetString(prefs::kCurrentThemeID, | 148 user_pref_store_->SetString(prefs::kCurrentThemeID, |
168 user_pref::kCurrentThemeIDValue); | 149 user_pref::kCurrentThemeIDValue); |
169 user_pref_store_->prefs()->SetString(prefs::kApplicationLocale, | 150 user_pref_store_->SetString(prefs::kApplicationLocale, |
170 user_pref::kApplicationLocaleValue); | 151 user_pref::kApplicationLocaleValue); |
171 user_pref_store_->prefs()->SetString(prefs::kDefaultSearchProviderName, | 152 user_pref_store_->SetString(prefs::kDefaultSearchProviderName, |
172 user_pref::kSearchProviderNameValue); | 153 user_pref::kSearchProviderNameValue); |
173 user_pref_store_->prefs()->SetString(prefs::kHomePage, | 154 user_pref_store_->SetString(prefs::kHomePage, |
174 user_pref::kHomepageValue); | 155 user_pref::kHomepageValue); |
175 } | 156 } |
176 | 157 |
177 void CreateManagedPlatformPrefs() { | 158 void CreateManagedPlatformPrefs() { |
178 managed_platform_pref_store_ = new TestingPrefStore; | 159 managed_platform_pref_store_ = new TestingPrefStore; |
179 managed_platform_pref_store_->prefs()->SetString( | 160 managed_platform_pref_store_->SetString(prefs::kHomePage, |
180 prefs::kHomePage, | |
181 managed_platform_pref::kHomepageValue); | 161 managed_platform_pref::kHomepageValue); |
182 expected_differing_paths_.insert(prefs::kHomePage); | |
183 } | 162 } |
184 | 163 |
185 void CreateDeviceManagementPrefs() { | 164 void CreateDeviceManagementPrefs() { |
186 device_management_pref_store_ = new TestingPrefStore; | 165 device_management_pref_store_ = new TestingPrefStore; |
187 device_management_pref_store_->prefs()->SetString( | 166 device_management_pref_store_->SetString(prefs::kDefaultSearchProviderName, |
188 prefs::kDefaultSearchProviderName, | |
189 device_management_pref::kSearchProviderNameValue); | 167 device_management_pref::kSearchProviderNameValue); |
190 expected_differing_paths_.insert("default_search_provider"); | 168 device_management_pref_store_->SetString(prefs::kHomePage, |
191 expected_differing_paths_.insert(prefs::kDefaultSearchProviderName); | |
192 device_management_pref_store_->prefs()->SetString(prefs::kHomePage, | |
193 device_management_pref::kHomepageValue); | 169 device_management_pref::kHomepageValue); |
194 } | 170 } |
195 | 171 |
196 void CreateExtensionPrefs() { | 172 void CreateExtensionPrefs() { |
197 extension_pref_store_ = new TestingPrefStore; | 173 extension_pref_store_ = new TestingPrefStore; |
198 extension_pref_store_->prefs()->SetString(prefs::kCurrentThemeID, | 174 extension_pref_store_->SetString(prefs::kCurrentThemeID, |
199 extension_pref::kCurrentThemeIDValue); | 175 extension_pref::kCurrentThemeIDValue); |
200 extension_pref_store_->prefs()->SetString(prefs::kHomePage, | 176 extension_pref_store_->SetString(prefs::kHomePage, |
201 extension_pref::kHomepageValue); | 177 extension_pref::kHomepageValue); |
202 extension_pref_store_->prefs()->SetString(prefs::kDefaultSearchProviderName, | 178 extension_pref_store_->SetString(prefs::kDefaultSearchProviderName, |
203 extension_pref::kSearchProviderNameValue); | 179 extension_pref::kSearchProviderNameValue); |
204 } | 180 } |
205 | 181 |
206 void CreateCommandLinePrefs() { | 182 void CreateCommandLinePrefs() { |
207 command_line_pref_store_ = new TestingPrefStore; | 183 command_line_pref_store_ = new TestingPrefStore; |
208 command_line_pref_store_->prefs()->SetString(prefs::kCurrentThemeID, | 184 command_line_pref_store_->SetString(prefs::kCurrentThemeID, |
209 command_line_pref::kCurrentThemeIDValue); | 185 command_line_pref::kCurrentThemeIDValue); |
210 command_line_pref_store_->prefs()->SetString(prefs::kApplicationLocale, | 186 command_line_pref_store_->SetString(prefs::kApplicationLocale, |
211 command_line_pref::kApplicationLocaleValue); | 187 command_line_pref::kApplicationLocaleValue); |
212 command_line_pref_store_->prefs()->SetString(prefs::kHomePage, | 188 command_line_pref_store_->SetString(prefs::kHomePage, |
213 command_line_pref::kHomepageValue); | 189 command_line_pref::kHomepageValue); |
214 command_line_pref_store_->prefs()->SetString( | 190 command_line_pref_store_->SetString(prefs::kDefaultSearchProviderName, |
215 prefs::kDefaultSearchProviderName, | |
216 command_line_pref::kSearchProviderNameValue); | 191 command_line_pref::kSearchProviderNameValue); |
217 } | 192 } |
218 | 193 |
219 void CreateRecommendedPrefs() { | 194 void CreateRecommendedPrefs() { |
220 recommended_pref_store_ = new TestingPrefStore; | 195 recommended_pref_store_ = new TestingPrefStore; |
221 recommended_pref_store_->prefs()->SetInteger(prefs::kStabilityLaunchCount, | 196 recommended_pref_store_->SetInteger(prefs::kStabilityLaunchCount, |
222 recommended_pref::kStabilityLaunchCountValue); | 197 recommended_pref::kStabilityLaunchCountValue); |
223 recommended_pref_store_->prefs()->SetBoolean( | 198 recommended_pref_store_->SetBoolean(prefs::kRecommendedPref, |
224 prefs::kRecommendedPref, | |
225 recommended_pref::kRecommendedPrefValue); | 199 recommended_pref::kRecommendedPrefValue); |
226 | |
227 expected_differing_paths_.insert("this"); | |
228 expected_differing_paths_.insert("this.pref"); | |
229 expected_differing_paths_.insert(prefs::kRecommendedPref); | |
230 expected_differing_paths_.insert("user_experience_metrics"); | |
231 expected_differing_paths_.insert("user_experience_metrics.stability"); | |
232 expected_differing_paths_.insert(prefs::kStabilityLaunchCount); | |
233 } | 200 } |
234 | 201 |
235 void CreateDefaultPrefs() { | 202 void CreateDefaultPrefs() { |
236 default_pref_store_ = new TestingPrefStore; | 203 default_pref_store_ = new TestingPrefStore; |
237 default_pref_store_->prefs()->SetInteger(prefs::kDefaultPref, | 204 default_pref_store_->SetInteger(prefs::kDefaultPref, |
238 default_pref::kDefaultValue); | 205 default_pref::kDefaultValue); |
239 } | 206 } |
240 | 207 |
241 DictionaryValue* CreateSampleDictValue() { | 208 DictionaryValue* CreateSampleDictValue() { |
242 DictionaryValue* sample_dict = new DictionaryValue(); | 209 DictionaryValue* sample_dict = new DictionaryValue(); |
243 sample_dict->SetBoolean("issample", true); | 210 sample_dict->SetBoolean("issample", true); |
244 sample_dict->SetInteger("value", 4); | 211 sample_dict->SetInteger("value", 4); |
245 sample_dict->SetString("descr", "Sample Test Dictionary"); | 212 sample_dict->SetString("descr", "Sample Test Dictionary"); |
246 return sample_dict; | 213 return sample_dict; |
247 } | 214 } |
248 | 215 |
249 ListValue* CreateSampleListValue() { | 216 ListValue* CreateSampleListValue() { |
250 ListValue* sample_list = new ListValue(); | 217 ListValue* sample_list = new ListValue(); |
251 sample_list->Set(0, Value::CreateIntegerValue(0)); | 218 sample_list->Set(0, Value::CreateIntegerValue(0)); |
252 sample_list->Set(1, Value::CreateIntegerValue(1)); | 219 sample_list->Set(1, Value::CreateIntegerValue(1)); |
253 sample_list->Set(2, Value::CreateIntegerValue(2)); | 220 sample_list->Set(2, Value::CreateIntegerValue(2)); |
254 sample_list->Set(3, Value::CreateIntegerValue(3)); | 221 sample_list->Set(3, Value::CreateIntegerValue(3)); |
255 return sample_list; | 222 return sample_list; |
256 } | 223 } |
257 | 224 |
258 virtual void TearDown() { | |
259 loop_.RunAllPending(); | |
260 } | |
261 | |
262 MessageLoop loop_; | |
263 MockPrefNotifier pref_notifier_; | 225 MockPrefNotifier pref_notifier_; |
264 scoped_refptr<PrefValueStore> pref_value_store_; | 226 scoped_refptr<PrefValueStore> pref_value_store_; |
265 | 227 |
266 // |PrefStore|s are owned by the |PrefValueStore|. | 228 // |PrefStore|s are owned by the |PrefValueStore|. |
267 TestingPrefStore* managed_platform_pref_store_; | 229 TestingPrefStore* managed_platform_pref_store_; |
268 TestingPrefStore* device_management_pref_store_; | 230 TestingPrefStore* device_management_pref_store_; |
269 TestingPrefStore* extension_pref_store_; | 231 TestingPrefStore* extension_pref_store_; |
270 TestingPrefStore* command_line_pref_store_; | 232 TestingPrefStore* command_line_pref_store_; |
271 TestingPrefStore* user_pref_store_; | 233 TestingPrefStore* user_pref_store_; |
272 TestingPrefStore* recommended_pref_store_; | 234 TestingPrefStore* recommended_pref_store_; |
273 TestingPrefStore* default_pref_store_; | 235 TestingPrefStore* default_pref_store_; |
274 | |
275 // A vector of the preferences paths in the managed and recommended | |
276 // PrefStores that are set at the beginning of a test. Can be modified | |
277 // by the test to track changes that it makes to the preferences | |
278 // stored in the managed and recommended PrefStores. | |
279 std::set<std::string> expected_differing_paths_; | |
280 | |
281 private: | |
282 scoped_ptr<BrowserThread> ui_thread_; | |
283 scoped_ptr<BrowserThread> file_thread_; | |
284 }; | 236 }; |
285 | 237 |
286 TEST_F(PrefValueStoreTest, IsReadOnly) { | |
287 managed_platform_pref_store_->set_read_only(true); | |
288 extension_pref_store_->set_read_only(true); | |
289 command_line_pref_store_->set_read_only(true); | |
290 user_pref_store_->set_read_only(true); | |
291 recommended_pref_store_->set_read_only(true); | |
292 default_pref_store_->set_read_only(true); | |
293 EXPECT_TRUE(pref_value_store_->ReadOnly()); | |
294 | |
295 user_pref_store_->set_read_only(false); | |
296 EXPECT_FALSE(pref_value_store_->ReadOnly()); | |
297 } | |
298 | |
299 TEST_F(PrefValueStoreTest, GetValue) { | 238 TEST_F(PrefValueStoreTest, GetValue) { |
300 Value* value; | 239 Value* value; |
301 | 240 |
302 // Test getting a managed platform value overwriting a user-defined and | 241 // Test getting a managed platform value overwriting a user-defined and |
303 // extension-defined value. | 242 // extension-defined value. |
304 value = NULL; | 243 value = NULL; |
305 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &value)); | 244 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &value)); |
306 std::string actual_str_value; | 245 std::string actual_str_value; |
307 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 246 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
308 EXPECT_EQ(managed_platform_pref::kHomepageValue, actual_str_value); | 247 EXPECT_EQ(managed_platform_pref::kHomepageValue, actual_str_value); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 // does not contain. | 300 // does not contain. |
362 FundamentalValue tmp_dummy_value(true); | 301 FundamentalValue tmp_dummy_value(true); |
363 Value* v_null = &tmp_dummy_value; | 302 Value* v_null = &tmp_dummy_value; |
364 ASSERT_FALSE(pref_value_store_->GetValue(prefs::kMissingPref, &v_null)); | 303 ASSERT_FALSE(pref_value_store_->GetValue(prefs::kMissingPref, &v_null)); |
365 ASSERT_TRUE(v_null == NULL); | 304 ASSERT_TRUE(v_null == NULL); |
366 } | 305 } |
367 | 306 |
368 // Make sure that if a preference changes type, so the wrong type is stored in | 307 // Make sure that if a preference changes type, so the wrong type is stored in |
369 // the user pref file, it uses the correct fallback value instead. | 308 // the user pref file, it uses the correct fallback value instead. |
370 TEST_F(PrefValueStoreTest, GetValueChangedType) { | 309 TEST_F(PrefValueStoreTest, GetValueChangedType) { |
310 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(AnyNumber()); | |
311 | |
371 // Check falling back to a recommended value. | 312 // Check falling back to a recommended value. |
372 user_pref_store_->prefs()->SetString(prefs::kStabilityLaunchCount, | 313 user_pref_store_->SetString(prefs::kStabilityLaunchCount, |
373 "not an integer"); | 314 "not an integer"); |
374 Value* value = NULL; | 315 Value* value = NULL; |
375 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kStabilityLaunchCount, | 316 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kStabilityLaunchCount, |
376 &value)); | 317 &value)); |
377 ASSERT_TRUE(value != NULL); | 318 ASSERT_TRUE(value != NULL); |
378 ASSERT_EQ(Value::TYPE_INTEGER, value->GetType()); | 319 ASSERT_EQ(Value::TYPE_INTEGER, value->GetType()); |
379 int actual_int_value = -1; | 320 int actual_int_value = -1; |
380 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); | 321 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); |
381 EXPECT_EQ(recommended_pref::kStabilityLaunchCountValue, actual_int_value); | 322 EXPECT_EQ(recommended_pref::kStabilityLaunchCountValue, actual_int_value); |
382 | 323 |
383 // Check falling back multiple times, to a default string. | 324 // Check falling back multiple times, to a default string. |
384 managed_platform_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1); | 325 default_pref_store_->SetString(prefs::kHomePage, |
385 device_management_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1); | 326 default_pref::kHomepageValue); |
386 extension_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1); | 327 managed_platform_pref_store_->SetInteger(prefs::kHomePage, 1); |
387 command_line_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1); | 328 device_management_pref_store_->SetInteger(prefs::kHomePage, 1); |
388 user_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1); | 329 extension_pref_store_->SetInteger(prefs::kHomePage, 1); |
389 recommended_pref_store_->prefs()->SetInteger(prefs::kHomePage, 1); | 330 command_line_pref_store_->SetInteger(prefs::kHomePage, 1); |
390 default_pref_store_->prefs()->SetString(prefs::kHomePage, | 331 user_pref_store_->SetInteger(prefs::kHomePage, 1); |
391 default_pref::kHomepageValue); | 332 recommended_pref_store_->SetInteger(prefs::kHomePage, 1); |
392 | 333 |
393 value = NULL; | 334 value = NULL; |
394 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &value)); | 335 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &value)); |
395 ASSERT_TRUE(value != NULL); | 336 ASSERT_TRUE(value != NULL); |
396 ASSERT_EQ(Value::TYPE_STRING, value->GetType()); | 337 ASSERT_EQ(Value::TYPE_STRING, value->GetType()); |
397 std::string actual_str_value; | 338 std::string actual_str_value; |
398 EXPECT_TRUE(value->GetAsString(&actual_str_value)); | 339 EXPECT_TRUE(value->GetAsString(&actual_str_value)); |
399 EXPECT_EQ(default_pref::kHomepageValue, actual_str_value); | 340 EXPECT_EQ(default_pref::kHomepageValue, actual_str_value); |
400 } | 341 } |
401 | 342 |
(...skipping 10 matching lines...) Expand all Loading... | |
412 // Recommended preference | 353 // Recommended preference |
413 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref)); | 354 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref)); |
414 // Default preference | 355 // Default preference |
415 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref)); | 356 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref)); |
416 // Unknown preference | 357 // Unknown preference |
417 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); | 358 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); |
418 } | 359 } |
419 | 360 |
420 TEST_F(PrefValueStoreTest, PrefChanges) { | 361 TEST_F(PrefValueStoreTest, PrefChanges) { |
421 // Setup. | 362 // Setup. |
363 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(AnyNumber()); | |
422 const char managed_platform_pref_path[] = "managed_platform_pref"; | 364 const char managed_platform_pref_path[] = "managed_platform_pref"; |
423 pref_value_store_->RegisterPreferenceType(managed_platform_pref_path, | 365 pref_value_store_->RegisterPreferenceType(managed_platform_pref_path, |
424 Value::TYPE_STRING); | 366 Value::TYPE_STRING); |
425 managed_platform_pref_store_->prefs()->SetString(managed_platform_pref_path, | 367 managed_platform_pref_store_->SetString(managed_platform_pref_path, |
426 "managed value"); | 368 "managed value"); |
427 const char user_pref_path[] = "user_pref"; | 369 const char user_pref_path[] = "user_pref"; |
428 pref_value_store_->RegisterPreferenceType(user_pref_path, Value::TYPE_STRING); | 370 pref_value_store_->RegisterPreferenceType(user_pref_path, Value::TYPE_STRING); |
429 user_pref_store_->prefs()->SetString(user_pref_path, "user value"); | 371 user_pref_store_->SetString(user_pref_path, "user value"); |
430 const char default_pref_path[] = "default_pref"; | 372 const char default_pref_path[] = "default_pref"; |
431 pref_value_store_->RegisterPreferenceType(default_pref_path, | 373 pref_value_store_->RegisterPreferenceType(default_pref_path, |
432 Value::TYPE_STRING); | 374 Value::TYPE_STRING); |
433 default_pref_store_->prefs()->SetString(default_pref_path, "default value"); | 375 default_pref_store_->SetString(default_pref_path, "default value"); |
376 Mock::VerifyAndClearExpectations(&pref_notifier_); | |
434 | 377 |
435 // Check pref controlled by highest-priority store. | 378 // Check pref controlled by highest-priority store. |
436 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(managed_platform_pref_path)); | 379 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(managed_platform_pref_path)); |
437 managed_platform_pref_store_->NotifyPrefValueChanged( | 380 managed_platform_pref_store_->NotifyPrefValueChanged( |
438 managed_platform_pref_path); | 381 managed_platform_pref_path); |
439 Mock::VerifyAndClearExpectations(&pref_notifier_); | 382 Mock::VerifyAndClearExpectations(&pref_notifier_); |
440 | 383 |
441 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(0); | 384 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(0); |
442 user_pref_store_->NotifyPrefValueChanged(managed_platform_pref_path); | 385 user_pref_store_->NotifyPrefValueChanged(managed_platform_pref_path); |
443 Mock::VerifyAndClearExpectations(&pref_notifier_); | 386 Mock::VerifyAndClearExpectations(&pref_notifier_); |
(...skipping 30 matching lines...) Expand all Loading... | |
474 recommended_pref_store_->SetInitializationCompleted(); | 417 recommended_pref_store_->SetInitializationCompleted(); |
475 default_pref_store_->SetInitializationCompleted(); | 418 default_pref_store_->SetInitializationCompleted(); |
476 Mock::VerifyAndClearExpectations(&pref_notifier_); | 419 Mock::VerifyAndClearExpectations(&pref_notifier_); |
477 | 420 |
478 // The notification should only be triggered after the last store is done. | 421 // The notification should only be triggered after the last store is done. |
479 EXPECT_CALL(pref_notifier_, OnInitializationCompleted()).Times(1); | 422 EXPECT_CALL(pref_notifier_, OnInitializationCompleted()).Times(1); |
480 user_pref_store_->SetInitializationCompleted(); | 423 user_pref_store_->SetInitializationCompleted(); |
481 Mock::VerifyAndClearExpectations(&pref_notifier_); | 424 Mock::VerifyAndClearExpectations(&pref_notifier_); |
482 } | 425 } |
483 | 426 |
484 TEST_F(PrefValueStoreTest, ReadPrefs) { | |
485 pref_value_store_->ReadPrefs(); | |
486 // The ReadPrefs method of the |TestingPrefStore| deletes the |pref_store|s | |
487 // internal dictionary and creates a new empty dictionary. Hence this | |
488 // dictionary does not contain any of the preloaded preferences. | |
489 // This shows that the ReadPrefs method of the |TestingPrefStore| was called. | |
490 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDeleteCache)); | |
491 } | |
492 | |
493 TEST_F(PrefValueStoreTest, WritePrefs) { | |
494 user_pref_store_->set_prefs_written(false); | |
495 pref_value_store_->WritePrefs(); | |
496 ASSERT_TRUE(user_pref_store_->get_prefs_written()); | |
497 } | |
498 | |
499 TEST_F(PrefValueStoreTest, SetUserPrefValue) { | |
500 Value* new_value = NULL; | |
501 Value* actual_value = NULL; | |
502 | |
503 // Test that managed platform values can not be set. | |
504 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(0); | |
505 ASSERT_TRUE(pref_value_store_->PrefValueInManagedPlatformStore( | |
506 prefs::kHomePage)); | |
507 // The ownership is transfered to PrefValueStore. | |
508 new_value = Value::CreateStringValue("http://www.youtube.com"); | |
509 pref_value_store_->SetUserPrefValue(prefs::kHomePage, new_value); | |
510 Mock::VerifyAndClearExpectations(&pref_notifier_); | |
511 | |
512 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &actual_value)); | |
513 std::string value_str; | |
514 actual_value->GetAsString(&value_str); | |
515 ASSERT_EQ(managed_platform_pref::kHomepageValue, value_str); | |
516 | |
517 // User preferences values can be set. | |
518 ASSERT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore( | |
519 prefs::kStabilityLaunchCount)); | |
520 actual_value = NULL; | |
521 pref_value_store_->GetValue(prefs::kStabilityLaunchCount, &actual_value); | |
522 int int_value; | |
523 EXPECT_TRUE(actual_value->GetAsInteger(&int_value)); | |
524 EXPECT_EQ(user_pref::kStabilityLaunchCountValue, int_value); | |
525 | |
526 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(1); | |
527 new_value = Value::CreateIntegerValue(1); | |
528 pref_value_store_->SetUserPrefValue(prefs::kStabilityLaunchCount, new_value); | |
529 actual_value = NULL; | |
530 pref_value_store_->GetValue(prefs::kStabilityLaunchCount, &actual_value); | |
531 EXPECT_TRUE(new_value->Equals(actual_value)); | |
532 Mock::VerifyAndClearExpectations(&pref_notifier_); | |
533 | |
534 // Set and Get DictionaryValue. | |
535 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(1); | |
536 DictionaryValue* expected_dict_value = CreateSampleDictValue(); | |
537 pref_value_store_->SetUserPrefValue(prefs::kSampleDict, expected_dict_value); | |
538 Mock::VerifyAndClearExpectations(&pref_notifier_); | |
539 | |
540 actual_value = NULL; | |
541 std::string key(prefs::kSampleDict); | |
542 pref_value_store_->GetValue(key, &actual_value); | |
543 | |
544 ASSERT_EQ(expected_dict_value, actual_value); | |
545 ASSERT_TRUE(expected_dict_value->Equals(actual_value)); | |
546 | |
547 // Set and Get a ListValue. | |
548 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(1); | |
549 ListValue* expected_list_value = CreateSampleListValue(); | |
550 pref_value_store_->SetUserPrefValue(prefs::kSampleList, expected_list_value); | |
551 Mock::VerifyAndClearExpectations(&pref_notifier_); | |
552 | |
553 actual_value = NULL; | |
554 key = prefs::kSampleList; | |
555 pref_value_store_->GetValue(key, &actual_value); | |
556 | |
557 ASSERT_EQ(expected_list_value, actual_value); | |
558 ASSERT_TRUE(expected_list_value->Equals(actual_value)); | |
559 } | |
560 | |
561 TEST_F(PrefValueStoreTest, PrefValueInManagedPlatformStore) { | 427 TEST_F(PrefValueStoreTest, PrefValueInManagedPlatformStore) { |
562 // Test a managed platform preference. | 428 // Test a managed platform preference. |
563 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage)); | 429 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage)); |
564 EXPECT_TRUE(pref_value_store_->PrefValueInManagedPlatformStore( | 430 EXPECT_TRUE(pref_value_store_->PrefValueInManagedPlatformStore( |
565 prefs::kHomePage)); | 431 prefs::kHomePage)); |
566 | 432 |
567 // Test a device management preference. | 433 // Test a device management preference. |
568 ASSERT_TRUE(pref_value_store_->HasPrefPath( | 434 ASSERT_TRUE(pref_value_store_->HasPrefPath( |
569 prefs::kDefaultSearchProviderName)); | 435 prefs::kDefaultSearchProviderName)); |
570 EXPECT_TRUE(pref_value_store_->PrefValueInDeviceManagementStore( | 436 EXPECT_TRUE(pref_value_store_->PrefValueInDeviceManagementStore( |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 prefs::kDefaultPref)); | 518 prefs::kDefaultPref)); |
653 | 519 |
654 // Test a preference for which the PrefValueStore does not contain a value. | 520 // Test a preference for which the PrefValueStore does not contain a value. |
655 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); | 521 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); |
656 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore( | 522 EXPECT_FALSE(pref_value_store_->PrefValueInExtensionStore( |
657 prefs::kMissingPref)); | 523 prefs::kMissingPref)); |
658 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore( | 524 EXPECT_FALSE(pref_value_store_->PrefValueFromExtensionStore( |
659 prefs::kMissingPref)); | 525 prefs::kMissingPref)); |
660 } | 526 } |
661 | 527 |
662 TEST_F(PrefValueStoreTest, DetectProxyConfigurationConflict) { | |
663 // There should be no conflicting proxy prefs in the default | |
664 // preference stores created for the test. | |
665 ASSERT_FALSE(pref_value_store_->HasPolicyConflictingUserProxySettings()); | |
666 | |
667 // Create conflicting proxy settings in the managed and command-line | |
668 // preference stores. | |
669 command_line_pref_store_->prefs()->SetBoolean(prefs::kProxyAutoDetect, false); | |
670 managed_platform_pref_store_->prefs()->SetBoolean(prefs::kProxyAutoDetect, | |
671 true); | |
672 ASSERT_TRUE(pref_value_store_->HasPolicyConflictingUserProxySettings()); | |
673 } | |
674 | |
675 TEST_F(PrefValueStoreTest, PrefValueInUserStore) { | 528 TEST_F(PrefValueStoreTest, PrefValueInUserStore) { |
676 // Test a managed platform preference. | 529 // Test a managed platform preference. |
677 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage)); | 530 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage)); |
678 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(prefs::kHomePage)); | 531 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(prefs::kHomePage)); |
679 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kHomePage)); | 532 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kHomePage)); |
680 | 533 |
681 // Test a device management preference. | 534 // Test a device management preference. |
682 ASSERT_TRUE(pref_value_store_->HasPrefPath( | 535 ASSERT_TRUE(pref_value_store_->HasPrefPath( |
683 prefs::kDefaultSearchProviderName)); | 536 prefs::kDefaultSearchProviderName)); |
684 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore( | 537 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore( |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref)); | 613 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref)); |
761 EXPECT_TRUE( | 614 EXPECT_TRUE( |
762 pref_value_store_->PrefValueFromDefaultStore(prefs::kDefaultPref)); | 615 pref_value_store_->PrefValueFromDefaultStore(prefs::kDefaultPref)); |
763 | 616 |
764 // Test a preference for which the PrefValueStore does not contain a value. | 617 // Test a preference for which the PrefValueStore does not contain a value. |
765 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); | 618 ASSERT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); |
766 EXPECT_FALSE( | 619 EXPECT_FALSE( |
767 pref_value_store_->PrefValueFromDefaultStore(prefs::kMissingPref)); | 620 pref_value_store_->PrefValueFromDefaultStore(prefs::kMissingPref)); |
768 } | 621 } |
769 | 622 |
770 TEST_F(PrefValueStoreTest, TestPolicyRefresh) { | 623 // TODO(mnissler, danno): Clean this up when refactoring |
624 // ConfigurationPolicyPrefStore. | |
625 class PrefValueStorePolicyRefreshTest : public testing::Test { | |
626 protected: | |
627 // Records preference changes. | |
628 class PrefChangeRecorder { | |
629 public: | |
630 void Record(const std::string& pref_name) { | |
631 changed_prefs_.insert(pref_name); | |
632 } | |
633 | |
634 void Clear() { | |
635 changed_prefs_.clear(); | |
636 } | |
637 | |
638 const std::set<std::string>& changed_prefs() { return changed_prefs_; } | |
639 | |
640 private: | |
641 std::set<std::string> changed_prefs_; | |
642 }; | |
643 | |
644 virtual void SetUp() { | |
645 using policy::ConfigurationPolicyPrefStore; | |
646 | |
647 ui_thread_.reset(new BrowserThread(BrowserThread::UI, &loop_)), | |
648 file_thread_.reset(new BrowserThread(BrowserThread::FILE, &loop_)), | |
649 policy_provider_.reset(new policy::DummyConfigurationPolicyProvider( | |
650 policy::ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList())); | |
651 | |
652 ConfigurationPolicyPrefStore* managed_store = | |
653 NewConfigurationPolicyPrefStore(); | |
654 managed_store->prefs()->SetString(prefs::kHomePage, | |
655 managed_platform_pref::kHomepageValue); | |
656 expected_differing_paths_.insert(prefs::kHomePage); | |
657 | |
658 ConfigurationPolicyPrefStore* device_management_store = | |
659 NewConfigurationPolicyPrefStore(); | |
660 device_management_store->prefs()->SetString( | |
661 prefs::kDefaultSearchProviderName, | |
662 device_management_pref::kSearchProviderNameValue); | |
663 expected_differing_paths_.insert("default_search_provider"); | |
664 expected_differing_paths_.insert(prefs::kDefaultSearchProviderName); | |
665 | |
666 ConfigurationPolicyPrefStore* recommended_store = | |
667 NewConfigurationPolicyPrefStore(); | |
668 recommended_store->prefs()->SetInteger(prefs::kStabilityLaunchCount, | |
669 recommended_pref::kStabilityLaunchCountValue); | |
670 recommended_store->prefs()->SetBoolean(prefs::kRecommendedPref, | |
671 recommended_pref::kRecommendedPrefValue); | |
672 | |
673 expected_differing_paths_.insert("this"); | |
674 expected_differing_paths_.insert("this.pref"); | |
675 expected_differing_paths_.insert(prefs::kRecommendedPref); | |
676 expected_differing_paths_.insert("user_experience_metrics"); | |
677 expected_differing_paths_.insert("user_experience_metrics.stability"); | |
678 expected_differing_paths_.insert(prefs::kStabilityLaunchCount); | |
679 | |
680 pref_value_store_ = new PrefValueStore( | |
681 managed_store, | |
682 device_management_store, | |
683 NULL, | |
684 NULL, | |
685 new TestingPrefStore(), | |
686 recommended_store, | |
687 NULL, | |
688 &pref_notifier_, | |
689 NULL); | |
690 } | |
691 | |
692 virtual void TearDown() { | |
693 loop_.RunAllPending(); | |
694 pref_value_store_ = NULL; | |
695 file_thread_.reset(); | |
696 ui_thread_.reset(); | |
697 } | |
698 | |
699 // Creates a new ConfigurationPolicyPrefStore for testing. | |
700 policy::ConfigurationPolicyPrefStore* NewConfigurationPolicyPrefStore() { | |
701 return new policy::ConfigurationPolicyPrefStore(policy_provider_.get()); | |
702 } | |
703 | |
704 // A vector of the preferences paths in policy PrefStores that are set at the | |
705 // beginning of a test. Can be modified by the test to track changes that it | |
706 // makes to the preferences stored in the managed and recommended PrefStores. | |
707 std::set<std::string> expected_differing_paths_; | |
708 | |
709 MessageLoop loop_; | |
710 MockPrefNotifier pref_notifier_; | |
711 scoped_refptr<PrefValueStore> pref_value_store_; | |
712 | |
713 private: | |
714 scoped_ptr<BrowserThread> ui_thread_; | |
715 scoped_ptr<BrowserThread> file_thread_; | |
716 | |
717 scoped_ptr<policy::DummyConfigurationPolicyProvider> policy_provider_; | |
718 }; | |
719 | |
720 TEST_F(PrefValueStorePolicyRefreshTest, TestPolicyRefresh) { | |
771 // pref_value_store_ is initialized by PrefValueStoreTest to have values in | 721 // pref_value_store_ is initialized by PrefValueStoreTest to have values in |
772 // the managed platform, device management and recommended stores. By | 722 // the managed platform, device management and recommended stores. By |
773 // replacing them with dummy stores, all of the paths of the prefs originally | 723 // replacing them with dummy stores, all of the paths of the prefs originally |
774 // in the managed platform, device management and recommended stores should | 724 // in the managed platform, device management and recommended stores should |
775 // change. | 725 // change. |
776 pref_value_store_->RefreshPolicyPrefs(); | 726 pref_value_store_->RefreshPolicyPrefs(); |
777 | 727 |
778 PrefChangeRecorder recorder; | 728 PrefChangeRecorder recorder; |
779 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)) | 729 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)) |
780 .WillRepeatedly(Invoke(&recorder, &PrefChangeRecorder::Record)); | 730 .WillRepeatedly(Invoke(&recorder, &PrefChangeRecorder::Record)); |
781 loop_.RunAllPending(); | 731 loop_.RunAllPending(); |
782 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); | 732 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
783 } | 733 } |
784 | 734 |
785 TEST_F(PrefValueStoreTest, TestRefreshPolicyPrefsCompletion) { | 735 TEST_F(PrefValueStorePolicyRefreshTest, TestRefreshPolicyPrefsCompletion) { |
736 using policy::ConfigurationPolicyPrefStore; | |
786 PrefChangeRecorder recorder; | 737 PrefChangeRecorder recorder; |
787 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)) | 738 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)) |
788 .WillRepeatedly(Invoke(&recorder, &PrefChangeRecorder::Record)); | 739 .WillRepeatedly(Invoke(&recorder, &PrefChangeRecorder::Record)); |
789 | 740 |
790 // Test changed preferences in the managed platform store and removed | 741 // Test changed preferences in the managed platform store and removed |
791 // preferences in the recommended store. In addition to "homepage", the other | 742 // preferences in the recommended store. In addition to "homepage", the other |
792 // prefs that are set by default in the test class are removed by the | 743 // prefs that are set by default in the test class are removed by the |
793 // DummyStore. | 744 // DummyStore. |
794 scoped_ptr<TestingPrefStore> new_managed_platform_store( | 745 scoped_ptr<ConfigurationPolicyPrefStore> new_managed_platform_store( |
795 new TestingPrefStore()); | 746 NewConfigurationPolicyPrefStore()); |
796 DictionaryValue* dict = new DictionaryValue(); | 747 new_managed_platform_store->prefs()->SetString("homepage", |
797 dict->SetString("homepage", "some other changed homepage"); | 748 "some other changed homepage"); |
798 new_managed_platform_store->set_prefs(dict); | |
799 | 749 |
800 recorder.Clear(); | 750 recorder.Clear(); |
801 pref_value_store_->RefreshPolicyPrefsCompletion( | 751 pref_value_store_->RefreshPolicyPrefsCompletion( |
802 new_managed_platform_store.release(), | 752 new_managed_platform_store.release(), |
803 new TestingPrefStore(), | 753 NewConfigurationPolicyPrefStore(), |
804 new TestingPrefStore()); | 754 NewConfigurationPolicyPrefStore()); |
805 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); | 755 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
806 | 756 |
807 // Test properties that have been removed from the managed platform store. | 757 // Test properties that have been removed from the managed platform store. |
808 // Homepage is still set in managed prefs. | 758 // Homepage is still set in managed prefs. |
809 expected_differing_paths_.clear(); | 759 expected_differing_paths_.clear(); |
810 expected_differing_paths_.insert(prefs::kHomePage); | 760 expected_differing_paths_.insert(prefs::kHomePage); |
811 | 761 |
812 recorder.Clear(); | 762 recorder.Clear(); |
813 pref_value_store_->RefreshPolicyPrefsCompletion( | 763 pref_value_store_->RefreshPolicyPrefsCompletion( |
814 new TestingPrefStore(), | 764 NewConfigurationPolicyPrefStore(), |
815 new TestingPrefStore(), | 765 NewConfigurationPolicyPrefStore(), |
816 new TestingPrefStore()); | 766 NewConfigurationPolicyPrefStore()); |
817 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); | 767 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
818 | 768 |
819 // Test properties that are added to the device management store. | 769 // Test properties that are added to the device management store. |
820 expected_differing_paths_.clear(); | 770 expected_differing_paths_.clear(); |
821 expected_differing_paths_.insert(prefs::kHomePage); | 771 expected_differing_paths_.insert(prefs::kHomePage); |
822 scoped_ptr<TestingPrefStore> new_device_management_store( | 772 scoped_ptr<ConfigurationPolicyPrefStore> new_device_management_store( |
823 new TestingPrefStore()); | 773 NewConfigurationPolicyPrefStore()); |
824 dict = new DictionaryValue(); | 774 new_device_management_store->prefs()->SetString( |
825 dict->SetString("homepage", "some other changed homepage"); | 775 "homepage", "some other changed homepage"); |
826 new_device_management_store->set_prefs(dict); | |
827 | 776 |
828 recorder.Clear(); | 777 recorder.Clear(); |
829 pref_value_store_->RefreshPolicyPrefsCompletion( | 778 pref_value_store_->RefreshPolicyPrefsCompletion( |
830 new TestingPrefStore(), | 779 NewConfigurationPolicyPrefStore(), |
831 new_device_management_store.release(), | 780 new_device_management_store.release(), |
832 new TestingPrefStore()); | 781 NewConfigurationPolicyPrefStore()); |
833 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); | 782 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
834 | 783 |
835 // Test properties that are added to the recommended store. | 784 // Test properties that are added to the recommended store. |
836 scoped_ptr<TestingPrefStore> new_recommended_store(new TestingPrefStore()); | 785 scoped_ptr<ConfigurationPolicyPrefStore> new_recommended_store( |
837 dict = new DictionaryValue(); | 786 NewConfigurationPolicyPrefStore()); |
838 dict->SetString("homepage", "some other changed homepage 2"); | 787 new_recommended_store->prefs()->SetString("homepage", |
839 new_recommended_store->set_prefs(dict); | 788 "some other changed homepage 2"); |
840 expected_differing_paths_.clear(); | 789 expected_differing_paths_.clear(); |
841 expected_differing_paths_.insert(prefs::kHomePage); | 790 expected_differing_paths_.insert(prefs::kHomePage); |
842 | 791 |
843 recorder.Clear(); | 792 recorder.Clear(); |
844 pref_value_store_->RefreshPolicyPrefsCompletion( | 793 pref_value_store_->RefreshPolicyPrefsCompletion( |
845 new TestingPrefStore(), | 794 NewConfigurationPolicyPrefStore(), |
846 new TestingPrefStore(), | 795 NewConfigurationPolicyPrefStore(), |
847 new_recommended_store.release()); | 796 new_recommended_store.release()); |
848 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); | 797 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
849 | 798 |
850 // Test adding a multi-key path. | 799 // Test adding a multi-key path. |
851 new_managed_platform_store.reset(new TestingPrefStore()); | 800 new_managed_platform_store.reset(NewConfigurationPolicyPrefStore()); |
852 dict = new DictionaryValue(); | 801 new_managed_platform_store->prefs()->SetString("segment1.segment2", "value"); |
853 dict->SetString("segment1.segment2", "value"); | |
854 new_managed_platform_store->set_prefs(dict); | |
855 expected_differing_paths_.clear(); | 802 expected_differing_paths_.clear(); |
856 expected_differing_paths_.insert(prefs::kHomePage); | 803 expected_differing_paths_.insert(prefs::kHomePage); |
857 expected_differing_paths_.insert("segment1"); | 804 expected_differing_paths_.insert("segment1"); |
858 expected_differing_paths_.insert("segment1.segment2"); | 805 expected_differing_paths_.insert("segment1.segment2"); |
859 | 806 |
860 recorder.Clear(); | 807 recorder.Clear(); |
861 pref_value_store_->RefreshPolicyPrefsCompletion( | 808 pref_value_store_->RefreshPolicyPrefsCompletion( |
862 new_managed_platform_store.release(), | 809 new_managed_platform_store.release(), |
863 new TestingPrefStore(), | 810 NewConfigurationPolicyPrefStore(), |
864 new TestingPrefStore()); | 811 NewConfigurationPolicyPrefStore()); |
865 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); | 812 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
866 } | 813 } |
867 | 814 |
868 TEST_F(PrefValueStoreTest, TestConcurrentPolicyRefresh) { | 815 TEST_F(PrefValueStorePolicyRefreshTest, TestConcurrentPolicyRefresh) { |
869 PrefChangeRecorder recorder; | 816 PrefChangeRecorder recorder; |
870 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)) | 817 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)) |
871 .WillRepeatedly(Invoke(&recorder, &PrefChangeRecorder::Record)); | 818 .WillRepeatedly(Invoke(&recorder, &PrefChangeRecorder::Record)); |
872 | 819 |
873 BrowserThread::PostTask( | 820 BrowserThread::PostTask( |
874 BrowserThread::UI, FROM_HERE, | 821 BrowserThread::UI, FROM_HERE, |
875 NewRunnableMethod( | 822 NewRunnableMethod( |
876 pref_value_store_.get(), | 823 pref_value_store_.get(), |
877 &PrefValueStore::RefreshPolicyPrefs)); | 824 &PrefValueStore::RefreshPolicyPrefs)); |
878 | 825 |
879 BrowserThread::PostTask( | 826 BrowserThread::PostTask( |
880 BrowserThread::UI, FROM_HERE, | 827 BrowserThread::UI, FROM_HERE, |
881 NewRunnableMethod( | 828 NewRunnableMethod( |
882 pref_value_store_.get(), | 829 pref_value_store_.get(), |
883 &PrefValueStore::RefreshPolicyPrefs)); | 830 &PrefValueStore::RefreshPolicyPrefs)); |
884 | 831 |
885 BrowserThread::PostTask( | 832 BrowserThread::PostTask( |
886 BrowserThread::UI, FROM_HERE, | 833 BrowserThread::UI, FROM_HERE, |
887 NewRunnableMethod( | 834 NewRunnableMethod( |
888 pref_value_store_.get(), | 835 pref_value_store_.get(), |
889 &PrefValueStore::RefreshPolicyPrefs)); | 836 &PrefValueStore::RefreshPolicyPrefs)); |
890 | 837 |
891 loop_.RunAllPending(); | 838 loop_.RunAllPending(); |
892 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); | 839 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
893 } | 840 } |
OLD | NEW |