| 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/string_util.h" | 5 #include "base/string_util.h" |
| 6 #include "base/synchronization/waitable_event.h" | 6 #include "base/synchronization/waitable_event.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| 11 #include "content/browser/download/download_manager_impl.h" | 11 #include "content/browser/download/download_manager_impl.h" |
| 12 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
| 13 #include "content/common/test_url_constants.h" | 13 #include "content/common/test_url_constants.h" |
| 14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
| 20 #include "content/test/net/url_request_failed_job.h" | 20 #include "content/test/net/url_request_failed_job.h" |
| 21 #include "content/test/net/url_request_mock_http_job.h" | 21 #include "content/test/net/url_request_mock_http_job.h" |
| 22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 23 #include "net/cookies/cookie_store.h" | 23 #include "net/cookies/cookie_store.h" |
| 24 #include "net/test/test_server.h" | 24 #include "net/test/test_server.h" |
| 25 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
| 26 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
| 27 | 27 |
| 28 using content::BrowserContext; |
| 28 using content::BrowserThread; | 29 using content::BrowserThread; |
| 29 using content::DownloadManager; | 30 using content::DownloadManager; |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 void GetCookiesCallback(std::string* cookies_out, | 34 void GetCookiesCallback(std::string* cookies_out, |
| 34 base::WaitableEvent* event, | 35 base::WaitableEvent* event, |
| 35 const std::string& cookies) { | 36 const std::string& cookies) { |
| 36 *cookies_out = cookies; | 37 *cookies_out = cookies; |
| 37 event->Signal(); | 38 event->Signal(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 184 |
| 184 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 185 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 185 DoNotSniffHTMLFromImageGIF) { | 186 DoNotSniffHTMLFromImageGIF) { |
| 186 CheckTitleTest(GetMockURL("content-sniffer-test2.html"), | 187 CheckTitleTest(GetMockURL("content-sniffer-test2.html"), |
| 187 "mock.http/content-sniffer-test2.html", 1); | 188 "mock.http/content-sniffer-test2.html", 1); |
| 188 } | 189 } |
| 189 | 190 |
| 190 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 191 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 191 SniffNoContentTypeNoData) { | 192 SniffNoContentTypeNoData) { |
| 192 // Make sure no downloads start. | 193 // Make sure no downloads start. |
| 193 GetBrowserContext()->GetDownloadManager()->AddObserver(this); | 194 BrowserContext::GetDownloadManager(GetBrowserContext())->AddObserver(this); |
| 194 CheckTitleTest(GetMockURL("content-sniffer-test3.html"), | 195 CheckTitleTest(GetMockURL("content-sniffer-test3.html"), |
| 195 "Content Sniffer Test 3", 1); | 196 "Content Sniffer Test 3", 1); |
| 196 EXPECT_EQ(1, browser()->tab_count()); | 197 EXPECT_EQ(1, browser()->tab_count()); |
| 197 ASSERT_FALSE(got_downloads()); | 198 ASSERT_FALSE(got_downloads()); |
| 198 } | 199 } |
| 199 | 200 |
| 200 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 201 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 201 ContentDispositionEmpty) { | 202 ContentDispositionEmpty) { |
| 202 CheckTitleTest(GetMockURL("content-disposition-empty.html"), "success", 1); | 203 CheckTitleTest(GetMockURL("content-disposition-empty.html"), "success", 1); |
| 203 } | 204 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 EXPECT_TRUE(success); | 242 EXPECT_TRUE(success); |
| 242 } | 243 } |
| 243 | 244 |
| 244 // Test for bug #1159553 -- A synchronous xhr (whose content-type is | 245 // Test for bug #1159553 -- A synchronous xhr (whose content-type is |
| 245 // downloadable) would trigger download and hang the renderer process, | 246 // downloadable) would trigger download and hang the renderer process, |
| 246 // if executed while navigating to a new page. | 247 // if executed while navigating to a new page. |
| 247 // If this flakes, use http://crbug.com/56264. | 248 // If this flakes, use http://crbug.com/56264. |
| 248 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 249 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 249 SyncXMLHttpRequest_DuringUnload) { | 250 SyncXMLHttpRequest_DuringUnload) { |
| 250 ASSERT_TRUE(test_server()->Start()); | 251 ASSERT_TRUE(test_server()->Start()); |
| 251 GetBrowserContext()->GetDownloadManager()->AddObserver(this); | 252 BrowserContext::GetDownloadManager(GetBrowserContext())->AddObserver(this); |
| 252 | 253 |
| 253 CheckTitleTest( | 254 CheckTitleTest( |
| 254 test_server()->GetURL("files/sync_xmlhttprequest_during_unload.html"), | 255 test_server()->GetURL("files/sync_xmlhttprequest_during_unload.html"), |
| 255 "sync xhr on unload", 1); | 256 "sync xhr on unload", 1); |
| 256 | 257 |
| 257 // Navigate to a new page, to dispatch unload event and trigger xhr. | 258 // Navigate to a new page, to dispatch unload event and trigger xhr. |
| 258 // (the bug would make this step hang the renderer). | 259 // (the bug would make this step hang the renderer). |
| 259 CheckTitleTest( | 260 CheckTitleTest( |
| 260 test_server()->GetURL("files/title2.html"), | 261 test_server()->GetURL("files/title2.html"), |
| 261 "Title Of Awesomeness", 1); | 262 "Title Of Awesomeness", 1); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 434 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 434 CrossSiteFailedRequest) { | 435 CrossSiteFailedRequest) { |
| 435 // Visit another URL first to trigger a cross-site navigation. | 436 // Visit another URL first to trigger a cross-site navigation. |
| 436 GURL url(chrome::kTestNewTabURL); | 437 GURL url(chrome::kTestNewTabURL); |
| 437 ui_test_utils::NavigateToURL(browser(), url); | 438 ui_test_utils::NavigateToURL(browser(), url); |
| 438 | 439 |
| 439 // Visit a URL that fails without calling ResourceDispatcherHost::Read. | 440 // Visit a URL that fails without calling ResourceDispatcherHost::Read. |
| 440 GURL broken_url("chrome://theme"); | 441 GURL broken_url("chrome://theme"); |
| 441 CheckTitleTest(broken_url, "chrome://theme/ is not available", 1); | 442 CheckTitleTest(broken_url, "chrome://theme/ is not available", 1); |
| 442 } | 443 } |
| OLD | NEW |