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