 Chromium Code Reviews
 Chromium Code Reviews Issue 2316003002:
  Notify the renderer if a history navigation has no subframe items.  (Closed)
    
  
    Issue 2316003002:
  Notify the renderer if a history navigation has no subframe items.  (Closed) 
  | 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 3624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3635 EXPECT_EQ(main_url_a, new_entry->root_node()->frame_entry->url()); | 3635 EXPECT_EQ(main_url_a, new_entry->root_node()->frame_entry->url()); | 
| 3636 ASSERT_EQ(1U, new_entry->root_node()->children.size()); | 3636 ASSERT_EQ(1U, new_entry->root_node()->children.size()); | 
| 3637 EXPECT_EQ(frame_url_b, | 3637 EXPECT_EQ(frame_url_b, | 
| 3638 new_entry->root_node()->children[0]->frame_entry->url()); | 3638 new_entry->root_node()->children[0]->frame_entry->url()); | 
| 3639 } else { | 3639 } else { | 
| 3640 // There are no subframe FrameNavigationEntries by default. | 3640 // There are no subframe FrameNavigationEntries by default. | 
| 3641 EXPECT_EQ(0U, new_entry->root_node()->children.size()); | 3641 EXPECT_EQ(0U, new_entry->root_node()->children.size()); | 
| 3642 } | 3642 } | 
| 3643 } | 3643 } | 
| 3644 | 3644 | 
| 3645 // Verify that we can finish loading a page on restore if the PageState is | |
| 3646 // missing subframes. See https://crbug.com/638088. | |
| 3647 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
| 3648 FrameNavigationEntry_RestoreViaPartialPageState) { | |
| 3649 GURL main_url(embedded_test_server()->GetURL( | |
| 3650 "a.com", "/navigation_controller/inject_into_blank_iframe.html")); | |
| 3651 GURL blank_url(url::kAboutBlankURL); | |
| 3652 const NavigationControllerImpl& controller = | |
| 3653 static_cast<const NavigationControllerImpl&>( | |
| 3654 shell()->web_contents()->GetController()); | |
| 3655 | |
| 3656 // Create a NavigationEntry to restore, as if it had been loaded before. The | |
| 3657 // page has an about:blank iframe and injects content into it, but the | |
| 3658 // PageState lacks any subframe history items. This may happen during a | |
| 3659 // restore of a bad session or if the page has changed since the last visit. | |
| 3660 // Chrome should be robust to this and should be able to load the frame from | |
| 3661 // its default URL. | |
| 3662 std::unique_ptr<NavigationEntryImpl> restored_entry = | |
| 3663 NavigationEntryImpl::FromNavigationEntry( | |
| 3664 NavigationControllerImpl::CreateNavigationEntry( | |
| 3665 main_url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, | |
| 3666 std::string(), controller.GetBrowserContext())); | |
| 3667 restored_entry->SetPageID(0); | |
| 3668 restored_entry->SetPageState(PageState::CreateFromURL(main_url)); | |
| 3669 EXPECT_EQ(0U, restored_entry->root_node()->children.size()); | |
| 3670 | |
| 3671 // Restore the new entry in a new tab and verify the iframe loads and has | |
| 3672 // content injected into it. | |
| 3673 std::vector<std::unique_ptr<NavigationEntry>> entries; | |
| 3674 entries.push_back(std::move(restored_entry)); | |
| 3675 Shell* new_shell = Shell::CreateNewWindow( | |
| 3676 controller.GetBrowserContext(), GURL::EmptyGURL(), nullptr, gfx::Size()); | |
| 3677 FrameTreeNode* new_root = | |
| 3678 static_cast<WebContentsImpl*>(new_shell->web_contents()) | |
| 3679 ->GetFrameTree() | |
| 3680 ->root(); | |
| 3681 NavigationControllerImpl& new_controller = | |
| 3682 static_cast<NavigationControllerImpl&>( | |
| 3683 new_shell->web_contents()->GetController()); | |
| 3684 new_controller.Restore(entries.size() - 1, | |
| 
alexmos
2016/09/22 01:44:06
Is there a reason why the restore has to be in a n
 
Charlie Reis
2016/09/22 21:00:37
Good call.  Done.
 | |
| 3685 RestoreType::LAST_SESSION_EXITED_CLEANLY, &entries); | |
| 3686 ASSERT_EQ(0u, entries.size()); | |
| 3687 { | |
| 3688 TestNavigationObserver restore_observer(new_shell->web_contents()); | |
| 3689 new_controller.LoadIfNecessary(); | |
| 3690 restore_observer.Wait(); | |
| 3691 } | |
| 3692 ASSERT_EQ(1U, new_root->child_count()); | |
| 3693 EXPECT_EQ(main_url, new_root->current_url()); | |
| 3694 EXPECT_EQ(blank_url, new_root->child_at(0)->current_url()); | |
| 3695 | |
| 3696 EXPECT_EQ(1, new_controller.GetEntryCount()); | |
| 3697 EXPECT_EQ(0, new_controller.GetLastCommittedEntryIndex()); | |
| 3698 NavigationEntryImpl* new_entry = new_controller.GetLastCommittedEntry(); | |
| 3699 | |
| 3700 // Verify subframe entries if they're enabled (e.g. in --site-per-process). | |
| 
alexmos
2016/09/22 01:44:06
Since they're enabled everywhere now, how long unt
 
Charlie Reis
2016/09/22 21:00:37
We plan to rip out the old path in M56.  That make
 | |
| 3701 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | |
| 3702 // The entry should have a FrameNavigationEntry for the blank subframe. | |
| 3703 EXPECT_EQ(main_url, new_entry->root_node()->frame_entry->url()); | |
| 3704 ASSERT_EQ(1U, new_entry->root_node()->children.size()); | |
| 3705 EXPECT_EQ(blank_url, | |
| 3706 new_entry->root_node()->children[0]->frame_entry->url()); | |
| 3707 } else { | |
| 3708 EXPECT_EQ(0U, new_entry->root_node()->children.size()); | |
| 3709 } | |
| 3710 | |
| 3711 // Verify that the parent was able to script the iframe. | |
| 3712 std::string expected_text("Injected text"); | |
| 3713 { | |
| 3714 std::string value; | |
| 3715 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 3716 new_root->child_at(0), | |
| 3717 "domAutomationController.send(document.body.innerHTML)", &value)); | |
| 3718 EXPECT_EQ(expected_text, value); | |
| 3719 } | |
| 3720 } | |
| 3721 | |
| 3645 // Verifies that the |frame_unique_name| is set to the correct frame, so that we | 3722 // Verifies that the |frame_unique_name| is set to the correct frame, so that we | 
| 3646 // can match subframe FrameNavigationEntries to newly created frames after | 3723 // can match subframe FrameNavigationEntries to newly created frames after | 
| 3647 // back/forward and restore. | 3724 // back/forward and restore. | 
| 3648 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 3725 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 
| 3649 FrameNavigationEntry_FrameUniqueName) { | 3726 FrameNavigationEntry_FrameUniqueName) { | 
| 3650 const NavigationControllerImpl& controller = | 3727 const NavigationControllerImpl& controller = | 
| 3651 static_cast<const NavigationControllerImpl&>( | 3728 static_cast<const NavigationControllerImpl&>( | 
| 3652 shell()->web_contents()->GetController()); | 3729 shell()->web_contents()->GetController()); | 
| 3653 | 3730 | 
| 3654 // 1. Navigate the main frame. | 3731 // 1. Navigate the main frame. | 
| (...skipping 2387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6042 content::FaviconStatus& favicon_status2 = entry->GetFavicon(); | 6119 content::FaviconStatus& favicon_status2 = entry->GetFavicon(); | 
| 6043 EXPECT_TRUE(favicon_status2.valid); | 6120 EXPECT_TRUE(favicon_status2.valid); | 
| 6044 | 6121 | 
| 6045 ASSERT_TRUE(RendererLocationReplace(shell(), GURL("data:text/html,page2"))); | 6122 ASSERT_TRUE(RendererLocationReplace(shell(), GURL("data:text/html,page2"))); | 
| 6046 entry = controller.GetLastCommittedEntry(); | 6123 entry = controller.GetLastCommittedEntry(); | 
| 6047 content::FaviconStatus& favicon_status3 = entry->GetFavicon(); | 6124 content::FaviconStatus& favicon_status3 = entry->GetFavicon(); | 
| 6048 EXPECT_FALSE(favicon_status3.valid); | 6125 EXPECT_FALSE(favicon_status3.valid); | 
| 6049 } | 6126 } | 
| 6050 | 6127 | 
| 6051 } // namespace content | 6128 } // namespace content | 
| OLD | NEW |