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 19 matching lines...) Expand all Loading... |
30 #include "components/google/core/browser/google_util.h" | 30 #include "components/google/core/browser/google_util.h" |
31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
34 #include "content/public/browser/render_frame_host.h" | 34 #include "content/public/browser/render_frame_host.h" |
35 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
36 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
37 #include "content/public/browser/web_contents_observer.h" | 37 #include "content/public/browser/web_contents_observer.h" |
38 #include "content/public/test/browser_test_utils.h" | 38 #include "content/public/test/browser_test_utils.h" |
39 #include "content/public/test/test_navigation_observer.h" | 39 #include "content/public/test/test_navigation_observer.h" |
40 #include "content/test/net/url_request_failed_job.h" | |
41 #include "net/base/net_errors.h" | 40 #include "net/base/net_errors.h" |
42 #include "net/base/net_util.h" | 41 #include "net/base/net_util.h" |
43 #include "net/http/failing_http_transaction_factory.h" | 42 #include "net/http/failing_http_transaction_factory.h" |
44 #include "net/http/http_cache.h" | 43 #include "net/http/http_cache.h" |
45 #include "net/test/spawned_test_server/spawned_test_server.h" | 44 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 45 #include "net/test/url_request/url_request_failed_job.h" |
46 #include "net/test/url_request/url_request_mock_http_job.h" | 46 #include "net/test/url_request/url_request_mock_http_job.h" |
47 #include "net/url_request/url_request_context.h" | 47 #include "net/url_request/url_request_context.h" |
48 #include "net/url_request/url_request_context_getter.h" | 48 #include "net/url_request/url_request_context_getter.h" |
49 #include "net/url_request/url_request_filter.h" | 49 #include "net/url_request/url_request_filter.h" |
50 #include "net/url_request/url_request_interceptor.h" | 50 #include "net/url_request/url_request_interceptor.h" |
51 #include "net/url_request/url_request_job.h" | 51 #include "net/url_request/url_request_job.h" |
52 #include "net/url_request/url_request_test_job.h" | 52 #include "net/url_request/url_request_test_job.h" |
53 #include "net/url_request/url_request_test_util.h" | 53 #include "net/url_request/url_request_test_util.h" |
54 #include "ui/base/l10n/l10n_util.h" | 54 #include "ui/base/l10n/l10n_util.h" |
55 | 55 |
56 using content::BrowserThread; | 56 using content::BrowserThread; |
57 using content::NavigationController; | 57 using content::NavigationController; |
58 using content::URLRequestFailedJob; | 58 using net::URLRequestFailedJob; |
59 using net::URLRequestTestJob; | 59 using net::URLRequestTestJob; |
60 | 60 |
61 namespace { | 61 namespace { |
62 | 62 |
63 // Returns true if |text| is displayed on the page |browser| is currently | 63 // Returns true if |text| is displayed on the page |browser| is currently |
64 // displaying. Uses "innerText", so will miss hidden text, and whitespace | 64 // displaying. Uses "innerText", so will miss hidden text, and whitespace |
65 // space handling may be weird. | 65 // space handling may be weird. |
66 bool WARN_UNUSED_RESULT IsDisplayingText(Browser* browser, | 66 bool WARN_UNUSED_RESULT IsDisplayingText(Browser* browser, |
67 const std::string& text) { | 67 const std::string& text) { |
68 std::string command = base::StringPrintf( | 68 std::string command = base::StringPrintf( |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 content::URLRequestFailedJob filter. | 977 // Also adds the net::URLRequestFailedJob filter. |
978 static void AddFilters() { | 978 static void AddFilters() { |
979 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 979 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
980 content::URLRequestFailedJob::AddUrlHandler(); | 980 URLRequestFailedJob::AddUrlHandler(); |
981 | 981 |
982 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 982 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
983 google_util::LinkDoctorBaseURL(), | 983 google_util::LinkDoctorBaseURL(), |
984 scoped_ptr<net::URLRequestInterceptor>( | 984 scoped_ptr<net::URLRequestInterceptor>( |
985 new AddressUnreachableInterceptor())); | 985 new AddressUnreachableInterceptor())); |
986 } | 986 } |
987 | 987 |
988 static void RemoveFilters() { | 988 static void RemoveFilters() { |
989 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 989 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
990 net::URLRequestFilter::GetInstance()->ClearHandlers(); | 990 net::URLRequestFilter::GetInstance()->ClearHandlers(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 content::URLRequestFailedJob::AddUrlHandlerForHostname(kHostname); | 1079 URLRequestFailedJob::AddUrlHandlerForHostname(kHostname); |
1080 } | 1080 } |
1081 | 1081 |
1082 static void RemoveFilters() { | 1082 static void RemoveFilters() { |
1083 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1083 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1084 net::URLRequestFilter::GetInstance()->ClearHandlers(); | 1084 net::URLRequestFilter::GetInstance()->ClearHandlers(); |
1085 } | 1085 } |
1086 }; | 1086 }; |
1087 | 1087 |
1088 const char ErrorPageForIDNTest::kHostname[] = | 1088 const char ErrorPageForIDNTest::kHostname[] = |
1089 "xn--d1abbgf6aiiy.xn--p1ai"; | 1089 "xn--d1abbgf6aiiy.xn--p1ai"; |
1090 const char ErrorPageForIDNTest::kHostnameJSUnicode[] = | 1090 const char ErrorPageForIDNTest::kHostnameJSUnicode[] = |
1091 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442." | 1091 "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d\\u0442." |
1092 "\\u0440\\u0444"; | 1092 "\\u0440\\u0444"; |
1093 | 1093 |
1094 // Make sure error page shows correct unicode for IDN. | 1094 // Make sure error page shows correct unicode for IDN. |
1095 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { | 1095 IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { |
1096 // ERR_UNSAFE_PORT will not trigger navigation corrections. | 1096 // ERR_UNSAFE_PORT will not trigger navigation corrections. |
1097 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 1097 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
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 |