| 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/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "chrome/browser/content_settings/cookie_settings.h" | 8 #include "chrome/browser/content_settings/cookie_settings.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/content_settings_pattern.h" | 11 #include "chrome/common/content_settings_pattern.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 14 #include "content/public/test/test_browser_thread.h" | 14 #include "content/public/test/test_browser_thread.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 #include "net/base/static_cookie_policy.h" | 16 #include "net/base/static_cookie_policy.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using content::BrowserThread; | 19 using content::BrowserThread; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class CookieSettingsTest : public testing::Test { | 23 class CookieSettingsTest : public testing::Test { |
| 24 public: | 24 public: |
| 25 CookieSettingsTest() : | 25 CookieSettingsTest() : |
| 26 ui_thread_(BrowserThread::UI, &message_loop_), | 26 ui_thread_(BrowserThread::UI, &message_loop_), |
| 27 cookie_settings_(CookieSettings::Factory::GetForProfile(&profile_)), |
| 27 kBlockedSite("http://ads.thirdparty.com"), | 28 kBlockedSite("http://ads.thirdparty.com"), |
| 28 kAllowedSite("http://good.allays.com"), | 29 kAllowedSite("http://good.allays.com"), |
| 29 kFirstPartySite("http://cool.things.com"), | 30 kFirstPartySite("http://cool.things.com"), |
| 30 kBlockedFirstPartySite("http://no.thirdparties.com"), | 31 kBlockedFirstPartySite("http://no.thirdparties.com"), |
| 31 kExtensionURL("chrome-extension://deadbeef") {} | 32 kExtensionURL("chrome-extension://deadbeef"), |
| 33 kHttpsSite("https://example.com"), |
| 34 kAllHttpsSitesPattern(ContentSettingsPattern::FromString("https://*")) { |
| 35 } |
| 32 | 36 |
| 33 protected: | 37 protected: |
| 34 MessageLoop message_loop_; | 38 MessageLoop message_loop_; |
| 35 content::TestBrowserThread ui_thread_; | 39 content::TestBrowserThread ui_thread_; |
| 40 TestingProfile profile_; |
| 41 CookieSettings* cookie_settings_; |
| 36 const GURL kBlockedSite; | 42 const GURL kBlockedSite; |
| 37 const GURL kAllowedSite; | 43 const GURL kAllowedSite; |
| 38 const GURL kFirstPartySite; | 44 const GURL kFirstPartySite; |
| 39 const GURL kBlockedFirstPartySite; | 45 const GURL kBlockedFirstPartySite; |
| 40 const GURL kExtensionURL; | 46 const GURL kExtensionURL; |
| 47 const GURL kHttpsSite; |
| 48 ContentSettingsPattern kAllHttpsSitesPattern; |
| 41 }; | 49 }; |
| 42 | 50 |
| 43 TEST_F(CookieSettingsTest, CookiesBlockSingle) { | 51 TEST_F(CookieSettingsTest, CookiesBlockSingle) { |
| 44 TestingProfile profile; | 52 cookie_settings_->SetCookieSetting( |
| 45 CookieSettings* cookie_settings = | 53 ContentSettingsPattern::FromURL(kBlockedSite), |
| 46 CookieSettings::Factory::GetForProfile(&profile); | 54 ContentSettingsPattern::Wildcard(), |
| 47 cookie_settings->SetCookieSetting( | 55 CONTENT_SETTING_BLOCK); |
| 48 ContentSettingsPattern::FromURL(kBlockedSite), | 56 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( |
| 49 ContentSettingsPattern::Wildcard(), | |
| 50 CONTENT_SETTING_BLOCK); | |
| 51 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( | |
| 52 kBlockedSite, kBlockedSite)); | 57 kBlockedSite, kBlockedSite)); |
| 53 } | 58 } |
| 54 | 59 |
| 55 TEST_F(CookieSettingsTest, CookiesBlockThirdParty) { | 60 TEST_F(CookieSettingsTest, CookiesBlockThirdParty) { |
| 56 TestingProfile profile; | 61 profile_.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
| 57 CookieSettings* cookie_settings = | 62 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( |
| 58 CookieSettings::Factory::GetForProfile(&profile); | 63 kBlockedSite, kFirstPartySite)); |
| 59 profile.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); | 64 EXPECT_FALSE(cookie_settings_->IsCookieSessionOnly(kBlockedSite)); |
| 60 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( | 65 EXPECT_FALSE(cookie_settings_->IsSettingCookieAllowed( |
| 61 kBlockedSite, kFirstPartySite)); | |
| 62 EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kBlockedSite)); | |
| 63 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( | |
| 64 kBlockedSite, kFirstPartySite)); | 66 kBlockedSite, kFirstPartySite)); |
| 65 | 67 |
| 66 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 68 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
| 67 AutoReset<CommandLine> auto_reset(cmd, *cmd); | 69 AutoReset<CommandLine> auto_reset(cmd, *cmd); |
| 68 cmd->AppendSwitch(switches::kOnlyBlockSettingThirdPartyCookies); | 70 cmd->AppendSwitch(switches::kOnlyBlockSettingThirdPartyCookies); |
| 69 | 71 |
| 70 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 72 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 71 kBlockedSite, kFirstPartySite)); | 73 kBlockedSite, kFirstPartySite)); |
| 72 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( | 74 EXPECT_FALSE(cookie_settings_->IsSettingCookieAllowed( |
| 73 kBlockedSite, kFirstPartySite)); | 75 kBlockedSite, kFirstPartySite)); |
| 74 } | 76 } |
| 75 | 77 |
| 76 TEST_F(CookieSettingsTest, CookiesAllowThirdParty) { | 78 TEST_F(CookieSettingsTest, CookiesAllowThirdParty) { |
| 77 TestingProfile profile; | 79 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 78 CookieSettings* cookie_settings = | 80 kBlockedSite, kFirstPartySite)); |
| 79 CookieSettings::Factory::GetForProfile(&profile); | 81 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 80 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 82 kBlockedSite, kFirstPartySite)); |
| 81 kBlockedSite, kFirstPartySite)); | 83 EXPECT_FALSE(cookie_settings_->IsCookieSessionOnly(kBlockedSite)); |
| 82 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | |
| 83 kBlockedSite, kFirstPartySite)); | |
| 84 EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kBlockedSite)); | |
| 85 } | 84 } |
| 86 | 85 |
| 87 TEST_F(CookieSettingsTest, CookiesExplicitBlockSingleThirdParty) { | 86 TEST_F(CookieSettingsTest, CookiesExplicitBlockSingleThirdParty) { |
| 88 TestingProfile profile; | 87 cookie_settings_->SetCookieSetting( |
| 89 CookieSettings* cookie_settings = | 88 ContentSettingsPattern::FromURL(kBlockedSite), |
| 90 CookieSettings::Factory::GetForProfile(&profile); | 89 ContentSettingsPattern::Wildcard(), |
| 91 cookie_settings->SetCookieSetting( | 90 CONTENT_SETTING_BLOCK); |
| 92 ContentSettingsPattern::FromURL(kBlockedSite), | 91 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( |
| 93 ContentSettingsPattern::Wildcard(), | 92 kBlockedSite, kFirstPartySite)); |
| 94 CONTENT_SETTING_BLOCK); | 93 EXPECT_FALSE(cookie_settings_->IsSettingCookieAllowed( |
| 95 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( | 94 kBlockedSite, kFirstPartySite)); |
| 96 kBlockedSite, kFirstPartySite)); | 95 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 97 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( | |
| 98 kBlockedSite, kFirstPartySite)); | |
| 99 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | |
| 100 kAllowedSite, kFirstPartySite)); | 96 kAllowedSite, kFirstPartySite)); |
| 101 } | 97 } |
| 102 | 98 |
| 103 TEST_F(CookieSettingsTest, CookiesExplicitSessionOnly) { | 99 TEST_F(CookieSettingsTest, CookiesExplicitSessionOnly) { |
| 104 TestingProfile profile; | 100 cookie_settings_->SetCookieSetting( |
| 105 CookieSettings* cookie_settings = | |
| 106 CookieSettings::Factory::GetForProfile(&profile); | |
| 107 cookie_settings->SetCookieSetting( | |
| 108 ContentSettingsPattern::FromURL(kBlockedSite), | 101 ContentSettingsPattern::FromURL(kBlockedSite), |
| 109 ContentSettingsPattern::Wildcard(), | 102 ContentSettingsPattern::Wildcard(), |
| 110 CONTENT_SETTING_SESSION_ONLY); | 103 CONTENT_SETTING_SESSION_ONLY); |
| 111 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 104 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 112 kBlockedSite, kFirstPartySite)); | 105 kBlockedSite, kFirstPartySite)); |
| 113 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | 106 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 114 kBlockedSite, kFirstPartySite)); | 107 kBlockedSite, kFirstPartySite)); |
| 115 EXPECT_TRUE(cookie_settings->IsCookieSessionOnly(kBlockedSite)); | 108 EXPECT_TRUE(cookie_settings_->IsCookieSessionOnly(kBlockedSite)); |
| 116 | 109 |
| 117 profile.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); | 110 profile_.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
| 118 EXPECT_TRUE(cookie_settings-> | 111 EXPECT_TRUE(cookie_settings_-> |
| 119 IsReadingCookieAllowed(kBlockedSite, kFirstPartySite)); | 112 IsReadingCookieAllowed(kBlockedSite, kFirstPartySite)); |
| 120 EXPECT_TRUE(cookie_settings-> | 113 EXPECT_TRUE(cookie_settings_-> |
| 121 IsSettingCookieAllowed(kBlockedSite, kFirstPartySite)); | 114 IsSettingCookieAllowed(kBlockedSite, kFirstPartySite)); |
| 122 EXPECT_TRUE(cookie_settings->IsCookieSessionOnly(kBlockedSite)); | 115 EXPECT_TRUE(cookie_settings_->IsCookieSessionOnly(kBlockedSite)); |
| 123 } | 116 } |
| 124 | 117 |
| 125 TEST_F(CookieSettingsTest, CookiesThirdPartyBlockedExplicitAllow) { | 118 TEST_F(CookieSettingsTest, CookiesThirdPartyBlockedExplicitAllow) { |
| 126 TestingProfile profile; | 119 cookie_settings_->SetCookieSetting( |
| 127 CookieSettings* cookie_settings = | 120 ContentSettingsPattern::FromURL(kAllowedSite), |
| 128 CookieSettings::Factory::GetForProfile(&profile); | 121 ContentSettingsPattern::Wildcard(), |
| 129 cookie_settings->SetCookieSetting( | 122 CONTENT_SETTING_ALLOW); |
| 130 ContentSettingsPattern::FromURL(kAllowedSite), | 123 profile_.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
| 131 ContentSettingsPattern::Wildcard(), | 124 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 132 CONTENT_SETTING_ALLOW); | 125 kAllowedSite, kFirstPartySite)); |
| 133 profile.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); | 126 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 134 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 127 kAllowedSite, kFirstPartySite)); |
| 135 kAllowedSite, kFirstPartySite)); | 128 EXPECT_FALSE(cookie_settings_->IsCookieSessionOnly(kAllowedSite)); |
| 136 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | |
| 137 kAllowedSite, kFirstPartySite)); | |
| 138 EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kAllowedSite)); | |
| 139 | 129 |
| 140 // Extensions should always be allowed to use cookies. | 130 // Extensions should always be allowed to use cookies. |
| 141 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 131 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 142 kAllowedSite, kExtensionURL)); | 132 kAllowedSite, kExtensionURL)); |
| 143 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | 133 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 144 kAllowedSite, kExtensionURL)); | 134 kAllowedSite, kExtensionURL)); |
| 145 | 135 |
| 146 // Extensions should always be allowed to use cookies. | 136 // Extensions should always be allowed to use cookies. |
| 147 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 137 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 148 kAllowedSite, kExtensionURL)); | 138 kAllowedSite, kExtensionURL)); |
| 149 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | 139 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 150 kAllowedSite, kExtensionURL)); | 140 kAllowedSite, kExtensionURL)); |
| 141 } |
| 142 |
| 143 TEST_F(CookieSettingsTest, CookiesThirdPartyBlockedAllSitesAllowed) { |
| 144 cookie_settings_->SetCookieSetting( |
| 145 ContentSettingsPattern::FromURL(kAllowedSite), |
| 146 ContentSettingsPattern::Wildcard(), |
| 147 CONTENT_SETTING_ALLOW); |
| 148 profile_.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
| 149 // As an example for a pattern that matches all hosts but not all origins, |
| 150 // match all HTTPS sites. |
| 151 cookie_settings_->SetCookieSetting( |
| 152 kAllHttpsSitesPattern, |
| 153 ContentSettingsPattern::Wildcard(), |
| 154 CONTENT_SETTING_ALLOW); |
| 155 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); |
| 156 |
| 157 // |kAllowedSite| should be allowed. |
| 158 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 159 kAllowedSite, kBlockedSite)); |
| 160 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 161 kAllowedSite, kBlockedSite)); |
| 162 EXPECT_FALSE(cookie_settings_->IsCookieSessionOnly(kAllowedSite)); |
| 163 |
| 164 // HTTPS sites should be allowed in a first-party context. |
| 165 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 166 kHttpsSite, kHttpsSite)); |
| 167 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 168 kHttpsSite, kHttpsSite)); |
| 169 EXPECT_FALSE(cookie_settings_->IsCookieSessionOnly(kAllowedSite)); |
| 170 |
| 171 // HTTP sites should be allowed, but session-only. |
| 172 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 173 kFirstPartySite, kFirstPartySite)); |
| 174 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 175 kFirstPartySite, kFirstPartySite)); |
| 176 EXPECT_TRUE(cookie_settings_->IsCookieSessionOnly(kFirstPartySite)); |
| 177 |
| 178 // Third-party cookies should be blocked. |
| 179 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( |
| 180 kFirstPartySite, kBlockedSite)); |
| 181 EXPECT_FALSE(cookie_settings_->IsSettingCookieAllowed( |
| 182 kFirstPartySite, kBlockedSite)); |
| 183 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( |
| 184 kHttpsSite, kBlockedSite)); |
| 185 EXPECT_FALSE(cookie_settings_->IsSettingCookieAllowed( |
| 186 kHttpsSite, kBlockedSite)); |
| 151 } | 187 } |
| 152 | 188 |
| 153 TEST_F(CookieSettingsTest, CookiesBlockEverything) { | 189 TEST_F(CookieSettingsTest, CookiesBlockEverything) { |
| 154 TestingProfile profile; | 190 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
| 155 CookieSettings* cookie_settings = | 191 |
| 156 CookieSettings::Factory::GetForProfile(&profile); | 192 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( |
| 157 cookie_settings->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 193 kFirstPartySite, kFirstPartySite)); |
| 158 | 194 EXPECT_FALSE(cookie_settings_->IsSettingCookieAllowed( |
| 159 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( | 195 kFirstPartySite, kFirstPartySite)); |
| 160 kFirstPartySite, kFirstPartySite)); | 196 EXPECT_FALSE(cookie_settings_->IsSettingCookieAllowed( |
| 161 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( | |
| 162 kFirstPartySite, kFirstPartySite)); | |
| 163 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( | |
| 164 kAllowedSite, kFirstPartySite)); | 197 kAllowedSite, kFirstPartySite)); |
| 165 } | 198 } |
| 166 | 199 |
| 167 TEST_F(CookieSettingsTest, CookiesBlockEverythingExceptAllowed) { | 200 TEST_F(CookieSettingsTest, CookiesBlockEverythingExceptAllowed) { |
| 168 TestingProfile profile; | 201 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
| 169 CookieSettings* cookie_settings = | 202 cookie_settings_->SetCookieSetting( |
| 170 CookieSettings::Factory::GetForProfile(&profile); | 203 ContentSettingsPattern::FromURL(kAllowedSite), |
| 171 cookie_settings->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 204 ContentSettingsPattern::Wildcard(), |
| 172 cookie_settings->SetCookieSetting( | 205 CONTENT_SETTING_ALLOW); |
| 173 ContentSettingsPattern::FromURL(kAllowedSite), | 206 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( |
| 174 ContentSettingsPattern::Wildcard(), | 207 kFirstPartySite, kFirstPartySite)); |
| 175 CONTENT_SETTING_ALLOW); | 208 EXPECT_FALSE(cookie_settings_->IsSettingCookieAllowed( |
| 176 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( | 209 kFirstPartySite, kFirstPartySite)); |
| 177 kFirstPartySite, kFirstPartySite)); | 210 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 178 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( | 211 kAllowedSite, kFirstPartySite)); |
| 179 kFirstPartySite, kFirstPartySite)); | 212 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 180 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 213 kAllowedSite, kFirstPartySite)); |
| 181 kAllowedSite, kFirstPartySite)); | 214 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 182 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | |
| 183 kAllowedSite, kFirstPartySite)); | |
| 184 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | |
| 185 kAllowedSite, kAllowedSite)); | 215 kAllowedSite, kAllowedSite)); |
| 186 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | 216 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 187 kAllowedSite, kAllowedSite)); | 217 kAllowedSite, kAllowedSite)); |
| 188 EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kAllowedSite)); | 218 EXPECT_FALSE(cookie_settings_->IsCookieSessionOnly(kAllowedSite)); |
| 189 } | 219 } |
| 190 | 220 |
| 191 TEST_F(CookieSettingsTest, CookiesBlockSingleFirstParty) { | 221 TEST_F(CookieSettingsTest, CookiesBlockSingleFirstParty) { |
| 192 TestingProfile profile; | 222 cookie_settings_->SetCookieSetting( |
| 193 CookieSettings* cookie_settings = | |
| 194 CookieSettings::Factory::GetForProfile(&profile); | |
| 195 cookie_settings->SetCookieSetting( | |
| 196 ContentSettingsPattern::FromURL(kAllowedSite), | 223 ContentSettingsPattern::FromURL(kAllowedSite), |
| 197 ContentSettingsPattern::FromURL(kFirstPartySite), | 224 ContentSettingsPattern::FromURL(kFirstPartySite), |
| 198 CONTENT_SETTING_ALLOW); | 225 CONTENT_SETTING_ALLOW); |
| 199 cookie_settings->SetCookieSetting( | 226 cookie_settings_->SetCookieSetting( |
| 200 ContentSettingsPattern::FromURL(kAllowedSite), | 227 ContentSettingsPattern::FromURL(kAllowedSite), |
| 201 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), | 228 ContentSettingsPattern::FromURL(kBlockedFirstPartySite), |
| 202 CONTENT_SETTING_BLOCK); | 229 CONTENT_SETTING_BLOCK); |
| 203 | 230 |
| 204 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 231 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 205 kAllowedSite, kFirstPartySite)); | 232 kAllowedSite, kFirstPartySite)); |
| 206 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | 233 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 207 kAllowedSite, kFirstPartySite)); | 234 kAllowedSite, kFirstPartySite)); |
| 208 EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kAllowedSite)); | 235 EXPECT_FALSE(cookie_settings_->IsCookieSessionOnly(kAllowedSite)); |
| 209 | 236 |
| 210 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( | 237 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( |
| 211 kAllowedSite, kBlockedFirstPartySite)); | 238 kAllowedSite, kBlockedFirstPartySite)); |
| 212 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( | 239 EXPECT_FALSE(cookie_settings_->IsSettingCookieAllowed( |
| 213 kAllowedSite, kBlockedFirstPartySite)); | 240 kAllowedSite, kBlockedFirstPartySite)); |
| 214 | 241 |
| 215 cookie_settings->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 242 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
| 216 | 243 |
| 217 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 244 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 218 kAllowedSite, kFirstPartySite)); | 245 kAllowedSite, kFirstPartySite)); |
| 219 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | 246 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 220 kAllowedSite, kFirstPartySite)); | 247 kAllowedSite, kFirstPartySite)); |
| 221 EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kAllowedSite)); | 248 EXPECT_FALSE(cookie_settings_->IsCookieSessionOnly(kAllowedSite)); |
| 222 | 249 |
| 223 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( | 250 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( |
| 224 kAllowedSite, kBlockedFirstPartySite)); | 251 kAllowedSite, kBlockedFirstPartySite)); |
| 225 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( | 252 EXPECT_FALSE(cookie_settings_->IsSettingCookieAllowed( |
| 226 kAllowedSite, kBlockedFirstPartySite)); | 253 kAllowedSite, kBlockedFirstPartySite)); |
| 227 | 254 |
| 228 cookie_settings->ResetCookieSetting( | 255 cookie_settings_->ResetCookieSetting( |
| 229 ContentSettingsPattern::FromURL(kAllowedSite), | 256 ContentSettingsPattern::FromURL(kAllowedSite), |
| 230 ContentSettingsPattern::FromURL(kFirstPartySite)); | 257 ContentSettingsPattern::FromURL(kFirstPartySite)); |
| 231 | 258 |
| 232 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( | 259 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( |
| 233 kAllowedSite, kFirstPartySite)); | 260 kAllowedSite, kFirstPartySite)); |
| 234 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( | 261 EXPECT_FALSE(cookie_settings_->IsSettingCookieAllowed( |
| 235 kAllowedSite, kFirstPartySite)); | 262 kAllowedSite, kFirstPartySite)); |
| 236 } | 263 } |
| 237 | 264 |
| 238 TEST_F(CookieSettingsTest, ExtensionsRegularSettings) { | 265 TEST_F(CookieSettingsTest, ExtensionsRegularSettings) { |
| 239 TestingProfile profile; | 266 cookie_settings_->SetCookieSetting( |
| 240 CookieSettings* cookie_settings = | |
| 241 CookieSettings::Factory::GetForProfile(&profile); | |
| 242 cookie_settings->SetCookieSetting( | |
| 243 ContentSettingsPattern::FromURL(kBlockedSite), | 267 ContentSettingsPattern::FromURL(kBlockedSite), |
| 244 ContentSettingsPattern::Wildcard(), | 268 ContentSettingsPattern::Wildcard(), |
| 245 CONTENT_SETTING_BLOCK); | 269 CONTENT_SETTING_BLOCK); |
| 246 | 270 |
| 247 // Regular cookie settings also apply to extensions. | 271 // Regular cookie settings also apply to extensions. |
| 248 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( | 272 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed( |
| 249 kBlockedSite, kExtensionURL)); | 273 kBlockedSite, kExtensionURL)); |
| 250 } | 274 } |
| 251 | 275 |
| 252 TEST_F(CookieSettingsTest, ExtensionsOwnCookies) { | 276 TEST_F(CookieSettingsTest, ExtensionsOwnCookies) { |
| 253 TestingProfile profile; | 277 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
| 254 CookieSettings* cookie_settings = | |
| 255 CookieSettings::Factory::GetForProfile(&profile); | |
| 256 cookie_settings->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | |
| 257 | 278 |
| 258 // Extensions can always use cookies (and site data) in their own origin. | 279 // Extensions can always use cookies (and site data) in their own origin. |
| 259 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 280 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed( |
| 260 kExtensionURL, kExtensionURL)); | 281 kExtensionURL, kExtensionURL)); |
| 261 } | 282 } |
| 262 | 283 |
| 263 TEST_F(CookieSettingsTest, ExtensionsThirdParty) { | 284 TEST_F(CookieSettingsTest, ExtensionsThirdParty) { |
| 264 TestingProfile profile; | 285 profile_.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
| 265 CookieSettings* cookie_settings = | |
| 266 CookieSettings::Factory::GetForProfile(&profile); | |
| 267 profile.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); | |
| 268 | 286 |
| 269 // XHRs stemming from extensions are exempt from third-party cookie blocking | 287 // XHRs stemming from extensions are exempt from third-party cookie blocking |
| 270 // rules (as the first party is always the extension's security origin). | 288 // rules (as the first party is always the extension's security origin). |
| 271 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | 289 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( |
| 272 kBlockedSite, kExtensionURL)); | 290 kBlockedSite, kExtensionURL)); |
| 273 } | 291 } |
| 274 | 292 |
| 275 } // namespace | 293 } // namespace |
| OLD | NEW |