Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_browsertest.cc

Issue 2383303002: Notify the renderer if a history navigation has no subframe items. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/frame_host/navigation_entry_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(
3663 entries.size() - 1,
3664 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries);
3665 ASSERT_EQ(0u, entries.size());
3666 {
3667 TestNavigationObserver restore_observer(shell()->web_contents());
3668 controller.LoadIfNecessary();
3669 restore_observer.Wait();
3670 }
3671 ASSERT_EQ(1U, root->child_count());
3672 EXPECT_EQ(main_url, root->current_url());
3673 EXPECT_EQ(blank_url, root->child_at(0)->current_url());
3674
3675 EXPECT_EQ(1, controller.GetEntryCount());
3676 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3677 NavigationEntryImpl* new_entry = controller.GetLastCommittedEntry();
3678
3679 // Verify subframe entries if they're enabled (e.g. in --site-per-process).
3680 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
3681 // The entry should have a FrameNavigationEntry for the blank subframe.
3682 EXPECT_EQ(main_url, new_entry->root_node()->frame_entry->url());
3683 ASSERT_EQ(1U, new_entry->root_node()->children.size());
3684 EXPECT_EQ(blank_url,
3685 new_entry->root_node()->children[0]->frame_entry->url());
3686 } else {
3687 EXPECT_EQ(0U, new_entry->root_node()->children.size());
3688 }
3689
3690 // Verify that the parent was able to script the iframe.
3691 std::string expected_text("Injected text");
3692 {
3693 std::string value;
3694 EXPECT_TRUE(ExecuteScriptAndExtractString(
3695 root->child_at(0),
3696 "domAutomationController.send(document.body.innerHTML)", &value));
3697 EXPECT_EQ(expected_text, value);
3698 }
3699 }
3700
3628 // Verifies that the |frame_unique_name| is set to the correct frame, so that we 3701 // Verifies that the |frame_unique_name| is set to the correct frame, so that we
3629 // can match subframe FrameNavigationEntries to newly created frames after 3702 // can match subframe FrameNavigationEntries to newly created frames after
3630 // back/forward and restore. 3703 // back/forward and restore.
3631 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 3704 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
3632 FrameNavigationEntry_FrameUniqueName) { 3705 FrameNavigationEntry_FrameUniqueName) {
3633 const NavigationControllerImpl& controller = 3706 const NavigationControllerImpl& controller =
3634 static_cast<const NavigationControllerImpl&>( 3707 static_cast<const NavigationControllerImpl&>(
3635 shell()->web_contents()->GetController()); 3708 shell()->web_contents()->GetController());
3636 3709
3637 // 1. Navigate the main frame. 3710 // 1. Navigate the main frame.
(...skipping 2279 matching lines...) Expand 10 before | Expand all | Expand 10 after
5917 &headers)); 5990 &headers));
5918 5991
5919 // Verify the Origin and Referer headers. 5992 // Verify the Origin and Referer headers.
5920 EXPECT_THAT(headers, ::testing::HasSubstr("Origin: null")); 5993 EXPECT_THAT(headers, ::testing::HasSubstr("Origin: null"));
5921 EXPECT_THAT(headers, 5994 EXPECT_THAT(headers,
5922 ::testing::ContainsRegex( 5995 ::testing::ContainsRegex(
5923 "Referer: http://a.com:.*/form_that_posts_cross_site.html")); 5996 "Referer: http://a.com:.*/form_that_posts_cross_site.html"));
5924 } 5997 }
5925 5998
5926 } // namespace content 5999 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/navigation_entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698