| 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 4459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4470 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 4470 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 4471 | 4471 |
| 4472 // We should be on url_b, and the renderer process shouldn't be killed. | 4472 // We should be on url_b, and the renderer process shouldn't be killed. |
| 4473 ASSERT_TRUE(root->current_frame_host()->IsRenderFrameLive()); | 4473 ASSERT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
| 4474 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 4474 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 4475 EXPECT_EQ(url_b, shell()->web_contents()->GetVisibleURL()); | 4475 EXPECT_EQ(url_b, shell()->web_contents()->GetVisibleURL()); |
| 4476 EXPECT_EQ(url_b, root->current_url()); | 4476 EXPECT_EQ(url_b, root->current_url()); |
| 4477 EXPECT_EQ(0U, root->child_count()); | 4477 EXPECT_EQ(0U, root->child_count()); |
| 4478 } | 4478 } |
| 4479 | 4479 |
| 4480 // Ensure that we do not corrupt a NavigationEntry's PageState if two forward |
| 4481 // navigations compete in different frames, and the main frame entry contains an |
| 4482 // iframe of its own. See https://crbug.com/623319. |
| 4483 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 4484 PageStateWithIframeAfterForwardInCompetingFrames) { |
| 4485 // Navigate to a page with an iframe. |
| 4486 GURL url_a(embedded_test_server()->GetURL( |
| 4487 "/navigation_controller/page_with_data_iframe.html")); |
| 4488 GURL data_url("data:text/html,Subframe"); |
| 4489 EXPECT_TRUE(NavigateToURL(shell(), url_a)); |
| 4490 |
| 4491 NavigationController& controller = shell()->web_contents()->GetController(); |
| 4492 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 4493 ->GetFrameTree() |
| 4494 ->root(); |
| 4495 EXPECT_EQ(url_a, root->current_url()); |
| 4496 EXPECT_EQ(data_url, root->child_at(0)->current_url()); |
| 4497 |
| 4498 // Navigate the iframe to a first real page. |
| 4499 GURL frame_url_a1 = embedded_test_server()->GetURL( |
| 4500 "/navigation_controller/simple_page_1.html"); |
| 4501 NavigateFrameToURL(root->child_at(0), frame_url_a1); |
| 4502 |
| 4503 // Navigate the iframe to a second real page. |
| 4504 GURL frame_url_a2 = embedded_test_server()->GetURL( |
| 4505 "/navigation_controller/simple_page_2.html"); |
| 4506 NavigateFrameToURL(root->child_at(0), frame_url_a2); |
| 4507 EXPECT_EQ(3, controller.GetEntryCount()); |
| 4508 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); |
| 4509 EXPECT_EQ(url_a, root->current_url()); |
| 4510 EXPECT_EQ(frame_url_a2, root->child_at(0)->current_url()); |
| 4511 |
| 4512 // Go back to the middle entry. |
| 4513 controller.GoBack(); |
| 4514 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 4515 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 4516 |
| 4517 // Replace the entry with a cross-site top-level page with an iframe. By |
| 4518 // doing a replacement, the main frame pages before and after have the same |
| 4519 // item sequence number, and thus going between them only requires loads in |
| 4520 // the subframe. |
| 4521 GURL url_b(embedded_test_server()->GetURL( |
| 4522 "b.com", "/navigation_controller/page_with_data_iframe.html")); |
| 4523 std::string replace_script = "location.replace('" + url_b.spec() + "')"; |
| 4524 TestNavigationObserver replace_observer(shell()->web_contents()); |
| 4525 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), replace_script)); |
| 4526 replace_observer.Wait(); |
| 4527 EXPECT_EQ(3, controller.GetEntryCount()); |
| 4528 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 4529 EXPECT_EQ(url_b, root->current_url()); |
| 4530 EXPECT_EQ(data_url, root->child_at(0)->current_url()); |
| 4531 |
| 4532 // Go back to the original page. |
| 4533 controller.GoBack(); |
| 4534 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 4535 |
| 4536 // Navigate forward twice using script. This will race, but in either outcome |
| 4537 // we want to ensure that the subframes target entry index 1 and not 2. In |
| 4538 // https://crbug.com/623319, the subframes targeted the wrong entry, leading |
| 4539 // to a URL spoof and renderer kill. |
| 4540 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
| 4541 "history.forward(); history.forward();")); |
| 4542 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 4543 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 4544 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
| 4545 EXPECT_EQ(url_b, root->current_url()); |
| 4546 EXPECT_EQ(data_url, root->child_at(0)->current_url()); |
| 4547 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 4548 EXPECT_EQ(url_b, entry->GetURL()); |
| 4549 ExplodedPageState exploded_state; |
| 4550 EXPECT_TRUE( |
| 4551 DecodePageState(entry->GetPageState().ToEncodedData(), &exploded_state)); |
| 4552 EXPECT_EQ(url_b, GURL(exploded_state.top.url_string.string())); |
| 4553 |
| 4554 // Go back and then forward to see if the PageState loads correctly. |
| 4555 controller.GoBack(); |
| 4556 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 4557 controller.GoForward(); |
| 4558 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 4559 |
| 4560 // We should be on url_b, and the renderer process shouldn't be killed. |
| 4561 ASSERT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
| 4562 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 4563 EXPECT_EQ(url_b, shell()->web_contents()->GetVisibleURL()); |
| 4564 EXPECT_EQ(url_b, root->current_url()); |
| 4565 EXPECT_EQ(data_url, root->child_at(0)->current_url()); |
| 4566 } |
| 4567 |
| 4480 // Ensure that forward navigations in cloned tabs can commit if they redirect to | 4568 // Ensure that forward navigations in cloned tabs can commit if they redirect to |
| 4481 // a different site than before. This causes the navigation's item sequence | 4569 // a different site than before. This causes the navigation's item sequence |
| 4482 // number to change, meaning that we can't use it for determining whether the | 4570 // number to change, meaning that we can't use it for determining whether the |
| 4483 // commit matches the history item. See https://crbug.com/600238. | 4571 // commit matches the history item. See https://crbug.com/600238. |
| 4484 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 4572 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 4485 ForwardRedirectWithNoCommittedEntry) { | 4573 ForwardRedirectWithNoCommittedEntry) { |
| 4486 NavigationController& controller = shell()->web_contents()->GetController(); | 4574 NavigationController& controller = shell()->web_contents()->GetController(); |
| 4487 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 4575 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 4488 ->GetFrameTree() | 4576 ->GetFrameTree() |
| 4489 ->root(); | 4577 ->root(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4590 // TODO(clamy): Check the post id as well when PlzNavigate handles it | 4678 // TODO(clamy): Check the post id as well when PlzNavigate handles it |
| 4591 // properly. | 4679 // properly. |
| 4592 if (!IsBrowserSideNavigationEnabled()) | 4680 if (!IsBrowserSideNavigationEnabled()) |
| 4593 EXPECT_NE(-1, frame_entry->post_id()); | 4681 EXPECT_NE(-1, frame_entry->post_id()); |
| 4594 EXPECT_FALSE(entry->GetHasPostData()); | 4682 EXPECT_FALSE(entry->GetHasPostData()); |
| 4595 EXPECT_EQ(-1, entry->GetPostID()); | 4683 EXPECT_EQ(-1, entry->GetPostID()); |
| 4596 } | 4684 } |
| 4597 } | 4685 } |
| 4598 | 4686 |
| 4599 } // namespace content | 4687 } // namespace content |
| OLD | NEW |