Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: chrome/browser/errorpage_browsertest.cc

Issue 15294012: Fix initial erroneous navigation in iframe to not add history entry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix in sync with Blink and modified the test case a bit Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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
286 // Load a regular web page, in which we will inject an iframe.
287 NavigateToFileURL(FILE_PATH_LITERAL("title2.html"));
288
289 // We expect to have two history entries, since we started off with navigation
290 // to "about:blank" and then navigated to "title2.html".
291 EXPECT_EQ(2, wc->GetController().GetEntryCount());
292
293 std::string script = "var frame = document.createElement('iframe');"
294 "frame.src = '" + fail_url.spec() + "';"
295 "document.body.appendChild(frame);";
296 {
297 TestFailProvisionalLoadObserver fail_observer(wc);
298 content::WindowedNotificationObserver load_observer(
299 content::NOTIFICATION_LOAD_STOP,
300 content::Source<NavigationController>(&wc->GetController()));
301 wc->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
302 string16(), ASCIIToUTF16(script));
303 load_observer.Wait();
304
305 // Ensure we saw the expected failure.
306 EXPECT_EQ(fail_url, fail_observer.fail_url());
307
308 // Failed initial navigation of an iframe shouldn't be adding any history
309 // entries.
310 EXPECT_EQ(2, wc->GetController().GetEntryCount());
311 }
312
313 // Do the same test, but with an iframe that doesn't have initial URL
314 // assigned.
315 script = "var frame = document.createElement('iframe');"
316 "frame.id = 'target_frame';"
317 "document.body.appendChild(frame);";
318 {
319 content::WindowedNotificationObserver load_observer(
320 content::NOTIFICATION_LOAD_STOP,
321 content::Source<NavigationController>(&wc->GetController()));
322 wc->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
323 string16(), ASCIIToUTF16(script));
324 load_observer.Wait();
325 }
326
327 script = "var f = document.getElementById('target_frame');"
328 "f.src = '" + fail_url.spec() + "';";
329 {
330 TestFailProvisionalLoadObserver fail_observer(wc);
331 content::WindowedNotificationObserver load_observer(
332 content::NOTIFICATION_LOAD_STOP,
333 content::Source<NavigationController>(&wc->GetController()));
334 wc->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
335 string16(), ASCIIToUTF16(script));
336 load_observer.Wait();
337
338 EXPECT_EQ(fail_url, fail_observer.fail_url());
339 EXPECT_EQ(2, wc->GetController().GetEntryCount());
340 }
341 }
342
242 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. 343 // Checks that the Link Doctor is not loaded when we receive an actual 404 page.
243 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { 344 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) {
244 NavigateToURLAndWaitForTitle( 345 NavigateToURLAndWaitForTitle(
245 content::URLRequestMockHTTPJob::GetMockUrl( 346 content::URLRequestMockHTTPJob::GetMockUrl(
246 base::FilePath(FILE_PATH_LITERAL("page404.html"))), 347 base::FilePath(FILE_PATH_LITERAL("page404.html"))),
247 "SUCCESS", 348 "SUCCESS",
248 1); 349 1);
249 } 350 }
250 351
251 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. 352 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 425 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
325 browser()->tab_strip_model()->GetActiveWebContents(), 426 browser()->tab_strip_model()->GetActiveWebContents(),
326 "var textContent = document.body.textContent;" 427 "var textContent = document.body.textContent;"
327 "var hasError = textContent.indexOf('ERR_NAME_NOT_RESOLVED') >= 0;" 428 "var hasError = textContent.indexOf('ERR_NAME_NOT_RESOLVED') >= 0;"
328 "domAutomationController.send(hasError);", 429 "domAutomationController.send(hasError);",
329 &result)); 430 &result));
330 EXPECT_TRUE(result); 431 EXPECT_TRUE(result);
331 } 432 }
332 433
333 } // namespace 434 } // namespace
OLDNEW
« no previous file with comments | « no previous file | content/renderer/render_view_impl.cc » ('j') | content/renderer/render_view_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698