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/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "chrome/browser/google/google_util.h" | 7 #include "chrome/browser/google/google_util.h" |
8 #include "chrome/browser/net/url_request_mock_util.h" | 8 #include "chrome/browser/net/url_request_mock_util.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/public/browser/notification_service.h" |
| 15 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/browser/web_contents_observer.h" |
15 #include "content/public/test/browser_test_utils.h" | 18 #include "content/public/test/browser_test_utils.h" |
16 #include "content/public/test/test_navigation_observer.h" | 19 #include "content/public/test/test_navigation_observer.h" |
17 #include "content/test/net/url_request_failed_job.h" | 20 #include "content/test/net/url_request_failed_job.h" |
18 #include "content/test/net/url_request_mock_http_job.h" | 21 #include "content/test/net/url_request_mock_http_job.h" |
19 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
20 #include "net/url_request/url_request_filter.h" | 23 #include "net/url_request/url_request_filter.h" |
21 #include "net/url_request/url_request_job_factory.h" | 24 #include "net/url_request/url_request_job_factory.h" |
22 | 25 |
23 using content::BrowserThread; | 26 using content::BrowserThread; |
24 using content::NavigationController; | 27 using content::NavigationController; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 110 } |
108 test_navigation_observer.WaitForObservation( | 111 test_navigation_observer.WaitForObservation( |
109 base::Bind(&content::RunMessageLoop), | 112 base::Bind(&content::RunMessageLoop), |
110 base::Bind(&base::MessageLoop::Quit, | 113 base::Bind(&base::MessageLoop::Quit, |
111 base::Unretained(base::MessageLoopForUI::current()))); | 114 base::Unretained(base::MessageLoopForUI::current()))); |
112 | 115 |
113 EXPECT_EQ(title_watcher.WaitAndGetTitle(), ASCIIToUTF16(expected_title)); | 116 EXPECT_EQ(title_watcher.WaitAndGetTitle(), ASCIIToUTF16(expected_title)); |
114 } | 117 } |
115 }; | 118 }; |
116 | 119 |
| 120 |
| 121 class TestFailProvisionalLoadObserver : public content::WebContentsObserver { |
| 122 public: |
| 123 explicit TestFailProvisionalLoadObserver(content::WebContents* contents) |
| 124 : content::WebContentsObserver(contents) {} |
| 125 virtual ~TestFailProvisionalLoadObserver() {} |
| 126 |
| 127 // This method is invoked when the provisional load failed. |
| 128 virtual void DidFailProvisionalLoad( |
| 129 int64 frame_id, |
| 130 bool is_main_frame, |
| 131 const GURL& validated_url, |
| 132 int error_code, |
| 133 const string16& error_description, |
| 134 content::RenderViewHost* render_view_host) OVERRIDE { |
| 135 fail_url_ = validated_url; |
| 136 } |
| 137 |
| 138 const GURL& fail_url() const { return fail_url_; } |
| 139 |
| 140 private: |
| 141 GURL fail_url_; |
| 142 |
| 143 DISALLOW_COPY_AND_ASSIGN(TestFailProvisionalLoadObserver); |
| 144 }; |
| 145 |
117 // See crbug.com/109669 | 146 // See crbug.com/109669 |
118 #if defined(USE_AURA) || defined(OS_WIN) | 147 #if defined(USE_AURA) || defined(OS_WIN) |
119 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic | 148 #define MAYBE_DNSError_Basic DISABLED_DNSError_Basic |
120 #else | 149 #else |
121 #define MAYBE_DNSError_Basic DNSError_Basic | 150 #define MAYBE_DNSError_Basic DNSError_Basic |
122 #endif | 151 #endif |
123 // Test that a DNS error occuring in the main frame redirects to an error page. | 152 // Test that a DNS error occuring in the main frame redirects to an error page. |
124 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) { | 153 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_DNSError_Basic) { |
125 // The first navigation should fail, and the second one should be the error | 154 // The first navigation should fail, and the second one should be the error |
126 // page. | 155 // page. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); | 230 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); |
202 } | 231 } |
203 | 232 |
204 // Test that a DNS error occuring in an iframe. | 233 // Test that a DNS error occuring in an iframe. |
205 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { | 234 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { |
206 NavigateToURLAndWaitForTitle( | 235 NavigateToURLAndWaitForTitle( |
207 content::URLRequestMockHTTPJob::GetMockUrl( | 236 content::URLRequestMockHTTPJob::GetMockUrl( |
208 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), | 237 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), |
209 "Blah", | 238 "Blah", |
210 1); | 239 1); |
| 240 // We expect to have two history entries, since we started off with navigation |
| 241 // to "about:blank" and then navigated to "iframe_dns_error.html". |
| 242 EXPECT_EQ(2, |
| 243 browser()->tab_strip_model()->GetActiveWebContents()-> |
| 244 GetController().GetEntryCount()); |
211 } | 245 } |
212 | 246 |
213 // This test fails regularly on win_rel trybots. See crbug.com/121540 | 247 // This test fails regularly on win_rel trybots. See crbug.com/121540 |
214 #if defined(OS_WIN) | 248 #if defined(OS_WIN) |
215 #define MAYBE_IFrameDNSError_GoBack DISABLED_IFrameDNSError_GoBack | 249 #define MAYBE_IFrameDNSError_GoBack DISABLED_IFrameDNSError_GoBack |
216 #else | 250 #else |
217 #define MAYBE_IFrameDNSError_GoBack IFrameDNSError_GoBack | 251 #define MAYBE_IFrameDNSError_GoBack IFrameDNSError_GoBack |
218 #endif | 252 #endif |
219 // Test that a DNS error occuring in an iframe does not result in an | 253 // Test that a DNS error occuring in an iframe does not result in an |
220 // additional session history entry. | 254 // additional session history entry. |
(...skipping 11 matching lines...) Expand all Loading... |
232 #endif | 266 #endif |
233 // Test that a DNS error occuring in an iframe does not result in an | 267 // Test that a DNS error occuring in an iframe does not result in an |
234 // additional session history entry. | 268 // additional session history entry. |
235 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBackAndForward) { | 269 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBackAndForward) { |
236 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 270 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
237 NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html")); | 271 NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html")); |
238 GoBackAndWaitForTitle("Title Of Awesomeness", 1); | 272 GoBackAndWaitForTitle("Title Of Awesomeness", 1); |
239 GoForwardAndWaitForTitle("Blah", 1); | 273 GoForwardAndWaitForTitle("Blah", 1); |
240 } | 274 } |
241 | 275 |
| 276 // Test that a DNS error occuring in an iframe, once the main document is |
| 277 // completed loading, does not result in an additional session history entry. |
| 278 // To ensure that the main document has completed loading, JavaScript is used to |
| 279 // inject an iframe after loading is done. |
| 280 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_JavaScript) { |
| 281 content::WebContents* wc = |
| 282 browser()->tab_strip_model()->GetActiveWebContents(); |
| 283 GURL fail_url = |
| 284 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); |
| 285 std::string script = "var frame = document.createElement('iframe');" |
| 286 "frame.src = '" + fail_url.spec() + "';" |
| 287 "document.body.appendChild(frame);"; |
| 288 |
| 289 // Load a regular web page, in which we will inject an iframe. |
| 290 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
| 291 |
| 292 // We expect to have two history entries, since we started off with navigation |
| 293 // to "about:blank" and then navigated to "title2.html". |
| 294 EXPECT_EQ(2, wc->GetController().GetEntryCount()); |
| 295 |
| 296 TestFailProvisionalLoadObserver fail_observer(wc); |
| 297 content::WindowedNotificationObserver load_observer( |
| 298 content::NOTIFICATION_LOAD_STOP, |
| 299 content::Source<NavigationController>(&wc->GetController())); |
| 300 wc->GetRenderViewHost()->ExecuteJavascriptInWebFrame( |
| 301 string16(), ASCIIToUTF16(script)); |
| 302 load_observer.Wait(); |
| 303 |
| 304 // Ensure we saw the expected failure. |
| 305 EXPECT_EQ(fail_url, fail_observer.fail_url()); |
| 306 |
| 307 // Failed initial navigation of an iframe shouldn't be adding any history |
| 308 // entries. |
| 309 EXPECT_EQ(2, wc->GetController().GetEntryCount()); |
| 310 } |
| 311 |
242 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. | 312 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. |
243 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { | 313 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { |
244 NavigateToURLAndWaitForTitle( | 314 NavigateToURLAndWaitForTitle( |
245 content::URLRequestMockHTTPJob::GetMockUrl( | 315 content::URLRequestMockHTTPJob::GetMockUrl( |
246 base::FilePath(FILE_PATH_LITERAL("page404.html"))), | 316 base::FilePath(FILE_PATH_LITERAL("page404.html"))), |
247 "SUCCESS", | 317 "SUCCESS", |
248 1); | 318 1); |
249 } | 319 } |
250 | 320 |
251 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. | 321 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 394 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
325 browser()->tab_strip_model()->GetActiveWebContents(), | 395 browser()->tab_strip_model()->GetActiveWebContents(), |
326 "var textContent = document.body.textContent;" | 396 "var textContent = document.body.textContent;" |
327 "var hasError = textContent.indexOf('ERR_NAME_NOT_RESOLVED') >= 0;" | 397 "var hasError = textContent.indexOf('ERR_NAME_NOT_RESOLVED') >= 0;" |
328 "domAutomationController.send(hasError);", | 398 "domAutomationController.send(hasError);", |
329 &result)); | 399 &result)); |
330 EXPECT_TRUE(result); | 400 EXPECT_TRUE(result); |
331 } | 401 } |
332 | 402 |
333 } // namespace | 403 } // namespace |
OLD | NEW |