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.h" | 9 #include "base/message_loop.h" |
10 #include "chrome/browser/content_settings/content_settings_details.h" | 10 #include "chrome/browser/content_settings/content_settings_details.h" |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 EXPECT_EQ("{\"[*.]example.com,*\":{\"per_plugin\":{\"otherplugin\":2}}}", | 817 EXPECT_EQ("{\"[*.]example.com,*\":{\"per_plugin\":{\"otherplugin\":2}}}", |
818 prefs_as_json); | 818 prefs_as_json); |
819 } | 819 } |
820 | 820 |
821 // If a default-content-setting is managed, the managed value should be used | 821 // If a default-content-setting is managed, the managed value should be used |
822 // instead of the default value. | 822 // instead of the default value. |
823 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { | 823 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { |
824 TestingProfile profile; | 824 TestingProfile profile; |
825 HostContentSettingsMap* host_content_settings_map = | 825 HostContentSettingsMap* host_content_settings_map = |
826 profile.GetHostContentSettingsMap(); | 826 profile.GetHostContentSettingsMap(); |
827 TestingPrefService* prefs = profile.GetTestingPrefService(); | 827 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
828 | 828 |
829 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 829 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
830 host_content_settings_map->GetDefaultContentSetting( | 830 host_content_settings_map->GetDefaultContentSetting( |
831 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 831 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
832 | 832 |
833 // Set managed-default-content-setting through the coresponding preferences. | 833 // Set managed-default-content-setting through the coresponding preferences. |
834 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, | 834 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, |
835 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 835 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
836 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 836 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
837 host_content_settings_map->GetDefaultContentSetting( | 837 host_content_settings_map->GetDefaultContentSetting( |
(...skipping 17 matching lines...) Expand all Loading... |
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_PLUGINS, NULL)); | 857 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
858 } | 858 } |
859 | 859 |
860 TEST_F(HostContentSettingsMapTest, | 860 TEST_F(HostContentSettingsMapTest, |
861 GetNonDefaultContentSettingsIfTypeManaged) { | 861 GetNonDefaultContentSettingsIfTypeManaged) { |
862 TestingProfile profile; | 862 TestingProfile profile; |
863 HostContentSettingsMap* host_content_settings_map = | 863 HostContentSettingsMap* host_content_settings_map = |
864 profile.GetHostContentSettingsMap(); | 864 profile.GetHostContentSettingsMap(); |
865 TestingPrefService* prefs = profile.GetTestingPrefService(); | 865 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
866 | 866 |
867 // Set pattern for JavaScript setting. | 867 // Set pattern for JavaScript setting. |
868 ContentSettingsPattern pattern = | 868 ContentSettingsPattern pattern = |
869 ContentSettingsPattern::FromString("[*.]example.com"); | 869 ContentSettingsPattern::FromString("[*.]example.com"); |
870 host_content_settings_map->SetContentSetting( | 870 host_content_settings_map->SetContentSetting( |
871 pattern, | 871 pattern, |
872 ContentSettingsPattern::Wildcard(), | 872 ContentSettingsPattern::Wildcard(), |
873 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 873 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
874 "", | 874 "", |
875 CONTENT_SETTING_BLOCK); | 875 CONTENT_SETTING_BLOCK); |
(...skipping 15 matching lines...) Expand all Loading... |
891 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); | 891 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); |
892 } | 892 } |
893 | 893 |
894 // Managed default content setting should have higher priority | 894 // Managed default content setting should have higher priority |
895 // than user defined patterns. | 895 // than user defined patterns. |
896 TEST_F(HostContentSettingsMapTest, | 896 TEST_F(HostContentSettingsMapTest, |
897 ManagedDefaultContentSettingIgnoreUserPattern) { | 897 ManagedDefaultContentSettingIgnoreUserPattern) { |
898 TestingProfile profile; | 898 TestingProfile profile; |
899 HostContentSettingsMap* host_content_settings_map = | 899 HostContentSettingsMap* host_content_settings_map = |
900 profile.GetHostContentSettingsMap(); | 900 profile.GetHostContentSettingsMap(); |
901 TestingPrefService* prefs = profile.GetTestingPrefService(); | 901 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
902 | 902 |
903 // Block all JavaScript. | 903 // Block all JavaScript. |
904 host_content_settings_map->SetDefaultContentSetting( | 904 host_content_settings_map->SetDefaultContentSetting( |
905 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 905 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
906 | 906 |
907 // Set an exception to allow "[*.]example.com" | 907 // Set an exception to allow "[*.]example.com" |
908 ContentSettingsPattern pattern = | 908 ContentSettingsPattern pattern = |
909 ContentSettingsPattern::FromString("[*.]example.com"); | 909 ContentSettingsPattern::FromString("[*.]example.com"); |
910 | 910 |
911 host_content_settings_map->SetContentSetting( | 911 host_content_settings_map->SetContentSetting( |
(...skipping 24 matching lines...) Expand all Loading... |
936 host_content_settings_map->GetContentSetting( | 936 host_content_settings_map->GetContentSetting( |
937 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); | 937 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); |
938 } | 938 } |
939 | 939 |
940 // If a default-content-setting is set to managed setting, the user defined | 940 // If a default-content-setting is set to managed setting, the user defined |
941 // setting should be preserved. | 941 // setting should be preserved. |
942 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) { | 942 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) { |
943 TestingProfile profile; | 943 TestingProfile profile; |
944 HostContentSettingsMap* host_content_settings_map = | 944 HostContentSettingsMap* host_content_settings_map = |
945 profile.GetHostContentSettingsMap(); | 945 profile.GetHostContentSettingsMap(); |
946 TestingPrefService* prefs = profile.GetTestingPrefService(); | 946 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
947 | 947 |
948 // Set user defined default-content-setting for Cookies. | 948 // Set user defined default-content-setting for Cookies. |
949 host_content_settings_map->SetDefaultContentSetting( | 949 host_content_settings_map->SetDefaultContentSetting( |
950 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 950 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
951 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 951 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
952 host_content_settings_map->GetDefaultContentSetting( | 952 host_content_settings_map->GetDefaultContentSetting( |
953 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | 953 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
954 | 954 |
955 // Set preference to manage the default-content-setting for Cookies. | 955 // Set preference to manage the default-content-setting for Cookies. |
956 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, | 956 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, |
957 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 957 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
958 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 958 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
959 host_content_settings_map->GetDefaultContentSetting( | 959 host_content_settings_map->GetDefaultContentSetting( |
960 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | 960 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
961 | 961 |
962 // Remove the preference to manage the default-content-setting for Cookies. | 962 // Remove the preference to manage the default-content-setting for Cookies. |
963 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); | 963 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); |
964 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 964 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
965 host_content_settings_map->GetDefaultContentSetting( | 965 host_content_settings_map->GetDefaultContentSetting( |
966 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | 966 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
967 } | 967 } |
968 | 968 |
969 // If a setting for a default-content-setting-type is set while the type is | 969 // If a setting for a default-content-setting-type is set while the type is |
970 // managed, then the new setting should be preserved and used after the | 970 // managed, then the new setting should be preserved and used after the |
971 // default-content-setting-type is not managed anymore. | 971 // default-content-setting-type is not managed anymore. |
972 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { | 972 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { |
973 TestingProfile profile; | 973 TestingProfile profile; |
974 HostContentSettingsMap* host_content_settings_map = | 974 HostContentSettingsMap* host_content_settings_map = |
975 profile.GetHostContentSettingsMap(); | 975 profile.GetHostContentSettingsMap(); |
976 TestingPrefService* prefs = profile.GetTestingPrefService(); | 976 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
977 | 977 |
978 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, | 978 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, |
979 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 979 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
980 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 980 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
981 host_content_settings_map->GetDefaultContentSetting( | 981 host_content_settings_map->GetDefaultContentSetting( |
982 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 982 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
983 | 983 |
984 host_content_settings_map->SetDefaultContentSetting( | 984 host_content_settings_map->SetDefaultContentSetting( |
985 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 985 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
986 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 986 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( | 1042 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( |
1043 extension, extension, CONTENT_SETTINGS_TYPE_PLUGINS)); | 1043 extension, extension, CONTENT_SETTINGS_TYPE_PLUGINS)); |
1044 EXPECT_TRUE(host_content_settings_map->ShouldAllowAllContent( | 1044 EXPECT_TRUE(host_content_settings_map->ShouldAllowAllContent( |
1045 extension, extension, CONTENT_SETTINGS_TYPE_INTENTS)); | 1045 extension, extension, CONTENT_SETTINGS_TYPE_INTENTS)); |
1046 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( | 1046 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( |
1047 extension, http_host, CONTENT_SETTINGS_TYPE_COOKIES)); | 1047 extension, http_host, CONTENT_SETTINGS_TYPE_COOKIES)); |
1048 } | 1048 } |
1049 | 1049 |
1050 TEST_F(HostContentSettingsMapTest, MigrateClearOnExit) { | 1050 TEST_F(HostContentSettingsMapTest, MigrateClearOnExit) { |
1051 TestingProfile profile; | 1051 TestingProfile profile; |
1052 TestingPrefService* prefs = profile.GetTestingPrefService(); | 1052 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
1053 | 1053 |
1054 prefs->SetBoolean(prefs::kClearSiteDataOnExit, true); | 1054 prefs->SetBoolean(prefs::kClearSiteDataOnExit, true); |
1055 | 1055 |
1056 scoped_ptr<Value> patterns(base::JSONReader::Read( | 1056 scoped_ptr<Value> patterns(base::JSONReader::Read( |
1057 "{\"[*.]example.com,*\":{\"cookies\": 1}," | 1057 "{\"[*.]example.com,*\":{\"cookies\": 1}," |
1058 " \"[*.]other.com,*\":{\"cookies\": 2}," | 1058 " \"[*.]other.com,*\":{\"cookies\": 2}," |
1059 " \"[*.]third.com,*\":{\"cookies\": 4}}")); | 1059 " \"[*.]third.com,*\":{\"cookies\": 4}}")); |
1060 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *patterns); | 1060 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *patterns); |
1061 | 1061 |
1062 scoped_ptr<Value> defaults(base::JSONReader::Read("{\"cookies\": 1}")); | 1062 scoped_ptr<Value> defaults(base::JSONReader::Read("{\"cookies\": 1}")); |
(...skipping 17 matching lines...) Expand all Loading... |
1080 GURL("http://other.com"), | 1080 GURL("http://other.com"), |
1081 CONTENT_SETTINGS_TYPE_COOKIES, | 1081 CONTENT_SETTINGS_TYPE_COOKIES, |
1082 std::string())); | 1082 std::string())); |
1083 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | 1083 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, |
1084 host_content_settings_map->GetContentSetting( | 1084 host_content_settings_map->GetContentSetting( |
1085 GURL("http://third.com"), | 1085 GURL("http://third.com"), |
1086 GURL("http://third.com"), | 1086 GURL("http://third.com"), |
1087 CONTENT_SETTINGS_TYPE_COOKIES, | 1087 CONTENT_SETTINGS_TYPE_COOKIES, |
1088 std::string())); | 1088 std::string())); |
1089 } | 1089 } |
OLD | NEW |