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 4582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4593 NavigationEntry* entry = controller.GetEntryAtIndex(1); | 4593 NavigationEntry* entry = controller.GetEntryAtIndex(1); |
4594 EXPECT_EQ(url_a, entry->GetURL()); | 4594 EXPECT_EQ(url_a, entry->GetURL()); |
4595 ExplodedPageState exploded_state; | 4595 ExplodedPageState exploded_state; |
4596 EXPECT_TRUE( | 4596 EXPECT_TRUE( |
4597 DecodePageState(entry->GetPageState().ToEncodedData(), &exploded_state)); | 4597 DecodePageState(entry->GetPageState().ToEncodedData(), &exploded_state)); |
4598 EXPECT_EQ(url_a, GURL(exploded_state.top.url_string.string())); | 4598 EXPECT_EQ(url_a, GURL(exploded_state.top.url_string.string())); |
4599 EXPECT_EQ(frame_url_a2, | 4599 EXPECT_EQ(frame_url_a2, |
4600 GURL(exploded_state.top.children.at(0).url_string.string())); | 4600 GURL(exploded_state.top.children.at(0).url_string.string())); |
4601 } | 4601 } |
4602 | 4602 |
4603 // Ensure that we do not corrupt a NavigationEntry's PageState if two forward | |
4604 // navigations compete in different frames. See https://crbug.com/623319. | |
4605 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
4606 PageStateAfterForwardInCompetingFrames) { | |
4607 // Navigate to a page with an iframe. | |
4608 GURL url_a(embedded_test_server()->GetURL( | |
4609 "/navigation_controller/page_with_data_iframe.html")); | |
4610 GURL frame_url_a1("data:text/html,Subframe"); | |
4611 EXPECT_TRUE(NavigateToURL(shell(), url_a)); | |
4612 | |
4613 NavigationController& controller = shell()->web_contents()->GetController(); | |
4614 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
4615 ->GetFrameTree() | |
4616 ->root(); | |
4617 EXPECT_EQ(url_a, root->current_url()); | |
4618 FrameTreeNode* frame = root->child_at(0); | |
ncarter (slow)
2016/07/08 21:09:22
I'd inline this, since a later navigation destroys
Charlie Reis
2016/07/08 21:15:06
Done.
| |
4619 EXPECT_EQ(frame_url_a1, frame->current_url()); | |
4620 | |
4621 // Navigate the iframe to a second page. | |
4622 GURL frame_url_a2 = embedded_test_server()->GetURL( | |
4623 "/navigation_controller/simple_page_1.html"); | |
4624 NavigateFrameToURL(frame, frame_url_a2); | |
4625 | |
4626 // Navigate the iframe to about:blank. | |
4627 GURL blank_url(url::kAboutBlankURL); | |
4628 NavigateFrameToURL(frame, blank_url); | |
4629 EXPECT_EQ(3, controller.GetEntryCount()); | |
4630 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex()); | |
4631 EXPECT_EQ(url_a, root->current_url()); | |
4632 EXPECT_EQ(blank_url, frame->current_url()); | |
4633 | |
4634 // Go back to the middle entry. | |
4635 controller.GoBack(); | |
4636 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
4637 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | |
4638 | |
4639 // Replace the entry with a cross-site top-level page. By doing a | |
4640 // replacement, the main frame pages before and after have the same item | |
4641 // sequence number, and thus going between them only requires loads in the | |
4642 // subframe. | |
4643 GURL url_b(embedded_test_server()->GetURL( | |
4644 "b.com", "/navigation_controller/simple_page_2.html")); | |
4645 std::string replace_script = "location.replace('" + url_b.spec() + "')"; | |
4646 TestNavigationObserver replace_observer(shell()->web_contents()); | |
4647 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), replace_script)); | |
4648 replace_observer.Wait(); | |
4649 EXPECT_EQ(3, controller.GetEntryCount()); | |
4650 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | |
4651 EXPECT_EQ(url_b, root->current_url()); | |
4652 | |
4653 // Go back to the original page. | |
4654 controller.GoBack(); | |
4655 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
4656 | |
4657 // Navigate forward twice using script. In https://crbug.com/623319, this | |
4658 // caused a mismatch between the NavigationEntry's URL and PageState. | |
4659 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | |
4660 "history.forward(); history.forward();")); | |
4661 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
4662 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | |
4663 EXPECT_EQ(url_b, root->current_url()); | |
4664 NavigationEntry* entry = controller.GetLastCommittedEntry(); | |
4665 EXPECT_EQ(url_b, entry->GetURL()); | |
4666 ExplodedPageState exploded_state; | |
4667 EXPECT_TRUE( | |
4668 DecodePageState(entry->GetPageState().ToEncodedData(), &exploded_state)); | |
4669 EXPECT_EQ(url_b, GURL(exploded_state.top.url_string.string())); | |
4670 // TODO(creis): Clear subframe FNEs after location.replace in | |
4671 // --isolate-extensions mode. See https://crbug.com/596707. | |
4672 if (!SiteIsolationPolicy::UseSubframeNavigationEntries()) | |
4673 EXPECT_EQ(0U, exploded_state.top.children.size()); | |
Charlie Reis
2016/07/08 18:11:12
Found that this was failing in --isolate-sites-for
| |
4674 | |
4675 // Go back and then forward to see if the PageState loads correctly. | |
4676 controller.GoBack(); | |
4677 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
4678 controller.GoForward(); | |
4679 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
4680 | |
4681 // We should be on url_b, and the renderer process shouldn't be killed. | |
4682 ASSERT_TRUE(root->current_frame_host()->IsRenderFrameLive()); | |
4683 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | |
4684 EXPECT_EQ(url_b, shell()->web_contents()->GetVisibleURL()); | |
4685 EXPECT_EQ(url_b, root->current_url()); | |
4686 EXPECT_EQ(0U, root->child_count()); | |
4687 } | |
4688 | |
4603 // Ensure that forward navigations in cloned tabs can commit if they redirect to | 4689 // Ensure that forward navigations in cloned tabs can commit if they redirect to |
4604 // a different site than before. This causes the navigation's item sequence | 4690 // a different site than before. This causes the navigation's item sequence |
4605 // number to change, meaning that we can't use it for determining whether the | 4691 // number to change, meaning that we can't use it for determining whether the |
4606 // commit matches the history item. See https://crbug.com/600238. | 4692 // commit matches the history item. See https://crbug.com/600238. |
4607 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 4693 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
4608 ForwardRedirectWithNoCommittedEntry) { | 4694 ForwardRedirectWithNoCommittedEntry) { |
4609 NavigationController& controller = shell()->web_contents()->GetController(); | 4695 NavigationController& controller = shell()->web_contents()->GetController(); |
4610 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 4696 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
4611 ->GetFrameTree() | 4697 ->GetFrameTree() |
4612 ->root(); | 4698 ->root(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4749 std::string body; | 4835 std::string body; |
4750 EXPECT_TRUE(ExecuteScriptAndExtractString( | 4836 EXPECT_TRUE(ExecuteScriptAndExtractString( |
4751 shell()->web_contents(), | 4837 shell()->web_contents(), |
4752 "window.domAutomationController.send(" | 4838 "window.domAutomationController.send(" |
4753 "document.getElementsByTagName('pre')[0].innerText);", | 4839 "document.getElementsByTagName('pre')[0].innerText);", |
4754 &body)); | 4840 &body)); |
4755 EXPECT_EQ("text=value\n", body); | 4841 EXPECT_EQ("text=value\n", body); |
4756 } | 4842 } |
4757 | 4843 |
4758 } // namespace content | 4844 } // namespace content |
OLD | NEW |