Chromium Code Reviews| 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 <memory> | 5 #include <memory> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 #include "content/public/browser/render_view_host.h" | 51 #include "content/public/browser/render_view_host.h" |
| 52 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
| 53 #include "content/public/browser/web_contents_observer.h" | 53 #include "content/public/browser/web_contents_observer.h" |
| 54 #include "content/public/test/browser_test_utils.h" | 54 #include "content/public/test/browser_test_utils.h" |
| 55 #include "content/public/test/test_navigation_observer.h" | 55 #include "content/public/test/test_navigation_observer.h" |
| 56 #include "net/base/filename_util.h" | 56 #include "net/base/filename_util.h" |
| 57 #include "net/base/net_errors.h" | 57 #include "net/base/net_errors.h" |
| 58 #include "net/http/failing_http_transaction_factory.h" | 58 #include "net/http/failing_http_transaction_factory.h" |
| 59 #include "net/http/http_cache.h" | 59 #include "net/http/http_cache.h" |
| 60 #include "net/test/embedded_test_server/embedded_test_server.h" | 60 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 61 #include "net/test/embedded_test_server/http_request.h" | |
| 62 #include "net/test/embedded_test_server/http_response.h" | |
| 61 #include "net/test/url_request/url_request_failed_job.h" | 63 #include "net/test/url_request/url_request_failed_job.h" |
| 62 #include "net/test/url_request/url_request_mock_http_job.h" | 64 #include "net/test/url_request/url_request_mock_http_job.h" |
| 63 #include "net/url_request/url_request_context.h" | 65 #include "net/url_request/url_request_context.h" |
| 64 #include "net/url_request/url_request_context_getter.h" | 66 #include "net/url_request/url_request_context_getter.h" |
| 65 #include "net/url_request/url_request_filter.h" | 67 #include "net/url_request/url_request_filter.h" |
| 66 #include "net/url_request/url_request_interceptor.h" | 68 #include "net/url_request/url_request_interceptor.h" |
| 67 #include "net/url_request/url_request_job.h" | 69 #include "net/url_request/url_request_job.h" |
| 68 #include "net/url_request/url_request_test_job.h" | 70 #include "net/url_request/url_request_test_job.h" |
| 69 #include "net/url_request/url_request_test_util.h" | 71 #include "net/url_request/url_request_test_util.h" |
| 70 #include "ui/base/l10n/l10n_util.h" | 72 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 | 318 |
| 317 // Add a mock for the search engine the error page will use. | 319 // Add a mock for the search engine the error page will use. |
| 318 base::FilePath root_http; | 320 base::FilePath root_http; |
| 319 PathService::Get(chrome::DIR_TEST_DATA, &root_http); | 321 PathService::Get(chrome::DIR_TEST_DATA, &root_http); |
| 320 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | 322 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( |
| 321 search_url.scheme(), search_url.host(), | 323 search_url.scheme(), search_url.host(), |
| 322 net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( | 324 net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( |
| 323 root_http.AppendASCII("title3.html"))); | 325 root_http.AppendASCII("title3.html"))); |
| 324 } | 326 } |
| 325 | 327 |
| 328 // When it sees a request for |path|, returns a 500 response with a body that | |
| 329 // will be sniffed as binary/octet-stream. | |
| 330 std::unique_ptr<net::test_server::HttpResponse> Return500WithBinaryBody( | |
| 331 const std::string& path, | |
| 332 const net::test_server::HttpRequest& request) { | |
| 333 if (path != request.relative_url) | |
| 334 return nullptr; | |
| 335 return std::unique_ptr<net::test_server::HttpResponse>( | |
| 336 new net::test_server::RawHttpResponse("HTTP/1.1 500 Server Sad :(", | |
|
Charlie Harrison
2017/07/06 18:09:37
Can you use base::MakeUnique here to avoid raw new
mmenke
2017/07/06 18:17:19
No - MakeUnique doesn't handle upcasting (I'm crea
Charlie Harrison
2017/07/06 18:23:09
I was thinking of just returning the base::MakeUni
| |
| 337 "\x01")); | |
| 338 } | |
| 339 | |
| 326 class ErrorPageTest : public InProcessBrowserTest { | 340 class ErrorPageTest : public InProcessBrowserTest { |
| 327 public: | 341 public: |
| 328 enum HistoryNavigationDirection { | 342 enum HistoryNavigationDirection { |
| 329 HISTORY_NAVIGATE_BACK, | 343 HISTORY_NAVIGATE_BACK, |
| 330 HISTORY_NAVIGATE_FORWARD, | 344 HISTORY_NAVIGATE_FORWARD, |
| 331 }; | 345 }; |
| 332 | 346 |
| 333 ErrorPageTest() : link_doctor_interceptor_(NULL) {} | 347 ErrorPageTest() : link_doctor_interceptor_(NULL) {} |
| 334 ~ErrorPageTest() override {} | 348 ~ErrorPageTest() override {} |
| 335 | 349 |
| (...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1550 IN_PROC_BROWSER_TEST_F(ErrorPageWithHttp09OnNonDefaultPortsTest, | 1564 IN_PROC_BROWSER_TEST_F(ErrorPageWithHttp09OnNonDefaultPortsTest, |
| 1551 Http09WeirdPortEnabled) { | 1565 Http09WeirdPortEnabled) { |
| 1552 const char kHttp09Response[] = "JumboShrimp"; | 1566 const char kHttp09Response[] = "JumboShrimp"; |
| 1553 ASSERT_TRUE(embedded_test_server()->Start()); | 1567 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1554 ui_test_utils::NavigateToURL( | 1568 ui_test_utils::NavigateToURL( |
| 1555 browser(), embedded_test_server()->GetURL(std::string("/echo-raw?") + | 1569 browser(), embedded_test_server()->GetURL(std::string("/echo-raw?") + |
| 1556 kHttp09Response)); | 1570 kHttp09Response)); |
| 1557 EXPECT_TRUE(IsDisplayingText(browser(), kHttp09Response)); | 1571 EXPECT_TRUE(IsDisplayingText(browser(), kHttp09Response)); |
| 1558 } | 1572 } |
| 1559 | 1573 |
| 1574 // Checks that when an HTTP error page is sniffed as a download, an error page | |
| 1575 // is displayed. This tests the particular case in which the response body | |
| 1576 // is small enough that the entire response must be read before its MIME type | |
| 1577 // can be determined. | |
| 1578 IN_PROC_BROWSER_TEST_F(ErrorPageTest, SniffSmallHttpErrorResponseAsDownload) { | |
| 1579 const char kErrorPath[] = "/foo"; | |
| 1580 embedded_test_server()->RegisterRequestHandler( | |
| 1581 base::Bind(&Return500WithBinaryBody, kErrorPath)); | |
| 1582 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1583 | |
| 1584 ui_test_utils::NavigateToURL(browser(), | |
| 1585 embedded_test_server()->GetURL(kErrorPath)); | |
| 1586 | |
| 1587 ExpectDisplayingLocalErrorPage(browser(), net::ERR_INVALID_RESPONSE); | |
| 1588 } | |
| 1589 | |
| 1560 } // namespace | 1590 } // namespace |
| OLD | NEW |