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 // Disabled because of http://crbug.com/433012 . | |
Charlie Reis
2014/12/11 00:43:39
nit: No space before period.
Let's also rephrase,
lfg
2014/12/11 23:55:24
Done.
| |
875 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
876 DISABLED_NavigateRemoteToDataURL) { | |
877 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | |
878 NavigateToURL(shell(), main_url); | |
879 | |
880 // It is safe to obtain the root frame tree node here, as it doesn't change. | |
881 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
882 ->GetFrameTree() | |
883 ->root(); | |
884 | |
885 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | |
886 | |
887 // Load cross-site page into iframe. | |
888 GURL url = embedded_test_server()->GetURL("foo.com", "/title1.html"); | |
889 NavigateFrameToURL(root->child_at(0), url); | |
890 EXPECT_TRUE(observer.navigation_succeeded()); | |
891 EXPECT_EQ(url, observer.navigation_url()); | |
892 | |
893 // Ensure that we have created a new process for the subframe. | |
894 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | |
895 root->child_at(0)->current_frame_host()->GetSiteInstance()); | |
896 | |
897 // Navigate iframe to a data URL. The navigation happens from a script in the | |
898 // parent renderer, so the data URL should be rendered in the parent renderer. | |
nasko
2014/12/11 01:14:44
I'd rephrase it a bit to be more specific.
The na
lfg
2014/12/11 23:55:24
Done.
| |
899 GURL data_url("data:text/html,dataurl"); | |
900 std::string script = base::StringPrintf( | |
901 "setTimeout(function() {" | |
902 "var iframe = document.getElementById('test');" | |
903 "iframe.onload = function() { document.title = 'LOADED'; };" | |
904 "iframe.src=\"%s\";" | |
905 "},0);", | |
906 data_url.spec().c_str()); | |
907 base::string16 passed_string(base::UTF8ToUTF16("LOADED")); | |
908 TitleWatcher title_watcher(shell()->web_contents(), passed_string); | |
909 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | |
910 (void)title_watcher.WaitAndGetTitle(); | |
911 EXPECT_TRUE(observer.navigation_succeeded()); | |
912 EXPECT_EQ(data_url, observer.navigation_url()); | |
913 | |
914 // Ensure that we have navigated using the top level process. | |
915 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | |
916 root->child_at(0)->current_frame_host()->GetSiteInstance()); | |
917 } | |
918 | |
919 // Disabled because of http://crbug.com/433012 . | |
Charlie Reis
2014/12/11 00:43:39
Same as above.
lfg
2014/12/11 23:55:24
Done.
| |
920 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
921 DISABLED_NavigateRemoteToBlankURL) { | |
922 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | |
nasko
2014/12/11 01:14:44
Both this method and the above differ only in the
lfg
2014/12/11 23:55:24
I think those two should be in the same test. The
| |
923 NavigateToURL(shell(), main_url); | |
924 | |
925 // It is safe to obtain the root frame tree node here, as it doesn't change. | |
926 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
927 ->GetFrameTree() | |
928 ->root(); | |
929 | |
930 SitePerProcessWebContentsObserver observer(shell()->web_contents()); | |
931 | |
932 // Load cross-site page into iframe. | |
933 GURL url = embedded_test_server()->GetURL("foo.com", "/title1.html"); | |
934 NavigateFrameToURL(root->child_at(0), url); | |
935 EXPECT_TRUE(observer.navigation_succeeded()); | |
936 EXPECT_EQ(url, observer.navigation_url()); | |
937 | |
938 // Ensure that we have created a new process for the subframe. | |
939 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | |
940 root->child_at(0)->current_frame_host()->GetSiteInstance()); | |
941 | |
942 // Navigate iframe to a data URL. The navigation happens from a script in the | |
943 // parent renderer, so the data URL should be rendered in the parent renderer. | |
944 GURL data_url("about:blank"); | |
nasko
2014/12/11 01:14:44
nit: this is no longer data_url
lfg
2014/12/11 23:55:24
Done.
| |
945 std::string script = base::StringPrintf( | |
946 "setTimeout(function() {" | |
947 "var iframe = document.getElementById('test');" | |
948 "iframe.onload = function() { document.title = 'LOADED'; };" | |
949 "iframe.src=\"%s\";" | |
950 "},0);", | |
951 data_url.spec().c_str()); | |
952 base::string16 passed_string(base::UTF8ToUTF16("LOADED")); | |
953 TitleWatcher title_watcher(shell()->web_contents(), passed_string); | |
954 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | |
955 (void)title_watcher.WaitAndGetTitle(); | |
956 EXPECT_TRUE(observer.navigation_succeeded()); | |
957 EXPECT_EQ(data_url, observer.navigation_url()); | |
958 | |
959 // Ensure that we have navigated using the top level process. | |
960 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | |
961 root->child_at(0)->current_frame_host()->GetSiteInstance()); | |
962 } | |
963 | |
871 } // namespace content | 964 } // namespace content |
OLD | NEW |