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

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

Issue 2756003: Make CookieMonster NonThreadSafe. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Address eroman's and cindylau's comments. 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
« 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"
5 #include "chrome/browser/browser.h" 7 #include "chrome/browser/browser.h"
6 #include "chrome/browser/host_content_settings_map.h" 8 #include "chrome/browser/host_content_settings_map.h"
7 #include "chrome/browser/profile.h" 9 #include "chrome/browser/profile.h"
8 #include "chrome/common/net/url_request_context_getter.h" 10 #include "chrome/common/net/url_request_context_getter.h"
9 #include "chrome/test/in_process_browser_test.h" 11 #include "chrome/test/in_process_browser_test.h"
10 #include "chrome/test/ui_test_utils.h" 12 #include "chrome/test/ui_test_utils.h"
11 #include "net/base/mock_host_resolver.h" 13 #include "net/base/mock_host_resolver.h"
12 14
15 namespace {
16
17 class GetCookiesTask : public Task {
18 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
13 class CookiePolicyBrowserTest : public InProcessBrowserTest { 42 class CookiePolicyBrowserTest : public InProcessBrowserTest {
14 public: 43 protected:
15 CookiePolicyBrowserTest() {} 44 CookiePolicyBrowserTest() {}
16 45
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
17 private: 60 private:
18 DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest); 61 DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest);
19 }; 62 };
20 63
21 // Visits a page that sets a first-party cookie. 64 // Visits a page that sets a first-party cookie.
22 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) { 65 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) {
23 HTTPTestServer* server = StartHTTPServer(); 66 HTTPTestServer* server = StartHTTPServer();
24 ASSERT_TRUE(server != NULL); 67 ASSERT_TRUE(server != NULL);
25 68
26 browser()->profile()->GetHostContentSettingsMap()-> 69 browser()->profile()->GetHostContentSettingsMap()->
27 SetBlockThirdPartyCookies(true); 70 SetBlockThirdPartyCookies(true);
28 71
29 net::CookieStore* cookie_store =
30 browser()->profile()->GetRequestContext()->GetCookieStore();
31
32 GURL url = server->TestServerPage("set-cookie?cookie1"); 72 GURL url = server->TestServerPage("set-cookie?cookie1");
33 73
34 std::string cookie = cookie_store->GetCookies(url); 74 std::string cookie = GetCookies(url);
35 ASSERT_EQ("", cookie); 75 ASSERT_EQ("", cookie);
36 76
37 ui_test_utils::NavigateToURL(browser(), url); 77 ui_test_utils::NavigateToURL(browser(), url);
38 78
39 cookie = cookie_store->GetCookies(url); 79 cookie = GetCookies(url);
40 EXPECT_EQ("cookie1", cookie); 80 EXPECT_EQ("cookie1", cookie);
41 } 81 }
42 82
43
44 // Visits a page that is a redirect across domain boundary to a page that sets 83 // Visits a page that is a redirect across domain boundary to a page that sets
45 // a first-party cookie. 84 // a first-party cookie.
46 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, 85 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest,
47 AllowFirstPartyCookiesRedirect) { 86 AllowFirstPartyCookiesRedirect) {
48 HTTPTestServer* server = StartHTTPServer(); 87 HTTPTestServer* server = StartHTTPServer();
49 ASSERT_TRUE(server != NULL); 88 ASSERT_TRUE(server != NULL);
50 89
51 browser()->profile()->GetHostContentSettingsMap()-> 90 browser()->profile()->GetHostContentSettingsMap()->
52 SetBlockThirdPartyCookies(true); 91 SetBlockThirdPartyCookies(true);
53 92
54 net::CookieStore* cookie_store =
55 browser()->profile()->GetRequestContext()->GetCookieStore();
56
57 GURL url = server->TestServerPage("server-redirect?"); 93 GURL url = server->TestServerPage("server-redirect?");
58 94
59 GURL redirected_url = server->TestServerPage("set-cookie?cookie2"); 95 GURL redirected_url = server->TestServerPage("set-cookie?cookie2");
60 // Change the host name from localhost to www.example.com so it triggers 96 // Change the host name from localhost to www.example.com so it triggers
61 // third-party cookie blocking if the first party for cookies URL is not 97 // third-party cookie blocking if the first party for cookies URL is not
62 // changed when we follow a redirect. 98 // changed when we follow a redirect.
63 ASSERT_EQ("localhost", redirected_url.host()); 99 ASSERT_EQ("localhost", redirected_url.host());
64 GURL::Replacements replacements; 100 GURL::Replacements replacements;
65 std::string new_host("www.example.com"); 101 std::string new_host("www.example.com");
66 replacements.SetHostStr(new_host); 102 replacements.SetHostStr(new_host);
67 redirected_url = redirected_url.ReplaceComponents(replacements); 103 redirected_url = redirected_url.ReplaceComponents(replacements);
68 104
69 std::string cookie = cookie_store->GetCookies(redirected_url); 105 std::string cookie = GetCookies(redirected_url);
70 ASSERT_EQ("", cookie); 106 ASSERT_EQ("", cookie);
71 107
72 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 108 host_resolver()->AddRule("www.example.com", "127.0.0.1");
73 109
74 ui_test_utils::NavigateToURL(browser(), 110 ui_test_utils::NavigateToURL(browser(),
75 GURL(url.spec() + redirected_url.spec())); 111 GURL(url.spec() + redirected_url.spec()));
76 112
77 cookie = cookie_store->GetCookies(redirected_url); 113 cookie = GetCookies(redirected_url);
78 EXPECT_EQ("cookie2", cookie); 114 EXPECT_EQ("cookie2", cookie);
79 } 115 }
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