| 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 3361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3372 // The in-page navigation should not have replaced the previous entry. | 3372 // The in-page navigation should not have replaced the previous entry. |
| 3373 GURL push_state_url( | 3373 GURL push_state_url( |
| 3374 embedded_test_server()->GetURL("/navigation_controller/pushed")); | 3374 embedded_test_server()->GetURL("/navigation_controller/pushed")); |
| 3375 EXPECT_EQ(entry_count + 1, controller.GetEntryCount()); | 3375 EXPECT_EQ(entry_count + 1, controller.GetEntryCount()); |
| 3376 EXPECT_EQ(push_state_url, controller.GetLastCommittedEntry()->GetURL()); | 3376 EXPECT_EQ(push_state_url, controller.GetLastCommittedEntry()->GetURL()); |
| 3377 EXPECT_EQ(start_url, controller.GetEntryAtIndex(0)->GetURL()); | 3377 EXPECT_EQ(start_url, controller.GetEntryAtIndex(0)->GetURL()); |
| 3378 | 3378 |
| 3379 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 3379 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
| 3380 } | 3380 } |
| 3381 | 3381 |
| 3382 // This test ensures that if we go back from a page that has a replaceState() |
| 3383 // call in the window.beforeunload function, we commit to the proper navigation |
| 3384 // entry. https://crbug.com/597239 |
| 3385 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 3386 BackFromPageWithReplaceStateInBeforeUnload) { |
| 3387 NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>( |
| 3388 shell()->web_contents()->GetController()); |
| 3389 |
| 3390 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 3391 ->GetFrameTree() |
| 3392 ->root(); |
| 3393 |
| 3394 // Load an initial page. |
| 3395 GURL start_url(embedded_test_server()->GetURL( |
| 3396 "/navigation_controller/beforeunload_replacestate_1.html")); |
| 3397 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| 3398 EXPECT_EQ(1, controller.GetEntryCount()); |
| 3399 EXPECT_EQ(start_url, controller.GetLastCommittedEntry()->GetURL()); |
| 3400 |
| 3401 // Go to the second page. |
| 3402 std::string script = "document.getElementById('thelink').click()"; |
| 3403 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script)); |
| 3404 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 3405 EXPECT_EQ(2, controller.GetEntryCount()); |
| 3406 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 3407 |
| 3408 // Go back to the first page, which never completes. The attempt to unload the |
| 3409 // second page, though, causes it to do a replaceState(). |
| 3410 NavigationStallDelegate stall_delegate(start_url); |
| 3411 ResourceDispatcherHost::Get()->SetDelegate(&stall_delegate); |
| 3412 TestNavigationObserver back_load_observer(shell()->web_contents()); |
| 3413 controller.GoBack(); |
| 3414 back_load_observer.Wait(); |
| 3415 |
| 3416 // The navigation that just happened was the replaceState(), which should not |
| 3417 // have changed the position into the navigation entry list. Make sure that |
| 3418 // the pending navigation didn't confuse anything. |
| 3419 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 3420 |
| 3421 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
| 3422 } |
| 3423 |
| 3382 // Ensure the renderer process does not get confused about the current entry | 3424 // Ensure the renderer process does not get confused about the current entry |
| 3383 // due to subframes and replaced entries. See https://crbug.com/480201. | 3425 // due to subframes and replaced entries. See https://crbug.com/480201. |
| 3384 // TODO(creis): Re-enable for Site Isolation FYI bots: https://crbug.com/502317. | 3426 // TODO(creis): Re-enable for Site Isolation FYI bots: https://crbug.com/502317. |
| 3385 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 3427 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 3386 PreventSpoofFromSubframeAndReplace) { | 3428 PreventSpoofFromSubframeAndReplace) { |
| 3387 // Start at an initial URL. | 3429 // Start at an initial URL. |
| 3388 GURL url1(embedded_test_server()->GetURL( | 3430 GURL url1(embedded_test_server()->GetURL( |
| 3389 "/navigation_controller/simple_page_1.html")); | 3431 "/navigation_controller/simple_page_1.html")); |
| 3390 NavigateToURL(shell(), url1); | 3432 NavigateToURL(shell(), url1); |
| 3391 | 3433 |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4088 // TODO(clamy): Check the post id as well when PlzNavigate handles it | 4130 // TODO(clamy): Check the post id as well when PlzNavigate handles it |
| 4089 // properly. | 4131 // properly. |
| 4090 if (!IsBrowserSideNavigationEnabled()) | 4132 if (!IsBrowserSideNavigationEnabled()) |
| 4091 EXPECT_NE(-1, frame_entry->post_id()); | 4133 EXPECT_NE(-1, frame_entry->post_id()); |
| 4092 EXPECT_FALSE(entry->GetHasPostData()); | 4134 EXPECT_FALSE(entry->GetHasPostData()); |
| 4093 EXPECT_EQ(-1, entry->GetPostID()); | 4135 EXPECT_EQ(-1, entry->GetPostID()); |
| 4094 } | 4136 } |
| 4095 } | 4137 } |
| 4096 | 4138 |
| 4097 } // namespace content | 4139 } // namespace content |
| OLD | NEW |