| 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 "chrome/browser/content_settings/cookie_settings.h" | 7 #include "chrome/browser/content_settings/cookie_settings.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/common/content_settings_pattern.h" | 10 #include "chrome/common/content_settings_pattern.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 cookie_settings->ResetCookieSetting( | 226 cookie_settings->ResetCookieSetting( |
| 227 ContentSettingsPattern::FromURL(kAllowedSite), | 227 ContentSettingsPattern::FromURL(kAllowedSite), |
| 228 ContentSettingsPattern::FromURL(kFirstPartySite)); | 228 ContentSettingsPattern::FromURL(kFirstPartySite)); |
| 229 | 229 |
| 230 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( | 230 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( |
| 231 kAllowedSite, kFirstPartySite)); | 231 kAllowedSite, kFirstPartySite)); |
| 232 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( | 232 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( |
| 233 kAllowedSite, kFirstPartySite)); | 233 kAllowedSite, kFirstPartySite)); |
| 234 } | 234 } |
| 235 | 235 |
| 236 TEST_F(CookieSettingsTest, ExtensionsRegularSettings) { |
| 237 TestingProfile profile; |
| 238 CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile); |
| 239 cookie_settings->SetCookieSetting( |
| 240 ContentSettingsPattern::FromURL(kBlockedSite), |
| 241 ContentSettingsPattern::Wildcard(), |
| 242 CONTENT_SETTING_BLOCK); |
| 243 |
| 244 // Regular cookie settings also apply to extensions. |
| 245 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( |
| 246 kBlockedSite, kExtensionURL)); |
| 247 } |
| 248 |
| 249 TEST_F(CookieSettingsTest, ExtensionsOwnCookies) { |
| 250 TestingProfile profile; |
| 251 CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile); |
| 252 cookie_settings->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
| 253 |
| 254 // Extensions can always use cookies (and site data) in their own origin. |
| 255 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( |
| 256 kExtensionURL, kExtensionURL)); |
| 257 } |
| 258 |
| 259 TEST_F(CookieSettingsTest, ExtensionsThirdParty) { |
| 260 TestingProfile profile; |
| 261 CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile); |
| 262 profile.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
| 263 |
| 264 // XHRs stemming from extensions are exempt from third-party cookie blocking |
| 265 // rules (as the first party is always the extension's security origin). |
| 266 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( |
| 267 kBlockedSite, kExtensionURL)); |
| 268 } |
| 269 |
| 236 } // namespace | 270 } // namespace |
| OLD | NEW |