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/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/content_settings/cookie_settings.h" | 8 #include "chrome/browser/content_settings/cookie_settings.h" |
9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 kAllowedSite, kFirstPartySite)); | 115 kAllowedSite, kFirstPartySite)); |
116 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( | 116 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
117 kAllowedSite, kFirstPartySite)); | 117 kAllowedSite, kFirstPartySite)); |
118 EXPECT_FALSE(cookie_settings_->IsCookieSessionOnly(kAllowedSite)); | 118 EXPECT_FALSE(cookie_settings_->IsCookieSessionOnly(kAllowedSite)); |
119 | 119 |
120 // Extensions should always be allowed to use cookies. | 120 // Extensions should always be allowed to use cookies. |
121 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( | 121 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
122 kAllowedSite, kExtensionURL)); | 122 kAllowedSite, kExtensionURL)); |
123 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( | 123 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
124 kAllowedSite, kExtensionURL)); | 124 kAllowedSite, kExtensionURL)); |
125 | |
126 // Extensions should always be allowed to use cookies. | |
127 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( | |
128 kAllowedSite, kExtensionURL)); | |
129 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( | |
130 kAllowedSite, kExtensionURL)); | |
131 } | 125 } |
132 | 126 |
133 TEST_F(CookieSettingsTest, CookiesThirdPartyBlockedAllSitesAllowed) { | 127 TEST_F(CookieSettingsTest, CookiesThirdPartyBlockedAllSitesAllowed) { |
134 cookie_settings_->SetCookieSetting( | 128 cookie_settings_->SetCookieSetting( |
135 ContentSettingsPattern::FromURL(kAllowedSite), | 129 ContentSettingsPattern::FromURL(kAllowedSite), |
136 ContentSettingsPattern::Wildcard(), | 130 ContentSettingsPattern::Wildcard(), |
137 CONTENT_SETTING_ALLOW); | 131 CONTENT_SETTING_ALLOW); |
138 profile_.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); | 132 profile_.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
139 // As an example for a pattern that matches all hosts but not all origins, | 133 // As an example for a pattern that matches all hosts but not all origins, |
140 // match all HTTPS sites. | 134 // match all HTTPS sites. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 CONTENT_SETTING_BLOCK); | 253 CONTENT_SETTING_BLOCK); |
260 | 254 |
261 // Regular cookie settings also apply to extensions. | 255 // Regular cookie settings also apply to extensions. |
262 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( | 256 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( |
263 kBlockedSite, kExtensionURL)); | 257 kBlockedSite, kExtensionURL)); |
264 } | 258 } |
265 | 259 |
266 TEST_F(CookieSettingsTest, ExtensionsOwnCookies) { | 260 TEST_F(CookieSettingsTest, ExtensionsOwnCookies) { |
267 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 261 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
268 | 262 |
| 263 #if defined(ENABLE_EXTENSIONS) |
269 // Extensions can always use cookies (and site data) in their own origin. | 264 // Extensions can always use cookies (and site data) in their own origin. |
270 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( | 265 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
271 kExtensionURL, kExtensionURL)); | 266 kExtensionURL, kExtensionURL)); |
| 267 #else |
| 268 // Except if extensions are disabled. Then the extension-specific checks do |
| 269 // not exist and the default setting is to block. |
| 270 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( |
| 271 kExtensionURL, kExtensionURL)); |
| 272 #endif |
272 } | 273 } |
273 | 274 |
274 TEST_F(CookieSettingsTest, ExtensionsThirdParty) { | 275 TEST_F(CookieSettingsTest, ExtensionsThirdParty) { |
275 profile_.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); | 276 profile_.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
276 | 277 |
277 // XHRs stemming from extensions are exempt from third-party cookie blocking | 278 // XHRs stemming from extensions are exempt from third-party cookie blocking |
278 // rules (as the first party is always the extension's security origin). | 279 // rules (as the first party is always the extension's security origin). |
279 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( | 280 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
280 kBlockedSite, kExtensionURL)); | 281 kBlockedSite, kExtensionURL)); |
281 } | 282 } |
282 | 283 |
283 } // namespace | 284 } // namespace |
OLD | NEW |