| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" | 
| 6 | 6 | 
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" | 
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" | 
|  | 9 #include "base/strings/utf_string_conversions.h" | 
| 9 #include "content/browser/frame_host/cross_process_frame_connector.h" | 10 #include "content/browser/frame_host/cross_process_frame_connector.h" | 
| 10 #include "content/browser/frame_host/frame_tree.h" | 11 #include "content/browser/frame_host/frame_tree.h" | 
| 11 #include "content/browser/frame_host/navigator.h" | 12 #include "content/browser/frame_host/navigator.h" | 
| 12 #include "content/browser/frame_host/render_frame_proxy_host.h" | 13 #include "content/browser/frame_host/render_frame_proxy_host.h" | 
| 13 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 14 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 
| 14 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" | 
| 15 #include "content/browser/web_contents/web_contents_impl.h" | 16 #include "content/browser/web_contents/web_contents_impl.h" | 
| 16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" | 
| 17 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" | 
| 18 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" | 
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 224   // for commit. | 225   // for commit. | 
| 225   std::string script = base::StringPrintf( | 226   std::string script = base::StringPrintf( | 
| 226       "setTimeout(\"" | 227       "setTimeout(\"" | 
| 227       "var iframes = document.getElementById('%s');iframes.src='%s';" | 228       "var iframes = document.getElementById('%s');iframes.src='%s';" | 
| 228       "\",0)", | 229       "\",0)", | 
| 229       iframe_id.c_str(), url.spec().c_str()); | 230       iframe_id.c_str(), url.spec().c_str()); | 
| 230   WindowedNotificationObserver load_observer( | 231   WindowedNotificationObserver load_observer( | 
| 231       NOTIFICATION_NAV_ENTRY_COMMITTED, | 232       NOTIFICATION_NAV_ENTRY_COMMITTED, | 
| 232       Source<NavigationController>( | 233       Source<NavigationController>( | 
| 233           &window->web_contents()->GetController())); | 234           &window->web_contents()->GetController())); | 
| 234   bool result = ExecuteScript(window->web_contents(), script); | 235   if (!ExecuteScript(window->web_contents(), script)) | 
|  | 236     return false; | 
| 235   load_observer.Wait(); | 237   load_observer.Wait(); | 
| 236   return result; | 238 | 
|  | 239   return true; | 
| 237 } | 240 } | 
| 238 | 241 | 
| 239 void SitePerProcessBrowserTest::SetUpCommandLine(CommandLine* command_line) { | 242 void SitePerProcessBrowserTest::SetUpCommandLine(CommandLine* command_line) { | 
| 240   command_line->AppendSwitch(switches::kSitePerProcess); | 243   command_line->AppendSwitch(switches::kSitePerProcess); | 
| 241 }; | 244 }; | 
| 242 | 245 | 
| 243 void SitePerProcessBrowserTest::SetUpOnMainThread() { | 246 void SitePerProcessBrowserTest::SetUpOnMainThread() { | 
| 244   host_resolver()->AddRule("*", "127.0.0.1"); | 247   host_resolver()->AddRule("*", "127.0.0.1"); | 
| 245   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 248   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 
| 246   SetupCrossSiteRedirector(embedded_test_server()); | 249   SetupCrossSiteRedirector(embedded_test_server()); | 
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 861       "window.domAutomationController.send(location.ancestorOrigins[0]);", | 864       "window.domAutomationController.send(location.ancestorOrigins[0]);", | 
| 862       &result)); | 865       &result)); | 
| 863   EXPECT_EQ(result + "/", foo_url.GetOrigin().spec()); | 866   EXPECT_EQ(result + "/", foo_url.GetOrigin().spec()); | 
| 864   EXPECT_TRUE(ExecuteScriptAndExtractString( | 867   EXPECT_TRUE(ExecuteScriptAndExtractString( | 
| 865       bottom_child->current_frame_host(), | 868       bottom_child->current_frame_host(), | 
| 866       "window.domAutomationController.send(location.ancestorOrigins[1]);", | 869       "window.domAutomationController.send(location.ancestorOrigins[1]);", | 
| 867       &result)); | 870       &result)); | 
| 868   EXPECT_EQ(result + "/", main_url.GetOrigin().spec()); | 871   EXPECT_EQ(result + "/", main_url.GetOrigin().spec()); | 
| 869 } | 872 } | 
| 870 | 873 | 
|  | 874 // TODO(lfg): Merge the test below with NavigateRemoteFrame test. | 
|  | 875 // TODO(lfg): Disabled because this triggers http://crbug.com/433012, and since | 
|  | 876 // the renderer process crashes, it causes the title watcher to never return. | 
|  | 877 // Alternatively, this could also be fixed if we could use NavigateIframeToURL | 
|  | 878 // and classified the navigation as MANUAL_SUBFRAME (http://crbug.com/441863) or | 
|  | 879 // if we waited for DidStopLoading (currently broken -- see comment in | 
|  | 880 // NavigateIframeToURL). | 
|  | 881 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 
|  | 882                        DISABLED_NavigateRemoteToDataURL) { | 
|  | 883   GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 
|  | 884   NavigateToURL(shell(), main_url); | 
|  | 885 | 
|  | 886   // It is safe to obtain the root frame tree node here, as it doesn't change. | 
|  | 887   FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 
|  | 888                             ->GetFrameTree() | 
|  | 889                             ->root(); | 
|  | 890 | 
|  | 891   SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 
|  | 892 | 
|  | 893   // Load cross-site page into iframe. | 
|  | 894   GURL url = embedded_test_server()->GetURL("foo.com", "/title1.html"); | 
|  | 895   NavigateFrameToURL(root->child_at(0), url); | 
|  | 896   EXPECT_TRUE(observer.navigation_succeeded()); | 
|  | 897   EXPECT_EQ(url, observer.navigation_url()); | 
|  | 898 | 
|  | 899   // Ensure that we have created a new process for the subframe. | 
|  | 900   EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 
|  | 901             root->child_at(0)->current_frame_host()->GetSiteInstance()); | 
|  | 902 | 
|  | 903   // Navigate iframe to a data URL. The navigation happens from a script in the | 
|  | 904   // parent frame, so the data URL should be committed in the same SiteInstance | 
|  | 905   // as the parent frame. | 
|  | 906   GURL data_url("data:text/html,dataurl"); | 
|  | 907   std::string script = base::StringPrintf( | 
|  | 908       "setTimeout(function() {" | 
|  | 909       "var iframe = document.getElementById('test');" | 
|  | 910       "iframe.onload = function() { document.title = 'LOADED'; };" | 
|  | 911       "iframe.src=\"%s\";" | 
|  | 912       "},0);", | 
|  | 913       data_url.spec().c_str()); | 
|  | 914   base::string16 passed_string(base::UTF8ToUTF16("LOADED")); | 
|  | 915   TitleWatcher title_watcher(shell()->web_contents(), passed_string); | 
|  | 916   EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | 
|  | 917   EXPECT_EQ(title_watcher.WaitAndGetTitle(), passed_string); | 
|  | 918   EXPECT_TRUE(observer.navigation_succeeded()); | 
|  | 919   EXPECT_EQ(data_url, observer.navigation_url()); | 
|  | 920 | 
|  | 921   // Ensure that we have navigated using the top level process. | 
|  | 922   EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 
|  | 923             root->child_at(0)->current_frame_host()->GetSiteInstance()); | 
|  | 924 } | 
|  | 925 | 
|  | 926 // TODO(lfg): Merge the test below with NavigateRemoteFrame test. | 
|  | 927 // Disabled due to the same reason as NavigateRemoteToDataURL. | 
|  | 928 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 
|  | 929                        DISABLED_NavigateRemoteToBlankURL) { | 
|  | 930   GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 
|  | 931   NavigateToURL(shell(), main_url); | 
|  | 932 | 
|  | 933   // It is safe to obtain the root frame tree node here, as it doesn't change. | 
|  | 934   FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 
|  | 935                             ->GetFrameTree() | 
|  | 936                             ->root(); | 
|  | 937 | 
|  | 938   SitePerProcessWebContentsObserver observer(shell()->web_contents()); | 
|  | 939 | 
|  | 940   // Load cross-site page into iframe. | 
|  | 941   GURL url = embedded_test_server()->GetURL("foo.com", "/title1.html"); | 
|  | 942   NavigateFrameToURL(root->child_at(0), url); | 
|  | 943   EXPECT_TRUE(observer.navigation_succeeded()); | 
|  | 944   EXPECT_EQ(url, observer.navigation_url()); | 
|  | 945 | 
|  | 946   // Ensure that we have created a new process for the subframe. | 
|  | 947   EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 
|  | 948             root->child_at(0)->current_frame_host()->GetSiteInstance()); | 
|  | 949 | 
|  | 950   // Navigate iframe to about:blank. The navigation happens from a script in the | 
|  | 951   // parent frame, so it should be committed in the same SiteInstance as the | 
|  | 952   // parent frame. | 
|  | 953   GURL about_blank_url("about:blank"); | 
|  | 954   std::string script = base::StringPrintf( | 
|  | 955       "setTimeout(function() {" | 
|  | 956       "var iframe = document.getElementById('test');" | 
|  | 957       "iframe.onload = function() { document.title = 'LOADED'; };" | 
|  | 958       "iframe.src=\"%s\";" | 
|  | 959       "},0);", | 
|  | 960       about_blank_url.spec().c_str()); | 
|  | 961   base::string16 passed_string(base::UTF8ToUTF16("LOADED")); | 
|  | 962   TitleWatcher title_watcher(shell()->web_contents(), passed_string); | 
|  | 963   EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | 
|  | 964   EXPECT_EQ(title_watcher.WaitAndGetTitle(), passed_string); | 
|  | 965   EXPECT_TRUE(observer.navigation_succeeded()); | 
|  | 966   EXPECT_EQ(about_blank_url, observer.navigation_url()); | 
|  | 967 | 
|  | 968   // Ensure that we have navigated using the top level process. | 
|  | 969   EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 
|  | 970             root->child_at(0)->current_frame_host()->GetSiteInstance()); | 
|  | 971 } | 
|  | 972 | 
| 871 }  // namespace content | 973 }  // namespace content | 
| OLD | NEW | 
|---|