Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: chrome/browser/content_settings/cookie_settings_unittest.cc

Issue 900803002: Introduce a CookieSettings for incognito mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/content_settings/cookie_settings.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 274
275 TEST_F(CookieSettingsTest, ExtensionsThirdParty) { 275 TEST_F(CookieSettingsTest, ExtensionsThirdParty) {
276 profile_.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true); 276 profile_.GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, true);
277 277
278 // XHRs stemming from extensions are exempt from third-party cookie blocking 278 // XHRs stemming from extensions are exempt from third-party cookie blocking
279 // 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).
280 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed( 280 EXPECT_TRUE(cookie_settings_->IsSettingCookieAllowed(
281 kBlockedSite, kExtensionURL)); 281 kBlockedSite, kExtensionURL));
282 } 282 }
283 283
284 TEST_F(CookieSettingsTest, IncognitoBehaviorOfBlockingRules) {
285 scoped_refptr<CookieSettings> incognito_settings =
286 CookieSettings::Factory::GetForProfile(profile_.GetOffTheRecordProfile());
287
288 // Modify the regular cookie settings after the incognito cookie settings have
289 // been instantiated.
290 cookie_settings_->SetCookieSetting(
291 ContentSettingsPattern::FromURL(kBlockedSite),
292 ContentSettingsPattern::Wildcard(),
293 CONTENT_SETTING_BLOCK);
294
295 // The modification should apply to the regular profile and incognito profile.
296 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed(
297 kBlockedSite, kBlockedSite));
298 EXPECT_FALSE(incognito_settings->IsReadingCookieAllowed(
299 kBlockedSite, kBlockedSite));
300
301 // Modify an incognito cookie setting and check that this does not propagate
302 // into regular mode.
303 incognito_settings->SetCookieSetting(
304 ContentSettingsPattern::FromURL(kHttpsSite),
305 ContentSettingsPattern::Wildcard(),
306 CONTENT_SETTING_BLOCK);
307 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(
308 kHttpsSite, kHttpsSite));
309 EXPECT_FALSE(incognito_settings->IsReadingCookieAllowed(
310 kHttpsSite, kHttpsSite));
311 }
312
313 TEST_F(CookieSettingsTest, IncognitoBehaviorOfBlockingEverything) {
314 scoped_refptr<CookieSettings> incognito_settings =
315 CookieSettings::Factory::GetForProfile(profile_.GetOffTheRecordProfile());
316
317 // Apply the general blocking to the regular profile.
318 cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
319
320 // It should be effective for regular and incognito session.
321 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed(
322 kFirstPartySite, kFirstPartySite));
323 EXPECT_FALSE(incognito_settings->IsReadingCookieAllowed(
324 kFirstPartySite, kFirstPartySite));
325
326 // A whitelisted item set in incognito mode should only apply to incognito
327 // mode.
328 incognito_settings->SetCookieSetting(
329 ContentSettingsPattern::FromURL(kAllowedSite),
330 ContentSettingsPattern::Wildcard(),
331 CONTENT_SETTING_ALLOW);
332 EXPECT_TRUE(incognito_settings->IsReadingCookieAllowed(
333 kAllowedSite, kAllowedSite));
334 EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed(
335 kAllowedSite, kAllowedSite));
336
337 // A whitelisted item set in regular mode should apply to regular and
338 // incognito mode.
339 cookie_settings_->SetCookieSetting(
340 ContentSettingsPattern::FromURL(kHttpsSite),
341 ContentSettingsPattern::Wildcard(),
342 CONTENT_SETTING_ALLOW);
343 EXPECT_TRUE(incognito_settings->IsReadingCookieAllowed(
344 kHttpsSite, kHttpsSite));
345 EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(
346 kHttpsSite, kHttpsSite));
347 }
348
284 } // namespace 349 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/cookie_settings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698