| 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 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 EXPECT_EQ(2, controller.GetEntryCount()); | 721 EXPECT_EQ(2, controller.GetEntryCount()); |
| 722 } | 722 } |
| 723 | 723 |
| 724 // Make a new entry ... | 724 // Make a new entry ... |
| 725 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 725 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 726 EXPECT_EQ(3, controller.GetEntryCount()); | 726 EXPECT_EQ(3, controller.GetEntryCount()); |
| 727 | 727 |
| 728 // ... and replace it with a failed load. | 728 // ... and replace it with a failed load. |
| 729 // TODO(creis): Make this be NEW_PAGE along with the other location.replace | 729 // TODO(creis): Make this be NEW_PAGE along with the other location.replace |
| 730 // cases. There isn't much impact to having this be EXISTING_PAGE for now. | 730 // cases. There isn't much impact to having this be EXISTING_PAGE for now. |
| 731 // See https://crbug.com/596707. | 731 // See https://crbug.com/317872. |
| 732 { | 732 { |
| 733 FrameNavigateParamsCapturer capturer(root); | 733 FrameNavigateParamsCapturer capturer(root); |
| 734 NavigateToURLAndReplace(shell(), error_url); | 734 NavigateToURLAndReplace(shell(), error_url); |
| 735 capturer.Wait(); | 735 capturer.Wait(); |
| 736 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | 736 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); |
| 737 NavigationEntry* entry = controller.GetLastCommittedEntry(); | 737 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 738 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); | 738 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
| 739 EXPECT_EQ(3, controller.GetEntryCount()); | 739 EXPECT_EQ(3, controller.GetEntryCount()); |
| 740 } | 740 } |
| 741 | 741 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 capturer.Wait(); | 964 capturer.Wait(); |
| 965 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | 965 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
| 966 capturer.params().transition); | 966 capturer.params().transition); |
| 967 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | 967 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); |
| 968 EXPECT_FALSE(capturer.details().is_in_page); | 968 EXPECT_FALSE(capturer.details().is_in_page); |
| 969 } | 969 } |
| 970 | 970 |
| 971 { | 971 { |
| 972 // location.replace(). | 972 // location.replace(). |
| 973 // TODO(creis): Change this to be NEW_PAGE with replacement in | 973 // TODO(creis): Change this to be NEW_PAGE with replacement in |
| 974 // https://crbug.com/596707. | 974 // https://crbug.com/317872. |
| 975 FrameNavigateParamsCapturer capturer(root); | 975 FrameNavigateParamsCapturer capturer(root); |
| 976 GURL frame_url(embedded_test_server()->GetURL( | 976 GURL frame_url(embedded_test_server()->GetURL( |
| 977 "/navigation_controller/simple_page_1.html")); | 977 "/navigation_controller/simple_page_1.html")); |
| 978 std::string script = "location.replace('" + frame_url.spec() + "')"; | 978 std::string script = "location.replace('" + frame_url.spec() + "')"; |
| 979 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 979 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 980 capturer.Wait(); | 980 capturer.Wait(); |
| 981 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | 981 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
| 982 capturer.params().transition); | 982 capturer.params().transition); |
| 983 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | 983 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); |
| 984 EXPECT_FALSE(capturer.details().is_in_page); | 984 EXPECT_FALSE(capturer.details().is_in_page); |
| (...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2277 EXPECT_EQ(frame_url_b, | 2277 EXPECT_EQ(frame_url_b, |
| 2278 entry4->root_node()->children[0]->frame_entry->url()); | 2278 entry4->root_node()->children[0]->frame_entry->url()); |
| 2279 EXPECT_EQ( | 2279 EXPECT_EQ( |
| 2280 frame_url_c, | 2280 frame_url_c, |
| 2281 entry4->root_node()->children[0]->children[0]->frame_entry->url()); | 2281 entry4->root_node()->children[0]->children[0]->frame_entry->url()); |
| 2282 } else { | 2282 } else { |
| 2283 // There are no subframe FrameNavigationEntries by default. | 2283 // There are no subframe FrameNavigationEntries by default. |
| 2284 EXPECT_EQ(0U, entry4->root_node()->children.size()); | 2284 EXPECT_EQ(0U, entry4->root_node()->children.size()); |
| 2285 } | 2285 } |
| 2286 | 2286 |
| 2287 // Inject a JS value so that we can check for it later. | |
| 2288 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), "foo=3;")); | |
| 2289 | |
| 2290 // 7. Go back again, to the data URL in the nested iframe. | 2287 // 7. Go back again, to the data URL in the nested iframe. |
| 2291 { | 2288 { |
| 2292 TestNavigationObserver back_load_observer(shell()->web_contents()); | 2289 TestNavigationObserver back_load_observer(shell()->web_contents()); |
| 2293 shell()->web_contents()->GetController().GoBack(); | 2290 shell()->web_contents()->GetController().GoBack(); |
| 2294 back_load_observer.Wait(); | 2291 back_load_observer.Wait(); |
| 2295 } | 2292 } |
| 2296 ASSERT_EQ(1U, root->child_count()); | 2293 ASSERT_EQ(1U, root->child_count()); |
| 2297 ASSERT_EQ(1U, root->child_at(0)->child_count()); | 2294 ASSERT_EQ(1U, root->child_at(0)->child_count()); |
| 2298 EXPECT_EQ(main_url_a, root->current_url()); | 2295 EXPECT_EQ(main_url_a, root->current_url()); |
| 2299 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url()); | 2296 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2311 EXPECT_EQ(frame_url_b, | 2308 EXPECT_EQ(frame_url_b, |
| 2312 entry3->root_node()->children[0]->frame_entry->url()); | 2309 entry3->root_node()->children[0]->frame_entry->url()); |
| 2313 EXPECT_EQ( | 2310 EXPECT_EQ( |
| 2314 data_url, | 2311 data_url, |
| 2315 entry3->root_node()->children[0]->children[0]->frame_entry->url()); | 2312 entry3->root_node()->children[0]->children[0]->frame_entry->url()); |
| 2316 } else { | 2313 } else { |
| 2317 // There are no subframe FrameNavigationEntries by default. | 2314 // There are no subframe FrameNavigationEntries by default. |
| 2318 EXPECT_EQ(0U, entry3->root_node()->children.size()); | 2315 EXPECT_EQ(0U, entry3->root_node()->children.size()); |
| 2319 } | 2316 } |
| 2320 | 2317 |
| 2321 // Verify that we did not reload the main frame. See https://crbug.com/586234. | |
| 2322 { | |
| 2323 int value = 0; | |
| 2324 EXPECT_TRUE(ExecuteScriptAndExtractInt(root->current_frame_host(), | |
| 2325 "domAutomationController.send(foo)", | |
| 2326 &value)); | |
| 2327 EXPECT_EQ(3, value); | |
| 2328 } | |
| 2329 | |
| 2330 // 8. Go back again, to the data URL in the first subframe. | 2318 // 8. Go back again, to the data URL in the first subframe. |
| 2331 { | 2319 { |
| 2332 TestNavigationObserver back_load_observer(shell()->web_contents()); | 2320 TestNavigationObserver back_load_observer(shell()->web_contents()); |
| 2333 shell()->web_contents()->GetController().GoBack(); | 2321 shell()->web_contents()->GetController().GoBack(); |
| 2334 back_load_observer.Wait(); | 2322 back_load_observer.Wait(); |
| 2335 } | 2323 } |
| 2336 ASSERT_EQ(1U, root->child_count()); | 2324 ASSERT_EQ(1U, root->child_count()); |
| 2337 ASSERT_EQ(0U, root->child_at(0)->child_count()); | 2325 ASSERT_EQ(0U, root->child_at(0)->child_count()); |
| 2338 EXPECT_EQ(main_url_a, root->current_url()); | 2326 EXPECT_EQ(main_url_a, root->current_url()); |
| 2339 EXPECT_EQ(data_url, root->child_at(0)->current_url()); | 2327 EXPECT_EQ(data_url, root->child_at(0)->current_url()); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2715 } else { | 2703 } else { |
| 2716 EXPECT_NE(main_site_instance, | 2704 EXPECT_NE(main_site_instance, |
| 2717 foo_subframe->current_frame_host()->GetSiteInstance()); | 2705 foo_subframe->current_frame_host()->GetSiteInstance()); |
| 2718 } | 2706 } |
| 2719 | 2707 |
| 2720 foo_subframe_entry = | 2708 foo_subframe_entry = |
| 2721 controller.GetLastCommittedEntry()->GetFrameEntry(foo_subframe); | 2709 controller.GetLastCommittedEntry()->GetFrameEntry(foo_subframe); |
| 2722 EXPECT_EQ(named_subframe_name, foo_subframe_entry->frame_unique_name()); | 2710 EXPECT_EQ(named_subframe_name, foo_subframe_entry->frame_unique_name()); |
| 2723 } | 2711 } |
| 2724 | 2712 |
| 2725 // Ensures that FrameNavigationEntries for dynamically added iframes can be | |
| 2726 // found correctly when cloning them during a transfer. If we don't look for | |
| 2727 // them based on unique name in AddOrUpdateFrameEntry, the FrameTreeNode ID | |
| 2728 // mismatch will cause us to create a second FrameNavigationEntry during the | |
| 2729 // transfer. Later, we'll find the wrong FrameNavigationEntry (the earlier one | |
| 2730 // from the clone which still has a PageState), and this will cause the renderer | |
| 2731 // to crash in NavigateInternal because the PageState is present but the page_id | |
| 2732 // is -1 (similar to https://crbug.com/568703). See https://crbug.com/568768. | |
| 2733 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
| 2734 FrameNavigationEntry_RepeatCreatedFrame) { | |
| 2735 NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>( | |
| 2736 shell()->web_contents()->GetController()); | |
| 2737 | |
| 2738 // 1. Navigate the main frame. | |
| 2739 GURL url(embedded_test_server()->GetURL( | |
| 2740 "/navigation_controller/page_with_links.html")); | |
| 2741 EXPECT_TRUE(NavigateToURL(shell(), url)); | |
| 2742 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 2743 ->GetFrameTree() | |
| 2744 ->root(); | |
| 2745 SiteInstance* main_site_instance = | |
| 2746 root->current_frame_host()->GetSiteInstance(); | |
| 2747 | |
| 2748 // 2. Add a cross-site subframe. | |
| 2749 GURL frame_url(embedded_test_server()->GetURL( | |
| 2750 "foo.com", "/navigation_controller/simple_page_1.html")); | |
| 2751 std::string script = "var iframe = document.createElement('iframe');" | |
| 2752 "iframe.src = '" + frame_url.spec() + "';" | |
| 2753 "document.body.appendChild(iframe);"; | |
| 2754 { | |
| 2755 LoadCommittedCapturer capturer(shell()->web_contents()); | |
| 2756 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script)); | |
| 2757 capturer.Wait(); | |
| 2758 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | |
| 2759 } | |
| 2760 | |
| 2761 FrameTreeNode* subframe = root->child_at(0); | |
| 2762 if (AreAllSitesIsolatedForTesting()) { | |
| 2763 EXPECT_NE(main_site_instance, | |
| 2764 subframe->current_frame_host()->GetSiteInstance()); | |
| 2765 } | |
| 2766 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | |
| 2767 FrameNavigationEntry* subframe_entry = | |
| 2768 controller.GetLastCommittedEntry()->GetFrameEntry(subframe); | |
| 2769 EXPECT_EQ(frame_url, subframe_entry->url()); | |
| 2770 } | |
| 2771 | |
| 2772 // 3. Reload the main frame. | |
| 2773 { | |
| 2774 FrameNavigateParamsCapturer capturer(root); | |
| 2775 controller.Reload(false); | |
| 2776 capturer.Wait(); | |
| 2777 EXPECT_EQ(ui::PAGE_TRANSITION_RELOAD, capturer.params().transition); | |
| 2778 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | |
| 2779 EXPECT_FALSE(capturer.details().is_in_page); | |
| 2780 } | |
| 2781 | |
| 2782 // 4. Add the iframe again. | |
| 2783 { | |
| 2784 LoadCommittedCapturer capturer(shell()->web_contents()); | |
| 2785 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script)); | |
| 2786 capturer.Wait(); | |
| 2787 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | |
| 2788 } | |
| 2789 if (AreAllSitesIsolatedForTesting()) { | |
| 2790 EXPECT_NE(main_site_instance, | |
| 2791 root->child_at(0)->current_frame_host()->GetSiteInstance()); | |
| 2792 } | |
| 2793 } | |
| 2794 | |
| 2795 // Verifies that item sequence numbers and document sequence numbers update | 2713 // Verifies that item sequence numbers and document sequence numbers update |
| 2796 // properly for main frames and subframes. | 2714 // properly for main frames and subframes. |
| 2797 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 2715 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 2798 FrameNavigationEntry_SequenceNumbers) { | 2716 FrameNavigationEntry_SequenceNumbers) { |
| 2799 const NavigationControllerImpl& controller = | 2717 const NavigationControllerImpl& controller = |
| 2800 static_cast<const NavigationControllerImpl&>( | 2718 static_cast<const NavigationControllerImpl&>( |
| 2801 shell()->web_contents()->GetController()); | 2719 shell()->web_contents()->GetController()); |
| 2802 | 2720 |
| 2803 // 1. Navigate the main frame. | 2721 // 1. Navigate the main frame. |
| 2804 GURL url(embedded_test_server()->GetURL( | 2722 GURL url(embedded_test_server()->GetURL( |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3596 observer.Wait(); | 3514 observer.Wait(); |
| 3597 | 3515 |
| 3598 EXPECT_EQ(3, controller.GetEntryCount()); | 3516 EXPECT_EQ(3, controller.GetEntryCount()); |
| 3599 EXPECT_EQ(3, RendererHistoryLength(shell())); | 3517 EXPECT_EQ(3, RendererHistoryLength(shell())); |
| 3600 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 3518 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 3601 | 3519 |
| 3602 EXPECT_EQ(frame_url_1, frame->current_url()); | 3520 EXPECT_EQ(frame_url_1, frame->current_url()); |
| 3603 } | 3521 } |
| 3604 | 3522 |
| 3605 } // namespace content | 3523 } // namespace content |
| OLD | NEW |