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 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1010 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1011 host_content_settings_map->GetDefaultContentSetting( | 1011 host_content_settings_map->GetDefaultContentSetting( |
1012 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 1012 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
1013 | 1013 |
1014 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); | 1014 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); |
1015 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1015 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
1016 host_content_settings_map->GetDefaultContentSetting( | 1016 host_content_settings_map->GetDefaultContentSetting( |
1017 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 1017 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
1018 } | 1018 } |
1019 | 1019 |
1020 TEST_F(HostContentSettingsMapTest, ShouldAllowAllContent) { | 1020 TEST_F(HostContentSettingsMapTest, GetContentSetting) { |
1021 TestingProfile profile; | 1021 TestingProfile profile; |
1022 HostContentSettingsMap* host_content_settings_map = | 1022 HostContentSettingsMap* host_content_settings_map = |
1023 profile.GetHostContentSettingsMap(); | 1023 profile.GetHostContentSettingsMap(); |
1024 | 1024 |
1025 GURL host("http://example.com/"); | 1025 GURL host("http://example.com/"); |
1026 GURL embedder("chrome://foo"); | 1026 GURL embedder("chrome://foo"); |
1027 ContentSettingsPattern pattern = | 1027 ContentSettingsPattern pattern = |
1028 ContentSettingsPattern::FromString("[*.]example.com"); | 1028 ContentSettingsPattern::FromString("[*.]example.com"); |
1029 host_content_settings_map->SetContentSetting( | 1029 host_content_settings_map->SetContentSetting( |
1030 pattern, | 1030 pattern, |
1031 ContentSettingsPattern::Wildcard(), | 1031 ContentSettingsPattern::Wildcard(), |
1032 CONTENT_SETTINGS_TYPE_IMAGES, | 1032 CONTENT_SETTINGS_TYPE_IMAGES, |
1033 std::string(), | 1033 std::string(), |
1034 CONTENT_SETTING_BLOCK); | 1034 CONTENT_SETTING_BLOCK); |
1035 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1035 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
1036 host_content_settings_map->GetContentSetting( | 1036 host_content_settings_map->GetContentSetting( |
1037 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 1037 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
1038 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1038 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1039 host_content_settings_map->GetContentSetting( | 1039 host_content_settings_map->GetContentSetting( |
1040 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 1040 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
1041 } | 1041 } |
1042 | 1042 |
| 1043 TEST_F(HostContentSettingsMapTest, ShouldAllowAllContent) { |
| 1044 TestingProfile profile; |
| 1045 HostContentSettingsMap* host_content_settings_map = |
| 1046 profile.GetHostContentSettingsMap(); |
| 1047 |
| 1048 GURL http_host("http://example.com/"); |
| 1049 GURL https_host("https://example.com/"); |
| 1050 GURL embedder("chrome://foo"); |
| 1051 GURL extension("chrome-extension://foo"); |
| 1052 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( |
| 1053 http_host, embedder, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
| 1054 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( |
| 1055 http_host, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 1056 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( |
| 1057 http_host, embedder, CONTENT_SETTINGS_TYPE_COOKIES)); |
| 1058 EXPECT_TRUE(host_content_settings_map->ShouldAllowAllContent( |
| 1059 https_host, embedder, CONTENT_SETTINGS_TYPE_COOKIES)); |
| 1060 EXPECT_TRUE(host_content_settings_map->ShouldAllowAllContent( |
| 1061 https_host, embedder, CONTENT_SETTINGS_TYPE_COOKIES)); |
| 1062 EXPECT_TRUE(host_content_settings_map->ShouldAllowAllContent( |
| 1063 embedder, http_host, CONTENT_SETTINGS_TYPE_COOKIES)); |
| 1064 EXPECT_TRUE(host_content_settings_map->ShouldAllowAllContent( |
| 1065 extension, extension, CONTENT_SETTINGS_TYPE_COOKIES)); |
| 1066 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( |
| 1067 extension, extension, CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 1068 EXPECT_TRUE(host_content_settings_map->ShouldAllowAllContent( |
| 1069 extension, extension, CONTENT_SETTINGS_TYPE_INTENTS)); |
| 1070 EXPECT_FALSE(host_content_settings_map->ShouldAllowAllContent( |
| 1071 extension, http_host, CONTENT_SETTINGS_TYPE_COOKIES)); |
| 1072 } |
| 1073 |
1043 TEST_F(HostContentSettingsMapTest, MigrateClearOnExit) { | 1074 TEST_F(HostContentSettingsMapTest, MigrateClearOnExit) { |
1044 TestingProfile profile; | 1075 TestingProfile profile; |
1045 TestingPrefService* prefs = profile.GetTestingPrefService(); | 1076 TestingPrefService* prefs = profile.GetTestingPrefService(); |
1046 | 1077 |
1047 prefs->SetBoolean(prefs::kClearSiteDataOnExit, true); | 1078 prefs->SetBoolean(prefs::kClearSiteDataOnExit, true); |
1048 | 1079 |
1049 scoped_ptr<Value> patterns(base::JSONReader::Read( | 1080 scoped_ptr<Value> patterns(base::JSONReader::Read( |
1050 "{\"[*.]example.com,*\":{\"cookies\": 1}," | 1081 "{\"[*.]example.com,*\":{\"cookies\": 1}," |
1051 " \"[*.]other.com,*\":{\"cookies\": 2}," | 1082 " \"[*.]other.com,*\":{\"cookies\": 2}," |
1052 " \"[*.]third.com,*\":{\"cookies\": 4}}")); | 1083 " \"[*.]third.com,*\":{\"cookies\": 4}}")); |
(...skipping 20 matching lines...) Expand all Loading... |
1073 GURL("http://other.com"), | 1104 GURL("http://other.com"), |
1074 CONTENT_SETTINGS_TYPE_COOKIES, | 1105 CONTENT_SETTINGS_TYPE_COOKIES, |
1075 std::string())); | 1106 std::string())); |
1076 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | 1107 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, |
1077 host_content_settings_map->GetContentSetting( | 1108 host_content_settings_map->GetContentSetting( |
1078 GURL("http://third.com"), | 1109 GURL("http://third.com"), |
1079 GURL("http://third.com"), | 1110 GURL("http://third.com"), |
1080 CONTENT_SETTINGS_TYPE_COOKIES, | 1111 CONTENT_SETTINGS_TYPE_COOKIES, |
1081 std::string())); | 1112 std::string())); |
1082 } | 1113 } |
OLD | NEW |