| 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 3607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3618 EXPECT_EQ(main_url_a, new_entry->root_node()->frame_entry->url()); | 3618 EXPECT_EQ(main_url_a, new_entry->root_node()->frame_entry->url()); |
| 3619 ASSERT_EQ(1U, new_entry->root_node()->children.size()); | 3619 ASSERT_EQ(1U, new_entry->root_node()->children.size()); |
| 3620 EXPECT_EQ(frame_url_b, | 3620 EXPECT_EQ(frame_url_b, |
| 3621 new_entry->root_node()->children[0]->frame_entry->url()); | 3621 new_entry->root_node()->children[0]->frame_entry->url()); |
| 3622 } else { | 3622 } else { |
| 3623 // There are no subframe FrameNavigationEntries by default. | 3623 // There are no subframe FrameNavigationEntries by default. |
| 3624 EXPECT_EQ(0U, new_entry->root_node()->children.size()); | 3624 EXPECT_EQ(0U, new_entry->root_node()->children.size()); |
| 3625 } | 3625 } |
| 3626 } | 3626 } |
| 3627 | 3627 |
| 3628 // Verify that we can finish loading a page on restore if the PageState is | |
| 3629 // missing subframes. See https://crbug.com/638088. | |
| 3630 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
| 3631 FrameNavigationEntry_RestoreViaPartialPageState) { | |
| 3632 GURL main_url(embedded_test_server()->GetURL( | |
| 3633 "a.com", "/navigation_controller/inject_into_blank_iframe.html")); | |
| 3634 GURL blank_url(url::kAboutBlankURL); | |
| 3635 NavigationControllerImpl& controller = | |
| 3636 static_cast<NavigationControllerImpl&>( | |
| 3637 shell()->web_contents()->GetController()); | |
| 3638 FrameTreeNode* root = | |
| 3639 static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 3640 ->GetFrameTree() | |
| 3641 ->root(); | |
| 3642 | |
| 3643 // Create a NavigationEntry to restore, as if it had been loaded before. The | |
| 3644 // page has an about:blank iframe and injects content into it, but the | |
| 3645 // PageState lacks any subframe history items. This may happen during a | |
| 3646 // restore of a bad session or if the page has changed since the last visit. | |
| 3647 // Chrome should be robust to this and should be able to load the frame from | |
| 3648 // its default URL. | |
| 3649 std::unique_ptr<NavigationEntryImpl> restored_entry = | |
| 3650 NavigationEntryImpl::FromNavigationEntry( | |
| 3651 NavigationControllerImpl::CreateNavigationEntry( | |
| 3652 main_url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, | |
| 3653 std::string(), controller.GetBrowserContext())); | |
| 3654 restored_entry->SetPageID(0); | |
| 3655 restored_entry->SetPageState(PageState::CreateFromURL(main_url)); | |
| 3656 EXPECT_EQ(0U, restored_entry->root_node()->children.size()); | |
| 3657 | |
| 3658 // Restore the new entry in a new tab and verify the iframe loads and has | |
| 3659 // content injected into it. | |
| 3660 std::vector<std::unique_ptr<NavigationEntry>> entries; | |
| 3661 entries.push_back(std::move(restored_entry)); | |
| 3662 controller.Restore(entries.size() - 1, | |
| 3663 RestoreType::LAST_SESSION_EXITED_CLEANLY, &entries); | |
| 3664 ASSERT_EQ(0u, entries.size()); | |
| 3665 { | |
| 3666 TestNavigationObserver restore_observer(shell()->web_contents()); | |
| 3667 controller.LoadIfNecessary(); | |
| 3668 restore_observer.Wait(); | |
| 3669 } | |
| 3670 ASSERT_EQ(1U, root->child_count()); | |
| 3671 EXPECT_EQ(main_url, root->current_url()); | |
| 3672 EXPECT_EQ(blank_url, root->child_at(0)->current_url()); | |
| 3673 | |
| 3674 EXPECT_EQ(1, controller.GetEntryCount()); | |
| 3675 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | |
| 3676 NavigationEntryImpl* new_entry = controller.GetLastCommittedEntry(); | |
| 3677 | |
| 3678 // Verify subframe entries if they're enabled (e.g. in --site-per-process). | |
| 3679 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | |
| 3680 // The entry should have a FrameNavigationEntry for the blank subframe. | |
| 3681 EXPECT_EQ(main_url, new_entry->root_node()->frame_entry->url()); | |
| 3682 ASSERT_EQ(1U, new_entry->root_node()->children.size()); | |
| 3683 EXPECT_EQ(blank_url, | |
| 3684 new_entry->root_node()->children[0]->frame_entry->url()); | |
| 3685 } else { | |
| 3686 EXPECT_EQ(0U, new_entry->root_node()->children.size()); | |
| 3687 } | |
| 3688 | |
| 3689 // Verify that the parent was able to script the iframe. | |
| 3690 std::string expected_text("Injected text"); | |
| 3691 { | |
| 3692 std::string value; | |
| 3693 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 3694 root->child_at(0), | |
| 3695 "domAutomationController.send(document.body.innerHTML)", &value)); | |
| 3696 EXPECT_EQ(expected_text, value); | |
| 3697 } | |
| 3698 } | |
| 3699 | |
| 3700 // Verifies that the |frame_unique_name| is set to the correct frame, so that we | 3628 // Verifies that the |frame_unique_name| is set to the correct frame, so that we |
| 3701 // can match subframe FrameNavigationEntries to newly created frames after | 3629 // can match subframe FrameNavigationEntries to newly created frames after |
| 3702 // back/forward and restore. | 3630 // back/forward and restore. |
| 3703 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 3631 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 3704 FrameNavigationEntry_FrameUniqueName) { | 3632 FrameNavigationEntry_FrameUniqueName) { |
| 3705 const NavigationControllerImpl& controller = | 3633 const NavigationControllerImpl& controller = |
| 3706 static_cast<const NavigationControllerImpl&>( | 3634 static_cast<const NavigationControllerImpl&>( |
| 3707 shell()->web_contents()->GetController()); | 3635 shell()->web_contents()->GetController()); |
| 3708 | 3636 |
| 3709 // 1. Navigate the main frame. | 3637 // 1. Navigate the main frame. |
| (...skipping 2279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5989 &headers)); | 5917 &headers)); |
| 5990 | 5918 |
| 5991 // Verify the Origin and Referer headers. | 5919 // Verify the Origin and Referer headers. |
| 5992 EXPECT_THAT(headers, ::testing::HasSubstr("Origin: null")); | 5920 EXPECT_THAT(headers, ::testing::HasSubstr("Origin: null")); |
| 5993 EXPECT_THAT(headers, | 5921 EXPECT_THAT(headers, |
| 5994 ::testing::ContainsRegex( | 5922 ::testing::ContainsRegex( |
| 5995 "Referer: http://a.com:.*/form_that_posts_cross_site.html")); | 5923 "Referer: http://a.com:.*/form_that_posts_cross_site.html")); |
| 5996 } | 5924 } |
| 5997 | 5925 |
| 5998 } // namespace content | 5926 } // namespace content |
| OLD | NEW |