| 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 "components/content_settings/core/browser/content_settings_pref_provide
r.h" | 5 #include "components/content_settings/core/browser/content_settings_pref_provide
r.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "components/prefs/default_pref_store.h" | 31 #include "components/prefs/default_pref_store.h" |
| 32 #include "components/prefs/overlay_user_pref_store.h" | 32 #include "components/prefs/overlay_user_pref_store.h" |
| 33 #include "components/prefs/pref_change_registrar.h" | 33 #include "components/prefs/pref_change_registrar.h" |
| 34 #include "components/prefs/pref_service.h" | 34 #include "components/prefs/pref_service.h" |
| 35 #include "components/prefs/scoped_user_pref_update.h" | 35 #include "components/prefs/scoped_user_pref_update.h" |
| 36 #include "components/prefs/testing_pref_store.h" | 36 #include "components/prefs/testing_pref_store.h" |
| 37 #include "components/sync_preferences/pref_service_mock_factory.h" | 37 #include "components/sync_preferences/pref_service_mock_factory.h" |
| 38 #include "components/sync_preferences/pref_service_syncable.h" | 38 #include "components/sync_preferences/pref_service_syncable.h" |
| 39 #include "components/sync_preferences/testing_pref_service_syncable.h" | 39 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 40 #include "content/public/test/test_browser_thread_bundle.h" | 40 #include "content/public/test/test_browser_thread_bundle.h" |
| 41 #include "ppapi/features/features.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
| 42 #include "url/gurl.h" | 43 #include "url/gurl.h" |
| 43 | 44 |
| 44 using ::testing::_; | 45 using ::testing::_; |
| 45 | 46 |
| 46 namespace content_settings { | 47 namespace content_settings { |
| 47 | 48 |
| 48 class DeadlockCheckerThread : public base::PlatformThread::Delegate { | 49 class DeadlockCheckerThread : public base::PlatformThread::Delegate { |
| 49 public: | 50 public: |
| 50 explicit DeadlockCheckerThread(const ContentSettingsPref* pref) | 51 explicit DeadlockCheckerThread(const ContentSettingsPref* pref) |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 pattern3, pattern3, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 331 pattern3, pattern3, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| 331 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 332 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); |
| 332 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 333 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 333 TestUtils::GetContentSetting(&pref_content_settings_provider, host4, | 334 TestUtils::GetContentSetting(&pref_content_settings_provider, host4, |
| 334 host4, CONTENT_SETTINGS_TYPE_COOKIES, | 335 host4, CONTENT_SETTINGS_TYPE_COOKIES, |
| 335 std::string(), false)); | 336 std::string(), false)); |
| 336 | 337 |
| 337 pref_content_settings_provider.ShutdownOnUIThread(); | 338 pref_content_settings_provider.ShutdownOnUIThread(); |
| 338 } | 339 } |
| 339 | 340 |
| 340 #if defined(ENABLE_PLUGINS) | 341 #if BUILDFLAG(ENABLE_PLUGINS) |
| 341 TEST_F(PrefProviderTest, ResourceIdentifier) { | 342 TEST_F(PrefProviderTest, ResourceIdentifier) { |
| 342 TestingProfile testing_profile; | 343 TestingProfile testing_profile; |
| 343 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), | 344 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), |
| 344 false); | 345 false); |
| 345 | 346 |
| 346 GURL host("http://example.com/"); | 347 GURL host("http://example.com/"); |
| 347 ContentSettingsPattern pattern = | 348 ContentSettingsPattern pattern = |
| 348 ContentSettingsPattern::FromString("[*.]example.com"); | 349 ContentSettingsPattern::FromString("[*.]example.com"); |
| 349 std::string resource1("someplugin"); | 350 std::string resource1("someplugin"); |
| 350 std::string resource2("otherplugin"); | 351 std::string resource2("otherplugin"); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 | 512 |
| 512 // Non-empty pattern, syncable, empty resource identifier. | 513 // Non-empty pattern, syncable, empty resource identifier. |
| 513 provider.SetWebsiteSetting(pattern, wildcard, | 514 provider.SetWebsiteSetting(pattern, wildcard, |
| 514 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 515 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 515 ResourceIdentifier(), value->DeepCopy()); | 516 ResourceIdentifier(), value->DeepCopy()); |
| 516 | 517 |
| 517 // Non-empty pattern, non-syncable, empty resource identifier. | 518 // Non-empty pattern, non-syncable, empty resource identifier. |
| 518 provider.SetWebsiteSetting(pattern, wildcard, | 519 provider.SetWebsiteSetting(pattern, wildcard, |
| 519 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 520 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 520 ResourceIdentifier(), value->DeepCopy()); | 521 ResourceIdentifier(), value->DeepCopy()); |
| 521 #if defined(ENABLE_PLUGINS) | 522 #if BUILDFLAG(ENABLE_PLUGINS) |
| 522 // Non-empty pattern, plugins, non-empty resource identifier. | 523 // Non-empty pattern, plugins, non-empty resource identifier. |
| 523 provider.SetWebsiteSetting(pattern, wildcard, CONTENT_SETTINGS_TYPE_PLUGINS, | 524 provider.SetWebsiteSetting(pattern, wildcard, CONTENT_SETTINGS_TYPE_PLUGINS, |
| 524 res_id, value->DeepCopy()); | 525 res_id, value->DeepCopy()); |
| 525 | 526 |
| 526 // Empty pattern, plugins, non-empty resource identifier. | 527 // Empty pattern, plugins, non-empty resource identifier. |
| 527 provider.SetWebsiteSetting(wildcard, wildcard, CONTENT_SETTINGS_TYPE_PLUGINS, | 528 provider.SetWebsiteSetting(wildcard, wildcard, CONTENT_SETTINGS_TYPE_PLUGINS, |
| 528 res_id, value->DeepCopy()); | 529 res_id, value->DeepCopy()); |
| 529 #endif | 530 #endif |
| 530 // Non-empty pattern, syncable, empty resource identifier. | 531 // Non-empty pattern, syncable, empty resource identifier. |
| 531 provider.SetWebsiteSetting(pattern, wildcard, CONTENT_SETTINGS_TYPE_COOKIES, | 532 provider.SetWebsiteSetting(pattern, wildcard, CONTENT_SETTINGS_TYPE_COOKIES, |
| 532 ResourceIdentifier(), value->DeepCopy()); | 533 ResourceIdentifier(), value->DeepCopy()); |
| 533 | 534 |
| 534 // Non-empty pattern, non-syncable, empty resource identifier. | 535 // Non-empty pattern, non-syncable, empty resource identifier. |
| 535 provider.SetWebsiteSetting(pattern, wildcard, | 536 provider.SetWebsiteSetting(pattern, wildcard, |
| 536 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 537 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 537 ResourceIdentifier(), value->DeepCopy()); | 538 ResourceIdentifier(), value->DeepCopy()); |
| 538 | 539 |
| 539 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_JAVASCRIPT); | 540 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_JAVASCRIPT); |
| 540 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 541 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 541 #if defined(ENABLE_PLUGINS) | 542 #if BUILDFLAG(ENABLE_PLUGINS) |
| 542 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_PLUGINS); | 543 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_PLUGINS); |
| 543 #endif | 544 #endif |
| 544 | 545 |
| 545 WebsiteSettingsRegistry* registry = WebsiteSettingsRegistry::GetInstance(); | 546 WebsiteSettingsRegistry* registry = WebsiteSettingsRegistry::GetInstance(); |
| 546 // Test that the preferences for images, geolocation and plugins are empty. | 547 // Test that the preferences for images, geolocation and plugins are empty. |
| 547 const char* empty_prefs[] = { | 548 const char* empty_prefs[] = { |
| 548 registry->Get(CONTENT_SETTINGS_TYPE_JAVASCRIPT)->pref_name().c_str(), | 549 registry->Get(CONTENT_SETTINGS_TYPE_JAVASCRIPT)->pref_name().c_str(), |
| 549 registry->Get(CONTENT_SETTINGS_TYPE_GEOLOCATION)->pref_name().c_str(), | 550 registry->Get(CONTENT_SETTINGS_TYPE_GEOLOCATION)->pref_name().c_str(), |
| 550 #if defined(ENABLE_PLUGINS) | 551 #if BUILDFLAG(ENABLE_PLUGINS) |
| 551 registry->Get(CONTENT_SETTINGS_TYPE_PLUGINS)->pref_name().c_str(), | 552 registry->Get(CONTENT_SETTINGS_TYPE_PLUGINS)->pref_name().c_str(), |
| 552 #endif | 553 #endif |
| 553 }; | 554 }; |
| 554 | 555 |
| 555 for (const char* pref : empty_prefs) { | 556 for (const char* pref : empty_prefs) { |
| 556 DictionaryPrefUpdate update(&prefs, pref); | 557 DictionaryPrefUpdate update(&prefs, pref); |
| 557 const base::DictionaryValue* dictionary = update.Get(); | 558 const base::DictionaryValue* dictionary = update.Get(); |
| 558 EXPECT_TRUE(dictionary->empty()); | 559 EXPECT_TRUE(dictionary->empty()); |
| 559 } | 560 } |
| 560 | 561 |
| 561 // Test that the preferences for cookies and notifications are not empty. | 562 // Test that the preferences for cookies and notifications are not empty. |
| 562 const char* nonempty_prefs[] = { | 563 const char* nonempty_prefs[] = { |
| 563 registry->Get(CONTENT_SETTINGS_TYPE_COOKIES)->pref_name().c_str(), | 564 registry->Get(CONTENT_SETTINGS_TYPE_COOKIES)->pref_name().c_str(), |
| 564 registry->Get(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)->pref_name().c_str(), | 565 registry->Get(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)->pref_name().c_str(), |
| 565 }; | 566 }; |
| 566 | 567 |
| 567 for (const char* pref : nonempty_prefs) { | 568 for (const char* pref : nonempty_prefs) { |
| 568 DictionaryPrefUpdate update(&prefs, pref); | 569 DictionaryPrefUpdate update(&prefs, pref); |
| 569 const base::DictionaryValue* dictionary = update.Get(); | 570 const base::DictionaryValue* dictionary = update.Get(); |
| 570 EXPECT_EQ(1u, dictionary->size()); | 571 EXPECT_EQ(1u, dictionary->size()); |
| 571 } | 572 } |
| 572 | 573 |
| 573 provider.ShutdownOnUIThread(); | 574 provider.ShutdownOnUIThread(); |
| 574 } | 575 } |
| 575 | 576 |
| 576 } // namespace content_settings | 577 } // namespace content_settings |
| OLD | NEW |