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 "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 309 } |
310 | 310 |
311 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { | 311 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { |
312 TestingProfile profile; | 312 TestingProfile profile; |
313 HostContentSettingsMap* host_content_settings_map = | 313 HostContentSettingsMap* host_content_settings_map = |
314 profile.GetHostContentSettingsMap(); | 314 profile.GetHostContentSettingsMap(); |
315 | 315 |
316 PrefService* prefs = profile.GetPrefs(); | 316 PrefService* prefs = profile.GetPrefs(); |
317 | 317 |
318 // Make a copy of the default pref value so we can reset it later. | 318 // Make a copy of the default pref value so we can reset it later. |
319 scoped_ptr<Value> default_value(prefs->FindPreference( | 319 scoped_ptr<base::Value> default_value(prefs->FindPreference( |
320 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 320 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
321 | 321 |
322 GURL host("http://example.com"); | 322 GURL host("http://example.com"); |
323 | 323 |
324 host_content_settings_map->SetDefaultContentSetting( | 324 host_content_settings_map->SetDefaultContentSetting( |
325 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 325 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); |
326 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 326 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
327 host_content_settings_map->GetContentSetting( | 327 host_content_settings_map->GetContentSetting( |
328 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 328 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
329 | 329 |
330 // Make a copy of the pref's new value so we can reset it later. | 330 // Make a copy of the pref's new value so we can reset it later. |
331 scoped_ptr<Value> new_value(prefs->FindPreference( | 331 scoped_ptr<base::Value> new_value(prefs->FindPreference( |
332 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 332 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
333 | 333 |
334 // Clearing the backing pref should also clear the internal cache. | 334 // Clearing the backing pref should also clear the internal cache. |
335 prefs->Set(prefs::kDefaultContentSettings, *default_value); | 335 prefs->Set(prefs::kDefaultContentSettings, *default_value); |
336 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 336 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
337 host_content_settings_map->GetContentSetting( | 337 host_content_settings_map->GetContentSetting( |
338 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 338 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
339 | 339 |
340 // Reseting the pref to its previous value should update the cache. | 340 // Reseting the pref to its previous value should update the cache. |
341 prefs->Set(prefs::kDefaultContentSettings, *new_value); | 341 prefs->Set(prefs::kDefaultContentSettings, *new_value); |
342 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 342 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
343 host_content_settings_map->GetContentSetting( | 343 host_content_settings_map->GetContentSetting( |
344 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 344 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
345 } | 345 } |
346 | 346 |
347 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { | 347 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { |
348 TestingProfile profile; | 348 TestingProfile profile; |
349 HostContentSettingsMap* host_content_settings_map = | 349 HostContentSettingsMap* host_content_settings_map = |
350 profile.GetHostContentSettingsMap(); | 350 profile.GetHostContentSettingsMap(); |
351 | 351 |
352 PrefService* prefs = profile.GetPrefs(); | 352 PrefService* prefs = profile.GetPrefs(); |
353 | 353 |
354 // Make a copy of the default pref value so we can reset it later. | 354 // Make a copy of the default pref value so we can reset it later. |
355 scoped_ptr<Value> default_value(prefs->FindPreference( | 355 scoped_ptr<base::Value> default_value(prefs->FindPreference( |
356 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); | 356 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); |
357 | 357 |
358 ContentSettingsPattern pattern = | 358 ContentSettingsPattern pattern = |
359 ContentSettingsPattern::FromString("[*.]example.com"); | 359 ContentSettingsPattern::FromString("[*.]example.com"); |
360 GURL host("http://example.com"); | 360 GURL host("http://example.com"); |
361 | 361 |
362 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 362 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
363 host_content_settings_map->GetContentSetting( | 363 host_content_settings_map->GetContentSetting( |
364 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 364 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
365 | 365 |
366 host_content_settings_map->SetContentSetting( | 366 host_content_settings_map->SetContentSetting( |
367 pattern, | 367 pattern, |
368 ContentSettingsPattern::Wildcard(), | 368 ContentSettingsPattern::Wildcard(), |
369 CONTENT_SETTINGS_TYPE_IMAGES, | 369 CONTENT_SETTINGS_TYPE_IMAGES, |
370 std::string(), | 370 std::string(), |
371 CONTENT_SETTING_BLOCK); | 371 CONTENT_SETTING_BLOCK); |
372 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 372 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
373 host_content_settings_map->GetContentSetting( | 373 host_content_settings_map->GetContentSetting( |
374 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 374 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
375 | 375 |
376 // Make a copy of the pref's new value so we can reset it later. | 376 // Make a copy of the pref's new value so we can reset it later. |
377 scoped_ptr<Value> new_value(prefs->FindPreference( | 377 scoped_ptr<base::Value> new_value(prefs->FindPreference( |
378 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); | 378 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); |
379 | 379 |
380 // Clearing the backing pref should also clear the internal cache. | 380 // Clearing the backing pref should also clear the internal cache. |
381 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value); | 381 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value); |
382 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 382 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
383 host_content_settings_map->GetContentSetting( | 383 host_content_settings_map->GetContentSetting( |
384 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 384 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
385 | 385 |
386 // Reseting the pref to its previous value should update the cache. | 386 // Reseting the pref to its previous value should update the cache. |
387 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); | 387 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 | 664 |
665 // For a single Unicode encoded pattern, check if it gets converted to punycode | 665 // For a single Unicode encoded pattern, check if it gets converted to punycode |
666 // and old pattern gets deleted. | 666 // and old pattern gets deleted. |
667 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { | 667 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { |
668 TestingProfile profile; | 668 TestingProfile profile; |
669 PrefService* prefs = profile.GetPrefs(); | 669 PrefService* prefs = profile.GetPrefs(); |
670 | 670 |
671 // Set utf-8 data. | 671 // Set utf-8 data. |
672 { | 672 { |
673 DictionaryPrefUpdate update(prefs, prefs::kContentSettingsPatternPairs); | 673 DictionaryPrefUpdate update(prefs, prefs::kContentSettingsPatternPairs); |
674 DictionaryValue* all_settings_dictionary = update.Get(); | 674 base::DictionaryValue* all_settings_dictionary = update.Get(); |
675 ASSERT_TRUE(NULL != all_settings_dictionary); | 675 ASSERT_TRUE(NULL != all_settings_dictionary); |
676 | 676 |
677 DictionaryValue* dummy_payload = new DictionaryValue; | 677 base::DictionaryValue* dummy_payload = new base::DictionaryValue; |
678 dummy_payload->SetInteger("images", CONTENT_SETTING_ALLOW); | 678 dummy_payload->SetInteger("images", CONTENT_SETTING_ALLOW); |
679 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*", | 679 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*", |
680 dummy_payload); | 680 dummy_payload); |
681 } | 681 } |
682 profile.GetHostContentSettingsMap(); | 682 profile.GetHostContentSettingsMap(); |
683 | 683 |
684 const DictionaryValue* all_settings_dictionary = | 684 const base::DictionaryValue* all_settings_dictionary = |
685 prefs->GetDictionary(prefs::kContentSettingsPatternPairs); | 685 prefs->GetDictionary(prefs::kContentSettingsPatternPairs); |
686 const DictionaryValue* result = NULL; | 686 const base::DictionaryValue* result = NULL; |
687 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( | 687 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
688 "[*.]\xC4\x87ira.com,*", &result)); | 688 "[*.]\xC4\x87ira.com,*", &result)); |
689 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( | 689 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
690 "[*.]xn--ira-ppa.com,*", &result)); | 690 "[*.]xn--ira-ppa.com,*", &result)); |
691 } | 691 } |
692 | 692 |
693 // If both Unicode and its punycode pattern exist, make sure we don't touch the | 693 // If both Unicode and its punycode pattern exist, make sure we don't touch the |
694 // settings for the punycode, and that Unicode pattern gets deleted. | 694 // settings for the punycode, and that Unicode pattern gets deleted. |
695 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { | 695 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { |
696 TestingProfile profile; | 696 TestingProfile profile; |
697 | 697 |
698 scoped_ptr<Value> value(base::JSONReader::Read( | 698 scoped_ptr<base::Value> value(base::JSONReader::Read( |
699 "{\"[*.]\\xC4\\x87ira.com,*\":{\"images\":1}}")); | 699 "{\"[*.]\\xC4\\x87ira.com,*\":{\"images\":1}}")); |
700 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *value); | 700 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *value); |
701 | 701 |
702 // Set punycode equivalent, with different setting. | 702 // Set punycode equivalent, with different setting. |
703 scoped_ptr<Value> puny_value(base::JSONReader::Read( | 703 scoped_ptr<base::Value> puny_value(base::JSONReader::Read( |
704 "{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}")); | 704 "{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}")); |
705 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *puny_value); | 705 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *puny_value); |
706 | 706 |
707 // Initialize the content map. | 707 // Initialize the content map. |
708 profile.GetHostContentSettingsMap(); | 708 profile.GetHostContentSettingsMap(); |
709 | 709 |
710 const DictionaryValue* content_setting_prefs = | 710 const base::DictionaryValue* content_setting_prefs = |
711 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); | 711 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); |
712 std::string prefs_as_json; | 712 std::string prefs_as_json; |
713 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); | 713 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); |
714 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}", | 714 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}", |
715 prefs_as_json.c_str()); | 715 prefs_as_json.c_str()); |
716 } | 716 } |
717 | 717 |
718 // If a default-content-setting is managed, the managed value should be used | 718 // If a default-content-setting is managed, the managed value should be used |
719 // instead of the default value. | 719 // instead of the default value. |
720 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { | 720 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { |
721 TestingProfile profile; | 721 TestingProfile profile; |
722 HostContentSettingsMap* host_content_settings_map = | 722 HostContentSettingsMap* host_content_settings_map = |
723 profile.GetHostContentSettingsMap(); | 723 profile.GetHostContentSettingsMap(); |
724 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | 724 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
725 | 725 |
726 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 726 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
727 host_content_settings_map->GetDefaultContentSetting( | 727 host_content_settings_map->GetDefaultContentSetting( |
728 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 728 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
729 | 729 |
730 // Set managed-default-content-setting through the coresponding preferences. | 730 // Set managed-default-content-setting through the coresponding preferences. |
731 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, | 731 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, |
732 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 732 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
733 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 733 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
734 host_content_settings_map->GetDefaultContentSetting( | 734 host_content_settings_map->GetDefaultContentSetting( |
735 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 735 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
736 | 736 |
737 // Remove managed-default-content-settings-preferences. | 737 // Remove managed-default-content-settings-preferences. |
738 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); | 738 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); |
739 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 739 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
740 host_content_settings_map->GetDefaultContentSetting( | 740 host_content_settings_map->GetDefaultContentSetting( |
741 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 741 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
742 | 742 |
743 // Set preference to manage the default-content-setting for Plugins. | 743 // Set preference to manage the default-content-setting for Plugins. |
744 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, | 744 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, |
745 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 745 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
746 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 746 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
747 host_content_settings_map->GetDefaultContentSetting( | 747 host_content_settings_map->GetDefaultContentSetting( |
748 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 748 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
749 | 749 |
750 // Remove the preference to manage the default-content-setting for Plugins. | 750 // Remove the preference to manage the default-content-setting for Plugins. |
751 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); | 751 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); |
752 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 752 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
753 host_content_settings_map->GetDefaultContentSetting( | 753 host_content_settings_map->GetDefaultContentSetting( |
754 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 754 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
755 } | 755 } |
(...skipping 19 matching lines...) Expand all Loading... |
775 host_content_settings_map->GetDefaultContentSetting( | 775 host_content_settings_map->GetDefaultContentSetting( |
776 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 776 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
777 | 777 |
778 GURL host("http://example.com/"); | 778 GURL host("http://example.com/"); |
779 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 779 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
780 host_content_settings_map->GetContentSetting( | 780 host_content_settings_map->GetContentSetting( |
781 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 781 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
782 | 782 |
783 // Set managed-default-content-setting for content-settings-type JavaScript. | 783 // Set managed-default-content-setting for content-settings-type JavaScript. |
784 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, | 784 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, |
785 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 785 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
786 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 786 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
787 host_content_settings_map->GetContentSetting( | 787 host_content_settings_map->GetContentSetting( |
788 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 788 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
789 } | 789 } |
790 | 790 |
791 // Managed default content setting should have higher priority | 791 // Managed default content setting should have higher priority |
792 // than user defined patterns. | 792 // than user defined patterns. |
793 TEST_F(HostContentSettingsMapTest, | 793 TEST_F(HostContentSettingsMapTest, |
794 ManagedDefaultContentSettingIgnoreUserPattern) { | 794 ManagedDefaultContentSettingIgnoreUserPattern) { |
795 TestingProfile profile; | 795 TestingProfile profile; |
(...skipping 19 matching lines...) Expand all Loading... |
815 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 815 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
816 host_content_settings_map->GetDefaultContentSetting( | 816 host_content_settings_map->GetDefaultContentSetting( |
817 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 817 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
818 GURL host("http://example.com/"); | 818 GURL host("http://example.com/"); |
819 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 819 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
820 host_content_settings_map->GetContentSetting( | 820 host_content_settings_map->GetContentSetting( |
821 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 821 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
822 | 822 |
823 // Set managed-default-content-settings-preferences. | 823 // Set managed-default-content-settings-preferences. |
824 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, | 824 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, |
825 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 825 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
826 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 826 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
827 host_content_settings_map->GetContentSetting( | 827 host_content_settings_map->GetContentSetting( |
828 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 828 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
829 | 829 |
830 // Remove managed-default-content-settings-preferences. | 830 // Remove managed-default-content-settings-preferences. |
831 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); | 831 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); |
832 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 832 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
833 host_content_settings_map->GetContentSetting( | 833 host_content_settings_map->GetContentSetting( |
834 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 834 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
835 } | 835 } |
836 | 836 |
837 // If a default-content-setting is set to managed setting, the user defined | 837 // If a default-content-setting is set to managed setting, the user defined |
838 // setting should be preserved. | 838 // setting should be preserved. |
839 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) { | 839 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) { |
840 TestingProfile profile; | 840 TestingProfile profile; |
841 HostContentSettingsMap* host_content_settings_map = | 841 HostContentSettingsMap* host_content_settings_map = |
842 profile.GetHostContentSettingsMap(); | 842 profile.GetHostContentSettingsMap(); |
843 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | 843 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
844 | 844 |
845 // Set user defined default-content-setting for Cookies. | 845 // Set user defined default-content-setting for Cookies. |
846 host_content_settings_map->SetDefaultContentSetting( | 846 host_content_settings_map->SetDefaultContentSetting( |
847 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 847 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
848 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 848 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
849 host_content_settings_map->GetDefaultContentSetting( | 849 host_content_settings_map->GetDefaultContentSetting( |
850 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | 850 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
851 | 851 |
852 // Set preference to manage the default-content-setting for Cookies. | 852 // Set preference to manage the default-content-setting for Cookies. |
853 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, | 853 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, |
854 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 854 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
855 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 855 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
856 host_content_settings_map->GetDefaultContentSetting( | 856 host_content_settings_map->GetDefaultContentSetting( |
857 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | 857 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
858 | 858 |
859 // Remove the preference to manage the default-content-setting for Cookies. | 859 // Remove the preference to manage the default-content-setting for Cookies. |
860 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); | 860 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); |
861 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 861 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
862 host_content_settings_map->GetDefaultContentSetting( | 862 host_content_settings_map->GetDefaultContentSetting( |
863 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | 863 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
864 } | 864 } |
865 | 865 |
866 // If a setting for a default-content-setting-type is set while the type is | 866 // If a setting for a default-content-setting-type is set while the type is |
867 // managed, then the new setting should be preserved and used after the | 867 // managed, then the new setting should be preserved and used after the |
868 // default-content-setting-type is not managed anymore. | 868 // default-content-setting-type is not managed anymore. |
869 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { | 869 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { |
870 TestingProfile profile; | 870 TestingProfile profile; |
871 HostContentSettingsMap* host_content_settings_map = | 871 HostContentSettingsMap* host_content_settings_map = |
872 profile.GetHostContentSettingsMap(); | 872 profile.GetHostContentSettingsMap(); |
873 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | 873 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
874 | 874 |
875 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, | 875 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, |
876 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 876 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
877 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 877 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
878 host_content_settings_map->GetDefaultContentSetting( | 878 host_content_settings_map->GetDefaultContentSetting( |
879 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 879 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
880 | 880 |
881 host_content_settings_map->SetDefaultContentSetting( | 881 host_content_settings_map->SetDefaultContentSetting( |
882 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 882 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
883 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 883 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
884 host_content_settings_map->GetDefaultContentSetting( | 884 host_content_settings_map->GetDefaultContentSetting( |
885 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 885 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
886 | 886 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( | 941 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( |
942 extension, http_host, CONTENT_SETTINGS_TYPE_COOKIES)); | 942 extension, http_host, CONTENT_SETTINGS_TYPE_COOKIES)); |
943 } | 943 } |
944 | 944 |
945 TEST_F(HostContentSettingsMapTest, MigrateClearOnExit) { | 945 TEST_F(HostContentSettingsMapTest, MigrateClearOnExit) { |
946 TestingProfile profile; | 946 TestingProfile profile; |
947 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | 947 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
948 | 948 |
949 prefs->SetBoolean(prefs::kClearSiteDataOnExit, true); | 949 prefs->SetBoolean(prefs::kClearSiteDataOnExit, true); |
950 | 950 |
951 scoped_ptr<Value> patterns(base::JSONReader::Read( | 951 scoped_ptr<base::Value> patterns(base::JSONReader::Read( |
952 "{\"[*.]example.com,*\":{\"cookies\": 1}," | 952 "{\"[*.]example.com,*\":{\"cookies\": 1}," |
953 " \"[*.]other.com,*\":{\"cookies\": 2}," | 953 " \"[*.]other.com,*\":{\"cookies\": 2}," |
954 " \"[*.]third.com,*\":{\"cookies\": 4}}")); | 954 " \"[*.]third.com,*\":{\"cookies\": 4}}")); |
955 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *patterns); | 955 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *patterns); |
956 | 956 |
957 scoped_ptr<Value> defaults(base::JSONReader::Read("{\"cookies\": 1}")); | 957 scoped_ptr<base::Value> defaults(base::JSONReader::Read("{\"cookies\": 1}")); |
958 profile.GetPrefs()->Set(prefs::kDefaultContentSettings, *defaults); | 958 profile.GetPrefs()->Set(prefs::kDefaultContentSettings, *defaults); |
959 | 959 |
960 HostContentSettingsMap* host_content_settings_map = | 960 HostContentSettingsMap* host_content_settings_map = |
961 profile.GetHostContentSettingsMap(); | 961 profile.GetHostContentSettingsMap(); |
962 | 962 |
963 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | 963 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, |
964 host_content_settings_map->GetDefaultContentSetting( | 964 host_content_settings_map->GetDefaultContentSetting( |
965 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | 965 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
966 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | 966 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, |
967 host_content_settings_map->GetContentSetting( | 967 host_content_settings_map->GetContentSetting( |
968 GURL("http://example.com"), | 968 GURL("http://example.com"), |
969 GURL("http://example.com"), | 969 GURL("http://example.com"), |
970 CONTENT_SETTINGS_TYPE_COOKIES, | 970 CONTENT_SETTINGS_TYPE_COOKIES, |
971 std::string())); | 971 std::string())); |
972 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 972 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
973 host_content_settings_map->GetContentSetting( | 973 host_content_settings_map->GetContentSetting( |
974 GURL("http://other.com"), | 974 GURL("http://other.com"), |
975 GURL("http://other.com"), | 975 GURL("http://other.com"), |
976 CONTENT_SETTINGS_TYPE_COOKIES, | 976 CONTENT_SETTINGS_TYPE_COOKIES, |
977 std::string())); | 977 std::string())); |
978 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | 978 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, |
979 host_content_settings_map->GetContentSetting( | 979 host_content_settings_map->GetContentSetting( |
980 GURL("http://third.com"), | 980 GURL("http://third.com"), |
981 GURL("http://third.com"), | 981 GURL("http://third.com"), |
982 CONTENT_SETTINGS_TYPE_COOKIES, | 982 CONTENT_SETTINGS_TYPE_COOKIES, |
983 std::string())); | 983 std::string())); |
984 } | 984 } |
OLD | NEW |