| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" |
| 6 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/frame_host/frame_navigation_entry.h" | 9 #include "content/browser/frame_host/frame_navigation_entry.h" |
| 9 #include "content/browser/frame_host/frame_tree.h" | 10 #include "content/browser/frame_host/frame_tree.h" |
| 10 #include "content/browser/frame_host/navigation_controller_impl.h" | 11 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 11 #include "content/browser/frame_host/navigation_entry_impl.h" | 12 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 12 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
| 13 #include "content/common/site_isolation_policy.h" | 14 #include "content/common/site_isolation_policy.h" |
| 14 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/browser/resource_controller.h" | 16 #include "content/public/browser/resource_controller.h" |
| 16 #include "content/public/browser/resource_dispatcher_host.h" | 17 #include "content/public/browser/resource_dispatcher_host.h" |
| 17 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 18 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 18 #include "content/public/browser/resource_throttle.h" | 19 #include "content/public/browser/resource_throttle.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
| 21 #include "content/public/common/bindings_policy.h" | 22 #include "content/public/common/bindings_policy.h" |
| 22 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
| 23 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
| 24 #include "content/public/test/content_browser_test.h" | 25 #include "content/public/test/content_browser_test.h" |
| 25 #include "content/public/test/content_browser_test_utils.h" | 26 #include "content/public/test/content_browser_test_utils.h" |
| 26 #include "content/public/test/test_navigation_observer.h" | 27 #include "content/public/test/test_navigation_observer.h" |
| 27 #include "content/public/test/test_utils.h" | 28 #include "content/public/test/test_utils.h" |
| 28 #include "content/shell/browser/shell.h" | 29 #include "content/shell/browser/shell.h" |
| 30 #include "content/shell/common/shell_switches.h" |
| 29 #include "content/test/content_browser_test_utils_internal.h" | 31 #include "content/test/content_browser_test_utils_internal.h" |
| 30 #include "net/dns/mock_host_resolver.h" | 32 #include "net/dns/mock_host_resolver.h" |
| 31 #include "net/test/embedded_test_server/embedded_test_server.h" | 33 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 32 #include "net/test/url_request/url_request_failed_job.h" | 34 #include "net/test/url_request/url_request_failed_job.h" |
| 33 | 35 |
| 34 namespace content { | 36 namespace content { |
| 35 | 37 |
| 36 class NavigationControllerBrowserTest : public ContentBrowserTest { | 38 class NavigationControllerBrowserTest : public ContentBrowserTest { |
| 37 protected: | 39 protected: |
| 38 void SetUpOnMainThread() override { | 40 void SetUpOnMainThread() override { |
| (...skipping 2634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2673 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 2675 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 2674 | 2676 |
| 2675 subframe_entry = controller.GetLastCommittedEntry()->GetFrameEntry(subframe); | 2677 subframe_entry = controller.GetLastCommittedEntry()->GetFrameEntry(subframe); |
| 2676 int64 isn_4 = subframe_entry->item_sequence_number(); | 2678 int64 isn_4 = subframe_entry->item_sequence_number(); |
| 2677 int64 dsn_4 = subframe_entry->document_sequence_number(); | 2679 int64 dsn_4 = subframe_entry->document_sequence_number(); |
| 2678 EXPECT_NE(-1, isn_4); | 2680 EXPECT_NE(-1, isn_4); |
| 2679 EXPECT_NE(isn_3, isn_4); | 2681 EXPECT_NE(isn_3, isn_4); |
| 2680 EXPECT_EQ(dsn_3, dsn_4); | 2682 EXPECT_EQ(dsn_3, dsn_4); |
| 2681 } | 2683 } |
| 2682 | 2684 |
| 2685 // Support a set of tests that isolate only a subset of sites with |
| 2686 // out-of-process iframes (OOPIFs). |
| 2687 class NavigationControllerOopifBrowserTest |
| 2688 : public NavigationControllerBrowserTest { |
| 2689 public: |
| 2690 NavigationControllerOopifBrowserTest() {} |
| 2691 |
| 2692 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 2693 // Enable the OOPIF framework but only isolate sites from a single TLD. |
| 2694 command_line->AppendSwitchASCII(switches::kIsolateSitesForTesting, "*.is"); |
| 2695 } |
| 2696 |
| 2697 private: |
| 2698 DISALLOW_COPY_AND_ASSIGN(NavigationControllerOopifBrowserTest); |
| 2699 }; |
| 2700 |
| 2701 // Verify that restoring a NavigationEntry with cross-site subframes does not |
| 2702 // create out-of-process iframes unless the current SiteIsolationPolicy says to. |
| 2703 IN_PROC_BROWSER_TEST_F(NavigationControllerOopifBrowserTest, |
| 2704 RestoreWithoutExtraOopifs) { |
| 2705 // This test requires OOPIFs to be possible. |
| 2706 EXPECT_TRUE(SiteIsolationPolicy::AreCrossProcessFramesPossible()); |
| 2707 |
| 2708 // 1. Start on a page with a data URL iframe. |
| 2709 GURL main_url_a(embedded_test_server()->GetURL( |
| 2710 "a.com", "/navigation_controller/page_with_data_iframe.html")); |
| 2711 GURL data_url("data:text/html,Subframe"); |
| 2712 EXPECT_TRUE(NavigateToURL(shell(), main_url_a)); |
| 2713 const NavigationControllerImpl& controller = |
| 2714 static_cast<const NavigationControllerImpl&>( |
| 2715 shell()->web_contents()->GetController()); |
| 2716 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 2717 ->GetFrameTree() |
| 2718 ->root(); |
| 2719 EXPECT_EQ(main_url_a, root->current_url()); |
| 2720 EXPECT_EQ(data_url, root->child_at(0)->current_url()); |
| 2721 |
| 2722 // 2. Navigate the iframe cross-site. |
| 2723 GURL frame_url_b(embedded_test_server()->GetURL( |
| 2724 "b.com", "/navigation_controller/simple_page_1.html")); |
| 2725 NavigateFrameToURL(root->child_at(0), frame_url_b); |
| 2726 EXPECT_EQ(main_url_a, root->current_url()); |
| 2727 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url()); |
| 2728 |
| 2729 EXPECT_EQ(2, controller.GetEntryCount()); |
| 2730 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 2731 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry(); |
| 2732 |
| 2733 // 3. Create a NavigationEntry with the same PageState as |entry2|. |
| 2734 scoped_ptr<NavigationEntryImpl> restored_entry = |
| 2735 NavigationEntryImpl::FromNavigationEntry( |
| 2736 NavigationControllerImpl::CreateNavigationEntry( |
| 2737 main_url_a, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, |
| 2738 std::string(), controller.GetBrowserContext())); |
| 2739 restored_entry->SetPageID(0); |
| 2740 EXPECT_EQ(0U, restored_entry->root_node()->children.size()); |
| 2741 restored_entry->SetPageState(entry2->GetPageState()); |
| 2742 |
| 2743 // The entry should have no SiteInstance in the FrameNavigationEntry for the |
| 2744 // b.com subframe. |
| 2745 EXPECT_FALSE( |
| 2746 restored_entry->root_node()->children[0]->frame_entry->site_instance()); |
| 2747 |
| 2748 // 4. Restore the new entry in a new tab and verify the correct URLs load. |
| 2749 std::vector<scoped_ptr<NavigationEntry>> entries; |
| 2750 entries.push_back(restored_entry.Pass()); |
| 2751 Shell* new_shell = Shell::CreateNewWindow( |
| 2752 controller.GetBrowserContext(), GURL::EmptyGURL(), nullptr, gfx::Size()); |
| 2753 FrameTreeNode* new_root = |
| 2754 static_cast<WebContentsImpl*>(new_shell->web_contents()) |
| 2755 ->GetFrameTree() |
| 2756 ->root(); |
| 2757 NavigationControllerImpl& new_controller = |
| 2758 static_cast<NavigationControllerImpl&>( |
| 2759 new_shell->web_contents()->GetController()); |
| 2760 new_controller.Restore( |
| 2761 entries.size() - 1, |
| 2762 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); |
| 2763 ASSERT_EQ(0u, entries.size()); |
| 2764 { |
| 2765 TestNavigationObserver restore_observer(new_shell->web_contents()); |
| 2766 new_controller.LoadIfNecessary(); |
| 2767 restore_observer.Wait(); |
| 2768 } |
| 2769 ASSERT_EQ(1U, new_root->child_count()); |
| 2770 EXPECT_EQ(main_url_a, new_root->current_url()); |
| 2771 EXPECT_EQ(frame_url_b, new_root->child_at(0)->current_url()); |
| 2772 |
| 2773 // The subframe should only be in a different SiteInstance if OOPIFs are |
| 2774 // required for all sites. |
| 2775 if (AreAllSitesIsolatedForTesting()) { |
| 2776 EXPECT_NE(new_root->current_frame_host()->GetSiteInstance(), |
| 2777 new_root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 2778 } else { |
| 2779 EXPECT_EQ(new_root->current_frame_host()->GetSiteInstance(), |
| 2780 new_root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 2781 } |
| 2782 } |
| 2783 |
| 2683 namespace { | 2784 namespace { |
| 2684 | 2785 |
| 2685 // Loads |start_url|, then loads |stalled_url| which stalls. While the page is | 2786 // Loads |start_url|, then loads |stalled_url| which stalls. While the page is |
| 2686 // stalled, an in-page navigation happens. Make sure that all the navigations | 2787 // stalled, an in-page navigation happens. Make sure that all the navigations |
| 2687 // are properly classified. | 2788 // are properly classified. |
| 2688 void DoReplaceStateWhilePending(Shell* shell, | 2789 void DoReplaceStateWhilePending(Shell* shell, |
| 2689 const GURL& start_url, | 2790 const GURL& start_url, |
| 2690 const GURL& stalled_url, | 2791 const GURL& stalled_url, |
| 2691 const std::string& replace_state_filename) { | 2792 const std::string& replace_state_filename) { |
| 2692 NavigationControllerImpl& controller = | 2793 NavigationControllerImpl& controller = |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3081 EXPECT_EQ(original_url, capturer.all_params()[1].url); | 3182 EXPECT_EQ(original_url, capturer.all_params()[1].url); |
| 3082 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); | 3183 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); |
| 3083 } | 3184 } |
| 3084 | 3185 |
| 3085 // Make sure the renderer is still alive. | 3186 // Make sure the renderer is still alive. |
| 3086 EXPECT_TRUE( | 3187 EXPECT_TRUE( |
| 3087 ExecuteScript(shell()->web_contents(), "console.log('Success');")); | 3188 ExecuteScript(shell()->web_contents(), "console.log('Success');")); |
| 3088 } | 3189 } |
| 3089 | 3190 |
| 3090 } // namespace content | 3191 } // namespace content |
| OLD | NEW |