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 <utility> |
| 6 |
5 #include "base/bind.h" | 7 #include "base/bind.h" |
6 #include "base/command_line.h" | 8 #include "base/command_line.h" |
7 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
8 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
13 #include "base/path_service.h" | 15 #include "base/path_service.h" |
14 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } | 174 } |
173 | 175 |
174 std::string GetShowSavedButtonLabel() { | 176 std::string GetShowSavedButtonLabel() { |
175 return l10n_util::GetStringUTF8(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY); | 177 return l10n_util::GetStringUTF8(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY); |
176 } | 178 } |
177 | 179 |
178 void AddInterceptorForURL( | 180 void AddInterceptorForURL( |
179 const GURL& url, | 181 const GURL& url, |
180 scoped_ptr<net::URLRequestInterceptor> handler) { | 182 scoped_ptr<net::URLRequestInterceptor> handler) { |
181 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 183 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
182 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 184 net::URLRequestFilter::GetInstance()->AddUrlInterceptor(url, |
183 url, handler.Pass()); | 185 std::move(handler)); |
184 } | 186 } |
185 | 187 |
186 // An interceptor that fails a configurable number of requests, then succeeds | 188 // An interceptor that fails a configurable number of requests, then succeeds |
187 // all requests after that, keeping count of failures and successes. | 189 // all requests after that, keeping count of failures and successes. |
188 class FailFirstNRequestsInterceptor : public net::URLRequestInterceptor { | 190 class FailFirstNRequestsInterceptor : public net::URLRequestInterceptor { |
189 public: | 191 public: |
190 explicit FailFirstNRequestsInterceptor(int requests_to_fail) | 192 explicit FailFirstNRequestsInterceptor(int requests_to_fail) |
191 : requests_(0), failures_(0), requests_to_fail_(requests_to_fail) {} | 193 : requests_(0), failures_(0), requests_to_fail_(requests_to_fail) {} |
192 ~FailFirstNRequestsInterceptor() override {} | 194 ~FailFirstNRequestsInterceptor() override {} |
193 | 195 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 304 |
303 DISALLOW_COPY_AND_ASSIGN(LinkDoctorInterceptor); | 305 DISALLOW_COPY_AND_ASSIGN(LinkDoctorInterceptor); |
304 }; | 306 }; |
305 | 307 |
306 void InstallMockInterceptors( | 308 void InstallMockInterceptors( |
307 const GURL& search_url, | 309 const GURL& search_url, |
308 scoped_ptr<net::URLRequestInterceptor> link_doctor_interceptor) { | 310 scoped_ptr<net::URLRequestInterceptor> link_doctor_interceptor) { |
309 chrome_browser_net::SetUrlRequestMocksEnabled(true); | 311 chrome_browser_net::SetUrlRequestMocksEnabled(true); |
310 | 312 |
311 AddInterceptorForURL(google_util::LinkDoctorBaseURL(), | 313 AddInterceptorForURL(google_util::LinkDoctorBaseURL(), |
312 link_doctor_interceptor.Pass()); | 314 std::move(link_doctor_interceptor)); |
313 | 315 |
314 // Add a mock for the search engine the error page will use. | 316 // Add a mock for the search engine the error page will use. |
315 base::FilePath root_http; | 317 base::FilePath root_http; |
316 PathService::Get(chrome::DIR_TEST_DATA, &root_http); | 318 PathService::Get(chrome::DIR_TEST_DATA, &root_http); |
317 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | 319 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( |
318 search_url.scheme(), search_url.host(), | 320 search_url.scheme(), search_url.host(), |
319 net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( | 321 net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( |
320 root_http.AppendASCII("title3.html"), | 322 root_http.AppendASCII("title3.html"), |
321 BrowserThread::GetBlockingPool())); | 323 BrowserThread::GetBlockingPool())); |
322 } | 324 } |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 void InterceptNetworkTransactions(net::URLRequestContextGetter* getter, | 536 void InterceptNetworkTransactions(net::URLRequestContextGetter* getter, |
535 net::Error error) { | 537 net::Error error) { |
536 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 538 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
537 net::HttpCache* cache( | 539 net::HttpCache* cache( |
538 getter->GetURLRequestContext()->http_transaction_factory()->GetCache()); | 540 getter->GetURLRequestContext()->http_transaction_factory()->GetCache()); |
539 DCHECK(cache); | 541 DCHECK(cache); |
540 scoped_ptr<net::HttpTransactionFactory> factory( | 542 scoped_ptr<net::HttpTransactionFactory> factory( |
541 new net::FailingHttpTransactionFactory(cache->GetSession(), error)); | 543 new net::FailingHttpTransactionFactory(cache->GetSession(), error)); |
542 // Throw away old version; since this is a a browser test, we don't | 544 // Throw away old version; since this is a a browser test, we don't |
543 // need to restore the old state. | 545 // need to restore the old state. |
544 cache->SetHttpNetworkTransactionFactoryForTesting(factory.Pass()); | 546 cache->SetHttpNetworkTransactionFactoryForTesting(std::move(factory)); |
545 } | 547 } |
546 | 548 |
547 // Test an error with a file URL, and make sure it doesn't have a | 549 // Test an error with a file URL, and make sure it doesn't have a |
548 // button to launch a network diagnostics tool. | 550 // button to launch a network diagnostics tool. |
549 IN_PROC_BROWSER_TEST_F(ErrorPageTest, FileNotFound) { | 551 IN_PROC_BROWSER_TEST_F(ErrorPageTest, FileNotFound) { |
550 // Create an empty temp directory, to be sure there's no file in it. | 552 // Create an empty temp directory, to be sure there's no file in it. |
551 base::ScopedTempDir temp_dir; | 553 base::ScopedTempDir temp_dir; |
552 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 554 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
553 GURL non_existent_file_url = | 555 GURL non_existent_file_url = |
554 net::FilePathToFileURL(temp_dir.path().AppendASCII("marmoset")); | 556 net::FilePathToFileURL(temp_dir.path().AppendASCII("marmoset")); |
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1473 ui_test_utils::NavigateToURL( | 1475 ui_test_utils::NavigateToURL( |
1474 browser(), | 1476 browser(), |
1475 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, | 1477 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, |
1476 kHostname)); | 1478 kHostname)); |
1477 | 1479 |
1478 ToggleHelpBox(browser()); | 1480 ToggleHelpBox(browser()); |
1479 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); | 1481 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); |
1480 } | 1482 } |
1481 | 1483 |
1482 } // namespace | 1484 } // namespace |
OLD | NEW |