OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 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 "chrome/browser/content_settings/content_settings_pref_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 CONTENT_SETTINGS_TYPE_IMAGES, | 115 CONTENT_SETTINGS_TYPE_IMAGES, |
116 "")); | 116 "")); |
117 | 117 |
118 pref_content_settings_provider.AddObserver(&mock_observer); | 118 pref_content_settings_provider.AddObserver(&mock_observer); |
119 | 119 |
120 pref_content_settings_provider.SetWebsiteSetting( | 120 pref_content_settings_provider.SetWebsiteSetting( |
121 pattern, | 121 pattern, |
122 ContentSettingsPattern::Wildcard(), | 122 ContentSettingsPattern::Wildcard(), |
123 CONTENT_SETTINGS_TYPE_IMAGES, | 123 CONTENT_SETTINGS_TYPE_IMAGES, |
124 std::string(), | 124 std::string(), |
125 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 125 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
126 | 126 |
127 pref_content_settings_provider.ShutdownOnUIThread(); | 127 pref_content_settings_provider.ShutdownOnUIThread(); |
128 } | 128 } |
129 | 129 |
130 // Test for regression in which the PrefProvider modified the user pref store | 130 // Test for regression in which the PrefProvider modified the user pref store |
131 // of the OTR unintentionally: http://crbug.com/74466. | 131 // of the OTR unintentionally: http://crbug.com/74466. |
132 TEST_F(PrefProviderTest, Incognito) { | 132 TEST_F(PrefProviderTest, Incognito) { |
133 PersistentPrefStore* user_prefs = new TestingPrefStore(); | 133 PersistentPrefStore* user_prefs = new TestingPrefStore(); |
134 OverlayUserPrefStore* otr_user_prefs = | 134 OverlayUserPrefStore* otr_user_prefs = |
135 new OverlayUserPrefStore(user_prefs); | 135 new OverlayUserPrefStore(user_prefs); |
(...skipping 28 matching lines...) Expand all Loading... |
164 | 164 |
165 PrefProvider pref_content_settings_provider(regular_prefs, false); | 165 PrefProvider pref_content_settings_provider(regular_prefs, false); |
166 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); | 166 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); |
167 ContentSettingsPattern pattern = | 167 ContentSettingsPattern pattern = |
168 ContentSettingsPattern::FromString("[*.]example.com"); | 168 ContentSettingsPattern::FromString("[*.]example.com"); |
169 pref_content_settings_provider.SetWebsiteSetting( | 169 pref_content_settings_provider.SetWebsiteSetting( |
170 pattern, | 170 pattern, |
171 pattern, | 171 pattern, |
172 CONTENT_SETTINGS_TYPE_IMAGES, | 172 CONTENT_SETTINGS_TYPE_IMAGES, |
173 std::string(), | 173 std::string(), |
174 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 174 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
175 | 175 |
176 GURL host("http://example.com/"); | 176 GURL host("http://example.com/"); |
177 // The value should of course be visible in the regular PrefProvider. | 177 // The value should of course be visible in the regular PrefProvider. |
178 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 178 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
179 GetContentSetting(&pref_content_settings_provider, | 179 GetContentSetting(&pref_content_settings_provider, |
180 host, | 180 host, |
181 host, | 181 host, |
182 CONTENT_SETTINGS_TYPE_IMAGES, | 182 CONTENT_SETTINGS_TYPE_IMAGES, |
183 std::string(), | 183 std::string(), |
184 false)); | 184 false)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 primary_url, | 219 primary_url, |
220 primary_url, | 220 primary_url, |
221 CONTENT_SETTINGS_TYPE_IMAGES, | 221 CONTENT_SETTINGS_TYPE_IMAGES, |
222 std::string(), | 222 std::string(), |
223 false)); | 223 false)); |
224 | 224 |
225 provider.SetWebsiteSetting(primary_pattern, | 225 provider.SetWebsiteSetting(primary_pattern, |
226 primary_pattern, | 226 primary_pattern, |
227 CONTENT_SETTINGS_TYPE_IMAGES, | 227 CONTENT_SETTINGS_TYPE_IMAGES, |
228 std::string(), | 228 std::string(), |
229 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 229 base::Value::CreateIntegerValue( |
| 230 CONTENT_SETTING_BLOCK)); |
230 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 231 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
231 GetContentSetting(&provider, | 232 GetContentSetting(&provider, |
232 primary_url, | 233 primary_url, |
233 primary_url, | 234 primary_url, |
234 CONTENT_SETTINGS_TYPE_IMAGES, | 235 CONTENT_SETTINGS_TYPE_IMAGES, |
235 std::string(), | 236 std::string(), |
236 false)); | 237 false)); |
237 scoped_ptr<Value> value_ptr( | 238 scoped_ptr<base::Value> value_ptr( |
238 GetContentSettingValue(&provider, | 239 GetContentSettingValue(&provider, |
239 primary_url, | 240 primary_url, |
240 primary_url, | 241 primary_url, |
241 CONTENT_SETTINGS_TYPE_IMAGES, | 242 CONTENT_SETTINGS_TYPE_IMAGES, |
242 std::string(), | 243 std::string(), |
243 false)); | 244 false)); |
244 int int_value = -1; | 245 int int_value = -1; |
245 value_ptr->GetAsInteger(&int_value); | 246 value_ptr->GetAsInteger(&int_value); |
246 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); | 247 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); |
247 | 248 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 host1, | 282 host1, |
282 host1, | 283 host1, |
283 CONTENT_SETTINGS_TYPE_IMAGES, | 284 CONTENT_SETTINGS_TYPE_IMAGES, |
284 std::string(), | 285 std::string(), |
285 false)); | 286 false)); |
286 pref_content_settings_provider.SetWebsiteSetting( | 287 pref_content_settings_provider.SetWebsiteSetting( |
287 pattern1, | 288 pattern1, |
288 pattern1, | 289 pattern1, |
289 CONTENT_SETTINGS_TYPE_IMAGES, | 290 CONTENT_SETTINGS_TYPE_IMAGES, |
290 std::string(), | 291 std::string(), |
291 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 292 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
292 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 293 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
293 GetContentSetting(&pref_content_settings_provider, | 294 GetContentSetting(&pref_content_settings_provider, |
294 host1, | 295 host1, |
295 host1, | 296 host1, |
296 CONTENT_SETTINGS_TYPE_IMAGES, | 297 CONTENT_SETTINGS_TYPE_IMAGES, |
297 std::string(), | 298 std::string(), |
298 false)); | 299 false)); |
299 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 300 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
300 GetContentSetting(&pref_content_settings_provider, | 301 GetContentSetting(&pref_content_settings_provider, |
301 host2, | 302 host2, |
302 host2, | 303 host2, |
303 CONTENT_SETTINGS_TYPE_IMAGES, | 304 CONTENT_SETTINGS_TYPE_IMAGES, |
304 std::string(), | 305 std::string(), |
305 false)); | 306 false)); |
306 | 307 |
307 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 308 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
308 GetContentSetting(&pref_content_settings_provider, | 309 GetContentSetting(&pref_content_settings_provider, |
309 host3, | 310 host3, |
310 host3, | 311 host3, |
311 CONTENT_SETTINGS_TYPE_IMAGES, | 312 CONTENT_SETTINGS_TYPE_IMAGES, |
312 std::string(), | 313 std::string(), |
313 false)); | 314 false)); |
314 pref_content_settings_provider.SetWebsiteSetting( | 315 pref_content_settings_provider.SetWebsiteSetting( |
315 pattern2, | 316 pattern2, |
316 pattern2, | 317 pattern2, |
317 CONTENT_SETTINGS_TYPE_IMAGES, | 318 CONTENT_SETTINGS_TYPE_IMAGES, |
318 std::string(), | 319 std::string(), |
319 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 320 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
320 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 321 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
321 GetContentSetting(&pref_content_settings_provider, | 322 GetContentSetting(&pref_content_settings_provider, |
322 host3, | 323 host3, |
323 host3, | 324 host3, |
324 CONTENT_SETTINGS_TYPE_IMAGES, | 325 CONTENT_SETTINGS_TYPE_IMAGES, |
325 std::string(), | 326 std::string(), |
326 false)); | 327 false)); |
327 | 328 |
328 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 329 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
329 GetContentSetting(&pref_content_settings_provider, | 330 GetContentSetting(&pref_content_settings_provider, |
330 host4, | 331 host4, |
331 host4, | 332 host4, |
332 CONTENT_SETTINGS_TYPE_IMAGES, | 333 CONTENT_SETTINGS_TYPE_IMAGES, |
333 std::string(), | 334 std::string(), |
334 false)); | 335 false)); |
335 pref_content_settings_provider.SetWebsiteSetting( | 336 pref_content_settings_provider.SetWebsiteSetting( |
336 pattern3, | 337 pattern3, |
337 pattern3, | 338 pattern3, |
338 CONTENT_SETTINGS_TYPE_IMAGES, | 339 CONTENT_SETTINGS_TYPE_IMAGES, |
339 std::string(), | 340 std::string(), |
340 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 341 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
341 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 342 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
342 GetContentSetting(&pref_content_settings_provider, | 343 GetContentSetting(&pref_content_settings_provider, |
343 host4, | 344 host4, |
344 host4, | 345 host4, |
345 CONTENT_SETTINGS_TYPE_IMAGES, | 346 CONTENT_SETTINGS_TYPE_IMAGES, |
346 std::string(), | 347 std::string(), |
347 false)); | 348 false)); |
348 | 349 |
349 pref_content_settings_provider.ShutdownOnUIThread(); | 350 pref_content_settings_provider.ShutdownOnUIThread(); |
350 } | 351 } |
(...skipping 12 matching lines...) Expand all Loading... |
363 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 364 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
364 GetContentSetting( | 365 GetContentSetting( |
365 &pref_content_settings_provider, | 366 &pref_content_settings_provider, |
366 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, | 367 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, |
367 resource1, false)); | 368 resource1, false)); |
368 pref_content_settings_provider.SetWebsiteSetting( | 369 pref_content_settings_provider.SetWebsiteSetting( |
369 pattern, | 370 pattern, |
370 pattern, | 371 pattern, |
371 CONTENT_SETTINGS_TYPE_PLUGINS, | 372 CONTENT_SETTINGS_TYPE_PLUGINS, |
372 resource1, | 373 resource1, |
373 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 374 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
374 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 375 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
375 GetContentSetting( | 376 GetContentSetting( |
376 &pref_content_settings_provider, | 377 &pref_content_settings_provider, |
377 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, | 378 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, |
378 resource1, false)); | 379 resource1, false)); |
379 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 380 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
380 GetContentSetting( | 381 GetContentSetting( |
381 &pref_content_settings_provider, | 382 &pref_content_settings_provider, |
382 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, | 383 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, |
383 resource2, false)); | 384 resource2, false)); |
(...skipping 16 matching lines...) Expand all Loading... |
400 primary_url, | 401 primary_url, |
401 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | 402 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
402 std::string(), | 403 std::string(), |
403 false)); | 404 false)); |
404 | 405 |
405 provider.SetWebsiteSetting( | 406 provider.SetWebsiteSetting( |
406 ContentSettingsPattern::FromURL(primary_url), | 407 ContentSettingsPattern::FromURL(primary_url), |
407 ContentSettingsPattern::Wildcard(), | 408 ContentSettingsPattern::Wildcard(), |
408 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | 409 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
409 std::string(), | 410 std::string(), |
410 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 411 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
411 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 412 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
412 GetContentSetting( | 413 GetContentSetting( |
413 &provider, | 414 &provider, |
414 primary_url, | 415 primary_url, |
415 secondary_url, | 416 secondary_url, |
416 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | 417 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
417 std::string(), | 418 std::string(), |
418 false)); | 419 false)); |
419 provider.ShutdownOnUIThread(); | 420 provider.ShutdownOnUIThread(); |
420 } | 421 } |
421 | 422 |
422 // http://crosbug.com/17760 | 423 // http://crosbug.com/17760 |
423 TEST_F(PrefProviderTest, Deadlock) { | 424 TEST_F(PrefProviderTest, Deadlock) { |
424 TestingPrefServiceSyncable prefs; | 425 TestingPrefServiceSyncable prefs; |
425 PrefProvider::RegisterProfilePrefs(prefs.registry()); | 426 PrefProvider::RegisterProfilePrefs(prefs.registry()); |
426 | 427 |
427 // Chain of events: a preference changes, |PrefProvider| notices it, and reads | 428 // Chain of events: a preference changes, |PrefProvider| notices it, and reads |
428 // and writes the preference. When the preference is written, a notification | 429 // and writes the preference. When the preference is written, a notification |
429 // is sent, and this used to happen when |PrefProvider| was still holding its | 430 // is sent, and this used to happen when |PrefProvider| was still holding its |
430 // lock. | 431 // lock. |
431 | 432 |
432 PrefProvider provider(&prefs, false); | 433 PrefProvider provider(&prefs, false); |
433 DeadlockCheckerObserver observer(&prefs, &provider); | 434 DeadlockCheckerObserver observer(&prefs, &provider); |
434 { | 435 { |
435 DictionaryPrefUpdate update(&prefs, | 436 DictionaryPrefUpdate update(&prefs, |
436 prefs::kContentSettingsPatternPairs); | 437 prefs::kContentSettingsPatternPairs); |
437 DictionaryValue* mutable_settings = update.Get(); | 438 base::DictionaryValue* mutable_settings = update.Get(); |
438 mutable_settings->SetWithoutPathExpansion("www.example.com,*", | 439 mutable_settings->SetWithoutPathExpansion("www.example.com,*", |
439 new base::DictionaryValue()); | 440 new base::DictionaryValue()); |
440 } | 441 } |
441 EXPECT_TRUE(observer.notification_received()); | 442 EXPECT_TRUE(observer.notification_received()); |
442 | 443 |
443 provider.ShutdownOnUIThread(); | 444 provider.ShutdownOnUIThread(); |
444 } | 445 } |
445 | 446 |
446 } // namespace content_settings | 447 } // namespace content_settings |
OLD | NEW |