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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // all requests after that, keeping count of failures and successes. | 152 // all requests after that, keeping count of failures and successes. |
153 class FailFirstNRequestsInterceptor : public net::URLRequestInterceptor { | 153 class FailFirstNRequestsInterceptor : public net::URLRequestInterceptor { |
154 public: | 154 public: |
155 explicit FailFirstNRequestsInterceptor(int requests_to_fail) | 155 explicit FailFirstNRequestsInterceptor(int requests_to_fail) |
156 : requests_(0), failures_(0), requests_to_fail_(requests_to_fail) {} | 156 : requests_(0), failures_(0), requests_to_fail_(requests_to_fail) {} |
157 virtual ~FailFirstNRequestsInterceptor() {} | 157 virtual ~FailFirstNRequestsInterceptor() {} |
158 | 158 |
159 // net::URLRequestInterceptor implementation | 159 // net::URLRequestInterceptor implementation |
160 virtual net::URLRequestJob* MaybeInterceptRequest( | 160 virtual net::URLRequestJob* MaybeInterceptRequest( |
161 net::URLRequest* request, | 161 net::URLRequest* request, |
162 net::NetworkDelegate* network_delegate) const OVERRIDE { | 162 net::NetworkDelegate* network_delegate) const override { |
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
164 requests_++; | 164 requests_++; |
165 if (failures_ < requests_to_fail_) { | 165 if (failures_ < requests_to_fail_) { |
166 failures_++; | 166 failures_++; |
167 // Note: net::ERR_CONNECTION_RESET does not summon the Link Doctor; see | 167 // Note: net::ERR_CONNECTION_RESET does not summon the Link Doctor; see |
168 // NetErrorHelperCore::GetErrorPageURL. | 168 // NetErrorHelperCore::GetErrorPageURL. |
169 return new URLRequestFailedJob(request, | 169 return new URLRequestFailedJob(request, |
170 network_delegate, | 170 network_delegate, |
171 net::ERR_CONNECTION_RESET); | 171 net::ERR_CONNECTION_RESET); |
172 } else { | 172 } else { |
(...skipping 25 matching lines...) Expand all Loading... |
198 LinkDoctorInterceptor() : num_requests_(0), | 198 LinkDoctorInterceptor() : num_requests_(0), |
199 requests_to_wait_for_(-1), | 199 requests_to_wait_for_(-1), |
200 weak_factory_(this) { | 200 weak_factory_(this) { |
201 } | 201 } |
202 | 202 |
203 virtual ~LinkDoctorInterceptor() {} | 203 virtual ~LinkDoctorInterceptor() {} |
204 | 204 |
205 // net::URLRequestInterceptor implementation | 205 // net::URLRequestInterceptor implementation |
206 virtual net::URLRequestJob* MaybeInterceptRequest( | 206 virtual net::URLRequestJob* MaybeInterceptRequest( |
207 net::URLRequest* request, | 207 net::URLRequest* request, |
208 net::NetworkDelegate* network_delegate) const OVERRIDE { | 208 net::NetworkDelegate* network_delegate) const override { |
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
210 | 210 |
211 BrowserThread::PostTask( | 211 BrowserThread::PostTask( |
212 BrowserThread::UI, FROM_HERE, | 212 BrowserThread::UI, FROM_HERE, |
213 base::Bind(&LinkDoctorInterceptor::RequestCreated, | 213 base::Bind(&LinkDoctorInterceptor::RequestCreated, |
214 weak_factory_.GetWeakPtr())); | 214 weak_factory_.GetWeakPtr())); |
215 | 215 |
216 base::FilePath root_http; | 216 base::FilePath root_http; |
217 PathService::Get(chrome::DIR_TEST_DATA, &root_http); | 217 PathService::Get(chrome::DIR_TEST_DATA, &root_http); |
218 return new net::URLRequestMockHTTPJob( | 218 return new net::URLRequestMockHTTPJob( |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 enum HistoryNavigationDirection { | 290 enum HistoryNavigationDirection { |
291 HISTORY_NAVIGATE_BACK, | 291 HISTORY_NAVIGATE_BACK, |
292 HISTORY_NAVIGATE_FORWARD, | 292 HISTORY_NAVIGATE_FORWARD, |
293 }; | 293 }; |
294 | 294 |
295 ErrorPageTest() : link_doctor_interceptor_(NULL) {} | 295 ErrorPageTest() : link_doctor_interceptor_(NULL) {} |
296 virtual ~ErrorPageTest() {} | 296 virtual ~ErrorPageTest() {} |
297 | 297 |
298 // Navigates the active tab to a mock url created for the file at |file_path|. | 298 // Navigates the active tab to a mock url created for the file at |file_path|. |
299 // Needed for StaleCacheStatus and StaleCacheStatusFailedCorrections tests. | 299 // Needed for StaleCacheStatus and StaleCacheStatusFailedCorrections tests. |
300 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 300 virtual void SetUpCommandLine(CommandLine* command_line) override { |
301 command_line->AppendSwitch(switches::kEnableOfflineLoadStaleCache); | 301 command_line->AppendSwitch(switches::kEnableOfflineLoadStaleCache); |
302 } | 302 } |
303 | 303 |
304 // Navigates the active tab to a mock url created for the file at |file_path|. | 304 // Navigates the active tab to a mock url created for the file at |file_path|. |
305 void NavigateToFileURL(const base::FilePath::StringType& file_path) { | 305 void NavigateToFileURL(const base::FilePath::StringType& file_path) { |
306 ui_test_utils::NavigateToURL( | 306 ui_test_utils::NavigateToURL( |
307 browser(), | 307 browser(), |
308 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(file_path))); | 308 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(file_path))); |
309 } | 309 } |
310 | 310 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 return testing::AssertionFailure(); | 398 return testing::AssertionFailure(); |
399 return ("success" == result ? testing::AssertionSuccess() : | 399 return ("success" == result ? testing::AssertionSuccess() : |
400 (testing::AssertionFailure() << "Exception message is " << result)); | 400 (testing::AssertionFailure() << "Exception message is " << result)); |
401 } | 401 } |
402 | 402 |
403 LinkDoctorInterceptor* link_doctor_interceptor() { | 403 LinkDoctorInterceptor* link_doctor_interceptor() { |
404 return link_doctor_interceptor_; | 404 return link_doctor_interceptor_; |
405 } | 405 } |
406 | 406 |
407 protected: | 407 protected: |
408 virtual void SetUpOnMainThread() OVERRIDE { | 408 virtual void SetUpOnMainThread() override { |
409 link_doctor_interceptor_ = new LinkDoctorInterceptor(); | 409 link_doctor_interceptor_ = new LinkDoctorInterceptor(); |
410 scoped_ptr<net::URLRequestInterceptor> owned_interceptor( | 410 scoped_ptr<net::URLRequestInterceptor> owned_interceptor( |
411 link_doctor_interceptor_); | 411 link_doctor_interceptor_); |
412 // Ownership of the |interceptor_| is passed to an object the IO thread, but | 412 // Ownership of the |interceptor_| is passed to an object the IO thread, but |
413 // a pointer is kept in the test fixture. As soon as anything calls | 413 // a pointer is kept in the test fixture. As soon as anything calls |
414 // URLRequestFilter::ClearHandlers(), |interceptor_| can become invalid. | 414 // URLRequestFilter::ClearHandlers(), |interceptor_| can become invalid. |
415 BrowserThread::PostTask( | 415 BrowserThread::PostTask( |
416 BrowserThread::IO, FROM_HERE, | 416 BrowserThread::IO, FROM_HERE, |
417 base::Bind(&InstallMockInterceptors, | 417 base::Bind(&InstallMockInterceptors, |
418 google_util::GetGoogleSearchURL( | 418 google_util::GetGoogleSearchURL( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 public: | 464 public: |
465 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) | 465 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) |
466 : content::WebContentsObserver(contents) {} | 466 : content::WebContentsObserver(contents) {} |
467 virtual ~TestFailProvisionalLoadObserver() {} | 467 virtual ~TestFailProvisionalLoadObserver() {} |
468 | 468 |
469 // This method is invoked when the provisional load failed. | 469 // This method is invoked when the provisional load failed. |
470 virtual void DidFailProvisionalLoad( | 470 virtual void DidFailProvisionalLoad( |
471 content::RenderFrameHost* render_frame_host, | 471 content::RenderFrameHost* render_frame_host, |
472 const GURL& validated_url, | 472 const GURL& validated_url, |
473 int error_code, | 473 int error_code, |
474 const base::string16& error_description) OVERRIDE { | 474 const base::string16& error_description) override { |
475 fail_url_ = validated_url; | 475 fail_url_ = validated_url; |
476 } | 476 } |
477 | 477 |
478 const GURL& fail_url() const { return fail_url_; } | 478 const GURL& fail_url() const { return fail_url_; } |
479 | 479 |
480 private: | 480 private: |
481 GURL fail_url_; | 481 GURL fail_url_; |
482 | 482 |
483 DISALLOW_COPY_AND_ASSIGN(TestFailProvisionalLoadObserver); | 483 DISALLOW_COPY_AND_ASSIGN(TestFailProvisionalLoadObserver); |
484 }; | 484 }; |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 BrowsingDataHelper::UNPROTECTED_WEB); | 869 BrowsingDataHelper::UNPROTECTED_WEB); |
870 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 870 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
871 browser(), test_url, 1); | 871 browser(), test_url, 1); |
872 EXPECT_TRUE(ProbeStaleCopyValue(false)); | 872 EXPECT_TRUE(ProbeStaleCopyValue(false)); |
873 EXPECT_FALSE(IsDisplayingText(browser(), GetLoadStaleButtonLabel())); | 873 EXPECT_FALSE(IsDisplayingText(browser(), GetLoadStaleButtonLabel())); |
874 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); | 874 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); |
875 } | 875 } |
876 | 876 |
877 class ErrorPageAutoReloadTest : public InProcessBrowserTest { | 877 class ErrorPageAutoReloadTest : public InProcessBrowserTest { |
878 public: | 878 public: |
879 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 879 virtual void SetUpCommandLine(CommandLine* command_line) override { |
880 command_line->AppendSwitch(switches::kEnableOfflineAutoReload); | 880 command_line->AppendSwitch(switches::kEnableOfflineAutoReload); |
881 } | 881 } |
882 | 882 |
883 void InstallInterceptor(const GURL& url, int requests_to_fail) { | 883 void InstallInterceptor(const GURL& url, int requests_to_fail) { |
884 interceptor_ = new FailFirstNRequestsInterceptor(requests_to_fail); | 884 interceptor_ = new FailFirstNRequestsInterceptor(requests_to_fail); |
885 scoped_ptr<net::URLRequestInterceptor> owned_interceptor(interceptor_); | 885 scoped_ptr<net::URLRequestInterceptor> owned_interceptor(interceptor_); |
886 | 886 |
887 // Tests don't need to wait for this task to complete before using the | 887 // Tests don't need to wait for this task to complete before using the |
888 // filter; any requests that might be affected by it will end up in the IO | 888 // filter; any requests that might be affected by it will end up in the IO |
889 // thread's message loop after this posted task anyway. | 889 // thread's message loop after this posted task anyway. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 | 934 |
935 // Interceptor that fails all requests with net::ERR_ADDRESS_UNREACHABLE. | 935 // Interceptor that fails all requests with net::ERR_ADDRESS_UNREACHABLE. |
936 class AddressUnreachableInterceptor : public net::URLRequestInterceptor { | 936 class AddressUnreachableInterceptor : public net::URLRequestInterceptor { |
937 public: | 937 public: |
938 AddressUnreachableInterceptor() {} | 938 AddressUnreachableInterceptor() {} |
939 virtual ~AddressUnreachableInterceptor() {} | 939 virtual ~AddressUnreachableInterceptor() {} |
940 | 940 |
941 // net::URLRequestInterceptor: | 941 // net::URLRequestInterceptor: |
942 virtual net::URLRequestJob* MaybeInterceptRequest( | 942 virtual net::URLRequestJob* MaybeInterceptRequest( |
943 net::URLRequest* request, | 943 net::URLRequest* request, |
944 net::NetworkDelegate* network_delegate) const OVERRIDE { | 944 net::NetworkDelegate* network_delegate) const override { |
945 return new URLRequestFailedJob(request, | 945 return new URLRequestFailedJob(request, |
946 network_delegate, | 946 network_delegate, |
947 net::ERR_ADDRESS_UNREACHABLE); | 947 net::ERR_ADDRESS_UNREACHABLE); |
948 } | 948 } |
949 | 949 |
950 private: | 950 private: |
951 DISALLOW_COPY_AND_ASSIGN(AddressUnreachableInterceptor); | 951 DISALLOW_COPY_AND_ASSIGN(AddressUnreachableInterceptor); |
952 }; | 952 }; |
953 | 953 |
954 // A test fixture that returns ERR_ADDRESS_UNREACHABLE for all navigation | 954 // A test fixture that returns ERR_ADDRESS_UNREACHABLE for all navigation |
955 // correction requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use | 955 // correction requests. ERR_NAME_NOT_RESOLVED is more typical, but need to use |
956 // a different error for the correction service and the original page to | 956 // a different error for the correction service and the original page to |
957 // validate the right page is being displayed. | 957 // validate the right page is being displayed. |
958 class ErrorPageNavigationCorrectionsFailTest : public ErrorPageTest { | 958 class ErrorPageNavigationCorrectionsFailTest : public ErrorPageTest { |
959 public: | 959 public: |
960 // InProcessBrowserTest: | 960 // InProcessBrowserTest: |
961 virtual void SetUpOnMainThread() OVERRIDE { | 961 virtual void SetUpOnMainThread() override { |
962 BrowserThread::PostTask( | 962 BrowserThread::PostTask( |
963 BrowserThread::IO, FROM_HERE, | 963 BrowserThread::IO, FROM_HERE, |
964 base::Bind(&ErrorPageNavigationCorrectionsFailTest::AddFilters)); | 964 base::Bind(&ErrorPageNavigationCorrectionsFailTest::AddFilters)); |
965 } | 965 } |
966 | 966 |
967 virtual void TearDownOnMainThread() OVERRIDE { | 967 virtual void TearDownOnMainThread() override { |
968 BrowserThread::PostTask( | 968 BrowserThread::PostTask( |
969 BrowserThread::IO, FROM_HERE, | 969 BrowserThread::IO, FROM_HERE, |
970 base::Bind(&ErrorPageNavigationCorrectionsFailTest::RemoveFilters)); | 970 base::Bind(&ErrorPageNavigationCorrectionsFailTest::RemoveFilters)); |
971 } | 971 } |
972 | 972 |
973 private: | 973 private: |
974 // Adds a filter that causes all correction service requests to fail with | 974 // Adds a filter that causes all correction service requests to fail with |
975 // ERR_ADDRESS_UNREACHABLE. | 975 // ERR_ADDRESS_UNREACHABLE. |
976 // | 976 // |
977 // Also adds the net::URLRequestFailedJob filter. | 977 // Also adds the net::URLRequestFailedJob filter. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 } | 1051 } |
1052 | 1052 |
1053 // A test fixture that simulates failing requests for an IDN domain name. | 1053 // A test fixture that simulates failing requests for an IDN domain name. |
1054 class ErrorPageForIDNTest : public InProcessBrowserTest { | 1054 class ErrorPageForIDNTest : public InProcessBrowserTest { |
1055 public: | 1055 public: |
1056 // Target hostname in different forms. | 1056 // Target hostname in different forms. |
1057 static const char kHostname[]; | 1057 static const char kHostname[]; |
1058 static const char kHostnameJSUnicode[]; | 1058 static const char kHostnameJSUnicode[]; |
1059 | 1059 |
1060 // InProcessBrowserTest: | 1060 // InProcessBrowserTest: |
1061 virtual void SetUpOnMainThread() OVERRIDE { | 1061 virtual void SetUpOnMainThread() override { |
1062 // Clear AcceptLanguages to force punycode decoding. | 1062 // Clear AcceptLanguages to force punycode decoding. |
1063 browser()->profile()->GetPrefs()->SetString(prefs::kAcceptLanguages, | 1063 browser()->profile()->GetPrefs()->SetString(prefs::kAcceptLanguages, |
1064 std::string()); | 1064 std::string()); |
1065 BrowserThread::PostTask( | 1065 BrowserThread::PostTask( |
1066 BrowserThread::IO, FROM_HERE, | 1066 BrowserThread::IO, FROM_HERE, |
1067 base::Bind(&ErrorPageForIDNTest::AddFilters)); | 1067 base::Bind(&ErrorPageForIDNTest::AddFilters)); |
1068 } | 1068 } |
1069 | 1069 |
1070 virtual void TearDownOnMainThread() OVERRIDE { | 1070 virtual void TearDownOnMainThread() override { |
1071 BrowserThread::PostTask( | 1071 BrowserThread::PostTask( |
1072 BrowserThread::IO, FROM_HERE, | 1072 BrowserThread::IO, FROM_HERE, |
1073 base::Bind(&ErrorPageForIDNTest::RemoveFilters)); | 1073 base::Bind(&ErrorPageForIDNTest::RemoveFilters)); |
1074 } | 1074 } |
1075 | 1075 |
1076 private: | 1076 private: |
1077 static void AddFilters() { | 1077 static void AddFilters() { |
1078 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1078 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1079 URLRequestFailedJob::AddUrlHandlerForHostname(kHostname); | 1079 URLRequestFailedJob::AddUrlHandlerForHostname(kHostname); |
1080 } | 1080 } |
(...skipping 17 matching lines...) Expand all Loading... |
1098 browser(), | 1098 browser(), |
1099 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, | 1099 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, |
1100 kHostname), | 1100 kHostname), |
1101 1); | 1101 1); |
1102 | 1102 |
1103 ToggleHelpBox(browser()); | 1103 ToggleHelpBox(browser()); |
1104 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); | 1104 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); |
1105 } | 1105 } |
1106 | 1106 |
1107 } // namespace | 1107 } // namespace |
OLD | NEW |