| 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 "components/content_settings/core/browser/cookie_settings.h" | 5 #include "components/content_settings/core/browser/cookie_settings.h" |
| 6 | 6 |
| 7 #include "components/content_settings/core/browser/host_content_settings_map.h" | 7 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 8 #include "components/content_settings/core/common/content_settings_pattern.h" | 8 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 9 #include "components/content_settings/core/common/pref_names.h" | 9 #include "components/content_settings/core/common/pref_names.h" |
| 10 #include "components/pref_registry/testing_pref_service_syncable.h" | 10 #include "components/pref_registry/testing_pref_service_syncable.h" |
| 11 #include "extensions/features/features.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 13 | 14 |
| 14 namespace content_settings { | 15 namespace content_settings { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 class CookieSettingsTest : public testing::Test { | 19 class CookieSettingsTest : public testing::Test { |
| 19 public: | 20 public: |
| 20 CookieSettingsTest() | 21 CookieSettingsTest() |
| (...skipping 27 matching lines...) Expand all Loading... |
| 48 const GURL kHttpSite; | 49 const GURL kHttpSite; |
| 49 const GURL kHttpsSite; | 50 const GURL kHttpsSite; |
| 50 ContentSettingsPattern kAllHttpsSitesPattern; | 51 ContentSettingsPattern kAllHttpsSitesPattern; |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 TEST_F(CookieSettingsTest, TestWhitelistedScheme) { | 54 TEST_F(CookieSettingsTest, TestWhitelistedScheme) { |
| 54 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 55 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
| 55 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed(kHttpSite, kChromeURL)); | 56 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed(kHttpSite, kChromeURL)); |
| 56 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(kHttpsSite, kChromeURL)); | 57 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(kHttpsSite, kChromeURL)); |
| 57 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(kChromeURL, kHttpSite)); | 58 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(kChromeURL, kHttpSite)); |
| 58 #if defined(ENABLE_EXTENSIONS) | 59 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 59 EXPECT_TRUE( | 60 EXPECT_TRUE( |
| 60 cookie_settings_->IsReadingCookieAllowed(kExtensionURL, kExtensionURL)); | 61 cookie_settings_->IsReadingCookieAllowed(kExtensionURL, kExtensionURL)); |
| 61 #else | 62 #else |
| 62 EXPECT_FALSE( | 63 EXPECT_FALSE( |
| 63 cookie_settings_->IsReadingCookieAllowed(kExtensionURL, kExtensionURL)); | 64 cookie_settings_->IsReadingCookieAllowed(kExtensionURL, kExtensionURL)); |
| 64 #endif | 65 #endif |
| 65 EXPECT_FALSE( | 66 EXPECT_FALSE( |
| 66 cookie_settings_->IsReadingCookieAllowed(kExtensionURL, kHttpSite)); | 67 cookie_settings_->IsReadingCookieAllowed(kExtensionURL, kHttpSite)); |
| 67 } | 68 } |
| 68 | 69 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 cookie_settings_->SetCookieSetting(kBlockedSite, CONTENT_SETTING_BLOCK); | 206 cookie_settings_->SetCookieSetting(kBlockedSite, CONTENT_SETTING_BLOCK); |
| 206 | 207 |
| 207 // Regular cookie settings also apply to extensions. | 208 // Regular cookie settings also apply to extensions. |
| 208 EXPECT_FALSE( | 209 EXPECT_FALSE( |
| 209 cookie_settings_->IsReadingCookieAllowed(kBlockedSite, kExtensionURL)); | 210 cookie_settings_->IsReadingCookieAllowed(kBlockedSite, kExtensionURL)); |
| 210 } | 211 } |
| 211 | 212 |
| 212 TEST_F(CookieSettingsTest, ExtensionsOwnCookies) { | 213 TEST_F(CookieSettingsTest, ExtensionsOwnCookies) { |
| 213 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 214 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
| 214 | 215 |
| 215 #if defined(ENABLE_EXTENSIONS) | 216 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 216 // Extensions can always use cookies (and site data) in their own origin. | 217 // Extensions can always use cookies (and site data) in their own origin. |
| 217 EXPECT_TRUE( | 218 EXPECT_TRUE( |
| 218 cookie_settings_->IsReadingCookieAllowed(kExtensionURL, kExtensionURL)); | 219 cookie_settings_->IsReadingCookieAllowed(kExtensionURL, kExtensionURL)); |
| 219 #else | 220 #else |
| 220 // Except if extensions are disabled. Then the extension-specific checks do | 221 // Except if extensions are disabled. Then the extension-specific checks do |
| 221 // not exist and the default setting is to block. | 222 // not exist and the default setting is to block. |
| 222 EXPECT_FALSE( | 223 EXPECT_FALSE( |
| 223 cookie_settings_->IsReadingCookieAllowed(kExtensionURL, kExtensionURL)); | 224 cookie_settings_->IsReadingCookieAllowed(kExtensionURL, kExtensionURL)); |
| 224 #endif | 225 #endif |
| 225 } | 226 } |
| 226 | 227 |
| 227 TEST_F(CookieSettingsTest, ExtensionsThirdParty) { | 228 TEST_F(CookieSettingsTest, ExtensionsThirdParty) { |
| 228 prefs_.SetBoolean(prefs::kBlockThirdPartyCookies, true); | 229 prefs_.SetBoolean(prefs::kBlockThirdPartyCookies, true); |
| 229 | 230 |
| 230 // XHRs stemming from extensions are exempt from third-party cookie blocking | 231 // XHRs stemming from extensions are exempt from third-party cookie blocking |
| 231 // rules (as the first party is always the extension's security origin). | 232 // rules (as the first party is always the extension's security origin). |
| 232 EXPECT_TRUE( | 233 EXPECT_TRUE( |
| 233 cookie_settings_->IsSettingCookieAllowed(kBlockedSite, kExtensionURL)); | 234 cookie_settings_->IsSettingCookieAllowed(kBlockedSite, kExtensionURL)); |
| 234 } | 235 } |
| 235 | 236 |
| 236 } // namespace | 237 } // namespace |
| 237 | 238 |
| 238 } // namespace content_settings | 239 } // namespace content_settings |
| OLD | NEW |