| 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 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 732 new base::FundamentalValue(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 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 745 new base::FundamentalValue(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 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 785 new base::FundamentalValue(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 base::Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 825 new base::FundamentalValue(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 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 854 new base::FundamentalValue(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 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 876 new base::FundamentalValue(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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |