| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 CONTENT_SETTINGS_TYPE_IMAGES, false, | 310 CONTENT_SETTINGS_TYPE_IMAGES, false, |
| 311 _, _, true)); | 311 _, _, true)); |
| 312 host_content_settings_map->SetDefaultContentSetting( | 312 host_content_settings_map->SetDefaultContentSetting( |
| 313 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 313 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); |
| 314 } | 314 } |
| 315 | 315 |
| 316 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { | 316 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { |
| 317 TestingProfile profile; | 317 TestingProfile profile; |
| 318 HostContentSettingsMap* host_content_settings_map = | 318 HostContentSettingsMap* host_content_settings_map = |
| 319 profile.GetHostContentSettingsMap(); | 319 profile.GetHostContentSettingsMap(); |
| 320 CookieContentSettings* cookie_content_settings = |
| 321 profile.GetCookieContentSettings(); |
| 320 | 322 |
| 321 PrefService* prefs = profile.GetPrefs(); | 323 PrefService* prefs = profile.GetPrefs(); |
| 322 | 324 |
| 323 // Make a copy of the default pref value so we can reset it later. | 325 // Make a copy of the default pref value so we can reset it later. |
| 324 scoped_ptr<Value> default_value(prefs->FindPreference( | 326 scoped_ptr<Value> default_value(prefs->FindPreference( |
| 325 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 327 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
| 326 | 328 |
| 327 GURL host("http://example.com"); | 329 GURL host("http://example.com"); |
| 328 | 330 |
| 329 host_content_settings_map->SetDefaultContentSetting( | 331 host_content_settings_map->SetDefaultContentSetting( |
| 330 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 332 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
| 331 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 333 EXPECT_FALSE(cookie_content_settings->Allow(host, host, true)); |
| 332 host_content_settings_map->GetCookieContentSetting( | |
| 333 host, host, true)); | |
| 334 | 334 |
| 335 // Make a copy of the pref's new value so we can reset it later. | 335 // Make a copy of the pref's new value so we can reset it later. |
| 336 scoped_ptr<Value> new_value(prefs->FindPreference( | 336 scoped_ptr<Value> new_value(prefs->FindPreference( |
| 337 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 337 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
| 338 | 338 |
| 339 // Clearing the backing pref should also clear the internal cache. | 339 // Clearing the backing pref should also clear the internal cache. |
| 340 prefs->Set(prefs::kDefaultContentSettings, *default_value); | 340 prefs->Set(prefs::kDefaultContentSettings, *default_value); |
| 341 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 341 EXPECT_TRUE(cookie_content_settings->Allow(host, host, true)); |
| 342 host_content_settings_map->GetCookieContentSetting( | 342 EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(host)); |
| 343 host, host, true)); | |
| 344 | 343 |
| 345 // Reseting the pref to its previous value should update the cache. | 344 // Reseting the pref to its previous value should update the cache. |
| 346 prefs->Set(prefs::kDefaultContentSettings, *new_value); | 345 prefs->Set(prefs::kDefaultContentSettings, *new_value); |
| 347 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 346 EXPECT_FALSE(cookie_content_settings->Allow(host, host, true)); |
| 348 host_content_settings_map->GetCookieContentSetting( | |
| 349 host, host, true)); | |
| 350 } | 347 } |
| 351 | 348 |
| 352 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { | 349 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { |
| 353 TestingProfile profile; | 350 TestingProfile profile; |
| 354 HostContentSettingsMap* host_content_settings_map = | 351 HostContentSettingsMap* host_content_settings_map = |
| 355 profile.GetHostContentSettingsMap(); | 352 profile.GetHostContentSettingsMap(); |
| 353 CookieContentSettings* cookie_content_settings = |
| 354 profile.GetCookieContentSettings(); |
| 356 | 355 |
| 357 PrefService* prefs = profile.GetPrefs(); | 356 PrefService* prefs = profile.GetPrefs(); |
| 358 | 357 |
| 359 // Make a copy of the default pref value so we can reset it later. | 358 // Make a copy of the default pref value so we can reset it later. |
| 360 scoped_ptr<Value> default_value(prefs->FindPreference( | 359 scoped_ptr<Value> default_value(prefs->FindPreference( |
| 361 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); | 360 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); |
| 362 | 361 |
| 363 ContentSettingsPattern pattern = | 362 ContentSettingsPattern pattern = |
| 364 ContentSettingsPattern::FromString("[*.]example.com"); | 363 ContentSettingsPattern::FromString("[*.]example.com"); |
| 365 GURL host("http://example.com"); | 364 GURL host("http://example.com"); |
| 366 | 365 |
| 367 host_content_settings_map->SetContentSetting( | 366 host_content_settings_map->SetContentSetting( |
| 368 pattern, | 367 pattern, |
| 369 ContentSettingsPattern::Wildcard(), | 368 ContentSettingsPattern::Wildcard(), |
| 370 CONTENT_SETTINGS_TYPE_COOKIES, | 369 CONTENT_SETTINGS_TYPE_COOKIES, |
| 371 std::string(), | 370 std::string(), |
| 372 CONTENT_SETTING_BLOCK); | 371 CONTENT_SETTING_BLOCK); |
| 373 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 372 |
| 374 host_content_settings_map->GetCookieContentSetting( | 373 EXPECT_FALSE(cookie_content_settings->Allow(host, host, true)); |
| 375 host, host, true)); | |
| 376 | 374 |
| 377 // Make a copy of the pref's new value so we can reset it later. | 375 // Make a copy of the pref's new value so we can reset it later. |
| 378 scoped_ptr<Value> new_value(prefs->FindPreference( | 376 scoped_ptr<Value> new_value(prefs->FindPreference( |
| 379 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); | 377 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); |
| 380 | 378 |
| 381 // Clearing the backing pref should also clear the internal cache. | 379 // Clearing the backing pref should also clear the internal cache. |
| 382 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value); | 380 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value); |
| 383 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 381 EXPECT_TRUE(cookie_content_settings->Allow(host, host, true)); |
| 384 host_content_settings_map->GetCookieContentSetting( | 382 EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(host)); |
| 385 host, host, true)); | |
| 386 | 383 |
| 387 // Reseting the pref to its previous value should update the cache. | 384 // Reseting the pref to its previous value should update the cache. |
| 388 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); | 385 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); |
| 389 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 386 EXPECT_FALSE(cookie_content_settings->Allow(host, host, true)); |
| 390 host_content_settings_map->GetCookieContentSetting( | |
| 391 host, host, true)); | |
| 392 } | 387 } |
| 393 | 388 |
| 394 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { | 389 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { |
| 395 TestingProfile profile; | 390 TestingProfile profile; |
| 396 HostContentSettingsMap* host_content_settings_map = | 391 HostContentSettingsMap* host_content_settings_map = |
| 397 profile.GetHostContentSettingsMap(); | 392 profile.GetHostContentSettingsMap(); |
| 393 CookieContentSettings* cookie_content_settings = |
| 394 profile.GetCookieContentSettings(); |
| 398 | 395 |
| 399 ContentSettingsPattern pattern = | 396 ContentSettingsPattern pattern = |
| 400 ContentSettingsPattern::FromString("[*.]example.com"); | 397 ContentSettingsPattern::FromString("[*.]example.com"); |
| 401 GURL host_ending_with_dot("http://example.com./"); | 398 GURL host_ending_with_dot("http://example.com./"); |
| 402 | 399 |
| 403 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 400 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 404 host_content_settings_map->GetContentSetting( | 401 host_content_settings_map->GetContentSetting( |
| 405 host_ending_with_dot, | 402 host_ending_with_dot, |
| 406 host_ending_with_dot, | 403 host_ending_with_dot, |
| 407 CONTENT_SETTINGS_TYPE_IMAGES, | 404 CONTENT_SETTINGS_TYPE_IMAGES, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 424 CONTENT_SETTINGS_TYPE_IMAGES, | 421 CONTENT_SETTINGS_TYPE_IMAGES, |
| 425 "", | 422 "", |
| 426 CONTENT_SETTING_BLOCK); | 423 CONTENT_SETTING_BLOCK); |
| 427 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 424 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 428 host_content_settings_map->GetContentSetting( | 425 host_content_settings_map->GetContentSetting( |
| 429 host_ending_with_dot, | 426 host_ending_with_dot, |
| 430 host_ending_with_dot, | 427 host_ending_with_dot, |
| 431 CONTENT_SETTINGS_TYPE_IMAGES, | 428 CONTENT_SETTINGS_TYPE_IMAGES, |
| 432 "")); | 429 "")); |
| 433 | 430 |
| 434 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 431 EXPECT_TRUE(cookie_content_settings->Allow( |
| 435 host_content_settings_map->GetCookieContentSetting( | 432 host_ending_with_dot, host_ending_with_dot, true)); |
| 436 host_ending_with_dot, host_ending_with_dot, true)); | |
| 437 host_content_settings_map->SetContentSetting( | 433 host_content_settings_map->SetContentSetting( |
| 438 pattern, | 434 pattern, |
| 439 ContentSettingsPattern::Wildcard(), | 435 ContentSettingsPattern::Wildcard(), |
| 440 CONTENT_SETTINGS_TYPE_COOKIES, | 436 CONTENT_SETTINGS_TYPE_COOKIES, |
| 441 "", | 437 "", |
| 442 CONTENT_SETTING_DEFAULT); | 438 CONTENT_SETTING_DEFAULT); |
| 443 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 439 EXPECT_TRUE(cookie_content_settings->Allow( |
| 444 host_content_settings_map->GetCookieContentSetting( | 440 host_ending_with_dot, host_ending_with_dot, true)); |
| 445 host_ending_with_dot, host_ending_with_dot, true)); | |
| 446 host_content_settings_map->SetContentSetting( | 441 host_content_settings_map->SetContentSetting( |
| 447 pattern, | 442 pattern, |
| 448 ContentSettingsPattern::Wildcard(), | 443 ContentSettingsPattern::Wildcard(), |
| 449 CONTENT_SETTINGS_TYPE_COOKIES, | 444 CONTENT_SETTINGS_TYPE_COOKIES, |
| 450 "", | 445 "", |
| 451 CONTENT_SETTING_BLOCK); | 446 CONTENT_SETTING_BLOCK); |
| 452 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 447 EXPECT_FALSE(cookie_content_settings->Allow( |
| 453 host_content_settings_map->GetCookieContentSetting( | 448 host_ending_with_dot, host_ending_with_dot, true)); |
| 454 host_ending_with_dot, host_ending_with_dot, true)); | |
| 455 | 449 |
| 456 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 450 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 457 host_content_settings_map->GetContentSetting( | 451 host_content_settings_map->GetContentSetting( |
| 458 host_ending_with_dot, | 452 host_ending_with_dot, |
| 459 host_ending_with_dot, | 453 host_ending_with_dot, |
| 460 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 454 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 461 "")); | 455 "")); |
| 462 host_content_settings_map->SetContentSetting( | 456 host_content_settings_map->SetContentSetting( |
| 463 pattern, | 457 pattern, |
| 464 ContentSettingsPattern::Wildcard(), | 458 ContentSettingsPattern::Wildcard(), |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 // Tests for cookie content settings. | 1075 // Tests for cookie content settings. |
| 1082 const GURL kBlockedSite = GURL("http://ads.thirdparty.com"); | 1076 const GURL kBlockedSite = GURL("http://ads.thirdparty.com"); |
| 1083 const GURL kAllowedSite = GURL("http://good.allays.com"); | 1077 const GURL kAllowedSite = GURL("http://good.allays.com"); |
| 1084 const GURL kFirstPartySite = GURL("http://cool.things.com"); | 1078 const GURL kFirstPartySite = GURL("http://cool.things.com"); |
| 1085 const GURL kExtensionURL = GURL("chrome-extension://deadbeef"); | 1079 const GURL kExtensionURL = GURL("chrome-extension://deadbeef"); |
| 1086 | 1080 |
| 1087 TEST_F(HostContentSettingsMapTest, CookiesBlockSingle) { | 1081 TEST_F(HostContentSettingsMapTest, CookiesBlockSingle) { |
| 1088 TestingProfile profile; | 1082 TestingProfile profile; |
| 1089 HostContentSettingsMap* host_content_settings_map = | 1083 HostContentSettingsMap* host_content_settings_map = |
| 1090 profile.GetHostContentSettingsMap(); | 1084 profile.GetHostContentSettingsMap(); |
| 1085 CookieContentSettings* cookie_content_settings = |
| 1086 profile.GetCookieContentSettings(); |
| 1087 |
| 1091 host_content_settings_map->AddExceptionForURL( | 1088 host_content_settings_map->AddExceptionForURL( |
| 1092 kBlockedSite, | 1089 kBlockedSite, |
| 1093 kBlockedSite, | 1090 kBlockedSite, |
| 1094 CONTENT_SETTINGS_TYPE_COOKIES, | 1091 CONTENT_SETTINGS_TYPE_COOKIES, |
| 1095 "", | 1092 "", |
| 1096 CONTENT_SETTING_BLOCK); | 1093 CONTENT_SETTING_BLOCK); |
| 1097 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1094 EXPECT_FALSE(cookie_content_settings->Allow( |
| 1098 host_content_settings_map->GetCookieContentSetting( | 1095 kBlockedSite, kBlockedSite, false)); |
| 1099 kBlockedSite, kBlockedSite, false)); | |
| 1100 } | 1096 } |
| 1101 | 1097 |
| 1102 TEST_F(HostContentSettingsMapTest, CookiesBlockThirdParty) { | 1098 TEST_F(HostContentSettingsMapTest, CookiesBlockThirdParty) { |
| 1103 TestingProfile profile; | 1099 TestingProfile profile; |
| 1104 HostContentSettingsMap* host_content_settings_map = | 1100 CookieContentSettings* cookie_content_settings = |
| 1105 profile.GetHostContentSettingsMap(); | 1101 profile.GetCookieContentSettings(); |
| 1106 host_content_settings_map->SetBlockThirdPartyCookies(true); | 1102 cookie_content_settings->SetBlockThirdPartyCookies(true); |
| 1107 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1103 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1108 host_content_settings_map->GetCookieContentSetting( | 1104 kBlockedSite, kFirstPartySite, false)); |
| 1109 kBlockedSite, kFirstPartySite, false)); | 1105 EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(kBlockedSite)); |
| 1110 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1106 EXPECT_FALSE(cookie_content_settings->Allow( |
| 1111 host_content_settings_map->GetCookieContentSetting( | 1107 kBlockedSite, kFirstPartySite, true)); |
| 1112 kBlockedSite, kFirstPartySite, true)); | |
| 1113 | 1108 |
| 1114 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 1109 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
| 1115 AutoReset<CommandLine> auto_reset(cmd, *cmd); | 1110 AutoReset<CommandLine> auto_reset(cmd, *cmd); |
| 1116 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies); | 1111 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies); |
| 1117 | 1112 |
| 1118 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1113 EXPECT_FALSE(cookie_content_settings->Allow( |
| 1119 host_content_settings_map->GetCookieContentSetting( | 1114 kBlockedSite, kFirstPartySite, false)); |
| 1120 kBlockedSite, kFirstPartySite, false)); | 1115 EXPECT_FALSE(cookie_content_settings->Allow( |
| 1121 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1116 kBlockedSite, kFirstPartySite, true)); |
| 1122 host_content_settings_map->GetCookieContentSetting( | |
| 1123 kBlockedSite, kFirstPartySite, true)); | |
| 1124 } | 1117 } |
| 1125 | 1118 |
| 1126 TEST_F(HostContentSettingsMapTest, CookiesAllowThirdParty) { | 1119 TEST_F(HostContentSettingsMapTest, CookiesAllowThirdParty) { |
| 1127 TestingProfile profile; | 1120 TestingProfile profile; |
| 1128 HostContentSettingsMap* host_content_settings_map = | 1121 CookieContentSettings* cookie_content_settings = |
| 1129 profile.GetHostContentSettingsMap(); | 1122 profile.GetCookieContentSettings(); |
| 1130 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1123 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1131 host_content_settings_map->GetCookieContentSetting( | 1124 kBlockedSite, kFirstPartySite, false)); |
| 1132 kBlockedSite, kFirstPartySite, false)); | 1125 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1133 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1126 kBlockedSite, kFirstPartySite, true)); |
| 1134 host_content_settings_map->GetCookieContentSetting( | 1127 EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(kBlockedSite)); |
| 1135 kBlockedSite, kFirstPartySite, true)); | |
| 1136 } | 1128 } |
| 1137 | 1129 |
| 1138 TEST_F(HostContentSettingsMapTest, CookiesExplicitBlockSingleThirdParty) { | 1130 TEST_F(HostContentSettingsMapTest, CookiesExplicitBlockSingleThirdParty) { |
| 1139 TestingProfile profile; | 1131 TestingProfile profile; |
| 1140 HostContentSettingsMap* host_content_settings_map = | 1132 HostContentSettingsMap* host_content_settings_map = |
| 1141 profile.GetHostContentSettingsMap(); | 1133 profile.GetHostContentSettingsMap(); |
| 1134 CookieContentSettings* cookie_content_settings = |
| 1135 profile.GetCookieContentSettings(); |
| 1142 host_content_settings_map->AddExceptionForURL( | 1136 host_content_settings_map->AddExceptionForURL( |
| 1143 kBlockedSite, kBlockedSite, CONTENT_SETTINGS_TYPE_COOKIES, "", | 1137 kBlockedSite, kBlockedSite, CONTENT_SETTINGS_TYPE_COOKIES, "", |
| 1144 CONTENT_SETTING_BLOCK); | 1138 CONTENT_SETTING_BLOCK); |
| 1145 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1139 EXPECT_FALSE(cookie_content_settings->Allow( |
| 1146 host_content_settings_map->GetCookieContentSetting( | 1140 kBlockedSite, kFirstPartySite, false)); |
| 1147 kBlockedSite, kFirstPartySite, false)); | 1141 EXPECT_FALSE(cookie_content_settings->Allow( |
| 1148 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1142 kBlockedSite, kFirstPartySite, true)); |
| 1149 host_content_settings_map->GetCookieContentSetting( | 1143 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1150 kBlockedSite, kFirstPartySite, true)); | 1144 kAllowedSite, kFirstPartySite, true)); |
| 1151 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 1152 host_content_settings_map->GetCookieContentSetting( | |
| 1153 kAllowedSite, kFirstPartySite, true)); | |
| 1154 } | 1145 } |
| 1155 | 1146 |
| 1156 TEST_F(HostContentSettingsMapTest, CookiesExplicitSessionOnly) { | 1147 TEST_F(HostContentSettingsMapTest, CookiesExplicitSessionOnly) { |
| 1157 TestingProfile profile; | 1148 TestingProfile profile; |
| 1158 HostContentSettingsMap* host_content_settings_map = | 1149 HostContentSettingsMap* host_content_settings_map = |
| 1159 profile.GetHostContentSettingsMap(); | 1150 profile.GetHostContentSettingsMap(); |
| 1151 CookieContentSettings* cookie_content_settings = |
| 1152 profile.GetCookieContentSettings(); |
| 1160 host_content_settings_map->AddExceptionForURL( | 1153 host_content_settings_map->AddExceptionForURL( |
| 1161 kBlockedSite, kBlockedSite, CONTENT_SETTINGS_TYPE_COOKIES, "", | 1154 kBlockedSite, kBlockedSite, CONTENT_SETTINGS_TYPE_COOKIES, "", |
| 1162 CONTENT_SETTING_SESSION_ONLY); | 1155 CONTENT_SETTING_SESSION_ONLY); |
| 1163 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | 1156 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1164 host_content_settings_map->GetCookieContentSetting( | 1157 kBlockedSite, kFirstPartySite, false)); |
| 1165 kBlockedSite, kFirstPartySite, false)); | 1158 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1166 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | 1159 kBlockedSite, kFirstPartySite, true)); |
| 1167 host_content_settings_map->GetCookieContentSetting( | 1160 EXPECT_TRUE(cookie_content_settings->EnforceSessionOnly(kBlockedSite)); |
| 1168 kBlockedSite, kFirstPartySite, true)); | |
| 1169 | 1161 |
| 1170 host_content_settings_map->SetBlockThirdPartyCookies(true); | 1162 cookie_content_settings->SetBlockThirdPartyCookies(true); |
| 1171 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | 1163 EXPECT_TRUE(cookie_content_settings-> |
| 1172 host_content_settings_map->GetCookieContentSetting( | 1164 Allow(kBlockedSite, kFirstPartySite, false)); |
| 1173 kBlockedSite, kFirstPartySite, false)); | 1165 EXPECT_TRUE(cookie_content_settings-> |
| 1174 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | 1166 Allow(kBlockedSite, kFirstPartySite, true)); |
| 1175 host_content_settings_map->GetCookieContentSetting( | 1167 EXPECT_TRUE(cookie_content_settings->EnforceSessionOnly(kBlockedSite)); |
| 1176 kBlockedSite, kFirstPartySite, true)); | |
| 1177 } | 1168 } |
| 1178 | 1169 |
| 1179 TEST_F(HostContentSettingsMapTest, CookiesThirdPartyBlockedExplicitAllow) { | 1170 TEST_F(HostContentSettingsMapTest, CookiesThirdPartyBlockedExplicitAllow) { |
| 1180 TestingProfile profile; | 1171 TestingProfile profile; |
| 1181 HostContentSettingsMap* host_content_settings_map = | 1172 HostContentSettingsMap* host_content_settings_map = |
| 1182 profile.GetHostContentSettingsMap(); | 1173 profile.GetHostContentSettingsMap(); |
| 1174 CookieContentSettings* cookie_content_settings = |
| 1175 profile.GetCookieContentSettings(); |
| 1183 host_content_settings_map->AddExceptionForURL( | 1176 host_content_settings_map->AddExceptionForURL( |
| 1184 kAllowedSite, kAllowedSite, CONTENT_SETTINGS_TYPE_COOKIES, "", | 1177 kAllowedSite, kAllowedSite, CONTENT_SETTINGS_TYPE_COOKIES, "", |
| 1185 CONTENT_SETTING_ALLOW); | 1178 CONTENT_SETTING_ALLOW); |
| 1186 host_content_settings_map->SetBlockThirdPartyCookies(true); | 1179 cookie_content_settings->SetBlockThirdPartyCookies(true); |
| 1187 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1180 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1188 host_content_settings_map->GetCookieContentSetting( | 1181 kAllowedSite, kFirstPartySite, false)); |
| 1189 kAllowedSite, kFirstPartySite, false)); | 1182 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1190 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1183 kAllowedSite, kFirstPartySite, true)); |
| 1191 host_content_settings_map->GetCookieContentSetting( | 1184 EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(kAllowedSite)); |
| 1192 kAllowedSite, kFirstPartySite, true)); | |
| 1193 | 1185 |
| 1194 // Extensions should always be allowed to use cookies. | 1186 // Extensions should always be allowed to use cookies. |
| 1195 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1187 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1196 host_content_settings_map->GetCookieContentSetting( | 1188 kAllowedSite, kExtensionURL, false)); |
| 1197 kAllowedSite, kExtensionURL, false)); | 1189 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1198 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1190 kAllowedSite, kExtensionURL, true)); |
| 1199 host_content_settings_map->GetCookieContentSetting( | |
| 1200 kAllowedSite, kExtensionURL, true)); | |
| 1201 | 1191 |
| 1202 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 1192 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
| 1203 AutoReset<CommandLine> auto_reset(cmd, *cmd); | 1193 AutoReset<CommandLine> auto_reset(cmd, *cmd); |
| 1204 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies); | 1194 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies); |
| 1205 | 1195 |
| 1206 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1196 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1207 host_content_settings_map->GetCookieContentSetting( | 1197 kAllowedSite, kFirstPartySite, false)); |
| 1208 kAllowedSite, kFirstPartySite, false)); | 1198 EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(kAllowedSite)); |
| 1209 | 1199 |
| 1210 // Extensions should always be allowed to use cookies. | 1200 // Extensions should always be allowed to use cookies. |
| 1211 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1201 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1212 host_content_settings_map->GetCookieContentSetting( | 1202 kAllowedSite, kExtensionURL, false)); |
| 1213 kAllowedSite, kExtensionURL, false)); | 1203 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1214 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1204 kAllowedSite, kExtensionURL, true)); |
| 1215 host_content_settings_map->GetCookieContentSetting( | |
| 1216 kAllowedSite, kExtensionURL, true)); | |
| 1217 } | 1205 } |
| 1218 | 1206 |
| 1219 TEST_F(HostContentSettingsMapTest, CookiesBlockEverything) { | 1207 TEST_F(HostContentSettingsMapTest, CookiesBlockEverything) { |
| 1220 TestingProfile profile; | 1208 TestingProfile profile; |
| 1221 HostContentSettingsMap* host_content_settings_map = | 1209 HostContentSettingsMap* host_content_settings_map = |
| 1222 profile.GetHostContentSettingsMap(); | 1210 profile.GetHostContentSettingsMap(); |
| 1211 CookieContentSettings* cookie_content_settings = |
| 1212 profile.GetCookieContentSettings(); |
| 1223 host_content_settings_map->SetDefaultContentSetting( | 1213 host_content_settings_map->SetDefaultContentSetting( |
| 1224 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 1214 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
| 1225 | 1215 |
| 1226 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1216 EXPECT_FALSE(cookie_content_settings->Allow( |
| 1227 host_content_settings_map->GetCookieContentSetting( | 1217 kFirstPartySite, kFirstPartySite, false)); |
| 1228 kFirstPartySite, kFirstPartySite, false)); | 1218 EXPECT_FALSE(cookie_content_settings->Allow( |
| 1229 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1219 kFirstPartySite, kFirstPartySite, true)); |
| 1230 host_content_settings_map->GetCookieContentSetting( | 1220 EXPECT_FALSE(cookie_content_settings->Allow( |
| 1231 kFirstPartySite, kFirstPartySite, true)); | 1221 kAllowedSite, kFirstPartySite, true)); |
| 1232 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 1233 host_content_settings_map->GetCookieContentSetting( | |
| 1234 kAllowedSite, kFirstPartySite, true)); | |
| 1235 } | 1222 } |
| 1236 | 1223 |
| 1237 TEST_F(HostContentSettingsMapTest, CookiesBlockEverythingExceptAllowed) { | 1224 TEST_F(HostContentSettingsMapTest, CookiesBlockEverythingExceptAllowed) { |
| 1238 TestingProfile profile; | 1225 TestingProfile profile; |
| 1239 HostContentSettingsMap* host_content_settings_map = | 1226 HostContentSettingsMap* host_content_settings_map = |
| 1240 profile.GetHostContentSettingsMap(); | 1227 profile.GetHostContentSettingsMap(); |
| 1228 CookieContentSettings* cookie_content_settings = |
| 1229 profile.GetCookieContentSettings(); |
| 1241 host_content_settings_map->SetDefaultContentSetting( | 1230 host_content_settings_map->SetDefaultContentSetting( |
| 1242 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 1231 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
| 1243 host_content_settings_map->AddExceptionForURL( | 1232 host_content_settings_map->AddExceptionForURL( |
| 1244 kAllowedSite, kAllowedSite, CONTENT_SETTINGS_TYPE_COOKIES, "", | 1233 kAllowedSite, kAllowedSite, CONTENT_SETTINGS_TYPE_COOKIES, "", |
| 1245 CONTENT_SETTING_ALLOW); | 1234 CONTENT_SETTING_ALLOW); |
| 1246 | 1235 |
| 1247 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1236 EXPECT_FALSE(cookie_content_settings->Allow( |
| 1248 host_content_settings_map->GetCookieContentSetting( | 1237 kFirstPartySite, kFirstPartySite, false)); |
| 1249 kFirstPartySite, kFirstPartySite, false)); | 1238 EXPECT_FALSE(cookie_content_settings->Allow( |
| 1250 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1239 kFirstPartySite, kFirstPartySite, true)); |
| 1251 host_content_settings_map->GetCookieContentSetting( | 1240 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1252 kFirstPartySite, kFirstPartySite, true)); | 1241 kAllowedSite, kFirstPartySite, false)); |
| 1253 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1242 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1254 host_content_settings_map->GetCookieContentSetting( | 1243 kAllowedSite, kFirstPartySite, true)); |
| 1255 kAllowedSite, kFirstPartySite, false)); | 1244 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1256 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1245 kAllowedSite, kAllowedSite, false)); |
| 1257 host_content_settings_map->GetCookieContentSetting( | 1246 EXPECT_TRUE(cookie_content_settings->Allow( |
| 1258 kAllowedSite, kFirstPartySite, true)); | 1247 kAllowedSite, kAllowedSite, true)); |
| 1259 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1248 EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(kAllowedSite)); |
| 1260 host_content_settings_map->GetCookieContentSetting( | |
| 1261 kAllowedSite, kAllowedSite, false)); | |
| 1262 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 1263 host_content_settings_map->GetCookieContentSetting( | |
| 1264 kAllowedSite, kAllowedSite, true)); | |
| 1265 } | 1249 } |
| 1266 | 1250 |
| 1267 } // namespace | 1251 } // namespace |
| OLD | NEW |