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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 10 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "content/public/browser/notification_observer.h" | 26 #include "content/public/browser/notification_observer.h" |
27 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
28 #include "content/public/browser/plugin_service.h" | 28 #include "content/public/browser/plugin_service.h" |
29 #include "content/public/browser/render_frame_host.h" | 29 #include "content/public/browser/render_frame_host.h" |
30 #include "content/public/browser/render_process_host.h" | 30 #include "content/public/browser/render_process_host.h" |
31 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
33 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
34 #include "content/public/test/browser_test_utils.h" | 34 #include "content/public/test/browser_test_utils.h" |
35 #include "content/public/test/test_utils.h" | 35 #include "content/public/test/test_utils.h" |
36 #include "net/test/spawned_test_server/spawned_test_server.h" | 36 #include "net/test/embedded_test_server/embedded_test_server.h" |
37 #include "net/test/url_request/url_request_mock_http_job.h" | 37 #include "net/test/url_request/url_request_mock_http_job.h" |
38 | 38 |
39 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 39 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
40 | 40 |
41 #if defined(OS_MACOSX) | 41 #if defined(OS_MACOSX) |
42 #include "base/mac/scoped_nsautorelease_pool.h" | 42 #include "base/mac/scoped_nsautorelease_pool.h" |
43 #endif | 43 #endif |
44 | 44 |
45 using content::BrowserThread; | 45 using content::BrowserThread; |
46 using net::URLRequestMockHTTPJob; | 46 using net::URLRequestMockHTTPJob; |
47 | 47 |
48 class ContentSettingsTest : public InProcessBrowserTest { | 48 class ContentSettingsTest : public InProcessBrowserTest { |
49 public: | 49 public: |
50 ContentSettingsTest() | 50 ContentSettingsTest() : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { |
51 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, | 51 https_server_.ServeFilesFromSourceDirectory("chrome/test/data"); |
52 net::SpawnedTestServer::SSLOptions( | |
53 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
54 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { | |
55 } | 52 } |
56 | 53 |
57 void SetUpOnMainThread() override { | 54 void SetUpOnMainThread() override { |
58 BrowserThread::PostTask( | 55 BrowserThread::PostTask( |
59 BrowserThread::IO, FROM_HERE, | 56 BrowserThread::IO, FROM_HERE, |
60 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 57 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
61 } | 58 } |
62 | 59 |
63 // Check the cookie for the given URL in an incognito window. | 60 // Check the cookie for the given URL in an incognito window. |
64 void CookieCheckIncognitoWindow(const GURL& url, bool cookies_enabled) { | 61 void CookieCheckIncognitoWindow(const GURL& url, bool cookies_enabled) { |
(...skipping 22 matching lines...) Expand all Loading... |
87 CookieCheckIncognitoWindow(url, true); | 84 CookieCheckIncognitoWindow(url, true); |
88 | 85 |
89 ui_test_utils::NavigateToURL(browser(), url); | 86 ui_test_utils::NavigateToURL(browser(), url); |
90 ASSERT_FALSE(GetCookies(browser()->profile(), url).empty()); | 87 ASSERT_FALSE(GetCookies(browser()->profile(), url).empty()); |
91 } | 88 } |
92 | 89 |
93 void Basic(const GURL& url) { | 90 void Basic(const GURL& url) { |
94 ASSERT_FALSE(GetCookies(browser()->profile(), url).empty()); | 91 ASSERT_FALSE(GetCookies(browser()->profile(), url).empty()); |
95 } | 92 } |
96 | 93 |
97 net::SpawnedTestServer https_server_; | 94 net::EmbeddedTestServer https_server_; |
98 }; | 95 }; |
99 | 96 |
100 // Sanity check on cookies before we do other tests. While these can be written | 97 // Sanity check on cookies before we do other tests. While these can be written |
101 // in content_browsertests, we want to verify Chrome's cookie storage and how it | 98 // in content_browsertests, we want to verify Chrome's cookie storage and how it |
102 // handles incognito windows. | 99 // handles incognito windows. |
103 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, PRE_BasicCookies) { | 100 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, PRE_BasicCookies) { |
104 ASSERT_TRUE(test_server()->Start()); | 101 ASSERT_TRUE(embedded_test_server()->Start()); |
105 GURL http_url = test_server()->GetURL("files/setcookie.html"); | 102 GURL http_url = embedded_test_server()->GetURL("/setcookie.html"); |
106 PreBasic(http_url); | 103 PreBasic(http_url); |
107 } | 104 } |
108 | 105 |
109 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, BasicCookies) { | 106 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, BasicCookies) { |
110 ASSERT_TRUE(test_server()->Start()); | 107 ASSERT_TRUE(embedded_test_server()->Start()); |
111 GURL http_url = test_server()->GetURL("files/setcookie.html"); | 108 GURL http_url = embedded_test_server()->GetURL("/setcookie.html"); |
112 Basic(http_url); | 109 Basic(http_url); |
113 } | 110 } |
114 | 111 |
115 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, PRE_BasicCookiesHttps) { | 112 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, PRE_BasicCookiesHttps) { |
116 ASSERT_TRUE(https_server_.Start()); | 113 ASSERT_TRUE(https_server_.Start()); |
117 GURL https_url = https_server_.GetURL("files/setcookie.html"); | 114 GURL https_url = https_server_.GetURL("/setcookie.html"); |
118 PreBasic(https_url); | 115 PreBasic(https_url); |
119 } | 116 } |
120 | 117 |
121 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, BasicCookiesHttps) { | 118 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, BasicCookiesHttps) { |
122 ASSERT_TRUE(https_server_.Start()); | 119 ASSERT_TRUE(https_server_.Start()); |
123 GURL https_url = https_server_.GetURL("files/setcookie.html"); | 120 GURL https_url = https_server_.GetURL("/setcookie.html"); |
124 Basic(https_url); | 121 Basic(https_url); |
125 } | 122 } |
126 | 123 |
127 // Verify that cookies are being blocked. | 124 // Verify that cookies are being blocked. |
128 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, PRE_BlockCookies) { | 125 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, PRE_BlockCookies) { |
129 ASSERT_TRUE(test_server()->Start()); | 126 ASSERT_TRUE(embedded_test_server()->Start()); |
130 CookieSettingsFactory::GetForProfile(browser()->profile()) | 127 CookieSettingsFactory::GetForProfile(browser()->profile()) |
131 ->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 128 ->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
132 GURL url = test_server()->GetURL("files/setcookie.html"); | 129 GURL url = embedded_test_server()->GetURL("/setcookie.html"); |
133 ui_test_utils::NavigateToURL(browser(), url); | 130 ui_test_utils::NavigateToURL(browser(), url); |
134 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty()); | 131 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty()); |
135 CookieCheckIncognitoWindow(url, false); | 132 CookieCheckIncognitoWindow(url, false); |
136 } | 133 } |
137 | 134 |
138 // Ensure that the setting persists. | 135 // Ensure that the setting persists. |
139 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, BlockCookies) { | 136 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, BlockCookies) { |
140 ASSERT_EQ(CONTENT_SETTING_BLOCK, | 137 ASSERT_EQ(CONTENT_SETTING_BLOCK, |
141 CookieSettingsFactory::GetForProfile(browser()->profile()) | 138 CookieSettingsFactory::GetForProfile(browser()->profile()) |
142 ->GetDefaultCookieSetting(NULL)); | 139 ->GetDefaultCookieSetting(NULL)); |
143 } | 140 } |
144 | 141 |
145 // Verify that cookies can be allowed and set using exceptions for particular | 142 // Verify that cookies can be allowed and set using exceptions for particular |
146 // website(s) when all others are blocked. | 143 // website(s) when all others are blocked. |
147 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, AllowCookiesUsingExceptions) { | 144 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, AllowCookiesUsingExceptions) { |
148 ASSERT_TRUE(test_server()->Start()); | 145 ASSERT_TRUE(embedded_test_server()->Start()); |
149 GURL url = test_server()->GetURL("files/setcookie.html"); | 146 GURL url = embedded_test_server()->GetURL("/setcookie.html"); |
150 content_settings::CookieSettings* settings = | 147 content_settings::CookieSettings* settings = |
151 CookieSettingsFactory::GetForProfile(browser()->profile()).get(); | 148 CookieSettingsFactory::GetForProfile(browser()->profile()).get(); |
152 settings->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 149 settings->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
153 | 150 |
154 ui_test_utils::NavigateToURL(browser(), url); | 151 ui_test_utils::NavigateToURL(browser(), url); |
155 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty()); | 152 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty()); |
156 | 153 |
157 settings->SetCookieSetting( | 154 settings->SetCookieSetting( |
158 ContentSettingsPattern::FromURL(url), | 155 ContentSettingsPattern::FromURL(url), |
159 ContentSettingsPattern::Wildcard(), CONTENT_SETTING_ALLOW); | 156 ContentSettingsPattern::Wildcard(), CONTENT_SETTING_ALLOW); |
160 | 157 |
161 ui_test_utils::NavigateToURL(browser(), url); | 158 ui_test_utils::NavigateToURL(browser(), url); |
162 ASSERT_FALSE(GetCookies(browser()->profile(), url).empty()); | 159 ASSERT_FALSE(GetCookies(browser()->profile(), url).empty()); |
163 } | 160 } |
164 | 161 |
165 // Verify that cookies can be blocked for a specific website using exceptions. | 162 // Verify that cookies can be blocked for a specific website using exceptions. |
166 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, BlockCookiesUsingExceptions) { | 163 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, BlockCookiesUsingExceptions) { |
167 ASSERT_TRUE(test_server()->Start()); | 164 ASSERT_TRUE(embedded_test_server()->Start()); |
168 GURL url = test_server()->GetURL("files/setcookie.html"); | 165 GURL url = embedded_test_server()->GetURL("/setcookie.html"); |
169 content_settings::CookieSettings* settings = | 166 content_settings::CookieSettings* settings = |
170 CookieSettingsFactory::GetForProfile(browser()->profile()).get(); | 167 CookieSettingsFactory::GetForProfile(browser()->profile()).get(); |
171 settings->SetCookieSetting(ContentSettingsPattern::FromURL(url), | 168 settings->SetCookieSetting(ContentSettingsPattern::FromURL(url), |
172 ContentSettingsPattern::Wildcard(), | 169 ContentSettingsPattern::Wildcard(), |
173 CONTENT_SETTING_BLOCK); | 170 CONTENT_SETTING_BLOCK); |
174 | 171 |
175 ui_test_utils::NavigateToURL(browser(), url); | 172 ui_test_utils::NavigateToURL(browser(), url); |
176 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty()); | 173 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty()); |
177 | 174 |
178 ASSERT_TRUE(https_server_.Start()); | 175 ASSERT_TRUE(https_server_.Start()); |
179 GURL unblocked_url = https_server_.GetURL("files/cookie1.html"); | 176 GURL unblocked_url = https_server_.GetURL("/cookie1.html"); |
180 | 177 |
181 ui_test_utils::NavigateToURL(browser(), unblocked_url); | 178 ui_test_utils::NavigateToURL(browser(), unblocked_url); |
182 ASSERT_FALSE(GetCookies(browser()->profile(), unblocked_url).empty()); | 179 ASSERT_FALSE(GetCookies(browser()->profile(), unblocked_url).empty()); |
183 } | 180 } |
184 | 181 |
185 // This fails on ChromeOS because kRestoreOnStartup is ignored and the startup | 182 // This fails on ChromeOS because kRestoreOnStartup is ignored and the startup |
186 // preference is always "continue where I left off. | 183 // preference is always "continue where I left off. |
187 #if !defined(OS_CHROMEOS) | 184 #if !defined(OS_CHROMEOS) |
188 | 185 |
189 // Verify that cookies can be allowed and set using exceptions for particular | 186 // Verify that cookies can be allowed and set using exceptions for particular |
(...skipping 20 matching lines...) Expand all Loading... |
210 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, | 207 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, |
211 AllowCookiesForASessionUsingExceptions) { | 208 AllowCookiesForASessionUsingExceptions) { |
212 GURL url = URLRequestMockHTTPJob::GetMockUrl("setcookie.html"); | 209 GURL url = URLRequestMockHTTPJob::GetMockUrl("setcookie.html"); |
213 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty()); | 210 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty()); |
214 } | 211 } |
215 | 212 |
216 #endif // !CHROME_OS | 213 #endif // !CHROME_OS |
217 | 214 |
218 // Regression test for http://crbug.com/63649. | 215 // Regression test for http://crbug.com/63649. |
219 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, RedirectLoopCookies) { | 216 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, RedirectLoopCookies) { |
220 ASSERT_TRUE(test_server()->Start()); | 217 ASSERT_TRUE(embedded_test_server()->Start()); |
221 | 218 |
222 GURL test_url = test_server()->GetURL("files/redirect-loop.html"); | 219 GURL test_url = embedded_test_server()->GetURL("/redirect-loop.html"); |
223 | 220 |
224 CookieSettingsFactory::GetForProfile(browser()->profile()) | 221 CookieSettingsFactory::GetForProfile(browser()->profile()) |
225 ->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 222 ->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
226 | 223 |
227 ui_test_utils::NavigateToURL(browser(), test_url); | 224 ui_test_utils::NavigateToURL(browser(), test_url); |
228 | 225 |
229 content::WebContents* web_contents = | 226 content::WebContents* web_contents = |
230 browser()->tab_strip_model()->GetActiveWebContents(); | 227 browser()->tab_strip_model()->GetActiveWebContents(); |
231 ASSERT_EQ(base::UTF8ToUTF16(test_url.spec() + " failed to load"), | 228 ASSERT_EQ(base::UTF8ToUTF16(test_url.spec() + " failed to load"), |
232 web_contents->GetTitle()); | 229 web_contents->GetTitle()); |
(...skipping 15 matching lines...) Expand all Loading... |
248 browser()->tab_strip_model()->GetActiveWebContents(); | 245 browser()->tab_strip_model()->GetActiveWebContents(); |
249 ASSERT_EQ(base::UTF8ToUTF16("Data URL"), web_contents->GetTitle()); | 246 ASSERT_EQ(base::UTF8ToUTF16("Data URL"), web_contents->GetTitle()); |
250 | 247 |
251 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> | 248 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> |
252 IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 249 IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); |
253 } | 250 } |
254 | 251 |
255 // Tests that if redirect across origins occurs, the new process still gets the | 252 // Tests that if redirect across origins occurs, the new process still gets the |
256 // content settings before the resource headers. | 253 // content settings before the resource headers. |
257 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, RedirectCrossOrigin) { | 254 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, RedirectCrossOrigin) { |
258 ASSERT_TRUE(test_server()->Start()); | 255 ASSERT_TRUE(embedded_test_server()->Start()); |
259 | 256 |
260 net::HostPortPair host_port = test_server()->host_port_pair(); | 257 net::HostPortPair host_port = embedded_test_server()->host_port_pair(); |
261 DCHECK_EQ(host_port.host(), std::string("127.0.0.1")); | 258 DCHECK_EQ(host_port.host(), std::string("127.0.0.1")); |
262 | 259 |
263 std::string redirect(base::StringPrintf( | 260 std::string redirect(base::StringPrintf( |
264 "http://localhost:%d/files/redirect-cross-origin.html", | 261 "http://localhost:%d/redirect-cross-origin.html", host_port.port())); |
265 host_port.port())); | 262 GURL test_url = |
266 GURL test_url = test_server()->GetURL("server-redirect?" + redirect); | 263 embedded_test_server()->GetURL("/server-redirect?" + redirect); |
267 | 264 |
268 CookieSettingsFactory::GetForProfile(browser()->profile()) | 265 CookieSettingsFactory::GetForProfile(browser()->profile()) |
269 ->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); | 266 ->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK); |
270 | 267 |
271 ui_test_utils::NavigateToURL(browser(), test_url); | 268 ui_test_utils::NavigateToURL(browser(), test_url); |
272 | 269 |
273 content::WebContents* web_contents = | 270 content::WebContents* web_contents = |
274 browser()->tab_strip_model()->GetActiveWebContents(); | 271 browser()->tab_strip_model()->GetActiveWebContents(); |
275 | 272 |
276 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> | 273 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 546 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
550 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 547 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
551 switches::kAshBrowserTests)) | 548 switches::kAshBrowserTests)) |
552 return; | 549 return; |
553 #endif | 550 #endif |
554 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); | 551 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); |
555 } | 552 } |
556 #endif // !defined(DISABLE_NACL) | 553 #endif // !defined(DISABLE_NACL) |
557 | 554 |
558 #endif // defined(ENABLE_PLUGINS) | 555 #endif // defined(ENABLE_PLUGINS) |
OLD | NEW |