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

Unified Diff: chrome/browser/net/cookie_policy_browsertest.cc

Issue 401009: Add browser tests for the BLOCK_THIRD_PARTY_COOKIES... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Upload before checkin Created 11 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/cookie_policy_browsertest.cc
===================================================================
--- chrome/browser/net/cookie_policy_browsertest.cc (revision 0)
+++ chrome/browser/net/cookie_policy_browsertest.cc (revision 0)
@@ -0,0 +1,87 @@
+// Copyright (c) 2009 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 "chrome/browser/browser.h"
+#include "chrome/browser/net/url_request_context_getter.h"
+#include "chrome/browser/profile.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/common/pref_service.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+
+class CookiePolicyBrowserTest : public InProcessBrowserTest {
+ public:
+ CookiePolicyBrowserTest() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest);
+};
+
+// Visits a page that sets a first-party cookie.
+IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) {
+ HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server != NULL);
+
+ PrefService* prefs = browser()->profile()->GetPrefs();
+ prefs->SetInteger(prefs::kCookieBehavior,
+ net::CookiePolicy::BLOCK_THIRD_PARTY_COOKIES);
+ net::CookiePolicy::Type policy_type = net::CookiePolicy::FromInt(
+ prefs->GetInteger(prefs::kCookieBehavior));
+ ASSERT_EQ(net::CookiePolicy::BLOCK_THIRD_PARTY_COOKIES, policy_type);
+
+ net::CookieStore* cookie_store =
+ browser()->profile()->GetRequestContext()->GetCookieStore();
+
+ GURL url = server->TestServerPage("set-cookie?cookie1");
+
+ std::string cookie = cookie_store->GetCookies(url);
+ ASSERT_EQ("", cookie);
+
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ cookie = cookie_store->GetCookies(url);
+ EXPECT_EQ("cookie1", cookie);
+}
+
+
+// Visits a page that is a redirect across domain boundary to a page that sets
+// a first-party cookie.
+IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
+ AllowFirstPartyCookiesRedirect) {
+ HTTPTestServer* server = StartHTTPServer();
+ ASSERT_TRUE(server != NULL);
+
+ PrefService* prefs = browser()->profile()->GetPrefs();
+ prefs->SetInteger(prefs::kCookieBehavior,
+ net::CookiePolicy::BLOCK_THIRD_PARTY_COOKIES);
+ net::CookiePolicy::Type policy_type = net::CookiePolicy::FromInt(
+ prefs->GetInteger(prefs::kCookieBehavior));
+ ASSERT_EQ(net::CookiePolicy::BLOCK_THIRD_PARTY_COOKIES, policy_type);
+
+ net::CookieStore* cookie_store =
+ browser()->profile()->GetRequestContext()->GetCookieStore();
+
+ GURL url = server->TestServerPage("server-redirect?");
+
+ GURL redirected_url = server->TestServerPage("set-cookie?cookie2");
+ // Change the host name from localhost to www.example.com so it triggers
+ // third-party cookie blocking if the first party for cookies URL is not
+ // changed when we follow a redirect.
+ ASSERT_EQ("localhost", redirected_url.host());
+ GURL::Replacements replacements;
+ std::string new_host("www.example.com");
+ replacements.SetHostStr(new_host);
+ redirected_url = redirected_url.ReplaceComponents(replacements);
+
+ std::string cookie = cookie_store->GetCookies(redirected_url);
+ ASSERT_EQ("", cookie);
+
+ host_resolver()->AddRule("www.example.com", "127.0.0.1");
+
+ ui_test_utils::NavigateToURL(browser(),
+ GURL(url.spec() + redirected_url.spec()));
+
+ cookie = cookie_store->GetCookies(redirected_url);
+ EXPECT_EQ("cookie2", cookie);
+}
Property changes on: chrome\browser\net\cookie_policy_browsertest.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « no previous file | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698