Chromium Code Reviews| 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. | |
| 426 { | |
| 427 FrameNavigateParamsCapturer capturer(root); | |
| 428 NavigateToURLAndReplace(shell(), error_url); | |
| 429 capturer.Wait(); | |
| 430 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | |
| 431 NavigationEntry* entry = controller.GetLastCommittedEntry(); | |
| 432 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); | |
| 433 EXPECT_EQ(3, controller.GetEntryCount()); | |
| 434 } | |
|
davidben
2015/03/31 17:26:08
There's a third case that's probably worth testing
Charlie Reis
2015/03/31 17:29:48
It looks like that's what NavigateToURLAndReplace
| |
| 435 } | |
| 436 | |
| 379 // Various tests for navigation type classifications. TODO(avi): It's rather | 437 // 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. | 438 // bogus that the same info is in two different enums; http://crbug.com/453555. |
| 381 | 439 |
| 382 // Verify that navigations for NAVIGATION_TYPE_NEW_PAGE are correctly | 440 // Verify that navigations for NAVIGATION_TYPE_NEW_PAGE are correctly |
| 383 // classified. | 441 // classified. |
| 384 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 442 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 385 NavigationTypeClassification_NewPage) { | 443 NavigationTypeClassification_NewPage) { |
| 386 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 444 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 387 | 445 |
| 388 FrameTreeNode* root = | 446 FrameTreeNode* root = |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 FrameNavigationEntry* frame_entry = | 959 FrameNavigationEntry* frame_entry = |
| 902 entry->root_node()->children[0]->frame_entry.get(); | 960 entry->root_node()->children[0]->frame_entry.get(); |
| 903 EXPECT_EQ(frame_url, frame_entry->url()); | 961 EXPECT_EQ(frame_url, frame_entry->url()); |
| 904 } else { | 962 } else { |
| 905 // There are no subframe FrameNavigationEntries by default. | 963 // There are no subframe FrameNavigationEntries by default. |
| 906 EXPECT_EQ(0U, entry->root_node()->children.size()); | 964 EXPECT_EQ(0U, entry->root_node()->children.size()); |
| 907 } | 965 } |
| 908 } | 966 } |
| 909 | 967 |
| 910 } // namespace content | 968 } // namespace content |
| OLD | NEW |