| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/content_settings/content_settings_mock_observer.h" | 10 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 297 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 298 pref_content_settings_provider_incognito.GetContentSetting( | 298 pref_content_settings_provider_incognito.GetContentSetting( |
| 299 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 299 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 300 // But the value should not be overridden in the OTR user prefs accidentally. | 300 // But the value should not be overridden in the OTR user prefs accidentally. |
| 301 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(prefs::kContentSettingsPatterns)); | 301 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(prefs::kContentSettingsPatterns)); |
| 302 | 302 |
| 303 pref_content_settings_provider.ShutdownOnUIThread(); | 303 pref_content_settings_provider.ShutdownOnUIThread(); |
| 304 pref_content_settings_provider_incognito.ShutdownOnUIThread(); | 304 pref_content_settings_provider_incognito.ShutdownOnUIThread(); |
| 305 } | 305 } |
| 306 | 306 |
| 307 TEST_F(PrefProviderTest, GetContentSettingsValue) { |
| 308 TestingProfile testing_profile; |
| 309 PrefProvider provider(testing_profile.GetPrefs(), false); |
| 310 |
| 311 GURL primary_url("http://example.com/"); |
| 312 ContentSettingsPattern primary_pattern = |
| 313 ContentSettingsPattern::FromString("[*.]example.com"); |
| 314 |
| 315 EXPECT_EQ(CONTENT_SETTING_DEFAULT, provider.GetContentSetting( |
| 316 primary_url, primary_url, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 317 |
| 318 EXPECT_EQ(NULL, provider.GetContentSettingValue( |
| 319 primary_url, primary_url, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 320 |
| 321 provider.SetContentSetting(primary_pattern, |
| 322 primary_pattern, |
| 323 CONTENT_SETTINGS_TYPE_IMAGES, |
| 324 "", |
| 325 CONTENT_SETTING_BLOCK); |
| 326 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 327 provider.GetContentSetting( |
| 328 primary_url, primary_url, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 329 scoped_ptr<Value> value_ptr(provider.GetContentSettingValue( |
| 330 primary_url, primary_url, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 331 int int_value = -1; |
| 332 value_ptr->GetAsInteger(&int_value); |
| 333 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); |
| 334 |
| 335 provider.SetContentSetting(primary_pattern, |
| 336 primary_pattern, |
| 337 CONTENT_SETTINGS_TYPE_IMAGES, |
| 338 "", |
| 339 CONTENT_SETTING_DEFAULT); |
| 340 EXPECT_EQ(NULL, provider.GetContentSettingValue( |
| 341 primary_url, primary_url, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 342 |
| 343 provider.ShutdownOnUIThread(); |
| 344 } |
| 345 |
| 307 TEST_F(PrefProviderTest, Patterns) { | 346 TEST_F(PrefProviderTest, Patterns) { |
| 308 TestingProfile testing_profile; | 347 TestingProfile testing_profile; |
| 309 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), | 348 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), |
| 310 false); | 349 false); |
| 311 | 350 |
| 312 GURL host1("http://example.com/"); | 351 GURL host1("http://example.com/"); |
| 313 GURL host2("http://www.example.com/"); | 352 GURL host2("http://www.example.com/"); |
| 314 GURL host3("http://example.org/"); | 353 GURL host3("http://example.org/"); |
| 315 GURL host4("file:///tmp/test.html"); | 354 GURL host4("file:///tmp/test.html"); |
| 316 ContentSettingsPattern pattern1 = | 355 ContentSettingsPattern pattern1 = |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 prefs->GetList(prefs::kDesktopNotificationAllowedOrigins); | 904 prefs->GetList(prefs::kDesktopNotificationAllowedOrigins); |
| 866 EXPECT_EQ(1U, denied_origin_list->GetSize()); | 905 EXPECT_EQ(1U, denied_origin_list->GetSize()); |
| 867 const ListValue* allowed_origin_list = | 906 const ListValue* allowed_origin_list = |
| 868 prefs->GetList(prefs::kDesktopNotificationDeniedOrigins); | 907 prefs->GetList(prefs::kDesktopNotificationDeniedOrigins); |
| 869 EXPECT_EQ(1U, allowed_origin_list->GetSize()); | 908 EXPECT_EQ(1U, allowed_origin_list->GetSize()); |
| 870 | 909 |
| 871 provider.ShutdownOnUIThread(); | 910 provider.ShutdownOnUIThread(); |
| 872 } | 911 } |
| 873 | 912 |
| 874 } // namespace content_settings | 913 } // namespace content_settings |
| OLD | NEW |