OLD | NEW |
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/task.h" | 5 #include "base/task.h" |
6 #include "base/synchronization/waitable_event.h" | 6 #include "base/synchronization/waitable_event.h" |
7 #include "chrome/browser/content_settings/host_content_settings_map.h" | 7 #include "chrome/browser/content_settings/host_content_settings_map.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 private: | 65 private: |
66 DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest); | 66 DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest); |
67 }; | 67 }; |
68 | 68 |
69 // Visits a page that sets a first-party cookie. | 69 // Visits a page that sets a first-party cookie. |
70 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) { | 70 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) { |
71 ASSERT_TRUE(test_server()->Start()); | 71 ASSERT_TRUE(test_server()->Start()); |
72 | 72 |
73 browser()->profile()->GetHostContentSettingsMap()-> | 73 browser()->profile()->GetCookieContentSettings()-> |
74 SetBlockThirdPartyCookies(true); | 74 SetBlockThirdPartyCookies(true); |
75 | 75 |
76 GURL url(test_server()->GetURL("set-cookie?cookie1")); | 76 GURL url(test_server()->GetURL("set-cookie?cookie1")); |
77 | 77 |
78 std::string cookie = GetCookies(url); | 78 std::string cookie = GetCookies(url); |
79 ASSERT_EQ("", cookie); | 79 ASSERT_EQ("", cookie); |
80 | 80 |
81 ui_test_utils::NavigateToURL(browser(), url); | 81 ui_test_utils::NavigateToURL(browser(), url); |
82 | 82 |
83 cookie = GetCookies(url); | 83 cookie = GetCookies(url); |
84 EXPECT_EQ("cookie1", cookie); | 84 EXPECT_EQ("cookie1", cookie); |
85 } | 85 } |
86 | 86 |
87 // Visits a page that is a redirect across domain boundary to a page that sets | 87 // Visits a page that is a redirect across domain boundary to a page that sets |
88 // a first-party cookie. | 88 // a first-party cookie. |
89 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, | 89 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, |
90 AllowFirstPartyCookiesRedirect) { | 90 AllowFirstPartyCookiesRedirect) { |
91 ASSERT_TRUE(test_server()->Start()); | 91 ASSERT_TRUE(test_server()->Start()); |
92 | 92 |
93 browser()->profile()->GetHostContentSettingsMap()-> | 93 browser()->profile()->GetCookieContentSettings()-> |
94 SetBlockThirdPartyCookies(true); | 94 SetBlockThirdPartyCookies(true); |
95 | 95 |
96 GURL url(test_server()->GetURL("server-redirect?")); | 96 GURL url(test_server()->GetURL("server-redirect?")); |
97 GURL redirected_url(test_server()->GetURL("set-cookie?cookie2")); | 97 GURL redirected_url(test_server()->GetURL("set-cookie?cookie2")); |
98 | 98 |
99 // Change the host name from 127.0.0.1 to www.example.com so it triggers | 99 // Change the host name from 127.0.0.1 to www.example.com so it triggers |
100 // third-party cookie blocking if the first party for cookies URL is not | 100 // third-party cookie blocking if the first party for cookies URL is not |
101 // changed when we follow a redirect. | 101 // changed when we follow a redirect. |
102 ASSERT_EQ("127.0.0.1", redirected_url.host()); | 102 ASSERT_EQ("127.0.0.1", redirected_url.host()); |
103 GURL::Replacements replacements; | 103 GURL::Replacements replacements; |
104 std::string new_host("www.example.com"); | 104 std::string new_host("www.example.com"); |
105 replacements.SetHostStr(new_host); | 105 replacements.SetHostStr(new_host); |
106 redirected_url = redirected_url.ReplaceComponents(replacements); | 106 redirected_url = redirected_url.ReplaceComponents(replacements); |
107 | 107 |
108 std::string cookie = GetCookies(redirected_url); | 108 std::string cookie = GetCookies(redirected_url); |
109 ASSERT_EQ("", cookie); | 109 ASSERT_EQ("", cookie); |
110 | 110 |
111 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 111 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
112 | 112 |
113 ui_test_utils::NavigateToURL(browser(), | 113 ui_test_utils::NavigateToURL(browser(), |
114 GURL(url.spec() + redirected_url.spec())); | 114 GURL(url.spec() + redirected_url.spec())); |
115 | 115 |
116 cookie = GetCookies(redirected_url); | 116 cookie = GetCookies(redirected_url); |
117 EXPECT_EQ("cookie2", cookie); | 117 EXPECT_EQ("cookie2", cookie); |
118 } | 118 } |
119 | 119 |
120 } // namespace | 120 } // namespace |
OLD | NEW |