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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 ContentSettingsPattern::Wildcard(), | 47 ContentSettingsPattern::Wildcard(), |
48 CONTENT_SETTING_BLOCK); | 48 CONTENT_SETTING_BLOCK); |
49 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( | 49 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( |
50 kBlockedSite, kBlockedSite)); | 50 kBlockedSite, kBlockedSite)); |
51 } | 51 } |
52 | 52 |
53 TEST_F(CookieSettingsTest, CookiesBlockThirdParty) { | 53 TEST_F(CookieSettingsTest, CookiesBlockThirdParty) { |
54 TestingProfile profile; | 54 TestingProfile profile; |
55 CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile); | 55 CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile); |
56 profile.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); | 56 profile.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
57 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 57 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( |
58 kBlockedSite, kFirstPartySite)); | 58 kBlockedSite, kFirstPartySite)); |
59 EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kBlockedSite)); | 59 EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kBlockedSite)); |
60 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( | 60 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( |
61 kBlockedSite, kFirstPartySite)); | 61 kBlockedSite, kFirstPartySite)); |
62 | 62 |
63 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 63 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
64 AutoReset<CommandLine> auto_reset(cmd, *cmd); | 64 AutoReset<CommandLine> auto_reset(cmd, *cmd); |
65 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies); | 65 cmd->AppendSwitch(switches::kOnlyBlockSettingThirdPartyCookies); |
66 | 66 |
67 EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed( | 67 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( |
68 kBlockedSite, kFirstPartySite)); | 68 kBlockedSite, kFirstPartySite)); |
69 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( | 69 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( |
70 kBlockedSite, kFirstPartySite)); | 70 kBlockedSite, kFirstPartySite)); |
71 } | 71 } |
72 | 72 |
73 TEST_F(CookieSettingsTest, CookiesAllowThirdParty) { | 73 TEST_F(CookieSettingsTest, CookiesAllowThirdParty) { |
74 TestingProfile profile; | 74 TestingProfile profile; |
75 CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile); | 75 CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile); |
76 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 76 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( |
77 kBlockedSite, kFirstPartySite)); | 77 kBlockedSite, kFirstPartySite)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | 129 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( |
130 kAllowedSite, kFirstPartySite)); | 130 kAllowedSite, kFirstPartySite)); |
131 EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kAllowedSite)); | 131 EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kAllowedSite)); |
132 | 132 |
133 // Extensions should always be allowed to use cookies. | 133 // Extensions should always be allowed to use cookies. |
134 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 134 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( |
135 kAllowedSite, kExtensionURL)); | 135 kAllowedSite, kExtensionURL)); |
136 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | 136 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( |
137 kAllowedSite, kExtensionURL)); | 137 kAllowedSite, kExtensionURL)); |
138 | 138 |
139 CommandLine* cmd = CommandLine::ForCurrentProcess(); | |
140 AutoReset<CommandLine> auto_reset(cmd, *cmd); | |
141 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies); | |
142 | |
143 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | |
144 kAllowedSite, kFirstPartySite)); | |
145 EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kAllowedSite)); | |
146 | |
147 // Extensions should always be allowed to use cookies. | 139 // Extensions should always be allowed to use cookies. |
148 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( | 140 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed( |
149 kAllowedSite, kExtensionURL)); | 141 kAllowedSite, kExtensionURL)); |
150 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | 142 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( |
151 kAllowedSite, kExtensionURL)); | 143 kAllowedSite, kExtensionURL)); |
152 } | 144 } |
153 | 145 |
154 TEST_F(CookieSettingsTest, CookiesBlockEverything) { | 146 TEST_F(CookieSettingsTest, CookiesBlockEverything) { |
155 TestingProfile profile; | 147 TestingProfile profile; |
156 CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile); | 148 CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile); | 253 CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile); |
262 profile.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); | 254 profile.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); |
263 | 255 |
264 // XHRs stemming from extensions are exempt from third-party cookie blocking | 256 // XHRs stemming from extensions are exempt from third-party cookie blocking |
265 // rules (as the first party is always the extension's security origin). | 257 // rules (as the first party is always the extension's security origin). |
266 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( | 258 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( |
267 kBlockedSite, kExtensionURL)); | 259 kBlockedSite, kExtensionURL)); |
268 } | 260 } |
269 | 261 |
270 } // namespace | 262 } // namespace |
OLD | NEW |