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> |
| 6 #include <string> |
| 7 |
5 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
6 #include "base/values.h" | 9 #include "base/values.h" |
7 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
8 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 11 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
9 #include "chrome/browser/prefs/dummy_pref_store.h" | 12 #include "chrome/browser/prefs/pref_notifier.h" |
10 #include "chrome/browser/prefs/pref_value_store.h" | 13 #include "chrome/browser/prefs/pref_value_store.h" |
| 14 #include "chrome/browser/prefs/testing_pref_store.h" |
11 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
12 #include "chrome/test/testing_pref_value_store.h" | |
13 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
15 | 18 |
16 using testing::_; | 19 using testing::_; |
| 20 using testing::AnyNumber; |
17 using testing::Mock; | 21 using testing::Mock; |
| 22 using testing::Invoke; |
18 | 23 |
19 namespace { | 24 namespace { |
20 | 25 |
21 class MockPolicyRefreshCallback { | 26 // Records preference changes. |
| 27 class PrefChangeRecorder { |
22 public: | 28 public: |
23 MockPolicyRefreshCallback() {} | 29 void Record(const std::string& pref_name) { |
24 MOCK_METHOD1(DoCallback, void(const std::vector<std::string>)); | 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. |
| 44 class MockPrefNotifier : public PrefNotifier { |
| 45 public: |
| 46 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&)); |
| 47 MOCK_METHOD0(OnInitializationCompleted, void()); |
25 }; | 48 }; |
26 | 49 |
27 } // namespace | 50 } // namespace |
28 | 51 |
29 // Names of the preferences used in this test program. | 52 // Names of the preferences used in this test program. |
30 namespace prefs { | 53 namespace prefs { |
31 const char kMissingPref[] = "this.pref.does_not_exist"; | 54 const char kMissingPref[] = "this.pref.does_not_exist"; |
32 const char kRecommendedPref[] = "this.pref.recommended_value_only"; | 55 const char kRecommendedPref[] = "this.pref.recommended_value_only"; |
33 const char kSampleDict[] = "sample.dict"; | 56 const char kSampleDict[] = "sample.dict"; |
34 const char kSampleList[] = "sample.list"; | 57 const char kSampleList[] = "sample.list"; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 99 |
77 namespace default_pref { | 100 namespace default_pref { |
78 const int kDefaultValue = 7; | 101 const int kDefaultValue = 7; |
79 const char kHomepageValue[] = "default homepage"; | 102 const char kHomepageValue[] = "default homepage"; |
80 const std::string kSearchProviderNameValue = "AreYouFeelingExtraLucky"; | 103 const std::string kSearchProviderNameValue = "AreYouFeelingExtraLucky"; |
81 } | 104 } |
82 | 105 |
83 class PrefValueStoreTest : public testing::Test { | 106 class PrefValueStoreTest : public testing::Test { |
84 protected: | 107 protected: |
85 virtual void SetUp() { | 108 virtual void SetUp() { |
86 // Create dummy user preferences. | 109 // Create TestingPrefStores. |
87 managed_platform_prefs_= CreateManagedPlatformPrefs(); | 110 CreateManagedPlatformPrefs(); |
88 device_management_prefs_ = CreateDeviceManagementPrefs(); | 111 CreateDeviceManagementPrefs(); |
89 extension_prefs_ = CreateExtensionPrefs(); | 112 CreateExtensionPrefs(); |
90 command_line_prefs_ = CreateCommandLinePrefs(); | 113 CreateCommandLinePrefs(); |
91 user_prefs_ = CreateUserPrefs(); | 114 CreateUserPrefs(); |
92 recommended_prefs_ = CreateRecommendedPrefs(); | 115 CreateRecommendedPrefs(); |
93 default_prefs_ = CreateDefaultPrefs(); | 116 CreateDefaultPrefs(); |
94 | |
95 std::sort(expected_differing_paths_.begin(), | |
96 expected_differing_paths_.end()); | |
97 | |
98 // Create |DummyPrefStore|s. | |
99 managed_platform_pref_store_ = new DummyPrefStore(); | |
100 managed_platform_pref_store_->set_prefs(managed_platform_prefs_); | |
101 device_management_pref_store_ = new DummyPrefStore(); | |
102 device_management_pref_store_->set_prefs(device_management_prefs_); | |
103 extension_pref_store_ = new DummyPrefStore(); | |
104 extension_pref_store_->set_prefs(extension_prefs_); | |
105 command_line_pref_store_ = new DummyPrefStore(); | |
106 command_line_pref_store_->set_prefs(command_line_prefs_); | |
107 user_pref_store_ = new DummyPrefStore(); | |
108 user_pref_store_->set_read_only(false); | |
109 user_pref_store_->set_prefs(user_prefs_); | |
110 recommended_pref_store_ = new DummyPrefStore(); | |
111 recommended_pref_store_->set_prefs(recommended_prefs_); | |
112 default_pref_store_ = new DummyPrefStore(); | |
113 default_pref_store_->set_prefs(default_prefs_); | |
114 | 117 |
115 // Create a new pref-value-store. | 118 // Create a new pref-value-store. |
116 pref_value_store_ = new TestingPrefValueStore( | 119 pref_value_store_ = new PrefValueStore( |
117 managed_platform_pref_store_, | 120 managed_platform_pref_store_, |
118 device_management_pref_store_, | 121 device_management_pref_store_, |
119 extension_pref_store_, | 122 extension_pref_store_, |
120 command_line_pref_store_, | 123 command_line_pref_store_, |
121 user_pref_store_, | 124 user_pref_store_, |
122 recommended_pref_store_, | 125 recommended_pref_store_, |
123 default_pref_store_); | 126 default_pref_store_, |
| 127 &pref_notifier_, |
| 128 NULL); |
124 | 129 |
125 // Register prefs with the PrefValueStore. | 130 // Register prefs with the PrefValueStore. |
126 pref_value_store_->RegisterPreferenceType(prefs::kApplicationLocale, | 131 pref_value_store_->RegisterPreferenceType(prefs::kApplicationLocale, |
127 Value::TYPE_STRING); | 132 Value::TYPE_STRING); |
128 pref_value_store_->RegisterPreferenceType(prefs::kCurrentThemeID, | 133 pref_value_store_->RegisterPreferenceType(prefs::kCurrentThemeID, |
129 Value::TYPE_STRING); | 134 Value::TYPE_STRING); |
130 pref_value_store_->RegisterPreferenceType( | 135 pref_value_store_->RegisterPreferenceType( |
131 prefs::kDefaultSearchProviderName, | 136 prefs::kDefaultSearchProviderName, |
132 Value::TYPE_STRING); | 137 Value::TYPE_STRING); |
133 pref_value_store_->RegisterPreferenceType(prefs::kDeleteCache, | 138 pref_value_store_->RegisterPreferenceType(prefs::kDeleteCache, |
(...skipping 12 matching lines...) Expand all Loading... |
146 Value::TYPE_INTEGER); | 151 Value::TYPE_INTEGER); |
147 pref_value_store_->RegisterPreferenceType(prefs::kProxyAutoDetect, | 152 pref_value_store_->RegisterPreferenceType(prefs::kProxyAutoDetect, |
148 Value::TYPE_BOOLEAN); | 153 Value::TYPE_BOOLEAN); |
149 | 154 |
150 ui_thread_.reset(new BrowserThread(BrowserThread::UI, &loop_)); | 155 ui_thread_.reset(new BrowserThread(BrowserThread::UI, &loop_)); |
151 file_thread_.reset(new BrowserThread(BrowserThread::FILE, &loop_)); | 156 file_thread_.reset(new BrowserThread(BrowserThread::FILE, &loop_)); |
152 } | 157 } |
153 | 158 |
154 // Creates a new dictionary and stores some sample user preferences | 159 // Creates a new dictionary and stores some sample user preferences |
155 // in it. | 160 // in it. |
156 DictionaryValue* CreateUserPrefs() { | 161 void CreateUserPrefs() { |
157 DictionaryValue* user_prefs = new DictionaryValue(); | 162 user_pref_store_ = new TestingPrefStore; |
158 user_prefs->SetBoolean(prefs::kDeleteCache, user_pref::kDeleteCacheValue); | 163 user_pref_store_->prefs()->SetBoolean(prefs::kDeleteCache, |
159 user_prefs->SetInteger(prefs::kStabilityLaunchCount, | 164 user_pref::kDeleteCacheValue); |
160 user_pref::kStabilityLaunchCountValue); | 165 user_pref_store_->prefs()->SetInteger(prefs::kStabilityLaunchCount, |
161 user_prefs->SetString(prefs::kCurrentThemeID, | 166 user_pref::kStabilityLaunchCountValue); |
| 167 user_pref_store_->prefs()->SetString(prefs::kCurrentThemeID, |
162 user_pref::kCurrentThemeIDValue); | 168 user_pref::kCurrentThemeIDValue); |
163 user_prefs->SetString(prefs::kApplicationLocale, | 169 user_pref_store_->prefs()->SetString(prefs::kApplicationLocale, |
164 user_pref::kApplicationLocaleValue); | 170 user_pref::kApplicationLocaleValue); |
165 user_prefs->SetString(prefs::kDefaultSearchProviderName, | 171 user_pref_store_->prefs()->SetString(prefs::kDefaultSearchProviderName, |
166 user_pref::kSearchProviderNameValue); | 172 user_pref::kSearchProviderNameValue); |
167 user_prefs->SetString(prefs::kHomePage, user_pref::kHomepageValue); | 173 user_pref_store_->prefs()->SetString(prefs::kHomePage, |
168 return user_prefs; | 174 user_pref::kHomepageValue); |
169 } | 175 } |
170 | 176 |
171 DictionaryValue* CreateManagedPlatformPrefs() { | 177 void CreateManagedPlatformPrefs() { |
172 DictionaryValue* managed_platform_prefs = new DictionaryValue(); | 178 managed_platform_pref_store_ = new TestingPrefStore; |
173 managed_platform_prefs->SetString( | 179 managed_platform_pref_store_->prefs()->SetString( |
174 prefs::kHomePage, | 180 prefs::kHomePage, |
175 managed_platform_pref::kHomepageValue); | 181 managed_platform_pref::kHomepageValue); |
176 expected_differing_paths_.push_back(prefs::kHomePage); | 182 expected_differing_paths_.insert(prefs::kHomePage); |
177 return managed_platform_prefs; | |
178 } | 183 } |
179 | 184 |
180 DictionaryValue* CreateDeviceManagementPrefs() { | 185 void CreateDeviceManagementPrefs() { |
181 DictionaryValue* device_management_prefs = new DictionaryValue(); | 186 device_management_pref_store_ = new TestingPrefStore; |
182 device_management_prefs->SetString( | 187 device_management_pref_store_->prefs()->SetString( |
183 prefs::kDefaultSearchProviderName, | 188 prefs::kDefaultSearchProviderName, |
184 device_management_pref::kSearchProviderNameValue); | 189 device_management_pref::kSearchProviderNameValue); |
185 expected_differing_paths_.push_back("default_search_provider"); | 190 expected_differing_paths_.insert("default_search_provider"); |
186 expected_differing_paths_.push_back(prefs::kDefaultSearchProviderName); | 191 expected_differing_paths_.insert(prefs::kDefaultSearchProviderName); |
187 device_management_prefs->SetString(prefs::kHomePage, | 192 device_management_pref_store_->prefs()->SetString(prefs::kHomePage, |
188 device_management_pref::kHomepageValue); | 193 device_management_pref::kHomepageValue); |
189 return device_management_prefs; | |
190 } | 194 } |
191 | 195 |
192 DictionaryValue* CreateExtensionPrefs() { | 196 void CreateExtensionPrefs() { |
193 DictionaryValue* extension_prefs = new DictionaryValue(); | 197 extension_pref_store_ = new TestingPrefStore; |
194 extension_prefs->SetString(prefs::kCurrentThemeID, | 198 extension_pref_store_->prefs()->SetString(prefs::kCurrentThemeID, |
195 extension_pref::kCurrentThemeIDValue); | 199 extension_pref::kCurrentThemeIDValue); |
196 extension_prefs->SetString(prefs::kHomePage, | 200 extension_pref_store_->prefs()->SetString(prefs::kHomePage, |
197 extension_pref::kHomepageValue); | 201 extension_pref::kHomepageValue); |
198 extension_prefs->SetString(prefs::kDefaultSearchProviderName, | 202 extension_pref_store_->prefs()->SetString(prefs::kDefaultSearchProviderName, |
199 extension_pref::kSearchProviderNameValue); | 203 extension_pref::kSearchProviderNameValue); |
200 return extension_prefs; | |
201 } | 204 } |
202 | 205 |
203 DictionaryValue* CreateCommandLinePrefs() { | 206 void CreateCommandLinePrefs() { |
204 DictionaryValue* command_line_prefs = new DictionaryValue(); | 207 command_line_pref_store_ = new TestingPrefStore; |
205 command_line_prefs->SetString(prefs::kCurrentThemeID, | 208 command_line_pref_store_->prefs()->SetString(prefs::kCurrentThemeID, |
206 command_line_pref::kCurrentThemeIDValue); | 209 command_line_pref::kCurrentThemeIDValue); |
207 command_line_prefs->SetString(prefs::kApplicationLocale, | 210 command_line_pref_store_->prefs()->SetString(prefs::kApplicationLocale, |
208 command_line_pref::kApplicationLocaleValue); | 211 command_line_pref::kApplicationLocaleValue); |
209 command_line_prefs->SetString(prefs::kHomePage, | 212 command_line_pref_store_->prefs()->SetString(prefs::kHomePage, |
210 command_line_pref::kHomepageValue); | 213 command_line_pref::kHomepageValue); |
211 command_line_prefs->SetString( | 214 command_line_pref_store_->prefs()->SetString( |
212 prefs::kDefaultSearchProviderName, | 215 prefs::kDefaultSearchProviderName, |
213 command_line_pref::kSearchProviderNameValue); | 216 command_line_pref::kSearchProviderNameValue); |
214 return command_line_prefs; | |
215 } | 217 } |
216 | 218 |
217 DictionaryValue* CreateRecommendedPrefs() { | 219 void CreateRecommendedPrefs() { |
218 DictionaryValue* recommended_prefs = new DictionaryValue(); | 220 recommended_pref_store_ = new TestingPrefStore; |
219 recommended_prefs->SetInteger(prefs::kStabilityLaunchCount, | 221 recommended_pref_store_->prefs()->SetInteger(prefs::kStabilityLaunchCount, |
220 recommended_pref::kStabilityLaunchCountValue); | 222 recommended_pref::kStabilityLaunchCountValue); |
221 recommended_prefs->SetBoolean( | 223 recommended_pref_store_->prefs()->SetBoolean( |
222 prefs::kRecommendedPref, | 224 prefs::kRecommendedPref, |
223 recommended_pref::kRecommendedPrefValue); | 225 recommended_pref::kRecommendedPrefValue); |
224 | 226 |
225 // Expected differing paths must be added in lexicographic order | 227 expected_differing_paths_.insert("this"); |
226 // to work properly | 228 expected_differing_paths_.insert("this.pref"); |
227 expected_differing_paths_.push_back("this"); | 229 expected_differing_paths_.insert(prefs::kRecommendedPref); |
228 expected_differing_paths_.push_back("this.pref"); | 230 expected_differing_paths_.insert("user_experience_metrics"); |
229 expected_differing_paths_.push_back(prefs::kRecommendedPref); | 231 expected_differing_paths_.insert("user_experience_metrics.stability"); |
230 expected_differing_paths_.push_back("user_experience_metrics"); | 232 expected_differing_paths_.insert(prefs::kStabilityLaunchCount); |
231 expected_differing_paths_.push_back("user_experience_metrics.stability"); | |
232 expected_differing_paths_.push_back(prefs::kStabilityLaunchCount); | |
233 return recommended_prefs; | |
234 } | 233 } |
235 | 234 |
236 DictionaryValue* CreateDefaultPrefs() { | 235 void CreateDefaultPrefs() { |
237 DictionaryValue* default_prefs = new DictionaryValue(); | 236 default_pref_store_ = new TestingPrefStore; |
238 default_prefs->SetInteger(prefs::kDefaultPref, default_pref::kDefaultValue); | 237 default_pref_store_->prefs()->SetInteger(prefs::kDefaultPref, |
239 return default_prefs; | 238 default_pref::kDefaultValue); |
240 } | 239 } |
241 | 240 |
242 DictionaryValue* CreateSampleDictValue() { | 241 DictionaryValue* CreateSampleDictValue() { |
243 DictionaryValue* sample_dict = new DictionaryValue(); | 242 DictionaryValue* sample_dict = new DictionaryValue(); |
244 sample_dict->SetBoolean("issample", true); | 243 sample_dict->SetBoolean("issample", true); |
245 sample_dict->SetInteger("value", 4); | 244 sample_dict->SetInteger("value", 4); |
246 sample_dict->SetString("descr", "Sample Test Dictionary"); | 245 sample_dict->SetString("descr", "Sample Test Dictionary"); |
247 return sample_dict; | 246 return sample_dict; |
248 } | 247 } |
249 | 248 |
250 ListValue* CreateSampleListValue() { | 249 ListValue* CreateSampleListValue() { |
251 ListValue* sample_list = new ListValue(); | 250 ListValue* sample_list = new ListValue(); |
252 sample_list->Set(0, Value::CreateIntegerValue(0)); | 251 sample_list->Set(0, Value::CreateIntegerValue(0)); |
253 sample_list->Set(1, Value::CreateIntegerValue(1)); | 252 sample_list->Set(1, Value::CreateIntegerValue(1)); |
254 sample_list->Set(2, Value::CreateIntegerValue(2)); | 253 sample_list->Set(2, Value::CreateIntegerValue(2)); |
255 sample_list->Set(3, Value::CreateIntegerValue(3)); | 254 sample_list->Set(3, Value::CreateIntegerValue(3)); |
256 return sample_list; | 255 return sample_list; |
257 } | 256 } |
258 | 257 |
259 virtual void TearDown() { | 258 virtual void TearDown() { |
260 loop_.RunAllPending(); | 259 loop_.RunAllPending(); |
261 } | 260 } |
262 | 261 |
263 MessageLoop loop_; | 262 MessageLoop loop_; |
264 | 263 MockPrefNotifier pref_notifier_; |
265 scoped_refptr<TestingPrefValueStore> pref_value_store_; | 264 scoped_refptr<PrefValueStore> pref_value_store_; |
266 | 265 |
267 // |PrefStore|s are owned by the |PrefValueStore|. | 266 // |PrefStore|s are owned by the |PrefValueStore|. |
268 DummyPrefStore* managed_platform_pref_store_; | 267 TestingPrefStore* managed_platform_pref_store_; |
269 DummyPrefStore* device_management_pref_store_; | 268 TestingPrefStore* device_management_pref_store_; |
270 DummyPrefStore* extension_pref_store_; | 269 TestingPrefStore* extension_pref_store_; |
271 DummyPrefStore* command_line_pref_store_; | 270 TestingPrefStore* command_line_pref_store_; |
272 DummyPrefStore* user_pref_store_; | 271 TestingPrefStore* user_pref_store_; |
273 DummyPrefStore* recommended_pref_store_; | 272 TestingPrefStore* recommended_pref_store_; |
274 DummyPrefStore* default_pref_store_; | 273 TestingPrefStore* default_pref_store_; |
275 | 274 |
276 // A vector of the preferences paths in the managed and recommended | 275 // A vector of the preferences paths in the managed and recommended |
277 // PrefStores that are set at the beginning of a test. Can be modified | 276 // PrefStores that are set at the beginning of a test. Can be modified |
278 // by the test to track changes that it makes to the preferences | 277 // by the test to track changes that it makes to the preferences |
279 // stored in the managed and recommended PrefStores. | 278 // stored in the managed and recommended PrefStores. |
280 std::vector<std::string> expected_differing_paths_; | 279 std::set<std::string> expected_differing_paths_; |
281 | |
282 // Preferences are owned by the individual |DummyPrefStores|. | |
283 DictionaryValue* managed_platform_prefs_; | |
284 DictionaryValue* device_management_prefs_; | |
285 DictionaryValue* extension_prefs_; | |
286 DictionaryValue* command_line_prefs_; | |
287 DictionaryValue* user_prefs_; | |
288 DictionaryValue* recommended_prefs_; | |
289 DictionaryValue* default_prefs_; | |
290 | 280 |
291 private: | 281 private: |
292 scoped_ptr<BrowserThread> ui_thread_; | 282 scoped_ptr<BrowserThread> ui_thread_; |
293 scoped_ptr<BrowserThread> file_thread_; | 283 scoped_ptr<BrowserThread> file_thread_; |
294 }; | 284 }; |
295 | 285 |
296 TEST_F(PrefValueStoreTest, IsReadOnly) { | 286 TEST_F(PrefValueStoreTest, IsReadOnly) { |
297 managed_platform_pref_store_->set_read_only(true); | 287 managed_platform_pref_store_->set_read_only(true); |
298 extension_pref_store_->set_read_only(true); | 288 extension_pref_store_->set_read_only(true); |
299 command_line_pref_store_->set_read_only(true); | 289 command_line_pref_store_->set_read_only(true); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 // User preference | 410 // User preference |
421 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kDeleteCache)); | 411 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kDeleteCache)); |
422 // Recommended preference | 412 // Recommended preference |
423 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref)); | 413 EXPECT_TRUE(pref_value_store_->HasPrefPath(prefs::kRecommendedPref)); |
424 // Default preference | 414 // Default preference |
425 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref)); | 415 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDefaultPref)); |
426 // Unknown preference | 416 // Unknown preference |
427 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); | 417 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kMissingPref)); |
428 } | 418 } |
429 | 419 |
430 TEST_F(PrefValueStoreTest, PrefHasChanged) { | 420 TEST_F(PrefValueStoreTest, PrefChanges) { |
431 // Setup. | 421 // Setup. |
432 const char managed_platform_pref_path[] = "managed_platform_pref"; | 422 const char managed_platform_pref_path[] = "managed_platform_pref"; |
433 pref_value_store_->RegisterPreferenceType(managed_platform_pref_path, | 423 pref_value_store_->RegisterPreferenceType(managed_platform_pref_path, |
434 Value::TYPE_STRING); | 424 Value::TYPE_STRING); |
435 managed_platform_pref_store_->prefs()->SetString(managed_platform_pref_path, | 425 managed_platform_pref_store_->prefs()->SetString(managed_platform_pref_path, |
436 "managed value"); | 426 "managed value"); |
437 const char user_pref_path[] = "user_pref"; | 427 const char user_pref_path[] = "user_pref"; |
438 pref_value_store_->RegisterPreferenceType(user_pref_path, Value::TYPE_STRING); | 428 pref_value_store_->RegisterPreferenceType(user_pref_path, Value::TYPE_STRING); |
439 user_pref_store_->prefs()->SetString(user_pref_path, "user value"); | 429 user_pref_store_->prefs()->SetString(user_pref_path, "user value"); |
440 const char default_pref_path[] = "default_pref"; | 430 const char default_pref_path[] = "default_pref"; |
441 pref_value_store_->RegisterPreferenceType(default_pref_path, | 431 pref_value_store_->RegisterPreferenceType(default_pref_path, |
442 Value::TYPE_STRING); | 432 Value::TYPE_STRING); |
443 default_pref_store_->prefs()->SetString(default_pref_path, "default value"); | 433 default_pref_store_->prefs()->SetString(default_pref_path, "default value"); |
444 | 434 |
445 // Check pref controlled by highest-priority store. | 435 // Check pref controlled by highest-priority store. |
446 EXPECT_TRUE(pref_value_store_->PrefHasChanged(managed_platform_pref_path, | 436 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(managed_platform_pref_path)); |
447 static_cast<PrefNotifier::PrefStoreType>(0))); | 437 managed_platform_pref_store_->NotifyPrefValueChanged( |
448 EXPECT_FALSE(pref_value_store_->PrefHasChanged(managed_platform_pref_path, | 438 managed_platform_pref_path); |
449 PrefNotifier::USER_STORE)); | 439 Mock::VerifyAndClearExpectations(&pref_notifier_); |
| 440 |
| 441 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(0); |
| 442 user_pref_store_->NotifyPrefValueChanged(managed_platform_pref_path); |
| 443 Mock::VerifyAndClearExpectations(&pref_notifier_); |
450 | 444 |
451 // Check pref controlled by user store. | 445 // Check pref controlled by user store. |
452 EXPECT_TRUE(pref_value_store_->PrefHasChanged(user_pref_path, | 446 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(user_pref_path)); |
453 static_cast<PrefNotifier::PrefStoreType>(0))); | 447 managed_platform_pref_store_->NotifyPrefValueChanged(user_pref_path); |
454 EXPECT_TRUE(pref_value_store_->PrefHasChanged(user_pref_path, | 448 Mock::VerifyAndClearExpectations(&pref_notifier_); |
455 PrefNotifier::USER_STORE)); | 449 |
456 EXPECT_FALSE(pref_value_store_->PrefHasChanged(user_pref_path, | 450 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(user_pref_path)); |
457 PrefNotifier::PREF_STORE_TYPE_MAX)); | 451 user_pref_store_->NotifyPrefValueChanged(user_pref_path); |
| 452 Mock::VerifyAndClearExpectations(&pref_notifier_); |
| 453 |
| 454 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(0); |
| 455 default_pref_store_->NotifyPrefValueChanged(user_pref_path); |
| 456 Mock::VerifyAndClearExpectations(&pref_notifier_); |
458 | 457 |
459 // Check pref controlled by default-pref store. | 458 // Check pref controlled by default-pref store. |
460 EXPECT_TRUE(pref_value_store_->PrefHasChanged(default_pref_path, | 459 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(default_pref_path)); |
461 PrefNotifier::USER_STORE)); | 460 user_pref_store_->NotifyPrefValueChanged(default_pref_path); |
462 EXPECT_TRUE(pref_value_store_->PrefHasChanged(default_pref_path, | 461 Mock::VerifyAndClearExpectations(&pref_notifier_); |
463 PrefNotifier::DEFAULT_STORE)); | 462 |
| 463 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(default_pref_path)); |
| 464 default_pref_store_->NotifyPrefValueChanged(default_pref_path); |
| 465 Mock::VerifyAndClearExpectations(&pref_notifier_); |
| 466 } |
| 467 |
| 468 TEST_F(PrefValueStoreTest, OnInitializationCompleted) { |
| 469 EXPECT_CALL(pref_notifier_, OnInitializationCompleted()).Times(0); |
| 470 managed_platform_pref_store_->SetInitializationCompleted(); |
| 471 device_management_pref_store_->SetInitializationCompleted(); |
| 472 extension_pref_store_->SetInitializationCompleted(); |
| 473 command_line_pref_store_->SetInitializationCompleted(); |
| 474 recommended_pref_store_->SetInitializationCompleted(); |
| 475 default_pref_store_->SetInitializationCompleted(); |
| 476 Mock::VerifyAndClearExpectations(&pref_notifier_); |
| 477 |
| 478 // The notification should only be triggered after the last store is done. |
| 479 EXPECT_CALL(pref_notifier_, OnInitializationCompleted()).Times(1); |
| 480 user_pref_store_->SetInitializationCompleted(); |
| 481 Mock::VerifyAndClearExpectations(&pref_notifier_); |
464 } | 482 } |
465 | 483 |
466 TEST_F(PrefValueStoreTest, ReadPrefs) { | 484 TEST_F(PrefValueStoreTest, ReadPrefs) { |
467 pref_value_store_->ReadPrefs(); | 485 pref_value_store_->ReadPrefs(); |
468 // The ReadPrefs method of the |DummyPrefStore| deletes the |pref_store|s | 486 // The ReadPrefs method of the |TestingPrefStore| deletes the |pref_store|s |
469 // internal dictionary and creates a new empty dictionary. Hence this | 487 // internal dictionary and creates a new empty dictionary. Hence this |
470 // dictionary does not contain any of the preloaded preferences. | 488 // dictionary does not contain any of the preloaded preferences. |
471 // This shows that the ReadPrefs method of the |DummyPrefStore| was called. | 489 // This shows that the ReadPrefs method of the |TestingPrefStore| was called. |
472 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDeleteCache)); | 490 EXPECT_FALSE(pref_value_store_->HasPrefPath(prefs::kDeleteCache)); |
473 } | 491 } |
474 | 492 |
475 TEST_F(PrefValueStoreTest, WritePrefs) { | 493 TEST_F(PrefValueStoreTest, WritePrefs) { |
476 user_pref_store_->set_prefs_written(false); | 494 user_pref_store_->set_prefs_written(false); |
477 pref_value_store_->WritePrefs(); | 495 pref_value_store_->WritePrefs(); |
478 ASSERT_TRUE(user_pref_store_->get_prefs_written()); | 496 ASSERT_TRUE(user_pref_store_->get_prefs_written()); |
479 } | 497 } |
480 | 498 |
481 TEST_F(PrefValueStoreTest, SetUserPrefValue) { | 499 TEST_F(PrefValueStoreTest, SetUserPrefValue) { |
482 Value* new_value = NULL; | 500 Value* new_value = NULL; |
483 Value* actual_value = NULL; | 501 Value* actual_value = NULL; |
484 | 502 |
485 // Test that managed platform values can not be set. | 503 // Test that managed platform values can not be set. |
| 504 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(0); |
486 ASSERT_TRUE(pref_value_store_->PrefValueInManagedPlatformStore( | 505 ASSERT_TRUE(pref_value_store_->PrefValueInManagedPlatformStore( |
487 prefs::kHomePage)); | 506 prefs::kHomePage)); |
488 // The Ownership is tranfered to |PrefValueStore|. | 507 // The ownership is transfered to PrefValueStore. |
489 new_value = Value::CreateStringValue("http://www.youtube.com"); | 508 new_value = Value::CreateStringValue("http://www.youtube.com"); |
490 pref_value_store_->SetUserPrefValue(prefs::kHomePage, new_value); | 509 pref_value_store_->SetUserPrefValue(prefs::kHomePage, new_value); |
| 510 Mock::VerifyAndClearExpectations(&pref_notifier_); |
491 | 511 |
492 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &actual_value)); | 512 ASSERT_TRUE(pref_value_store_->GetValue(prefs::kHomePage, &actual_value)); |
493 std::string value_str; | 513 std::string value_str; |
494 actual_value->GetAsString(&value_str); | 514 actual_value->GetAsString(&value_str); |
495 ASSERT_EQ(managed_platform_pref::kHomepageValue, value_str); | 515 ASSERT_EQ(managed_platform_pref::kHomepageValue, value_str); |
496 | 516 |
497 // User preferences values can be set | 517 // User preferences values can be set. |
498 ASSERT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore( | 518 ASSERT_FALSE(pref_value_store_->PrefValueInManagedPlatformStore( |
499 prefs::kStabilityLaunchCount)); | 519 prefs::kStabilityLaunchCount)); |
500 actual_value = NULL; | 520 actual_value = NULL; |
501 pref_value_store_->GetValue(prefs::kStabilityLaunchCount, &actual_value); | 521 pref_value_store_->GetValue(prefs::kStabilityLaunchCount, &actual_value); |
502 int int_value; | 522 int int_value; |
503 EXPECT_TRUE(actual_value->GetAsInteger(&int_value)); | 523 EXPECT_TRUE(actual_value->GetAsInteger(&int_value)); |
504 EXPECT_EQ(user_pref::kStabilityLaunchCountValue, int_value); | 524 EXPECT_EQ(user_pref::kStabilityLaunchCountValue, int_value); |
505 | 525 |
| 526 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(1); |
506 new_value = Value::CreateIntegerValue(1); | 527 new_value = Value::CreateIntegerValue(1); |
507 pref_value_store_->SetUserPrefValue(prefs::kStabilityLaunchCount, new_value); | 528 pref_value_store_->SetUserPrefValue(prefs::kStabilityLaunchCount, new_value); |
508 actual_value = NULL; | 529 actual_value = NULL; |
509 pref_value_store_->GetValue(prefs::kStabilityLaunchCount, &actual_value); | 530 pref_value_store_->GetValue(prefs::kStabilityLaunchCount, &actual_value); |
510 EXPECT_TRUE(new_value->Equals(actual_value)); | 531 EXPECT_TRUE(new_value->Equals(actual_value)); |
| 532 Mock::VerifyAndClearExpectations(&pref_notifier_); |
511 | 533 |
512 // Set and Get |DictionaryValue| | 534 // Set and Get DictionaryValue. |
| 535 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(1); |
513 DictionaryValue* expected_dict_value = CreateSampleDictValue(); | 536 DictionaryValue* expected_dict_value = CreateSampleDictValue(); |
514 pref_value_store_->SetUserPrefValue(prefs::kSampleDict, expected_dict_value); | 537 pref_value_store_->SetUserPrefValue(prefs::kSampleDict, expected_dict_value); |
| 538 Mock::VerifyAndClearExpectations(&pref_notifier_); |
515 | 539 |
516 actual_value = NULL; | 540 actual_value = NULL; |
517 std::string key(prefs::kSampleDict); | 541 std::string key(prefs::kSampleDict); |
518 pref_value_store_->GetValue(key, &actual_value); | 542 pref_value_store_->GetValue(key, &actual_value); |
519 | 543 |
520 ASSERT_EQ(expected_dict_value, actual_value); | 544 ASSERT_EQ(expected_dict_value, actual_value); |
521 ASSERT_TRUE(expected_dict_value->Equals(actual_value)); | 545 ASSERT_TRUE(expected_dict_value->Equals(actual_value)); |
522 | 546 |
523 // Set and Get a |ListValue| | 547 // Set and Get a ListValue. |
| 548 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)).Times(1); |
524 ListValue* expected_list_value = CreateSampleListValue(); | 549 ListValue* expected_list_value = CreateSampleListValue(); |
525 pref_value_store_->SetUserPrefValue(prefs::kSampleList, expected_list_value); | 550 pref_value_store_->SetUserPrefValue(prefs::kSampleList, expected_list_value); |
| 551 Mock::VerifyAndClearExpectations(&pref_notifier_); |
526 | 552 |
527 actual_value = NULL; | 553 actual_value = NULL; |
528 key = prefs::kSampleList; | 554 key = prefs::kSampleList; |
529 pref_value_store_->GetValue(key, &actual_value); | 555 pref_value_store_->GetValue(key, &actual_value); |
530 | 556 |
531 ASSERT_EQ(expected_list_value, actual_value); | 557 ASSERT_EQ(expected_list_value, actual_value); |
532 ASSERT_TRUE(expected_list_value->Equals(actual_value)); | 558 ASSERT_TRUE(expected_list_value->Equals(actual_value)); |
533 } | 559 } |
534 | 560 |
535 TEST_F(PrefValueStoreTest, PrefValueInManagedPlatformStore) { | 561 TEST_F(PrefValueStoreTest, PrefValueInManagedPlatformStore) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 prefs::kMissingPref)); | 659 prefs::kMissingPref)); |
634 } | 660 } |
635 | 661 |
636 TEST_F(PrefValueStoreTest, DetectProxyConfigurationConflict) { | 662 TEST_F(PrefValueStoreTest, DetectProxyConfigurationConflict) { |
637 // There should be no conflicting proxy prefs in the default | 663 // There should be no conflicting proxy prefs in the default |
638 // preference stores created for the test. | 664 // preference stores created for the test. |
639 ASSERT_FALSE(pref_value_store_->HasPolicyConflictingUserProxySettings()); | 665 ASSERT_FALSE(pref_value_store_->HasPolicyConflictingUserProxySettings()); |
640 | 666 |
641 // Create conflicting proxy settings in the managed and command-line | 667 // Create conflicting proxy settings in the managed and command-line |
642 // preference stores. | 668 // preference stores. |
643 command_line_prefs_->SetBoolean(prefs::kProxyAutoDetect, false); | 669 command_line_pref_store_->prefs()->SetBoolean(prefs::kProxyAutoDetect, false); |
644 managed_platform_prefs_->SetBoolean(prefs::kProxyAutoDetect, true); | 670 managed_platform_pref_store_->prefs()->SetBoolean(prefs::kProxyAutoDetect, |
| 671 true); |
645 ASSERT_TRUE(pref_value_store_->HasPolicyConflictingUserProxySettings()); | 672 ASSERT_TRUE(pref_value_store_->HasPolicyConflictingUserProxySettings()); |
646 } | 673 } |
647 | 674 |
648 TEST_F(PrefValueStoreTest, PrefValueInUserStore) { | 675 TEST_F(PrefValueStoreTest, PrefValueInUserStore) { |
649 // Test a managed platform preference. | 676 // Test a managed platform preference. |
650 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage)); | 677 ASSERT_TRUE(pref_value_store_->HasPrefPath(prefs::kHomePage)); |
651 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(prefs::kHomePage)); | 678 EXPECT_TRUE(pref_value_store_->PrefValueInUserStore(prefs::kHomePage)); |
652 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kHomePage)); | 679 EXPECT_FALSE(pref_value_store_->PrefValueFromUserStore(prefs::kHomePage)); |
653 | 680 |
654 // Test a device management preference. | 681 // Test a device management preference. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 EXPECT_FALSE( | 766 EXPECT_FALSE( |
740 pref_value_store_->PrefValueFromDefaultStore(prefs::kMissingPref)); | 767 pref_value_store_->PrefValueFromDefaultStore(prefs::kMissingPref)); |
741 } | 768 } |
742 | 769 |
743 TEST_F(PrefValueStoreTest, TestPolicyRefresh) { | 770 TEST_F(PrefValueStoreTest, TestPolicyRefresh) { |
744 // pref_value_store_ is initialized by PrefValueStoreTest to have values in | 771 // pref_value_store_ is initialized by PrefValueStoreTest to have values in |
745 // the managed platform, device management and recommended stores. By | 772 // the managed platform, device management and recommended stores. By |
746 // replacing them with dummy stores, all of the paths of the prefs originally | 773 // replacing them with dummy stores, all of the paths of the prefs originally |
747 // in the managed platform, device management and recommended stores should | 774 // in the managed platform, device management and recommended stores should |
748 // change. | 775 // change. |
749 MockPolicyRefreshCallback callback; | 776 pref_value_store_->RefreshPolicyPrefs(); |
750 EXPECT_CALL(callback, DoCallback(_)).Times(0); | 777 |
| 778 PrefChangeRecorder recorder; |
| 779 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)) |
| 780 .WillRepeatedly(Invoke(&recorder, &PrefChangeRecorder::Record)); |
| 781 loop_.RunAllPending(); |
| 782 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
| 783 } |
| 784 |
| 785 TEST_F(PrefValueStoreTest, TestRefreshPolicyPrefsCompletion) { |
| 786 PrefChangeRecorder recorder; |
| 787 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)) |
| 788 .WillRepeatedly(Invoke(&recorder, &PrefChangeRecorder::Record)); |
| 789 |
| 790 // Test changed preferences in the managed platform store and removed |
| 791 // 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 |
| 793 // DummyStore. |
| 794 scoped_ptr<TestingPrefStore> new_managed_platform_store( |
| 795 new TestingPrefStore()); |
| 796 DictionaryValue* dict = new DictionaryValue(); |
| 797 dict->SetString("homepage", "some other changed homepage"); |
| 798 new_managed_platform_store->set_prefs(dict); |
| 799 |
| 800 recorder.Clear(); |
| 801 pref_value_store_->RefreshPolicyPrefsCompletion( |
| 802 new_managed_platform_store.release(), |
| 803 new TestingPrefStore(), |
| 804 new TestingPrefStore()); |
| 805 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
| 806 |
| 807 // Test properties that have been removed from the managed platform store. |
| 808 // Homepage is still set in managed prefs. |
| 809 expected_differing_paths_.clear(); |
| 810 expected_differing_paths_.insert(prefs::kHomePage); |
| 811 |
| 812 recorder.Clear(); |
| 813 pref_value_store_->RefreshPolicyPrefsCompletion( |
| 814 new TestingPrefStore(), |
| 815 new TestingPrefStore(), |
| 816 new TestingPrefStore()); |
| 817 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
| 818 |
| 819 // Test properties that are added to the device management store. |
| 820 expected_differing_paths_.clear(); |
| 821 expected_differing_paths_.insert(prefs::kHomePage); |
| 822 scoped_ptr<TestingPrefStore> new_device_management_store( |
| 823 new TestingPrefStore()); |
| 824 dict = new DictionaryValue(); |
| 825 dict->SetString("homepage", "some other changed homepage"); |
| 826 new_device_management_store->set_prefs(dict); |
| 827 |
| 828 recorder.Clear(); |
| 829 pref_value_store_->RefreshPolicyPrefsCompletion( |
| 830 new TestingPrefStore(), |
| 831 new_device_management_store.release(), |
| 832 new TestingPrefStore()); |
| 833 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
| 834 |
| 835 // Test properties that are added to the recommended store. |
| 836 scoped_ptr<TestingPrefStore> new_recommended_store(new TestingPrefStore()); |
| 837 dict = new DictionaryValue(); |
| 838 dict->SetString("homepage", "some other changed homepage 2"); |
| 839 new_recommended_store->set_prefs(dict); |
| 840 expected_differing_paths_.clear(); |
| 841 expected_differing_paths_.insert(prefs::kHomePage); |
| 842 |
| 843 recorder.Clear(); |
| 844 pref_value_store_->RefreshPolicyPrefsCompletion( |
| 845 new TestingPrefStore(), |
| 846 new TestingPrefStore(), |
| 847 new_recommended_store.release()); |
| 848 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
| 849 |
| 850 // Test adding a multi-key path. |
| 851 new_managed_platform_store.reset(new TestingPrefStore()); |
| 852 dict = new DictionaryValue(); |
| 853 dict->SetString("segment1.segment2", "value"); |
| 854 new_managed_platform_store->set_prefs(dict); |
| 855 expected_differing_paths_.clear(); |
| 856 expected_differing_paths_.insert(prefs::kHomePage); |
| 857 expected_differing_paths_.insert("segment1"); |
| 858 expected_differing_paths_.insert("segment1.segment2"); |
| 859 |
| 860 recorder.Clear(); |
| 861 pref_value_store_->RefreshPolicyPrefsCompletion( |
| 862 new_managed_platform_store.release(), |
| 863 new TestingPrefStore(), |
| 864 new TestingPrefStore()); |
| 865 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
| 866 } |
| 867 |
| 868 TEST_F(PrefValueStoreTest, TestConcurrentPolicyRefresh) { |
| 869 PrefChangeRecorder recorder; |
| 870 EXPECT_CALL(pref_notifier_, OnPreferenceChanged(_)) |
| 871 .WillRepeatedly(Invoke(&recorder, &PrefChangeRecorder::Record)); |
| 872 |
751 BrowserThread::PostTask( | 873 BrowserThread::PostTask( |
752 BrowserThread::UI, FROM_HERE, | 874 BrowserThread::UI, FROM_HERE, |
753 NewRunnableMethod( | 875 NewRunnableMethod( |
754 pref_value_store_.get(), | 876 pref_value_store_.get(), |
755 &PrefValueStore::RefreshPolicyPrefs, | 877 &PrefValueStore::RefreshPolicyPrefs)); |
756 NewCallback(&callback, | |
757 &MockPolicyRefreshCallback::DoCallback))); | |
758 Mock::VerifyAndClearExpectations(&callback); | |
759 EXPECT_CALL(callback, DoCallback(expected_differing_paths_)).Times(1); | |
760 loop_.RunAllPending(); | |
761 } | |
762 | 878 |
763 TEST_F(PrefValueStoreTest, TestRefreshPolicyPrefsCompletion) { | |
764 // Test changed preferences in the managed platform store and removed | |
765 // preferences in the recommended store. In addition to "homepage", the other | |
766 // prefs that are set by default in the test class are removed by the | |
767 // DummyStore. | |
768 scoped_ptr<DummyPrefStore> new_managed_platform_store(new DummyPrefStore()); | |
769 DictionaryValue* dict = new DictionaryValue(); | |
770 dict->SetString("homepage", "some other changed homepage"); | |
771 new_managed_platform_store->set_prefs(dict); | |
772 MockPolicyRefreshCallback callback; | |
773 EXPECT_CALL(callback, DoCallback(expected_differing_paths_)).Times(1); | |
774 pref_value_store_->RefreshPolicyPrefsCompletion( | |
775 new_managed_platform_store.release(), | |
776 new DummyPrefStore(), | |
777 new DummyPrefStore(), | |
778 NewCallback(&callback, | |
779 &MockPolicyRefreshCallback::DoCallback)); | |
780 | |
781 // Test properties that have been removed from the managed platform store. | |
782 // Homepage is still set in managed prefs. | |
783 expected_differing_paths_.clear(); | |
784 expected_differing_paths_.push_back(std::string("homepage")); | |
785 MockPolicyRefreshCallback callback2; | |
786 EXPECT_CALL(callback2, DoCallback(expected_differing_paths_)).Times(1); | |
787 pref_value_store_->RefreshPolicyPrefsCompletion( | |
788 new DummyPrefStore(), | |
789 new DummyPrefStore(), | |
790 new DummyPrefStore(), | |
791 NewCallback(&callback2, | |
792 &MockPolicyRefreshCallback::DoCallback)); | |
793 | |
794 // Test properties that are added to the device management store. | |
795 expected_differing_paths_.clear(); | |
796 expected_differing_paths_.push_back(std::string("homepage")); | |
797 scoped_ptr<DummyPrefStore> new_device_management_store( | |
798 new DummyPrefStore()); | |
799 dict = new DictionaryValue(); | |
800 dict->SetString("homepage", "some other changed homepage"); | |
801 new_device_management_store->set_prefs(dict); | |
802 MockPolicyRefreshCallback callback3; | |
803 EXPECT_CALL(callback3, DoCallback(expected_differing_paths_)).Times(1); | |
804 pref_value_store_->RefreshPolicyPrefsCompletion( | |
805 new DummyPrefStore(), | |
806 new_device_management_store.release(), | |
807 new DummyPrefStore(), | |
808 NewCallback(&callback3, | |
809 &MockPolicyRefreshCallback::DoCallback)); | |
810 | |
811 // Test properties that are added to the recommended store. | |
812 scoped_ptr<DummyPrefStore> new_recommended_store(new DummyPrefStore()); | |
813 dict = new DictionaryValue(); | |
814 dict->SetString("homepage", "some other changed homepage 2"); | |
815 new_recommended_store->set_prefs(dict); | |
816 expected_differing_paths_.clear(); | |
817 expected_differing_paths_.push_back(std::string("homepage")); | |
818 MockPolicyRefreshCallback callback4; | |
819 EXPECT_CALL(callback4, DoCallback(expected_differing_paths_)).Times(1); | |
820 pref_value_store_->RefreshPolicyPrefsCompletion( | |
821 new DummyPrefStore(), | |
822 new DummyPrefStore(), | |
823 new_recommended_store.release(), | |
824 NewCallback(&callback4, | |
825 &MockPolicyRefreshCallback::DoCallback)); | |
826 | |
827 // Test adding a multi-key path. | |
828 new_managed_platform_store.reset(new DummyPrefStore()); | |
829 dict = new DictionaryValue(); | |
830 dict->SetString("segment1.segment2", "value"); | |
831 new_managed_platform_store->set_prefs(dict); | |
832 expected_differing_paths_.clear(); | |
833 expected_differing_paths_.push_back(std::string("homepage")); | |
834 expected_differing_paths_.push_back(std::string("segment1")); | |
835 expected_differing_paths_.push_back(std::string("segment1.segment2")); | |
836 MockPolicyRefreshCallback callback5; | |
837 EXPECT_CALL(callback5, DoCallback(expected_differing_paths_)).Times(1); | |
838 pref_value_store_->RefreshPolicyPrefsCompletion( | |
839 new_managed_platform_store.release(), | |
840 new DummyPrefStore(), | |
841 new DummyPrefStore(), | |
842 NewCallback(&callback5, | |
843 &MockPolicyRefreshCallback::DoCallback)); | |
844 } | |
845 | |
846 TEST_F(PrefValueStoreTest, TestConcurrentPolicyRefresh) { | |
847 MockPolicyRefreshCallback callback1; | |
848 BrowserThread::PostTask( | 879 BrowserThread::PostTask( |
849 BrowserThread::UI, FROM_HERE, | 880 BrowserThread::UI, FROM_HERE, |
850 NewRunnableMethod( | 881 NewRunnableMethod( |
851 pref_value_store_.get(), | 882 pref_value_store_.get(), |
852 &PrefValueStore::RefreshPolicyPrefs, | 883 &PrefValueStore::RefreshPolicyPrefs)); |
853 NewCallback(&callback1, | |
854 &MockPolicyRefreshCallback::DoCallback))); | |
855 EXPECT_CALL(callback1, DoCallback(_)).Times(0); | |
856 | 884 |
857 MockPolicyRefreshCallback callback2; | |
858 BrowserThread::PostTask( | 885 BrowserThread::PostTask( |
859 BrowserThread::UI, FROM_HERE, | 886 BrowserThread::UI, FROM_HERE, |
860 NewRunnableMethod( | 887 NewRunnableMethod( |
861 pref_value_store_.get(), | 888 pref_value_store_.get(), |
862 &PrefValueStore::RefreshPolicyPrefs, | 889 &PrefValueStore::RefreshPolicyPrefs)); |
863 NewCallback(&callback2, | |
864 &MockPolicyRefreshCallback::DoCallback))); | |
865 EXPECT_CALL(callback2, DoCallback(_)).Times(0); | |
866 | 890 |
867 MockPolicyRefreshCallback callback3; | |
868 BrowserThread::PostTask( | |
869 BrowserThread::UI, FROM_HERE, | |
870 NewRunnableMethod( | |
871 pref_value_store_.get(), | |
872 &PrefValueStore::RefreshPolicyPrefs, | |
873 NewCallback(&callback3, | |
874 &MockPolicyRefreshCallback::DoCallback))); | |
875 EXPECT_CALL(callback3, DoCallback(_)).Times(0); | |
876 Mock::VerifyAndClearExpectations(&callback1); | |
877 Mock::VerifyAndClearExpectations(&callback2); | |
878 Mock::VerifyAndClearExpectations(&callback3); | |
879 | |
880 EXPECT_CALL(callback1, DoCallback(expected_differing_paths_)).Times(1); | |
881 std::vector<std::string> no_differing_paths; | |
882 EXPECT_CALL(callback2, DoCallback(no_differing_paths)).Times(1); | |
883 EXPECT_CALL(callback3, DoCallback(no_differing_paths)).Times(1); | |
884 loop_.RunAllPending(); | 891 loop_.RunAllPending(); |
| 892 EXPECT_EQ(expected_differing_paths_, recorder.changed_prefs()); |
885 } | 893 } |
OLD | NEW |