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

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

Issue 3034038: GTTF: Move more test server code from net/url_request/url_request_unittest.h (Closed)
Patch Set: hopefully final Created 10 years, 4 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/net/connection_tester_unittest.cc ('k') | chrome/browser/net/ftp_browsertest.cc » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/task.h" 5 #include "base/task.h"
6 #include "base/waitable_event.h" 6 #include "base/waitable_event.h"
7 #include "chrome/browser/browser.h" 7 #include "chrome/browser/browser.h"
8 #include "chrome/browser/host_content_settings_map.h" 8 #include "chrome/browser/host_content_settings_map.h"
9 #include "chrome/browser/profile.h" 9 #include "chrome/browser/profile.h"
10 #include "chrome/common/net/url_request_context_getter.h" 10 #include "chrome/common/net/url_request_context_getter.h"
11 #include "chrome/test/in_process_browser_test.h" 11 #include "chrome/test/in_process_browser_test.h"
12 #include "chrome/test/ui_test_utils.h" 12 #include "chrome/test/ui_test_utils.h"
13 #include "net/base/cookie_store.h"
13 #include "net/base/mock_host_resolver.h" 14 #include "net/base/mock_host_resolver.h"
15 #include "net/test/test_server.h"
14 16
15 namespace { 17 namespace {
16 18
17 class GetCookiesTask : public Task { 19 class GetCookiesTask : public Task {
18 public: 20 public:
19 GetCookiesTask(const GURL& url, 21 GetCookiesTask(const GURL& url,
20 URLRequestContextGetter* context_getter, 22 URLRequestContextGetter* context_getter,
21 base::WaitableEvent* event, 23 base::WaitableEvent* event,
22 std::string* cookies) 24 std::string* cookies)
23 : url_(url), 25 : url_(url),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 EXPECT_TRUE(event.Wait()); 58 EXPECT_TRUE(event.Wait());
57 return cookies; 59 return cookies;
58 } 60 }
59 61
60 private: 62 private:
61 DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest); 63 DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest);
62 }; 64 };
63 65
64 // Visits a page that sets a first-party cookie. 66 // Visits a page that sets a first-party cookie.
65 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) { 67 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) {
66 HTTPTestServer* server = StartHTTPServer(); 68 net::HTTPTestServer* server = StartHTTPServer();
67 ASSERT_TRUE(server != NULL); 69 ASSERT_TRUE(server != NULL);
68 70
69 browser()->profile()->GetHostContentSettingsMap()-> 71 browser()->profile()->GetHostContentSettingsMap()->
70 SetBlockThirdPartyCookies(true); 72 SetBlockThirdPartyCookies(true);
71 73
72 GURL url = server->TestServerPage("set-cookie?cookie1"); 74 GURL url = server->TestServerPage("set-cookie?cookie1");
73 75
74 std::string cookie = GetCookies(url); 76 std::string cookie = GetCookies(url);
75 ASSERT_EQ("", cookie); 77 ASSERT_EQ("", cookie);
76 78
77 ui_test_utils::NavigateToURL(browser(), url); 79 ui_test_utils::NavigateToURL(browser(), url);
78 80
79 cookie = GetCookies(url); 81 cookie = GetCookies(url);
80 EXPECT_EQ("cookie1", cookie); 82 EXPECT_EQ("cookie1", cookie);
81 } 83 }
82 84
83 // Visits a page that is a redirect across domain boundary to a page that sets 85 // Visits a page that is a redirect across domain boundary to a page that sets
84 // a first-party cookie. 86 // a first-party cookie.
85 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, 87 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
86 AllowFirstPartyCookiesRedirect) { 88 AllowFirstPartyCookiesRedirect) {
87 HTTPTestServer* server = StartHTTPServer(); 89 net::HTTPTestServer* server = StartHTTPServer();
88 ASSERT_TRUE(server != NULL); 90 ASSERT_TRUE(server != NULL);
89 91
90 browser()->profile()->GetHostContentSettingsMap()-> 92 browser()->profile()->GetHostContentSettingsMap()->
91 SetBlockThirdPartyCookies(true); 93 SetBlockThirdPartyCookies(true);
92 94
93 GURL url = server->TestServerPage("server-redirect?"); 95 GURL url = server->TestServerPage("server-redirect?");
94 96
95 GURL redirected_url = server->TestServerPage("set-cookie?cookie2"); 97 GURL redirected_url = server->TestServerPage("set-cookie?cookie2");
96 // Change the host name from localhost to www.example.com so it triggers 98 // Change the host name from localhost to www.example.com so it triggers
97 // third-party cookie blocking if the first party for cookies URL is not 99 // third-party cookie blocking if the first party for cookies URL is not
(...skipping 10 matching lines...) Expand all
108 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 110 host_resolver()->AddRule("www.example.com", "127.0.0.1");
109 111
110 ui_test_utils::NavigateToURL(browser(), 112 ui_test_utils::NavigateToURL(browser(),
111 GURL(url.spec() + redirected_url.spec())); 113 GURL(url.spec() + redirected_url.spec()));
112 114
113 cookie = GetCookies(redirected_url); 115 cookie = GetCookies(redirected_url);
114 EXPECT_EQ("cookie2", cookie); 116 EXPECT_EQ("cookie2", cookie);
115 } 117 }
116 118
117 } // namespace 119 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/net/connection_tester_unittest.cc ('k') | chrome/browser/net/ftp_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698