| 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/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.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 "content/browser/download/download_manager_impl.h" | 9 #include "content/browser/download/download_manager_impl.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 BrowserThread::IO, FROM_HERE, | 50 BrowserThread::IO, FROM_HERE, |
| 51 base::Bind(&net::URLRequestFailedJob::AddUrlHandler)); | 51 base::Bind(&net::URLRequestFailedJob::AddUrlHandler)); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void OnDownloadCreated(DownloadManager* manager, | 54 void OnDownloadCreated(DownloadManager* manager, |
| 55 DownloadItem* item) override { | 55 DownloadItem* item) override { |
| 56 if (!got_downloads_) | 56 if (!got_downloads_) |
| 57 got_downloads_ = !!manager->InProgressCount(); | 57 got_downloads_ = !!manager->InProgressCount(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 GURL GetMockURL(const std::string& file) { | |
| 61 return net::URLRequestMockHTTPJob::GetMockUrl( | |
| 62 base::FilePath().AppendASCII(file)); | |
| 63 } | |
| 64 | |
| 65 void CheckTitleTest(const GURL& url, | 60 void CheckTitleTest(const GURL& url, |
| 66 const std::string& expected_title) { | 61 const std::string& expected_title) { |
| 67 base::string16 expected_title16(ASCIIToUTF16(expected_title)); | 62 base::string16 expected_title16(ASCIIToUTF16(expected_title)); |
| 68 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); | 63 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); |
| 69 NavigateToURL(shell(), url); | 64 NavigateToURL(shell(), url); |
| 70 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); | 65 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); |
| 71 } | 66 } |
| 72 | 67 |
| 73 bool GetPopupTitle(const GURL& url, base::string16* title) { | 68 bool GetPopupTitle(const GURL& url, base::string16* title) { |
| 74 NavigateToURL(shell(), url); | 69 NavigateToURL(shell(), url); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 GURL url(embedded_test_server()->GetURL("/dynamic2.html")); | 111 GURL url(embedded_test_server()->GetURL("/dynamic2.html")); |
| 117 base::string16 title; | 112 base::string16 title; |
| 118 ASSERT_TRUE(GetPopupTitle(url, &title)); | 113 ASSERT_TRUE(GetPopupTitle(url, &title)); |
| 119 EXPECT_TRUE(base::StartsWith(title, ASCIIToUTF16("My Dynamic Title"), | 114 EXPECT_TRUE(base::StartsWith(title, ASCIIToUTF16("My Dynamic Title"), |
| 120 base::CompareCase::SENSITIVE)) | 115 base::CompareCase::SENSITIVE)) |
| 121 << "Actual title: " << title; | 116 << "Actual title: " << title; |
| 122 } | 117 } |
| 123 | 118 |
| 124 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 119 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 125 SniffHTMLWithNoContentType) { | 120 SniffHTMLWithNoContentType) { |
| 126 CheckTitleTest(GetMockURL("content-sniffer-test0.html"), | 121 CheckTitleTest( |
| 127 "Content Sniffer Test 0"); | 122 net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test0.html"), |
| 123 "Content Sniffer Test 0"); |
| 128 } | 124 } |
| 129 | 125 |
| 130 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 126 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 131 RespectNoSniffDirective) { | 127 RespectNoSniffDirective) { |
| 132 CheckTitleTest(GetMockURL("nosniff-test.html"), | 128 CheckTitleTest(net::URLRequestMockHTTPJob::GetMockUrl("nosniff-test.html"), |
| 133 "mock.http/nosniff-test.html"); | 129 "mock.http/nosniff-test.html"); |
| 134 } | 130 } |
| 135 | 131 |
| 136 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 132 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 137 DoNotSniffHTMLFromTextPlain) { | 133 DoNotSniffHTMLFromTextPlain) { |
| 138 CheckTitleTest(GetMockURL("content-sniffer-test1.html"), | 134 CheckTitleTest( |
| 139 "mock.http/content-sniffer-test1.html"); | 135 net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test1.html"), |
| 136 "mock.http/content-sniffer-test1.html"); |
| 140 } | 137 } |
| 141 | 138 |
| 142 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 139 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 143 DoNotSniffHTMLFromImageGIF) { | 140 DoNotSniffHTMLFromImageGIF) { |
| 144 CheckTitleTest(GetMockURL("content-sniffer-test2.html"), | 141 CheckTitleTest( |
| 145 "mock.http/content-sniffer-test2.html"); | 142 net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test2.html"), |
| 143 "mock.http/content-sniffer-test2.html"); |
| 146 } | 144 } |
| 147 | 145 |
| 148 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 146 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 149 SniffNoContentTypeNoData) { | 147 SniffNoContentTypeNoData) { |
| 150 // Make sure no downloads start. | 148 // Make sure no downloads start. |
| 151 BrowserContext::GetDownloadManager( | 149 BrowserContext::GetDownloadManager( |
| 152 shell()->web_contents()->GetBrowserContext())->AddObserver(this); | 150 shell()->web_contents()->GetBrowserContext())->AddObserver(this); |
| 153 CheckTitleTest(GetMockURL("content-sniffer-test3.html"), | 151 CheckTitleTest( |
| 154 "Content Sniffer Test 3"); | 152 net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test3.html"), |
| 153 "Content Sniffer Test 3"); |
| 155 EXPECT_EQ(1u, Shell::windows().size()); | 154 EXPECT_EQ(1u, Shell::windows().size()); |
| 156 ASSERT_FALSE(got_downloads()); | 155 ASSERT_FALSE(got_downloads()); |
| 157 } | 156 } |
| 158 | 157 |
| 159 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 158 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 160 ContentDispositionEmpty) { | 159 ContentDispositionEmpty) { |
| 161 CheckTitleTest(GetMockURL("content-disposition-empty.html"), "success"); | 160 CheckTitleTest( |
| 161 net::URLRequestMockHTTPJob::GetMockUrl("content-disposition-empty.html"), |
| 162 "success"); |
| 162 } | 163 } |
| 163 | 164 |
| 164 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 165 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 165 ContentDispositionInline) { | 166 ContentDispositionInline) { |
| 166 CheckTitleTest(GetMockURL("content-disposition-inline.html"), "success"); | 167 CheckTitleTest( |
| 168 net::URLRequestMockHTTPJob::GetMockUrl("content-disposition-inline.html"), |
| 169 "success"); |
| 167 } | 170 } |
| 168 | 171 |
| 169 // Test for bug #1091358. | 172 // Test for bug #1091358. |
| 170 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, SyncXMLHttpRequest) { | 173 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, SyncXMLHttpRequest) { |
| 171 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 174 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 172 NavigateToURL( | 175 NavigateToURL( |
| 173 shell(), embedded_test_server()->GetURL("/sync_xmlhttprequest.html")); | 176 shell(), embedded_test_server()->GetURL("/sync_xmlhttprequest.html")); |
| 174 | 177 |
| 175 // Let's check the XMLHttpRequest ran successfully. | 178 // Let's check the XMLHttpRequest ran successfully. |
| 176 bool success = false; | 179 bool success = false; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // Tests that onunload is run for cross-site requests. (Bug 1114994) | 233 // Tests that onunload is run for cross-site requests. (Bug 1114994) |
| 231 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 234 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 232 DISABLED_CrossSiteOnunloadCookie) { | 235 DISABLED_CrossSiteOnunloadCookie) { |
| 233 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 236 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 234 | 237 |
| 235 GURL url = embedded_test_server()->GetURL("/onunload_cookie.html"); | 238 GURL url = embedded_test_server()->GetURL("/onunload_cookie.html"); |
| 236 CheckTitleTest(url, "set cookie on unload"); | 239 CheckTitleTest(url, "set cookie on unload"); |
| 237 | 240 |
| 238 // Navigate to a new cross-site page, to dispatch unload event and set the | 241 // Navigate to a new cross-site page, to dispatch unload event and set the |
| 239 // cookie. | 242 // cookie. |
| 240 CheckTitleTest(GetMockURL("content-sniffer-test0.html"), | 243 CheckTitleTest( |
| 241 "Content Sniffer Test 0"); | 244 net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test0.html"), |
| 245 "Content Sniffer Test 0"); |
| 242 | 246 |
| 243 // Check that the cookie was set. | 247 // Check that the cookie was set. |
| 244 EXPECT_EQ("onunloadCookie=foo", GetCookies(url)); | 248 EXPECT_EQ("onunloadCookie=foo", GetCookies(url)); |
| 245 } | 249 } |
| 246 | 250 |
| 247 // If this flakes, use http://crbug.com/130404 | 251 // If this flakes, use http://crbug.com/130404 |
| 248 // Tests that onunload is run for cross-site requests to URLs that complete | 252 // Tests that onunload is run for cross-site requests to URLs that complete |
| 249 // without network loads (e.g., about:blank, data URLs). | 253 // without network loads (e.g., about:blank, data URLs). |
| 250 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 254 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 251 DISABLED_CrossSiteImmediateLoadOnunloadCookie) { | 255 DISABLED_CrossSiteImmediateLoadOnunloadCookie) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 // Cause the renderer to crash. | 325 // Cause the renderer to crash. |
| 322 RenderProcessHostWatcher crash_observer( | 326 RenderProcessHostWatcher crash_observer( |
| 323 shell()->web_contents(), | 327 shell()->web_contents(), |
| 324 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 328 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 325 NavigateToURL(shell(), GURL(kChromeUICrashURL)); | 329 NavigateToURL(shell(), GURL(kChromeUICrashURL)); |
| 326 // Wait for browser to notice the renderer crash. | 330 // Wait for browser to notice the renderer crash. |
| 327 crash_observer.Wait(); | 331 crash_observer.Wait(); |
| 328 | 332 |
| 329 // Navigate to a new cross-site page. The browser should not wait around for | 333 // Navigate to a new cross-site page. The browser should not wait around for |
| 330 // the old renderer's on{before}unload handlers to run. | 334 // the old renderer's on{before}unload handlers to run. |
| 331 CheckTitleTest(GetMockURL("content-sniffer-test0.html"), | 335 CheckTitleTest( |
| 332 "Content Sniffer Test 0"); | 336 net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test0.html"), |
| 337 "Content Sniffer Test 0"); |
| 333 } | 338 } |
| 334 | 339 |
| 335 // Tests that cross-site navigations work when the new page does not go through | 340 // Tests that cross-site navigations work when the new page does not go through |
| 336 // the BufferedEventHandler (e.g., non-http{s} URLs). (Bug 1225872) | 341 // the BufferedEventHandler (e.g., non-http{s} URLs). (Bug 1225872) |
| 337 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 342 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 338 CrossSiteNavigationNonBuffered) { | 343 CrossSiteNavigationNonBuffered) { |
| 339 // Start with an HTTP page. | 344 // Start with an HTTP page. |
| 340 CheckTitleTest(GetMockURL("content-sniffer-test0.html"), | 345 CheckTitleTest( |
| 341 "Content Sniffer Test 0"); | 346 net::URLRequestMockHTTPJob::GetMockUrl("content-sniffer-test0.html"), |
| 347 "Content Sniffer Test 0"); |
| 342 | 348 |
| 343 // Now load a file:// page, which does not use the BufferedEventHandler. | 349 // Now load a file:// page, which does not use the BufferedEventHandler. |
| 344 // Make sure that the page loads and displays a title, and doesn't get stuck. | 350 // Make sure that the page loads and displays a title, and doesn't get stuck. |
| 345 GURL url = GetTestUrl("", "title2.html"); | 351 GURL url = GetTestUrl("", "title2.html"); |
| 346 CheckTitleTest(url, "Title Of Awesomeness"); | 352 CheckTitleTest(url, "Title Of Awesomeness"); |
| 347 } | 353 } |
| 348 | 354 |
| 349 // Flaky everywhere. http://crbug.com/130404 | 355 // Flaky everywhere. http://crbug.com/130404 |
| 350 // Tests that a cross-site navigation to an error page (resulting in the link | 356 // Tests that a cross-site navigation to an error page (resulting in the link |
| 351 // doctor page) still runs the onunload handler and can support navigations | 357 // doctor page) still runs the onunload handler and can support navigations |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 427 |
| 422 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 428 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 423 CrossOriginRedirectBlocked) { | 429 CrossOriginRedirectBlocked) { |
| 424 // We expect the following URL requests from this test: | 430 // We expect the following URL requests from this test: |
| 425 // 1- http://mock.http/cross-origin-redirect-blocked.html | 431 // 1- http://mock.http/cross-origin-redirect-blocked.html |
| 426 // 2- http://mock.http/redirect-to-title2.html | 432 // 2- http://mock.http/redirect-to-title2.html |
| 427 // 3- http://mock.http/title2.html | 433 // 3- http://mock.http/title2.html |
| 428 // | 434 // |
| 429 // If the redirect in #2 were not blocked, we'd also see a request | 435 // If the redirect in #2 were not blocked, we'd also see a request |
| 430 // for http://mock.http:4000/title2.html, and the title would be different. | 436 // for http://mock.http:4000/title2.html, and the title would be different. |
| 431 CheckTitleTest(GetMockURL("cross-origin-redirect-blocked.html"), | 437 CheckTitleTest(net::URLRequestMockHTTPJob::GetMockUrl( |
| 438 "cross-origin-redirect-blocked.html"), |
| 432 "Title Of More Awesomeness"); | 439 "Title Of More Awesomeness"); |
| 433 } | 440 } |
| 434 | 441 |
| 435 // Tests that ResourceRequestInfoImpl is updated correctly on failed | 442 // Tests that ResourceRequestInfoImpl is updated correctly on failed |
| 436 // requests, to prevent calling Read on a request that has already failed. | 443 // requests, to prevent calling Read on a request that has already failed. |
| 437 // See bug 40250. | 444 // See bug 40250. |
| 438 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 445 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 439 CrossSiteFailedRequest) { | 446 CrossSiteFailedRequest) { |
| 440 // Visit another URL first to trigger a cross-site navigation. | 447 // Visit another URL first to trigger a cross-site navigation. |
| 441 NavigateToURL(shell(), GetTestUrl("", "simple_page.html")); | 448 NavigateToURL(shell(), GetTestUrl("", "simple_page.html")); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 NavigateToURLBlockUntilNavigationsComplete( | 527 NavigateToURLBlockUntilNavigationsComplete( |
| 521 shell(), | 528 shell(), |
| 522 embedded_test_server()->GetURL("/client_redirect.html"), | 529 embedded_test_server()->GetURL("/client_redirect.html"), |
| 523 2); | 530 2); |
| 524 | 531 |
| 525 EXPECT_TRUE( | 532 EXPECT_TRUE( |
| 526 delegate.page_transition() & ui::PAGE_TRANSITION_CLIENT_REDIRECT); | 533 delegate.page_transition() & ui::PAGE_TRANSITION_CLIENT_REDIRECT); |
| 527 } | 534 } |
| 528 | 535 |
| 529 } // namespace content | 536 } // namespace content |
| OLD | NEW |