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

Side by Side Diff: chrome/browser/net/cookie_policy_browsertest.cc

Issue 8383004: Adding CookieSettings for storing cookie content settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing the rebase. Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h" 5 #include "base/bind.h"
6 #include "base/task.h" 6 #include "base/task.h"
7 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "chrome/browser/content_settings/host_content_settings_map.h" 8 #include "chrome/browser/content_settings/host_content_settings_map.h"
9 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/common/pref_names.h"
11 #include "chrome/test/base/in_process_browser_test.h" 13 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
13 #include "net/base/cookie_store.h" 15 #include "net/base/cookie_store.h"
14 #include "net/base/mock_host_resolver.h" 16 #include "net/base/mock_host_resolver.h"
15 #include "net/test/test_server.h" 17 #include "net/test/test_server.h"
16 #include "net/url_request/url_request_context.h" 18 #include "net/url_request/url_request_context.h"
17 #include "net/url_request/url_request_context_getter.h" 19 #include "net/url_request/url_request_context_getter.h"
18 20
19 namespace { 21 namespace {
20 22
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 75 }
74 76
75 private: 77 private:
76 DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest); 78 DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest);
77 }; 79 };
78 80
79 // Visits a page that sets a first-party cookie. 81 // Visits a page that sets a first-party cookie.
80 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) { 82 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) {
81 ASSERT_TRUE(test_server()->Start()); 83 ASSERT_TRUE(test_server()->Start());
82 84
83 browser()->profile()->GetHostContentSettingsMap()-> 85 browser()->profile()->GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies,
84 SetBlockThirdPartyCookies(true); 86 true);
85 87
86 GURL url(test_server()->GetURL("set-cookie?cookie1")); 88 GURL url(test_server()->GetURL("set-cookie?cookie1"));
87 89
88 std::string cookie = GetCookies(url); 90 std::string cookie = GetCookies(url);
89 ASSERT_EQ("", cookie); 91 ASSERT_EQ("", cookie);
90 92
91 ui_test_utils::NavigateToURL(browser(), url); 93 ui_test_utils::NavigateToURL(browser(), url);
92 94
93 cookie = GetCookies(url); 95 cookie = GetCookies(url);
94 EXPECT_EQ("cookie1", cookie); 96 EXPECT_EQ("cookie1", cookie);
95 } 97 }
96 98
97 // Visits a page that is a redirect across domain boundary to a page that sets 99 // Visits a page that is a redirect across domain boundary to a page that sets
98 // a first-party cookie. 100 // a first-party cookie.
99 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, 101 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
100 AllowFirstPartyCookiesRedirect) { 102 AllowFirstPartyCookiesRedirect) {
101 ASSERT_TRUE(test_server()->Start()); 103 ASSERT_TRUE(test_server()->Start());
102 104
103 browser()->profile()->GetHostContentSettingsMap()-> 105 browser()->profile()->GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies,
104 SetBlockThirdPartyCookies(true); 106 true);
105 107
106 GURL url(test_server()->GetURL("server-redirect?")); 108 GURL url(test_server()->GetURL("server-redirect?"));
107 GURL redirected_url(test_server()->GetURL("set-cookie?cookie2")); 109 GURL redirected_url(test_server()->GetURL("set-cookie?cookie2"));
108 110
109 // Change the host name from 127.0.0.1 to www.example.com so it triggers 111 // Change the host name from 127.0.0.1 to www.example.com so it triggers
110 // third-party cookie blocking if the first party for cookies URL is not 112 // third-party cookie blocking if the first party for cookies URL is not
111 // changed when we follow a redirect. 113 // changed when we follow a redirect.
112 ASSERT_EQ("127.0.0.1", redirected_url.host()); 114 ASSERT_EQ("127.0.0.1", redirected_url.host());
113 GURL::Replacements replacements; 115 GURL::Replacements replacements;
114 std::string new_host("www.example.com"); 116 std::string new_host("www.example.com");
115 replacements.SetHostStr(new_host); 117 replacements.SetHostStr(new_host);
116 redirected_url = redirected_url.ReplaceComponents(replacements); 118 redirected_url = redirected_url.ReplaceComponents(replacements);
117 119
118 std::string cookie = GetCookies(redirected_url); 120 std::string cookie = GetCookies(redirected_url);
119 ASSERT_EQ("", cookie); 121 ASSERT_EQ("", cookie);
120 122
121 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 123 host_resolver()->AddRule("www.example.com", "127.0.0.1");
122 124
123 ui_test_utils::NavigateToURL(browser(), 125 ui_test_utils::NavigateToURL(browser(),
124 GURL(url.spec() + redirected_url.spec())); 126 GURL(url.spec() + redirected_url.spec()));
125 127
126 cookie = GetCookies(redirected_url); 128 cookie = GetCookies(redirected_url);
127 EXPECT_EQ("cookie2", cookie); 129 EXPECT_EQ("cookie2", cookie);
128 } 130 }
129 131
130 } // namespace 132 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_special_storage_policy_unittest.cc ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698