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

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

Issue 1816763002: OOPIF: Fix subframe back/forward after recreating FTNs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix AddOrUpdateEntry, add test Created 4 years, 8 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
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 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 EXPECT_EQ(2, controller.GetEntryCount()); 722 EXPECT_EQ(2, controller.GetEntryCount());
723 } 723 }
724 724
725 // Make a new entry ... 725 // Make a new entry ...
726 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 726 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
727 EXPECT_EQ(3, controller.GetEntryCount()); 727 EXPECT_EQ(3, controller.GetEntryCount());
728 728
729 // ... and replace it with a failed load. 729 // ... and replace it with a failed load.
730 // TODO(creis): Make this be NEW_PAGE along with the other location.replace 730 // TODO(creis): Make this be NEW_PAGE along with the other location.replace
731 // cases. There isn't much impact to having this be EXISTING_PAGE for now. 731 // cases. There isn't much impact to having this be EXISTING_PAGE for now.
732 // See https://crbug.com/317872. 732 // See https://crbug.com/596707.
733 { 733 {
734 FrameNavigateParamsCapturer capturer(root); 734 FrameNavigateParamsCapturer capturer(root);
735 NavigateToURLAndReplace(shell(), error_url); 735 NavigateToURLAndReplace(shell(), error_url);
736 capturer.Wait(); 736 capturer.Wait();
737 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); 737 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
738 NavigationEntry* entry = controller.GetLastCommittedEntry(); 738 NavigationEntry* entry = controller.GetLastCommittedEntry();
739 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); 739 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType());
740 EXPECT_EQ(3, controller.GetEntryCount()); 740 EXPECT_EQ(3, controller.GetEntryCount());
741 } 741 }
742 742
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 capturer.Wait(); 965 capturer.Wait();
966 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, 966 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT,
967 capturer.params().transition); 967 capturer.params().transition);
968 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); 968 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
969 EXPECT_FALSE(capturer.details().is_in_page); 969 EXPECT_FALSE(capturer.details().is_in_page);
970 } 970 }
971 971
972 { 972 {
973 // location.replace(). 973 // location.replace().
974 // TODO(creis): Change this to be NEW_PAGE with replacement in 974 // TODO(creis): Change this to be NEW_PAGE with replacement in
975 // https://crbug.com/317872. 975 // https://crbug.com/596707.
976 FrameNavigateParamsCapturer capturer(root); 976 FrameNavigateParamsCapturer capturer(root);
977 GURL frame_url(embedded_test_server()->GetURL( 977 GURL frame_url(embedded_test_server()->GetURL(
978 "/navigation_controller/simple_page_1.html")); 978 "/navigation_controller/simple_page_1.html"));
979 std::string script = "location.replace('" + frame_url.spec() + "')"; 979 std::string script = "location.replace('" + frame_url.spec() + "')";
980 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); 980 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
981 capturer.Wait(); 981 capturer.Wait();
982 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, 982 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT,
983 capturer.params().transition); 983 capturer.params().transition);
984 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); 984 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
985 EXPECT_FALSE(capturer.details().is_in_page); 985 EXPECT_FALSE(capturer.details().is_in_page);
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 EXPECT_EQ(frame_url_b, 2278 EXPECT_EQ(frame_url_b,
2279 entry4->root_node()->children[0]->frame_entry->url()); 2279 entry4->root_node()->children[0]->frame_entry->url());
2280 EXPECT_EQ( 2280 EXPECT_EQ(
2281 frame_url_c, 2281 frame_url_c,
2282 entry4->root_node()->children[0]->children[0]->frame_entry->url()); 2282 entry4->root_node()->children[0]->children[0]->frame_entry->url());
2283 } else { 2283 } else {
2284 // There are no subframe FrameNavigationEntries by default. 2284 // There are no subframe FrameNavigationEntries by default.
2285 EXPECT_EQ(0U, entry4->root_node()->children.size()); 2285 EXPECT_EQ(0U, entry4->root_node()->children.size());
2286 } 2286 }
2287 2287
2288 // Inject a JS value so that we can check for it later.
2289 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), "foo=3;"));
2290
2288 // 7. Go back again, to the data URL in the nested iframe. 2291 // 7. Go back again, to the data URL in the nested iframe.
2289 { 2292 {
2290 TestNavigationObserver back_load_observer(shell()->web_contents()); 2293 TestNavigationObserver back_load_observer(shell()->web_contents());
2291 shell()->web_contents()->GetController().GoBack(); 2294 shell()->web_contents()->GetController().GoBack();
2292 back_load_observer.Wait(); 2295 back_load_observer.Wait();
2293 } 2296 }
2294 ASSERT_EQ(1U, root->child_count()); 2297 ASSERT_EQ(1U, root->child_count());
2295 ASSERT_EQ(1U, root->child_at(0)->child_count()); 2298 ASSERT_EQ(1U, root->child_at(0)->child_count());
2296 EXPECT_EQ(main_url_a, root->current_url()); 2299 EXPECT_EQ(main_url_a, root->current_url());
2297 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url()); 2300 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url());
(...skipping 11 matching lines...) Expand all
2309 EXPECT_EQ(frame_url_b, 2312 EXPECT_EQ(frame_url_b,
2310 entry3->root_node()->children[0]->frame_entry->url()); 2313 entry3->root_node()->children[0]->frame_entry->url());
2311 EXPECT_EQ( 2314 EXPECT_EQ(
2312 data_url, 2315 data_url,
2313 entry3->root_node()->children[0]->children[0]->frame_entry->url()); 2316 entry3->root_node()->children[0]->children[0]->frame_entry->url());
2314 } else { 2317 } else {
2315 // There are no subframe FrameNavigationEntries by default. 2318 // There are no subframe FrameNavigationEntries by default.
2316 EXPECT_EQ(0U, entry3->root_node()->children.size()); 2319 EXPECT_EQ(0U, entry3->root_node()->children.size());
2317 } 2320 }
2318 2321
2322 // Verify that we did not reload the main frame. See https://crbug.com/586234.
2323 {
2324 int value = 0;
2325 EXPECT_TRUE(ExecuteScriptAndExtractInt(root->current_frame_host(),
2326 "domAutomationController.send(foo)",
2327 &value));
2328 EXPECT_EQ(3, value);
2329 }
2330
2319 // 8. Go back again, to the data URL in the first subframe. 2331 // 8. Go back again, to the data URL in the first subframe.
2320 { 2332 {
2321 TestNavigationObserver back_load_observer(shell()->web_contents()); 2333 TestNavigationObserver back_load_observer(shell()->web_contents());
2322 shell()->web_contents()->GetController().GoBack(); 2334 shell()->web_contents()->GetController().GoBack();
2323 back_load_observer.Wait(); 2335 back_load_observer.Wait();
2324 } 2336 }
2325 ASSERT_EQ(1U, root->child_count()); 2337 ASSERT_EQ(1U, root->child_count());
2326 ASSERT_EQ(0U, root->child_at(0)->child_count()); 2338 ASSERT_EQ(0U, root->child_at(0)->child_count());
2327 EXPECT_EQ(main_url_a, root->current_url()); 2339 EXPECT_EQ(main_url_a, root->current_url());
2328 EXPECT_EQ(data_url, root->child_at(0)->current_url()); 2340 EXPECT_EQ(data_url, root->child_at(0)->current_url());
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
2704 } else { 2716 } else {
2705 EXPECT_NE(main_site_instance, 2717 EXPECT_NE(main_site_instance,
2706 foo_subframe->current_frame_host()->GetSiteInstance()); 2718 foo_subframe->current_frame_host()->GetSiteInstance());
2707 } 2719 }
2708 2720
2709 foo_subframe_entry = 2721 foo_subframe_entry =
2710 controller.GetLastCommittedEntry()->GetFrameEntry(foo_subframe); 2722 controller.GetLastCommittedEntry()->GetFrameEntry(foo_subframe);
2711 EXPECT_EQ(named_subframe_name, foo_subframe_entry->frame_unique_name()); 2723 EXPECT_EQ(named_subframe_name, foo_subframe_entry->frame_unique_name());
2712 } 2724 }
2713 2725
2726 // Ensures that FrameNavigationEntries for dynamically added iframes can be
2727 // found correctly. If we don't find them based on unique name in
2728 // AddOrUpdateEntry, we'll end up using the old entry (with a PageState) during
alexmos 2016/04/06 17:14:22 nit: s/AddOrUpdateEntry/AddOrUpdateFrameEntry/ ?
Charlie Reis 2016/04/12 16:25:51 Done.
2729 // the transfer, causing the renderer to crash. See https://crbug.com/568768.
alexmos 2016/04/06 17:14:22 In 568768, the second problem was "restoring the s
alexmos 2016/04/06 17:14:22 I'm not sure I fully understand this bit: "we'll e
Charlie Reis 2016/04/12 16:25:51 Ah, yes, that comment could have been clearer. I'
Charlie Reis 2016/04/12 16:25:51 I'm not able to repro that part of the bug anymore
alexmos 2016/04/12 18:55:40 Acknowledged. The new comment is great.
alexmos 2016/04/12 18:55:40 Acknowledged.
2730 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
2731 FrameNavigationEntry_RepeatCreatedFrame) {
2732 const NavigationControllerImpl& controller =
2733 static_cast<const NavigationControllerImpl&>(
2734 shell()->web_contents()->GetController());
2735
2736 // 1. Navigate the main frame.
2737 GURL url(embedded_test_server()->GetURL(
2738 "/navigation_controller/page_with_links.html"));
2739 NavigateToURL(shell(), url);
alexmos 2016/04/06 17:14:22 nit: EXPECT_TRUE
Charlie Reis 2016/04/12 16:25:51 Done.
2740 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
2741 ->GetFrameTree()
2742 ->root();
2743 SiteInstance* main_site_instance =
2744 root->current_frame_host()->GetSiteInstance();
2745
2746 // 2. Add a cross-site subframe.
2747 GURL frame_url(embedded_test_server()->GetURL(
2748 "foo.com", "/navigation_controller/simple_page_1.html"));
2749 std::string script = "var iframe = document.createElement('iframe');"
2750 "iframe.src = '" + frame_url.spec() + "';"
2751 "document.body.appendChild(iframe);";
2752 {
2753 LoadCommittedCapturer capturer(shell()->web_contents());
2754 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
2755 capturer.Wait();
2756 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
2757 }
2758
2759 FrameTreeNode* subframe = root->child_at(0);
2760 if (AreAllSitesIsolatedForTesting()) {
2761 EXPECT_NE(main_site_instance,
2762 subframe->current_frame_host()->GetSiteInstance());
2763 }
2764 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
2765 FrameNavigationEntry* subframe_entry =
2766 controller.GetLastCommittedEntry()->GetFrameEntry(subframe);
2767 EXPECT_EQ(frame_url, subframe_entry->url());
2768 }
2769
2770 // 3. Reload the main frame.
2771 {
2772 FrameNavigateParamsCapturer capturer(root);
2773 shell()->web_contents()->GetController().Reload(false);
2774 capturer.Wait();
2775 EXPECT_EQ(ui::PAGE_TRANSITION_RELOAD, capturer.params().transition);
2776 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
2777 EXPECT_FALSE(capturer.details().is_in_page);
2778 }
2779
2780 // 4. Add the iframe again.
2781 {
2782 LoadCommittedCapturer capturer(shell()->web_contents());
2783 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
2784 capturer.Wait();
2785 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type());
2786 }
2787 if (AreAllSitesIsolatedForTesting()) {
2788 EXPECT_NE(main_site_instance,
2789 root->child_at(0)->current_frame_host()->GetSiteInstance());
2790 }
2791 }
2792
2714 // Verifies that item sequence numbers and document sequence numbers update 2793 // Verifies that item sequence numbers and document sequence numbers update
2715 // properly for main frames and subframes. 2794 // properly for main frames and subframes.
2716 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 2795 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
2717 FrameNavigationEntry_SequenceNumbers) { 2796 FrameNavigationEntry_SequenceNumbers) {
2718 const NavigationControllerImpl& controller = 2797 const NavigationControllerImpl& controller =
2719 static_cast<const NavigationControllerImpl&>( 2798 static_cast<const NavigationControllerImpl&>(
2720 shell()->web_contents()->GetController()); 2799 shell()->web_contents()->GetController());
2721 2800
2722 // 1. Navigate the main frame. 2801 // 1. Navigate the main frame.
2723 GURL url(embedded_test_server()->GetURL( 2802 GURL url(embedded_test_server()->GetURL(
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
3515 observer.Wait(); 3594 observer.Wait();
3516 3595
3517 EXPECT_EQ(3, controller.GetEntryCount()); 3596 EXPECT_EQ(3, controller.GetEntryCount());
3518 EXPECT_EQ(3, RendererHistoryLength(shell())); 3597 EXPECT_EQ(3, RendererHistoryLength(shell()));
3519 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 3598 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3520 3599
3521 EXPECT_EQ(frame_url_1, frame->current_url()); 3600 EXPECT_EQ(frame_url_1, frame->current_url());
3522 } 3601 }
3523 3602
3524 } // namespace content 3603 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698