| Index: chrome/browser/content_settings/cookie_settings_unittest.cc
|
| diff --git a/chrome/browser/content_settings/cookie_settings_unittest.cc b/chrome/browser/content_settings/cookie_settings_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2cad9ba8b1ae125da294c76259d1c49372b722dc
|
| --- /dev/null
|
| +++ b/chrome/browser/content_settings/cookie_settings_unittest.cc
|
| @@ -0,0 +1,177 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/auto_reset.h"
|
| +#include "base/command_line.h"
|
| +#include "chrome/browser/content_settings/content_settings_pattern.h"
|
| +#include "chrome/browser/content_settings/cookie_settings.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| +#include "chrome/test/base/testing_profile.h"
|
| +#include "googleurl/src/gurl.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace {
|
| +
|
| +// Tests for cookie content settings.
|
| +const GURL kBlockedSite = GURL("http://ads.thirdparty.com");
|
| +const GURL kAllowedSite = GURL("http://good.allays.com");
|
| +const GURL kFirstPartySite = GURL("http://cool.things.com");
|
| +const GURL kExtensionURL = GURL("chrome-extension://deadbeef");
|
| +
|
| +class CookieSettingsTest : public testing::Test {
|
| + public:
|
| + CookieSettingsTest() : ui_thread_(BrowserThread::UI, &message_loop_) {
|
| + }
|
| +
|
| + protected:
|
| + MessageLoop message_loop_;
|
| + BrowserThread ui_thread_;
|
| +};
|
| +
|
| +TEST_F(CookieSettingsTest, CookiesBlockSingle) {
|
| + TestingProfile profile;
|
| + CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile);
|
| +
|
| + cookie_settings->SetCookieSetting(
|
| + ContentSettingsPattern::FromURL(kBlockedSite),
|
| + CONTENT_SETTING_BLOCK);
|
| +
|
| + EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed(
|
| + kBlockedSite, kBlockedSite));
|
| +}
|
| +
|
| +TEST_F(CookieSettingsTest, CookiesBlockThirdParty) {
|
| + TestingProfile profile;
|
| + CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile);
|
| + cookie_settings->SetBlockThirdPartyCookies(true);
|
| + EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(
|
| + kBlockedSite, kFirstPartySite));
|
| + EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kBlockedSite));
|
| + EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed(
|
| + kBlockedSite, kFirstPartySite));
|
| +
|
| + CommandLine* cmd = CommandLine::ForCurrentProcess();
|
| + AutoReset<CommandLine> auto_reset(cmd, *cmd);
|
| + cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies);
|
| +
|
| + EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed(
|
| + kBlockedSite, kFirstPartySite));
|
| + EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed(
|
| + kBlockedSite, kFirstPartySite));
|
| +}
|
| +
|
| +TEST_F(CookieSettingsTest, CookiesAllowThirdParty) {
|
| + TestingProfile profile;
|
| + CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile);
|
| + EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(
|
| + kBlockedSite, kFirstPartySite));
|
| + EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
|
| + kBlockedSite, kFirstPartySite));
|
| + EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kBlockedSite));
|
| +}
|
| +
|
| +TEST_F(CookieSettingsTest, CookiesExplicitBlockSingleThirdParty) {
|
| + TestingProfile profile;
|
| + CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile);
|
| + cookie_settings->SetCookieSetting(
|
| + ContentSettingsPattern::FromURL(kBlockedSite),
|
| + CONTENT_SETTING_BLOCK);
|
| + EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed(
|
| + kBlockedSite, kFirstPartySite));
|
| + EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed(
|
| + kBlockedSite, kFirstPartySite));
|
| + EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
|
| + kAllowedSite, kFirstPartySite));
|
| +}
|
| +
|
| +TEST_F(CookieSettingsTest, CookiesExplicitSessionOnly) {
|
| + TestingProfile profile;
|
| + CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile);
|
| + cookie_settings->SetCookieSetting(
|
| + ContentSettingsPattern::FromURL(kBlockedSite),
|
| + CONTENT_SETTING_SESSION_ONLY);
|
| + EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(
|
| + kBlockedSite, kFirstPartySite));
|
| + EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
|
| + kBlockedSite, kFirstPartySite));
|
| + EXPECT_TRUE(cookie_settings->IsCookieSessionOnly(kBlockedSite));
|
| +
|
| + cookie_settings->SetBlockThirdPartyCookies(true);
|
| + EXPECT_TRUE(cookie_settings->
|
| + IsReadingCookieAllowed(kBlockedSite, kFirstPartySite));
|
| + EXPECT_TRUE(cookie_settings->
|
| + IsSettingCookieAllowed(kBlockedSite, kFirstPartySite));
|
| + EXPECT_TRUE(cookie_settings->IsCookieSessionOnly(kBlockedSite));
|
| +}
|
| +
|
| +TEST_F(CookieSettingsTest, CookiesThirdPartyBlockedExplicitAllow) {
|
| + TestingProfile profile;
|
| + CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile);
|
| + cookie_settings->SetCookieSetting(
|
| + ContentSettingsPattern::FromURL(kAllowedSite),
|
| + CONTENT_SETTING_ALLOW);
|
| + cookie_settings->SetBlockThirdPartyCookies(true);
|
| + EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(
|
| + kAllowedSite, kFirstPartySite));
|
| + EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
|
| + kAllowedSite, kFirstPartySite));
|
| + EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kAllowedSite));
|
| +
|
| + // Extensions should always be allowed to use cookies.
|
| + EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(
|
| + kAllowedSite, kExtensionURL));
|
| + EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
|
| + kAllowedSite, kExtensionURL));
|
| +
|
| + CommandLine* cmd = CommandLine::ForCurrentProcess();
|
| + AutoReset<CommandLine> auto_reset(cmd, *cmd);
|
| + cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies);
|
| +
|
| + EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(
|
| + kAllowedSite, kFirstPartySite));
|
| + EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kAllowedSite));
|
| +
|
| + // Extensions should always be allowed to use cookies.
|
| + EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(
|
| + kAllowedSite, kExtensionURL));
|
| + EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
|
| + kAllowedSite, kExtensionURL));
|
| +}
|
| +
|
| +TEST_F(CookieSettingsTest, CookiesBlockEverything) {
|
| + TestingProfile profile;
|
| + CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile);
|
| + cookie_settings->SetDefaultSetting(CONTENT_SETTING_BLOCK);
|
| +
|
| + EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed(
|
| + kFirstPartySite, kFirstPartySite));
|
| + EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed(
|
| + kFirstPartySite, kFirstPartySite));
|
| + EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed(
|
| + kAllowedSite, kFirstPartySite));
|
| +}
|
| +
|
| +TEST_F(CookieSettingsTest, CookiesBlockEverythingExceptAllowed) {
|
| + TestingProfile profile;
|
| + CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile);
|
| + cookie_settings->SetDefaultSetting(CONTENT_SETTING_BLOCK);
|
| + cookie_settings->SetCookieSetting(
|
| + ContentSettingsPattern::FromURL(kAllowedSite),
|
| + CONTENT_SETTING_ALLOW);
|
| + EXPECT_FALSE(cookie_settings->IsReadingCookieAllowed(
|
| + kFirstPartySite, kFirstPartySite));
|
| + EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed(
|
| + kFirstPartySite, kFirstPartySite));
|
| + EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(
|
| + kAllowedSite, kFirstPartySite));
|
| + EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
|
| + kAllowedSite, kFirstPartySite));
|
| + EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(
|
| + kAllowedSite, kAllowedSite));
|
| + EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
|
| + kAllowedSite, kAllowedSite));
|
| + EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(kAllowedSite));
|
| +}
|
| +
|
| +} // namespace
|
|
|