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

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