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 | |
|
Charlie Reis
2015/03/30 21:36:54
Let's put a bit of your explanation in this commen
Avi (use Gerrit)
2015/03/31 16:08:49
Done.
| |
| 408 // list. | |
| 409 { | |
| 410 FrameNavigateParamsCapturer capturer(root); | |
| 411 NavigateFrameToURL(root, error_url); | |
| 412 capturer.Wait(); | |
| 413 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | |
| 414 NavigationEntry* entry = controller.GetLastCommittedEntry(); | |
| 415 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); | |
| 416 EXPECT_EQ(2, controller.GetEntryCount()); | |
| 417 } | |
| 418 } | |
|
Charlie Reis
2015/03/30 21:36:54
Can you add a test for location.replace to error_u
Avi (use Gerrit)
2015/03/31 16:08:49
Done.
| |
| 419 | |
| 379 // Various tests for navigation type classifications. TODO(avi): It's rather | 420 // 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. | 421 // bogus that the same info is in two different enums; http://crbug.com/453555. |
| 381 | 422 |
| 382 // Verify that navigations for NAVIGATION_TYPE_NEW_PAGE are correctly | 423 // Verify that navigations for NAVIGATION_TYPE_NEW_PAGE are correctly |
| 383 // classified. | 424 // classified. |
| 384 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 425 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 385 NavigationTypeClassification_NewPage) { | 426 NavigationTypeClassification_NewPage) { |
| 386 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 427 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 387 | 428 |
| 388 FrameTreeNode* root = | 429 FrameTreeNode* root = |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 FrameNavigationEntry* frame_entry = | 942 FrameNavigationEntry* frame_entry = |
| 902 entry->root_node()->children[0]->frame_entry.get(); | 943 entry->root_node()->children[0]->frame_entry.get(); |
| 903 EXPECT_EQ(frame_url, frame_entry->url()); | 944 EXPECT_EQ(frame_url, frame_entry->url()); |
| 904 } else { | 945 } else { |
| 905 // There are no subframe FrameNavigationEntries by default. | 946 // There are no subframe FrameNavigationEntries by default. |
| 906 EXPECT_EQ(0U, entry->root_node()->children.size()); | 947 EXPECT_EQ(0U, entry->root_node()->children.size()); |
| 907 } | 948 } |
| 908 } | 949 } |
| 909 | 950 |
| 910 } // namespace content | 951 } // namespace content |
| OLD | NEW |