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

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

Issue 2860012: Revert 50296 (Causes DCHECK failures) - Make CookieMonster NonThreadSafe.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension_function.h ('k') | net/base/cookie_monster.h » ('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"
6 #include "base/waitable_event.h"
7 #include "chrome/browser/browser.h" 5 #include "chrome/browser/browser.h"
8 #include "chrome/browser/host_content_settings_map.h" 6 #include "chrome/browser/host_content_settings_map.h"
9 #include "chrome/browser/profile.h" 7 #include "chrome/browser/profile.h"
10 #include "chrome/common/net/url_request_context_getter.h" 8 #include "chrome/common/net/url_request_context_getter.h"
11 #include "chrome/test/in_process_browser_test.h" 9 #include "chrome/test/in_process_browser_test.h"
12 #include "chrome/test/ui_test_utils.h" 10 #include "chrome/test/ui_test_utils.h"
13 #include "net/base/mock_host_resolver.h" 11 #include "net/base/mock_host_resolver.h"
14 12
15 namespace { 13 class CookiePolicyBrowserTest : public InProcessBrowserTest {
16
17 class GetCookiesTask : public Task {
18 public: 14 public:
19 GetCookiesTask(const GURL& url,
20 URLRequestContextGetter* context_getter,
21 base::WaitableEvent* event,
22 std::string* cookies)
23 : url_(url),
24 context_getter_(context_getter),
25 event_(event),
26 cookies_(cookies) {}
27
28 virtual void Run() {
29 *cookies_ = context_getter_->GetCookieStore()->GetCookies(url_);
30 event_->Signal();
31 }
32
33 private:
34 const GURL& url_;
35 URLRequestContextGetter* const context_getter_;
36 base::WaitableEvent* const event_;
37 std::string* const cookies_;
38
39 DISALLOW_COPY_AND_ASSIGN(GetCookiesTask);
40 };
41
42 class CookiePolicyBrowserTest : public InProcessBrowserTest {
43 protected:
44 CookiePolicyBrowserTest() {} 15 CookiePolicyBrowserTest() {}
45 16
46 std::string GetCookies(const GURL& url) {
47 std::string cookies;
48 base::WaitableEvent event(true /* manual reset */,
49 false /* not initially signaled */);
50 URLRequestContextGetter* context_getter =
51 browser()->profile()->GetRequestContext();
52 EXPECT_TRUE(
53 ChromeThread::PostTask(
54 ChromeThread::IO, FROM_HERE,
55 new GetCookiesTask(url, context_getter, &event, &cookies)));
56 EXPECT_TRUE(event.Wait());
57 return cookies;
58 }
59
60 private: 17 private:
61 DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest); 18 DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest);
62 }; 19 };
63 20
64 // Visits a page that sets a first-party cookie. 21 // Visits a page that sets a first-party cookie.
65 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) { 22 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) {
66 HTTPTestServer* server = StartHTTPServer(); 23 HTTPTestServer* server = StartHTTPServer();
67 ASSERT_TRUE(server != NULL); 24 ASSERT_TRUE(server != NULL);
68 25
69 browser()->profile()->GetHostContentSettingsMap()-> 26 browser()->profile()->GetHostContentSettingsMap()->
70 SetBlockThirdPartyCookies(true); 27 SetBlockThirdPartyCookies(true);
71 28
29 net::CookieStore* cookie_store =
30 browser()->profile()->GetRequestContext()->GetCookieStore();
31
72 GURL url = server->TestServerPage("set-cookie?cookie1"); 32 GURL url = server->TestServerPage("set-cookie?cookie1");
73 33
74 std::string cookie = GetCookies(url); 34 std::string cookie = cookie_store->GetCookies(url);
75 ASSERT_EQ("", cookie); 35 ASSERT_EQ("", cookie);
76 36
77 ui_test_utils::NavigateToURL(browser(), url); 37 ui_test_utils::NavigateToURL(browser(), url);
78 38
79 cookie = GetCookies(url); 39 cookie = cookie_store->GetCookies(url);
80 EXPECT_EQ("cookie1", cookie); 40 EXPECT_EQ("cookie1", cookie);
81 } 41 }
82 42
43
83 // Visits a page that is a redirect across domain boundary to a page that sets 44 // Visits a page that is a redirect across domain boundary to a page that sets
84 // a first-party cookie. 45 // a first-party cookie.
85 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, 46 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
86 AllowFirstPartyCookiesRedirect) { 47 AllowFirstPartyCookiesRedirect) {
87 HTTPTestServer* server = StartHTTPServer(); 48 HTTPTestServer* server = StartHTTPServer();
88 ASSERT_TRUE(server != NULL); 49 ASSERT_TRUE(server != NULL);
89 50
90 browser()->profile()->GetHostContentSettingsMap()-> 51 browser()->profile()->GetHostContentSettingsMap()->
91 SetBlockThirdPartyCookies(true); 52 SetBlockThirdPartyCookies(true);
92 53
54 net::CookieStore* cookie_store =
55 browser()->profile()->GetRequestContext()->GetCookieStore();
56
93 GURL url = server->TestServerPage("server-redirect?"); 57 GURL url = server->TestServerPage("server-redirect?");
94 58
95 GURL redirected_url = server->TestServerPage("set-cookie?cookie2"); 59 GURL redirected_url = server->TestServerPage("set-cookie?cookie2");
96 // Change the host name from localhost to www.example.com so it triggers 60 // 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 61 // third-party cookie blocking if the first party for cookies URL is not
98 // changed when we follow a redirect. 62 // changed when we follow a redirect.
99 ASSERT_EQ("localhost", redirected_url.host()); 63 ASSERT_EQ("localhost", redirected_url.host());
100 GURL::Replacements replacements; 64 GURL::Replacements replacements;
101 std::string new_host("www.example.com"); 65 std::string new_host("www.example.com");
102 replacements.SetHostStr(new_host); 66 replacements.SetHostStr(new_host);
103 redirected_url = redirected_url.ReplaceComponents(replacements); 67 redirected_url = redirected_url.ReplaceComponents(replacements);
104 68
105 std::string cookie = GetCookies(redirected_url); 69 std::string cookie = cookie_store->GetCookies(redirected_url);
106 ASSERT_EQ("", cookie); 70 ASSERT_EQ("", cookie);
107 71
108 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 72 host_resolver()->AddRule("www.example.com", "127.0.0.1");
109 73
110 ui_test_utils::NavigateToURL(browser(), 74 ui_test_utils::NavigateToURL(browser(),
111 GURL(url.spec() + redirected_url.spec())); 75 GURL(url.spec() + redirected_url.spec()));
112 76
113 cookie = GetCookies(redirected_url); 77 cookie = cookie_store->GetCookies(redirected_url);
114 EXPECT_EQ("cookie2", cookie); 78 EXPECT_EQ("cookie2", cookie);
115 } 79 }
116
117 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_function.h ('k') | net/base/cookie_monster.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698