| 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 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/prefs/browser_prefs.h" | 22 #include "chrome/browser/prefs/browser_prefs.h" |
| 23 #include "chrome/browser/prefs/pref_service_mock_factory.h" | 23 #include "chrome/browser/prefs/pref_service_mock_factory.h" |
| 24 #include "chrome/browser/prefs/pref_service_syncable.h" | 24 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "chrome/test/base/testing_pref_service_syncable.h" | 28 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 29 #include "chrome/test/base/testing_profile.h" | 29 #include "chrome/test/base/testing_profile.h" |
| 30 #include "components/pref_registry/pref_registry_syncable.h" | 30 #include "components/pref_registry/pref_registry_syncable.h" |
| 31 #include "content/public/test/test_browser_thread.h" | 31 #include "content/public/test/test_browser_thread.h" |
| 32 #include "extensions/common/constants.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 34 | 35 |
| 35 using ::testing::_; | 36 using ::testing::_; |
| 36 using content::BrowserThread; | 37 using content::BrowserThread; |
| 37 | 38 |
| 38 namespace content_settings { | 39 namespace content_settings { |
| 39 | 40 |
| 40 class DeadlockCheckerThread : public base::PlatformThread::Delegate { | 41 class DeadlockCheckerThread : public base::PlatformThread::Delegate { |
| 41 public: | 42 public: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 protected: | 102 protected: |
| 102 base::MessageLoop message_loop_; | 103 base::MessageLoop message_loop_; |
| 103 content::TestBrowserThread ui_thread_; | 104 content::TestBrowserThread ui_thread_; |
| 104 }; | 105 }; |
| 105 | 106 |
| 106 TEST_F(PrefProviderTest, Observer) { | 107 TEST_F(PrefProviderTest, Observer) { |
| 107 TestingProfile profile; | 108 TestingProfile profile; |
| 108 PrefProvider pref_content_settings_provider(profile.GetPrefs(), false); | 109 PrefProvider pref_content_settings_provider(profile.GetPrefs(), false); |
| 109 | 110 |
| 110 ContentSettingsPattern pattern = | 111 ContentSettingsPattern pattern = |
| 111 ContentSettingsPattern::FromString("[*.]example.com"); | 112 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 113 "[*.]example.com"); |
| 112 content_settings::MockObserver mock_observer; | 114 content_settings::MockObserver mock_observer; |
| 113 EXPECT_CALL(mock_observer, | 115 EXPECT_CALL(mock_observer, |
| 114 OnContentSettingChanged(pattern, | 116 OnContentSettingChanged(pattern, |
| 115 ContentSettingsPattern::Wildcard(), | 117 ContentSettingsPattern::Wildcard(), |
| 116 CONTENT_SETTINGS_TYPE_IMAGES, | 118 CONTENT_SETTINGS_TYPE_IMAGES, |
| 117 "")); | 119 "")); |
| 118 | 120 |
| 119 pref_content_settings_provider.AddObserver(&mock_observer); | 121 pref_content_settings_provider.AddObserver(&mock_observer); |
| 120 | 122 |
| 121 pref_content_settings_provider.SetWebsiteSetting( | 123 pref_content_settings_provider.SetWebsiteSetting( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 161 |
| 160 TestingProfile::Builder otr_profile_builder; | 162 TestingProfile::Builder otr_profile_builder; |
| 161 otr_profile_builder.SetIncognito(); | 163 otr_profile_builder.SetIncognito(); |
| 162 otr_profile_builder.SetPrefService(make_scoped_ptr(otr_prefs)); | 164 otr_profile_builder.SetPrefService(make_scoped_ptr(otr_prefs)); |
| 163 scoped_ptr<TestingProfile> otr_profile(otr_profile_builder.Build()); | 165 scoped_ptr<TestingProfile> otr_profile(otr_profile_builder.Build()); |
| 164 profile->SetOffTheRecordProfile(otr_profile.PassAs<Profile>()); | 166 profile->SetOffTheRecordProfile(otr_profile.PassAs<Profile>()); |
| 165 | 167 |
| 166 PrefProvider pref_content_settings_provider(regular_prefs, false); | 168 PrefProvider pref_content_settings_provider(regular_prefs, false); |
| 167 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); | 169 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); |
| 168 ContentSettingsPattern pattern = | 170 ContentSettingsPattern pattern = |
| 169 ContentSettingsPattern::FromString("[*.]example.com"); | 171 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 172 "[*.]example.com"); |
| 170 pref_content_settings_provider.SetWebsiteSetting( | 173 pref_content_settings_provider.SetWebsiteSetting( |
| 171 pattern, | 174 pattern, |
| 172 pattern, | 175 pattern, |
| 173 CONTENT_SETTINGS_TYPE_IMAGES, | 176 CONTENT_SETTINGS_TYPE_IMAGES, |
| 174 std::string(), | 177 std::string(), |
| 175 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | 178 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); |
| 176 | 179 |
| 177 GURL host("http://example.com/"); | 180 GURL host("http://example.com/"); |
| 178 // The value should of course be visible in the regular PrefProvider. | 181 // The value should of course be visible in the regular PrefProvider. |
| 179 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 182 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 198 pref_content_settings_provider.ShutdownOnUIThread(); | 201 pref_content_settings_provider.ShutdownOnUIThread(); |
| 199 pref_content_settings_provider_incognito.ShutdownOnUIThread(); | 202 pref_content_settings_provider_incognito.ShutdownOnUIThread(); |
| 200 } | 203 } |
| 201 | 204 |
| 202 TEST_F(PrefProviderTest, GetContentSettingsValue) { | 205 TEST_F(PrefProviderTest, GetContentSettingsValue) { |
| 203 TestingProfile testing_profile; | 206 TestingProfile testing_profile; |
| 204 PrefProvider provider(testing_profile.GetPrefs(), false); | 207 PrefProvider provider(testing_profile.GetPrefs(), false); |
| 205 | 208 |
| 206 GURL primary_url("http://example.com/"); | 209 GURL primary_url("http://example.com/"); |
| 207 ContentSettingsPattern primary_pattern = | 210 ContentSettingsPattern primary_pattern = |
| 208 ContentSettingsPattern::FromString("[*.]example.com"); | 211 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 212 "[*.]example.com"); |
| 209 | 213 |
| 210 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 214 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 211 GetContentSetting(&provider, | 215 GetContentSetting(&provider, |
| 212 primary_url, | 216 primary_url, |
| 213 primary_url, | 217 primary_url, |
| 214 CONTENT_SETTINGS_TYPE_IMAGES, | 218 CONTENT_SETTINGS_TYPE_IMAGES, |
| 215 std::string(), | 219 std::string(), |
| 216 false)); | 220 false)); |
| 217 | 221 |
| 218 EXPECT_EQ(NULL, | 222 EXPECT_EQ(NULL, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 TEST_F(PrefProviderTest, Patterns) { | 268 TEST_F(PrefProviderTest, Patterns) { |
| 265 TestingProfile testing_profile; | 269 TestingProfile testing_profile; |
| 266 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), | 270 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), |
| 267 false); | 271 false); |
| 268 | 272 |
| 269 GURL host1("http://example.com/"); | 273 GURL host1("http://example.com/"); |
| 270 GURL host2("http://www.example.com/"); | 274 GURL host2("http://www.example.com/"); |
| 271 GURL host3("http://example.org/"); | 275 GURL host3("http://example.org/"); |
| 272 GURL host4("file:///tmp/test.html"); | 276 GURL host4("file:///tmp/test.html"); |
| 273 ContentSettingsPattern pattern1 = | 277 ContentSettingsPattern pattern1 = |
| 274 ContentSettingsPattern::FromString("[*.]example.com"); | 278 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 279 "[*.]example.com"); |
| 275 ContentSettingsPattern pattern2 = | 280 ContentSettingsPattern pattern2 = |
| 276 ContentSettingsPattern::FromString("example.org"); | 281 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 282 "example.org"); |
| 277 ContentSettingsPattern pattern3 = | 283 ContentSettingsPattern pattern3 = |
| 278 ContentSettingsPattern::FromString("file:///tmp/test.html"); | 284 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 285 "file:///tmp/test.html"); |
| 279 | 286 |
| 280 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 287 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 281 GetContentSetting(&pref_content_settings_provider, | 288 GetContentSetting(&pref_content_settings_provider, |
| 282 host1, | 289 host1, |
| 283 host1, | 290 host1, |
| 284 CONTENT_SETTINGS_TYPE_IMAGES, | 291 CONTENT_SETTINGS_TYPE_IMAGES, |
| 285 std::string(), | 292 std::string(), |
| 286 false)); | 293 false)); |
| 287 pref_content_settings_provider.SetWebsiteSetting( | 294 pref_content_settings_provider.SetWebsiteSetting( |
| 288 pattern1, | 295 pattern1, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 pref_content_settings_provider.ShutdownOnUIThread(); | 357 pref_content_settings_provider.ShutdownOnUIThread(); |
| 351 } | 358 } |
| 352 | 359 |
| 353 TEST_F(PrefProviderTest, ResourceIdentifier) { | 360 TEST_F(PrefProviderTest, ResourceIdentifier) { |
| 354 TestingProfile testing_profile; | 361 TestingProfile testing_profile; |
| 355 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), | 362 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), |
| 356 false); | 363 false); |
| 357 | 364 |
| 358 GURL host("http://example.com/"); | 365 GURL host("http://example.com/"); |
| 359 ContentSettingsPattern pattern = | 366 ContentSettingsPattern pattern = |
| 360 ContentSettingsPattern::FromString("[*.]example.com"); | 367 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 368 "[*.]example.com"); |
| 361 std::string resource1("someplugin"); | 369 std::string resource1("someplugin"); |
| 362 std::string resource2("otherplugin"); | 370 std::string resource2("otherplugin"); |
| 363 | 371 |
| 364 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 372 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 365 GetContentSetting( | 373 GetContentSetting( |
| 366 &pref_content_settings_provider, | 374 &pref_content_settings_provider, |
| 367 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, | 375 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, |
| 368 resource1, false)); | 376 resource1, false)); |
| 369 pref_content_settings_provider.SetWebsiteSetting( | 377 pref_content_settings_provider.SetWebsiteSetting( |
| 370 pattern, | 378 pattern, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 TestingProfile testing_profile; | 455 TestingProfile testing_profile; |
| 448 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), | 456 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), |
| 449 false); | 457 false); |
| 450 base::SimpleTestClock* test_clock = new base::SimpleTestClock; | 458 base::SimpleTestClock* test_clock = new base::SimpleTestClock; |
| 451 test_clock->SetNow(base::Time::Now()); | 459 test_clock->SetNow(base::Time::Now()); |
| 452 | 460 |
| 453 pref_content_settings_provider.SetClockForTesting( | 461 pref_content_settings_provider.SetClockForTesting( |
| 454 scoped_ptr<base::Clock>(test_clock)); | 462 scoped_ptr<base::Clock>(test_clock)); |
| 455 GURL host("http://example.com/"); | 463 GURL host("http://example.com/"); |
| 456 ContentSettingsPattern pattern = | 464 ContentSettingsPattern pattern = |
| 457 ContentSettingsPattern::FromString("[*.]example.com"); | 465 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 466 "[*.]example.com"); |
| 458 | 467 |
| 459 base::Time no_usage = pref_content_settings_provider.GetLastUsage( | 468 base::Time no_usage = pref_content_settings_provider.GetLastUsage( |
| 460 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 469 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 461 EXPECT_EQ(no_usage.ToDoubleT(), 0); | 470 EXPECT_EQ(no_usage.ToDoubleT(), 0); |
| 462 | 471 |
| 463 pref_content_settings_provider.UpdateLastUsage( | 472 pref_content_settings_provider.UpdateLastUsage( |
| 464 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 473 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 465 base::Time first = pref_content_settings_provider.GetLastUsage( | 474 base::Time first = pref_content_settings_provider.GetLastUsage( |
| 466 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 475 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 467 | 476 |
| 468 test_clock->Advance(base::TimeDelta::FromSeconds(10)); | 477 test_clock->Advance(base::TimeDelta::FromSeconds(10)); |
| 469 | 478 |
| 470 pref_content_settings_provider.UpdateLastUsage( | 479 pref_content_settings_provider.UpdateLastUsage( |
| 471 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 480 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 472 base::Time second = pref_content_settings_provider.GetLastUsage( | 481 base::Time second = pref_content_settings_provider.GetLastUsage( |
| 473 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 482 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 474 | 483 |
| 475 base::TimeDelta delta = second - first; | 484 base::TimeDelta delta = second - first; |
| 476 EXPECT_EQ(delta.InSeconds(), 10); | 485 EXPECT_EQ(delta.InSeconds(), 10); |
| 477 | 486 |
| 478 pref_content_settings_provider.ShutdownOnUIThread(); | 487 pref_content_settings_provider.ShutdownOnUIThread(); |
| 479 } | 488 } |
| 480 | 489 |
| 481 } // namespace content_settings | 490 } // namespace content_settings |
| OLD | NEW |