OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "content/browser/frame_host/frame_navigation_entry.h" | 8 #include "content/browser/frame_host/frame_navigation_entry.h" |
9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
10 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
11 #include "content/browser/frame_host/navigation_entry_impl.h" | 11 #include "content/browser/frame_host/navigation_entry_impl.h" |
12 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
13 #include "content/public/browser/render_view_host.h" | 13 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
16 #include "content/public/common/bindings_policy.h" | 16 #include "content/public/common/bindings_policy.h" |
17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
18 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
19 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
20 #include "content/public/test/content_browser_test.h" | 20 #include "content/public/test/content_browser_test.h" |
21 #include "content/public/test/content_browser_test_utils.h" | 21 #include "content/public/test/content_browser_test_utils.h" |
22 #include "content/public/test/test_navigation_observer.h" | 22 #include "content/public/test/test_navigation_observer.h" |
23 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
24 #include "content/shell/browser/shell.h" | 24 #include "content/shell/browser/shell.h" |
25 #include "content/test/content_browser_test_utils_internal.h" | 25 #include "content/test/content_browser_test_utils_internal.h" |
26 #include "net/dns/mock_host_resolver.h" | 26 #include "net/dns/mock_host_resolver.h" |
27 #include "net/test/embedded_test_server/embedded_test_server.h" | 27 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 28 #include "net/test/url_request/url_request_failed_job.h" |
28 | 29 |
29 namespace content { | 30 namespace content { |
30 | 31 |
31 class NavigationControllerBrowserTest : public ContentBrowserTest { | 32 class NavigationControllerBrowserTest : public ContentBrowserTest { |
32 protected: | 33 protected: |
33 void SetUpOnMainThread() override { | 34 void SetUpOnMainThread() override { |
34 host_resolver()->AddRule("*", "127.0.0.1"); | 35 host_resolver()->AddRule("*", "127.0.0.1"); |
35 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 36 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
36 } | 37 } |
37 }; | 38 }; |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 370 |
370 // The transition_type of the last navigation. | 371 // The transition_type of the last navigation. |
371 ui::PageTransition transition_type_; | 372 ui::PageTransition transition_type_; |
372 | 373 |
373 // The MessageLoopRunner used to spin the message loop. | 374 // The MessageLoopRunner used to spin the message loop. |
374 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 375 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
375 }; | 376 }; |
376 | 377 |
377 } // namespace | 378 } // namespace |
378 | 379 |
| 380 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 381 ErrorPageReplacement) { |
| 382 NavigationController& controller = shell()->web_contents()->GetController(); |
| 383 GURL error_url( |
| 384 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_RESET)); |
| 385 net::URLRequestFailedJob::AddUrlHandler(); |
| 386 |
| 387 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 388 EXPECT_EQ(1, controller.GetEntryCount()); |
| 389 |
| 390 FrameTreeNode* root = |
| 391 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 392 GetFrameTree()->root(); |
| 393 |
| 394 // Navigate to a page that fails to load. It must result in an error page, the |
| 395 // NEW_PAGE navigation type, and an addition to the history list. |
| 396 { |
| 397 FrameNavigateParamsCapturer capturer(root); |
| 398 NavigateFrameToURL(root, error_url); |
| 399 capturer.Wait(); |
| 400 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); |
| 401 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 402 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
| 403 EXPECT_EQ(2, controller.GetEntryCount()); |
| 404 } |
| 405 |
| 406 // Navigate again to the page that fails to load. It must result in an error |
| 407 // page, the EXISTING_PAGE navigation type, and no addition to the history |
| 408 // list. We do not use SAME_PAGE here; that case only differs in that it |
| 409 // clears the pending entry, and there is no pending entry after a load |
| 410 // failure. |
| 411 { |
| 412 FrameNavigateParamsCapturer capturer(root); |
| 413 NavigateFrameToURL(root, error_url); |
| 414 capturer.Wait(); |
| 415 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); |
| 416 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 417 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
| 418 EXPECT_EQ(2, controller.GetEntryCount()); |
| 419 } |
| 420 |
| 421 // Make a new entry ... |
| 422 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 423 EXPECT_EQ(3, controller.GetEntryCount()); |
| 424 |
| 425 // ... and replace it with a failed load. (Note that when you set the |
| 426 // should_replace_current_entry flag, the navigation is classified as NEW_PAGE |
| 427 // because that is a classification of the renderer's behavior, and the flag |
| 428 // is a browser-side flag.) |
| 429 { |
| 430 FrameNavigateParamsCapturer capturer(root); |
| 431 NavigateToURLAndReplace(shell(), error_url); |
| 432 capturer.Wait(); |
| 433 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); |
| 434 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 435 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
| 436 EXPECT_EQ(3, controller.GetEntryCount()); |
| 437 } |
| 438 |
| 439 // Make a new web ui page to force a process swap ... |
| 440 GURL web_ui_page(std::string(kChromeUIScheme) + "://" + |
| 441 std::string(kChromeUIGpuHost)); |
| 442 NavigateToURL(shell(), web_ui_page); |
| 443 EXPECT_EQ(4, controller.GetEntryCount()); |
| 444 |
| 445 // ... and replace it with a failed load. (It is NEW_PAGE for the reason noted |
| 446 // above.) |
| 447 { |
| 448 FrameNavigateParamsCapturer capturer(root); |
| 449 NavigateToURLAndReplace(shell(), error_url); |
| 450 capturer.Wait(); |
| 451 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); |
| 452 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 453 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
| 454 EXPECT_EQ(4, controller.GetEntryCount()); |
| 455 } |
| 456 } |
| 457 |
379 // Various tests for navigation type classifications. TODO(avi): It's rather | 458 // Various tests for navigation type classifications. TODO(avi): It's rather |
380 // bogus that the same info is in two different enums; http://crbug.com/453555. | 459 // bogus that the same info is in two different enums; http://crbug.com/453555. |
381 | 460 |
382 // Verify that navigations for NAVIGATION_TYPE_NEW_PAGE are correctly | 461 // Verify that navigations for NAVIGATION_TYPE_NEW_PAGE are correctly |
383 // classified. | 462 // classified. |
384 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 463 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
385 NavigationTypeClassification_NewPage) { | 464 NavigationTypeClassification_NewPage) { |
386 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 465 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
387 | 466 |
388 FrameTreeNode* root = | 467 FrameTreeNode* root = |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 FrameNavigationEntry* frame_entry = | 980 FrameNavigationEntry* frame_entry = |
902 entry->root_node()->children[0]->frame_entry.get(); | 981 entry->root_node()->children[0]->frame_entry.get(); |
903 EXPECT_EQ(frame_url, frame_entry->url()); | 982 EXPECT_EQ(frame_url, frame_entry->url()); |
904 } else { | 983 } else { |
905 // There are no subframe FrameNavigationEntries by default. | 984 // There are no subframe FrameNavigationEntries by default. |
906 EXPECT_EQ(0U, entry->root_node()->children.size()); | 985 EXPECT_EQ(0U, entry->root_node()->children.size()); |
907 } | 986 } |
908 } | 987 } |
909 | 988 |
910 } // namespace content | 989 } // namespace content |
OLD | NEW |