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

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

Issue 1505343002: Don't create unexpected OOPIFs in --isolate-extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 "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
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 // 1. Start on a page with a data URL iframe.
2706 GURL main_url_a(embedded_test_server()->GetURL(
2707 "a.com", "/navigation_controller/page_with_data_iframe.html"));
2708 GURL data_url("data:text/html,Subframe");
2709 EXPECT_TRUE(NavigateToURL(shell(), main_url_a));
2710 const NavigationControllerImpl& controller =
2711 static_cast<const NavigationControllerImpl&>(
2712 shell()->web_contents()->GetController());
2713 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
2714 ->GetFrameTree()
2715 ->root();
2716 EXPECT_EQ(main_url_a, root->current_url());
2717 EXPECT_EQ(data_url, root->child_at(0)->current_url());
2718
2719 // 2. Navigate the iframe cross-site.
2720 GURL frame_url_b(embedded_test_server()->GetURL(
2721 "b.com", "/navigation_controller/simple_page_1.html"));
2722 {
2723 TestNavigationObserver observer(shell()->web_contents());
ncarter (slow) 2015/12/08 20:14:13 This TNO (and its enclosing scope) might be unnece
Charlie Reis 2015/12/08 20:34:11 Done.
2724 NavigateFrameToURL(root->child_at(0), frame_url_b);
2725 observer.Wait();
2726 }
2727 EXPECT_EQ(main_url_a, root->current_url());
2728 EXPECT_EQ(frame_url_b, root->child_at(0)->current_url());
2729
2730 EXPECT_EQ(2, controller.GetEntryCount());
2731 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
2732 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry();
2733
2734 // 3. Create a NavigationEntry with the same PageState as |entry2|.
2735 scoped_ptr<NavigationEntryImpl> restored_entry =
2736 NavigationEntryImpl::FromNavigationEntry(
2737 NavigationControllerImpl::CreateNavigationEntry(
2738 main_url_a, Referrer(), ui::PAGE_TRANSITION_RELOAD, false,
2739 std::string(), controller.GetBrowserContext()));
2740 restored_entry->SetPageID(0);
2741 EXPECT_EQ(0U, restored_entry->root_node()->children.size());
2742 restored_entry->SetPageState(entry2->GetPageState());
2743
2744 // Verify subframe entries if they're enabled (e.g. in --site-per-process).
2745 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
ncarter (slow) 2015/12/08 20:14:13 I think you can EXPECT_TRUE(SiteIsolationPolicy::U
Charlie Reis 2015/12/08 20:34:11 Done, with AreCrossProcessFramesPossible.
2746 // The entry should have no SiteInstance in the FrameNavigationEntry for the
2747 // b.com subframe.
2748 EXPECT_FALSE(
2749 restored_entry->root_node()->children[0]->frame_entry->site_instance());
2750 } else {
2751 // There are no subframe FrameNavigationEntries by default.
2752 EXPECT_EQ(0U, restored_entry->root_node()->children.size());
2753 }
2754
2755 // 4. Restore the new entry in a new tab and verify the correct URLs load.
2756 std::vector<scoped_ptr<NavigationEntry>> entries;
2757 entries.push_back(restored_entry.Pass());
2758 Shell* new_shell = Shell::CreateNewWindow(
2759 controller.GetBrowserContext(), GURL::EmptyGURL(), nullptr, gfx::Size());
2760 FrameTreeNode* new_root =
2761 static_cast<WebContentsImpl*>(new_shell->web_contents())
2762 ->GetFrameTree()
2763 ->root();
2764 NavigationControllerImpl& new_controller =
2765 static_cast<NavigationControllerImpl&>(
2766 new_shell->web_contents()->GetController());
2767 new_controller.Restore(
2768 entries.size() - 1,
2769 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries);
2770 ASSERT_EQ(0u, entries.size());
2771 {
2772 TestNavigationObserver restore_observer(new_shell->web_contents());
2773 new_controller.LoadIfNecessary();
2774 restore_observer.Wait();
2775 }
2776 ASSERT_EQ(1U, new_root->child_count());
2777 EXPECT_EQ(main_url_a, new_root->current_url());
2778 EXPECT_EQ(frame_url_b, new_root->child_at(0)->current_url());
2779
2780 // The subframe should only be in a different SiteInstance if OOPIFs are
2781 // required for all sites.
2782 if (SiteIsolationPolicy::UseDedicatedProcessesForAllSites()) {
ncarter (slow) 2015/12/08 20:14:13 AreAllSitesIsolatedForTesting() would be a better
Charlie Reis 2015/12/08 20:34:11 Done.
2783 EXPECT_NE(new_root->current_frame_host()->GetSiteInstance(),
2784 new_root->child_at(0)->current_frame_host()->GetSiteInstance());
2785 } else {
2786 EXPECT_EQ(new_root->current_frame_host()->GetSiteInstance(),
2787 new_root->child_at(0)->current_frame_host()->GetSiteInstance());
2788 }
2789 }
2790
2683 namespace { 2791 namespace {
2684 2792
2685 // Loads |start_url|, then loads |stalled_url| which stalls. While the page is 2793 // 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 2794 // stalled, an in-page navigation happens. Make sure that all the navigations
2687 // are properly classified. 2795 // are properly classified.
2688 void DoReplaceStateWhilePending(Shell* shell, 2796 void DoReplaceStateWhilePending(Shell* shell,
2689 const GURL& start_url, 2797 const GURL& start_url,
2690 const GURL& stalled_url, 2798 const GURL& stalled_url,
2691 const std::string& replace_state_filename) { 2799 const std::string& replace_state_filename) {
2692 NavigationControllerImpl& controller = 2800 NavigationControllerImpl& controller =
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
3081 EXPECT_EQ(original_url, capturer.all_params()[1].url); 3189 EXPECT_EQ(original_url, capturer.all_params()[1].url);
3082 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); 3190 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL());
3083 } 3191 }
3084 3192
3085 // Make sure the renderer is still alive. 3193 // Make sure the renderer is still alive.
3086 EXPECT_TRUE( 3194 EXPECT_TRUE(
3087 ExecuteScript(shell()->web_contents(), "console.log('Success');")); 3195 ExecuteScript(shell()->web_contents(), "console.log('Success');"));
3088 } 3196 }
3089 3197
3090 } // namespace content 3198 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698