| 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 "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 "chrome/browser/content_settings/content_settings_details.h" | 9 #include "chrome/browser/content_settings/content_settings_details.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| (...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1102 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1103 host_content_settings_map->GetCookieContentSetting( | 1103 host_content_settings_map->GetCookieContentSetting( |
| 1104 kBlockedSite, kBlockedSite, false)); | 1104 kBlockedSite, kBlockedSite, false)); |
| 1105 } | 1105 } |
| 1106 | 1106 |
| 1107 TEST_F(HostContentSettingsMapTest, CookiesBlockThirdParty) { | 1107 TEST_F(HostContentSettingsMapTest, CookiesBlockThirdParty) { |
| 1108 TestingProfile profile; | 1108 TestingProfile profile; |
| 1109 HostContentSettingsMap* host_content_settings_map = | 1109 HostContentSettingsMap* host_content_settings_map = |
| 1110 profile.GetHostContentSettingsMap(); | 1110 profile.GetHostContentSettingsMap(); |
| 1111 host_content_settings_map->SetBlockThirdPartyCookies(true); | 1111 host_content_settings_map->SetBlockThirdPartyCookies(true); |
| 1112 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 1113 host_content_settings_map->GetCookieContentSetting( | |
| 1114 kBlockedSite, kFirstPartySite, false)); | |
| 1115 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 1116 host_content_settings_map->GetCookieContentSetting( | |
| 1117 kBlockedSite, kFirstPartySite, true)); | |
| 1118 | |
| 1119 CommandLine* cmd = CommandLine::ForCurrentProcess(); | |
| 1120 AutoReset<CommandLine> auto_reset(cmd, *cmd); | |
| 1121 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies); | |
| 1122 | 1112 |
| 1123 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1113 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1124 host_content_settings_map->GetCookieContentSetting( | 1114 host_content_settings_map->GetCookieContentSetting( |
| 1125 kBlockedSite, kFirstPartySite, false)); | 1115 kBlockedSite, kFirstPartySite, false)); |
| 1126 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1116 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1127 host_content_settings_map->GetCookieContentSetting( | 1117 host_content_settings_map->GetCookieContentSetting( |
| 1128 kBlockedSite, kFirstPartySite, true)); | 1118 kBlockedSite, kFirstPartySite, true)); |
| 1129 } | 1119 } |
| 1130 | 1120 |
| 1131 TEST_F(HostContentSettingsMapTest, CookiesAllowThirdParty) { | 1121 TEST_F(HostContentSettingsMapTest, CookiesAllowThirdParty) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 host_content_settings_map->GetCookieContentSetting( | 1186 host_content_settings_map->GetCookieContentSetting( |
| 1197 kAllowedSite, kFirstPartySite, true)); | 1187 kAllowedSite, kFirstPartySite, true)); |
| 1198 | 1188 |
| 1199 // Extensions should always be allowed to use cookies. | 1189 // Extensions should always be allowed to use cookies. |
| 1200 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1190 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1201 host_content_settings_map->GetCookieContentSetting( | 1191 host_content_settings_map->GetCookieContentSetting( |
| 1202 kAllowedSite, kExtensionURL, false)); | 1192 kAllowedSite, kExtensionURL, false)); |
| 1203 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1193 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1204 host_content_settings_map->GetCookieContentSetting( | 1194 host_content_settings_map->GetCookieContentSetting( |
| 1205 kAllowedSite, kExtensionURL, true)); | 1195 kAllowedSite, kExtensionURL, true)); |
| 1206 | |
| 1207 CommandLine* cmd = CommandLine::ForCurrentProcess(); | |
| 1208 AutoReset<CommandLine> auto_reset(cmd, *cmd); | |
| 1209 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies); | |
| 1210 | |
| 1211 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 1212 host_content_settings_map->GetCookieContentSetting( | |
| 1213 kAllowedSite, kFirstPartySite, false)); | |
| 1214 | |
| 1215 // Extensions should always be allowed to use cookies. | |
| 1216 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 1217 host_content_settings_map->GetCookieContentSetting( | |
| 1218 kAllowedSite, kExtensionURL, false)); | |
| 1219 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 1220 host_content_settings_map->GetCookieContentSetting( | |
| 1221 kAllowedSite, kExtensionURL, true)); | |
| 1222 } | 1196 } |
| 1223 | 1197 |
| 1224 TEST_F(HostContentSettingsMapTest, CookiesBlockEverything) { | 1198 TEST_F(HostContentSettingsMapTest, CookiesBlockEverything) { |
| 1225 TestingProfile profile; | 1199 TestingProfile profile; |
| 1226 HostContentSettingsMap* host_content_settings_map = | 1200 HostContentSettingsMap* host_content_settings_map = |
| 1227 profile.GetHostContentSettingsMap(); | 1201 profile.GetHostContentSettingsMap(); |
| 1228 host_content_settings_map->SetDefaultContentSetting( | 1202 host_content_settings_map->SetDefaultContentSetting( |
| 1229 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 1203 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
| 1230 | 1204 |
| 1231 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1205 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1261 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1235 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1262 host_content_settings_map->GetCookieContentSetting( | 1236 host_content_settings_map->GetCookieContentSetting( |
| 1263 kAllowedSite, kFirstPartySite, true)); | 1237 kAllowedSite, kFirstPartySite, true)); |
| 1264 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1238 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1265 host_content_settings_map->GetCookieContentSetting( | 1239 host_content_settings_map->GetCookieContentSetting( |
| 1266 kAllowedSite, kAllowedSite, false)); | 1240 kAllowedSite, kAllowedSite, false)); |
| 1267 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1241 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1268 host_content_settings_map->GetCookieContentSetting( | 1242 host_content_settings_map->GetCookieContentSetting( |
| 1269 kAllowedSite, kAllowedSite, true)); | 1243 kAllowedSite, kAllowedSite, true)); |
| 1270 } | 1244 } |
| OLD | NEW |