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 "content/browser/frame_host/navigation_controller_impl.h" | 5 #include "content/browser/frame_host/navigation_controller_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 2816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2827 EXPECT_EQ(new_root->current_frame_host()->GetSiteInstance(), | 2827 EXPECT_EQ(new_root->current_frame_host()->GetSiteInstance(), |
2828 new_root->child_at(0)->current_frame_host()->GetSiteInstance()); | 2828 new_root->child_at(0)->current_frame_host()->GetSiteInstance()); |
2829 } | 2829 } |
2830 } | 2830 } |
2831 | 2831 |
2832 namespace { | 2832 namespace { |
2833 | 2833 |
2834 // Loads |start_url|, then loads |stalled_url| which stalls. While the page is | 2834 // Loads |start_url|, then loads |stalled_url| which stalls. While the page is |
2835 // stalled, an in-page navigation happens. Make sure that all the navigations | 2835 // stalled, an in-page navigation happens. Make sure that all the navigations |
2836 // are properly classified. | 2836 // are properly classified. |
2837 void DoReplaceStateWhilePending(Shell* shell, | 2837 void DoReplaceStateWhilePending(Shell* shell, |
Charlie Reis
2016/03/11 00:22:09
Amusingly, this is almost exactly the test I neede
| |
2838 const GURL& start_url, | 2838 const GURL& start_url, |
2839 const GURL& stalled_url, | 2839 const GURL& stalled_url, |
2840 const std::string& replace_state_filename) { | 2840 const std::string& replace_state_filename) { |
2841 NavigationControllerImpl& controller = | 2841 NavigationControllerImpl& controller = |
2842 static_cast<NavigationControllerImpl&>( | 2842 static_cast<NavigationControllerImpl&>( |
2843 shell->web_contents()->GetController()); | 2843 shell->web_contents()->GetController()); |
2844 | 2844 |
2845 FrameTreeNode* root = | 2845 FrameTreeNode* root = |
2846 static_cast<WebContentsImpl*>(shell->web_contents())-> | 2846 static_cast<WebContentsImpl*>(shell->web_contents())-> |
2847 GetFrameTree()->root(); | 2847 GetFrameTree()->root(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2907 DoReplaceStateWhilePending(shell(), url, url, "x"); | 2907 DoReplaceStateWhilePending(shell(), url, url, "x"); |
2908 } | 2908 } |
2909 | 2909 |
2910 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 2910 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
2911 NavigationTypeClassification_On1InPageTo1While1Pending) { | 2911 NavigationTypeClassification_On1InPageTo1While1Pending) { |
2912 GURL url(embedded_test_server()->GetURL( | 2912 GURL url(embedded_test_server()->GetURL( |
2913 "/navigation_controller/simple_page_1.html")); | 2913 "/navigation_controller/simple_page_1.html")); |
2914 DoReplaceStateWhilePending(shell(), url, url, "simple_page_1.html"); | 2914 DoReplaceStateWhilePending(shell(), url, url, "simple_page_1.html"); |
2915 } | 2915 } |
2916 | 2916 |
2917 // Ensure that a pending NavigationEntry for a different navigation doesn't | |
2918 // cause a commit to be incorrectly treated as a replacement. | |
2919 // See https://crbug.com/593153. | |
2920 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
2921 OtherCommitDuringPendingEntryWithReplacement) { | |
2922 NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>( | |
2923 shell()->web_contents()->GetController()); | |
2924 | |
2925 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
2926 ->GetFrameTree() | |
2927 ->root(); | |
2928 | |
2929 // Load an initial page. | |
2930 GURL start_url(embedded_test_server()->GetURL( | |
2931 "/navigation_controller/simple_page_1.html")); | |
2932 EXPECT_TRUE(NavigateToURL(shell(), start_url)); | |
2933 int entry_count = controller.GetEntryCount(); | |
2934 EXPECT_EQ(1, controller.GetEntryCount()); | |
2935 EXPECT_EQ(start_url, controller.GetLastCommittedEntry()->GetURL()); | |
2936 | |
2937 // Start a cross-process navigation with replacement, which never completes. | |
2938 GURL foo_url(embedded_test_server()->GetURL( | |
2939 "foo.com", "/navigation_controller/page_with_links.html")); | |
2940 NavigationStallDelegate stall_delegate(foo_url); | |
2941 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate); | |
2942 NavigationController::LoadURLParams params(foo_url); | |
2943 params.should_replace_current_entry = true; | |
2944 controller.LoadURLWithParams(params); | |
2945 | |
2946 // That should be the pending entry. | |
2947 NavigationEntryImpl* entry = controller.GetPendingEntry(); | |
2948 ASSERT_NE(nullptr, entry); | |
2949 EXPECT_EQ(foo_url, entry->GetURL()); | |
2950 EXPECT_EQ(entry_count, controller.GetEntryCount()); | |
2951 | |
2952 { | |
2953 // Now the existing page uses history.pushState() while the pending entry | |
2954 // for the other navigation still exists. | |
2955 FrameNavigateParamsCapturer capturer(root); | |
2956 capturer.set_wait_for_load(false); | |
2957 std::string script = "history.pushState({}, '', 'pushed')"; | |
2958 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
2959 capturer.Wait(); | |
2960 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); | |
2961 EXPECT_TRUE(capturer.details().is_in_page); | |
2962 } | |
2963 | |
2964 // The in-page navigation should not have replaced the previous entry. | |
2965 GURL push_state_url( | |
2966 embedded_test_server()->GetURL("/navigation_controller/pushed")); | |
2967 EXPECT_EQ(entry_count + 1, controller.GetEntryCount()); | |
2968 EXPECT_EQ(push_state_url, controller.GetLastCommittedEntry()->GetURL()); | |
2969 EXPECT_EQ(start_url, controller.GetEntryAtIndex(0)->GetURL()); | |
2970 | |
2971 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | |
2972 } | |
2973 | |
2917 // Ensure the renderer process does not get confused about the current entry | 2974 // Ensure the renderer process does not get confused about the current entry |
2918 // due to subframes and replaced entries. See https://crbug.com/480201. | 2975 // due to subframes and replaced entries. See https://crbug.com/480201. |
2919 // TODO(creis): Re-enable for Site Isolation FYI bots: https://crbug.com/502317. | 2976 // TODO(creis): Re-enable for Site Isolation FYI bots: https://crbug.com/502317. |
2920 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 2977 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
2921 PreventSpoofFromSubframeAndReplace) { | 2978 PreventSpoofFromSubframeAndReplace) { |
2922 // Start at an initial URL. | 2979 // Start at an initial URL. |
2923 GURL url1(embedded_test_server()->GetURL( | 2980 GURL url1(embedded_test_server()->GetURL( |
2924 "/navigation_controller/simple_page_1.html")); | 2981 "/navigation_controller/simple_page_1.html")); |
2925 NavigateToURL(shell(), url1); | 2982 NavigateToURL(shell(), url1); |
2926 | 2983 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3401 observer.Wait(); | 3458 observer.Wait(); |
3402 | 3459 |
3403 EXPECT_EQ(3, controller.GetEntryCount()); | 3460 EXPECT_EQ(3, controller.GetEntryCount()); |
3404 EXPECT_EQ(3, RendererHistoryLength(shell())); | 3461 EXPECT_EQ(3, RendererHistoryLength(shell())); |
3405 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 3462 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
3406 | 3463 |
3407 EXPECT_EQ(frame_url_1, frame->current_url()); | 3464 EXPECT_EQ(frame_url_1, frame->current_url()); |
3408 } | 3465 } |
3409 | 3466 |
3410 } // namespace content | 3467 } // namespace content |
OLD | NEW |