OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/macros.h" | 7 #include "base/macros.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/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
12 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
14 #include "components/content_settings/core/browser/host_content_settings_map.h" | 14 #include "components/content_settings/core/browser/host_content_settings_map.h" |
15 #include "components/content_settings/core/common/pref_names.h" | 15 #include "components/content_settings/core/common/pref_names.h" |
16 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
17 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
18 #include "net/dns/mock_host_resolver.h" | 18 #include "net/dns/mock_host_resolver.h" |
19 #include "net/test/embedded_test_server/embedded_test_server.h" | 19 #include "net/test/embedded_test_server/embedded_test_server.h" |
20 | 20 |
21 using content::BrowserThread; | 21 using content::BrowserThread; |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 class CookiePolicyBrowserTest : public InProcessBrowserTest { | 25 class CookiePolicyBrowserTest : public InProcessBrowserTest { |
26 protected: | 26 protected: |
27 CookiePolicyBrowserTest() {} | 27 CookiePolicyBrowserTest() {} |
28 | 28 |
| 29 void SetUpOnMainThread() override { |
| 30 host_resolver()->AddRule("*", "127.0.0.1"); |
| 31 } |
| 32 |
29 private: | 33 private: |
30 DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest); | 34 DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest); |
31 }; | 35 }; |
32 | 36 |
33 // Visits a page that sets a first-party cookie. | 37 // Visits a page that sets a first-party cookie. |
34 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) { | 38 IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) { |
35 ASSERT_TRUE(embedded_test_server()->Start()); | 39 ASSERT_TRUE(embedded_test_server()->Start()); |
36 | 40 |
37 browser()->profile()->GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, | 41 browser()->profile()->GetPrefs()->SetBoolean(prefs::kBlockThirdPartyCookies, |
38 true); | 42 true); |
(...skipping 26 matching lines...) Expand all Loading... |
65 // changed when we follow a redirect. | 69 // changed when we follow a redirect. |
66 ASSERT_EQ("127.0.0.1", redirected_url.host()); | 70 ASSERT_EQ("127.0.0.1", redirected_url.host()); |
67 GURL::Replacements replacements; | 71 GURL::Replacements replacements; |
68 replacements.SetHostStr("www.example.com"); | 72 replacements.SetHostStr("www.example.com"); |
69 redirected_url = redirected_url.ReplaceComponents(replacements); | 73 redirected_url = redirected_url.ReplaceComponents(replacements); |
70 | 74 |
71 std::string cookie = | 75 std::string cookie = |
72 content::GetCookies(browser()->profile(), redirected_url); | 76 content::GetCookies(browser()->profile(), redirected_url); |
73 ASSERT_EQ("", cookie); | 77 ASSERT_EQ("", cookie); |
74 | 78 |
75 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | |
76 | |
77 ui_test_utils::NavigateToURL(browser(), | 79 ui_test_utils::NavigateToURL(browser(), |
78 GURL(url.spec() + redirected_url.spec())); | 80 GURL(url.spec() + redirected_url.spec())); |
79 | 81 |
80 cookie = content::GetCookies(browser()->profile(), redirected_url); | 82 cookie = content::GetCookies(browser()->profile(), redirected_url); |
81 EXPECT_EQ("cookie2", cookie); | 83 EXPECT_EQ("cookie2", cookie); |
82 } | 84 } |
83 | 85 |
84 } // namespace | 86 } // namespace |
OLD | NEW |