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 "base/strings/utf_string_conversions.h" |
10 #include "content/browser/frame_host/cross_process_frame_connector.h" | 10 #include "content/browser/frame_host/cross_process_frame_connector.h" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 EXPECT_EQ(proxy_to_parent, child->render_manager()->GetProxyToParent()); | 276 EXPECT_EQ(proxy_to_parent, child->render_manager()->GetProxyToParent()); |
277 EXPECT_TRUE(proxy_to_parent->cross_process_frame_connector()); | 277 EXPECT_TRUE(proxy_to_parent->cross_process_frame_connector()); |
278 EXPECT_NE( | 278 EXPECT_NE( |
279 child->current_frame_host()->render_view_host()->GetView(), | 279 child->current_frame_host()->render_view_host()->GetView(), |
280 proxy_to_parent->cross_process_frame_connector()->get_view_for_testing()); | 280 proxy_to_parent->cross_process_frame_connector()->get_view_for_testing()); |
281 EXPECT_TRUE(child->current_frame_host()->GetRenderWidgetHost()); | 281 EXPECT_TRUE(child->current_frame_host()->GetRenderWidgetHost()); |
282 } | 282 } |
283 | 283 |
284 // Disabled for flaky crashing: crbug.com/446575 | 284 // Disabled for flaky crashing: crbug.com/446575 |
285 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 285 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
286 DISABLED_NavigateRemoteFrame) { | 286 NavigateRemoteFrame) { |
287 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 287 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
288 NavigateToURL(shell(), main_url); | 288 NavigateToURL(shell(), main_url); |
289 | 289 |
290 // It is safe to obtain the root frame tree node here, as it doesn't change. | 290 // It is safe to obtain the root frame tree node here, as it doesn't change. |
291 FrameTreeNode* root = | 291 FrameTreeNode* root = |
292 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 292 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
293 GetFrameTree()->root(); | 293 GetFrameTree()->root(); |
294 | 294 |
295 TestNavigationObserver observer(shell()->web_contents()); | 295 TestNavigationObserver observer(shell()->web_contents()); |
296 | 296 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 330 |
331 // Navigate back to the parent's origin and ensure we return to the | 331 // Navigate back to the parent's origin and ensure we return to the |
332 // parent's process. | 332 // parent's process. |
333 NavigateFrameToURL(child, http_url); | 333 NavigateFrameToURL(child, http_url); |
334 EXPECT_EQ(http_url, observer.last_navigation_url()); | 334 EXPECT_EQ(http_url, observer.last_navigation_url()); |
335 EXPECT_TRUE(observer.last_navigation_succeeded()); | 335 EXPECT_TRUE(observer.last_navigation_succeeded()); |
336 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 336 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
337 child->current_frame_host()->GetSiteInstance()); | 337 child->current_frame_host()->GetSiteInstance()); |
338 } | 338 } |
339 | 339 |
| 340 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 341 NavigateRemoteFrameToBlankAndDataURLs) { |
| 342 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| 343 NavigateToURL(shell(), main_url); |
| 344 |
| 345 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 346 FrameTreeNode* root = |
| 347 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 348 GetFrameTree()->root(); |
| 349 |
| 350 TestNavigationObserver observer(shell()->web_contents()); |
| 351 |
| 352 // Load same-site page into iframe. |
| 353 FrameTreeNode* child = root->child_at(0); |
| 354 GURL http_url(embedded_test_server()->GetURL("/title1.html")); |
| 355 NavigateFrameToURL(child, http_url); |
| 356 EXPECT_EQ(http_url, observer.last_navigation_url()); |
| 357 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 358 |
| 359 // Load cross-site page into iframe. |
| 360 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 361 NavigateFrameToURL(root->child_at(0), url); |
| 362 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 363 EXPECT_EQ(url, observer.last_navigation_url()); |
| 364 ASSERT_EQ(2U, root->child_count()); |
| 365 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 366 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 367 |
| 368 // Navigate iframe to a data URL. The navigation happens from a script in the |
| 369 // parent frame, so the data URL should be committed in the same SiteInstance |
| 370 // as the parent frame. |
| 371 GURL data_url("data:text/html,dataurl"); |
| 372 NavigateIframeToURL(shell()->web_contents(), "test", data_url); |
| 373 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 374 EXPECT_EQ(data_url, observer.last_navigation_url()); |
| 375 |
| 376 // Ensure that we have navigated using the top level process. |
| 377 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
| 378 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 379 |
| 380 // Load cross-site page into iframe. |
| 381 url = embedded_test_server()->GetURL("bar.com", "/title2.html"); |
| 382 NavigateFrameToURL(root->child_at(0), url); |
| 383 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 384 EXPECT_EQ(url, observer.last_navigation_url()); |
| 385 ASSERT_EQ(2U, root->child_count()); |
| 386 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 387 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 388 |
| 389 // Navigate iframe to about:blank. The navigation happens from a script in the |
| 390 // parent frame, so it should be committed in the same SiteInstance as the |
| 391 // parent frame. |
| 392 GURL about_blank_url("about:blank"); |
| 393 NavigateIframeToURL(shell()->web_contents(), "test", about_blank_url); |
| 394 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 395 EXPECT_EQ(about_blank_url, observer.last_navigation_url()); |
| 396 |
| 397 // Ensure that we have navigated using the top level process. |
| 398 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
| 399 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 400 } |
| 401 |
340 // This test checks that killing a renderer process of a remote frame | 402 // This test checks that killing a renderer process of a remote frame |
341 // and then navigating some other frame to the same SiteInstance of the killed | 403 // and then navigating some other frame to the same SiteInstance of the killed |
342 // process works properly. | 404 // process works properly. |
343 // This can be illustrated as follows, | 405 // This can be illustrated as follows, |
344 // where 1/2/3 are FrameTreeNode-s and A/B are processes and B* is the killed | 406 // where 1/2/3 are FrameTreeNode-s and A/B are processes and B* is the killed |
345 // B process: | 407 // B process: |
346 // | 408 // |
347 // 1 A A A | 409 // 1 A A A |
348 // / \ -> / \ -> Kill B -> / \ -> Navigate 3 to B -> / \ . | 410 // / \ -> / \ -> Kill B -> / \ -> Navigate 3 to B -> / \ . |
349 // 2 3 B A B* A B* B | 411 // 2 3 B A B* A B* B |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 | 1239 |
1178 // Check that the window.name seen by the frame matches the name attribute | 1240 // Check that the window.name seen by the frame matches the name attribute |
1179 // specified by its parent in the iframe tag. | 1241 // specified by its parent in the iframe tag. |
1180 std::string result; | 1242 std::string result; |
1181 EXPECT_TRUE(ExecuteScriptAndExtractString( | 1243 EXPECT_TRUE(ExecuteScriptAndExtractString( |
1182 root->child_at(0)->current_frame_host(), | 1244 root->child_at(0)->current_frame_host(), |
1183 "window.domAutomationController.send(window.name);", &result)); | 1245 "window.domAutomationController.send(window.name);", &result)); |
1184 EXPECT_EQ(result, "3-1-name"); | 1246 EXPECT_EQ(result, "3-1-name"); |
1185 } | 1247 } |
1186 | 1248 |
1187 // TODO(lfg): Merge the test below with NavigateRemoteFrame test. | |
1188 // TODO(lfg): Disabled because this triggers http://crbug.com/433012, and since | |
1189 // the renderer process crashes, it causes the title watcher to never return. | |
1190 // Alternatively, this could also be fixed if we could use NavigateIframeToURL | |
1191 // and classified the navigation as MANUAL_SUBFRAME (http://crbug.com/441863) or | |
1192 // if we waited for DidStopLoading (currently broken -- see comment in | |
1193 // NavigateIframeToURL). | |
1194 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
1195 DISABLED_NavigateRemoteToDataURL) { | |
1196 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | |
1197 NavigateToURL(shell(), main_url); | |
1198 | |
1199 // It is safe to obtain the root frame tree node here, as it doesn't change. | |
1200 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
1201 ->GetFrameTree() | |
1202 ->root(); | |
1203 | |
1204 TestNavigationObserver observer(shell()->web_contents()); | |
1205 | |
1206 // Load cross-site page into iframe. | |
1207 GURL url = embedded_test_server()->GetURL("foo.com", "/title1.html"); | |
1208 NavigateFrameToURL(root->child_at(0), url); | |
1209 EXPECT_TRUE(observer.last_navigation_succeeded()); | |
1210 EXPECT_EQ(url, observer.last_navigation_url()); | |
1211 | |
1212 // Ensure that we have created a new process for the subframe. | |
1213 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | |
1214 root->child_at(0)->current_frame_host()->GetSiteInstance()); | |
1215 | |
1216 // Navigate iframe to a data URL. The navigation happens from a script in the | |
1217 // parent frame, so the data URL should be committed in the same SiteInstance | |
1218 // as the parent frame. | |
1219 GURL data_url("data:text/html,dataurl"); | |
1220 std::string script = base::StringPrintf( | |
1221 "setTimeout(function() {" | |
1222 "var iframe = document.getElementById('test');" | |
1223 "iframe.onload = function() { document.title = 'LOADED'; };" | |
1224 "iframe.src=\"%s\";" | |
1225 "},0);", | |
1226 data_url.spec().c_str()); | |
1227 base::string16 passed_string(base::UTF8ToUTF16("LOADED")); | |
1228 TitleWatcher title_watcher(shell()->web_contents(), passed_string); | |
1229 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | |
1230 EXPECT_EQ(title_watcher.WaitAndGetTitle(), passed_string); | |
1231 EXPECT_TRUE(observer.last_navigation_succeeded()); | |
1232 EXPECT_EQ(data_url, observer.last_navigation_url()); | |
1233 | |
1234 // Ensure that we have navigated using the top level process. | |
1235 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | |
1236 root->child_at(0)->current_frame_host()->GetSiteInstance()); | |
1237 } | |
1238 | |
1239 // TODO(lfg): Merge the test below with NavigateRemoteFrame test. | |
1240 // Disabled due to the same reason as NavigateRemoteToDataURL. | |
1241 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
1242 DISABLED_NavigateRemoteToBlankURL) { | |
1243 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | |
1244 NavigateToURL(shell(), main_url); | |
1245 | |
1246 // It is safe to obtain the root frame tree node here, as it doesn't change. | |
1247 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
1248 ->GetFrameTree() | |
1249 ->root(); | |
1250 | |
1251 TestNavigationObserver observer(shell()->web_contents()); | |
1252 | |
1253 // Load cross-site page into iframe. | |
1254 GURL url = embedded_test_server()->GetURL("foo.com", "/title1.html"); | |
1255 NavigateFrameToURL(root->child_at(0), url); | |
1256 EXPECT_TRUE(observer.last_navigation_succeeded()); | |
1257 EXPECT_EQ(url, observer.last_navigation_url()); | |
1258 | |
1259 // Ensure that we have created a new process for the subframe. | |
1260 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | |
1261 root->child_at(0)->current_frame_host()->GetSiteInstance()); | |
1262 | |
1263 // Navigate iframe to about:blank. The navigation happens from a script in the | |
1264 // parent frame, so it should be committed in the same SiteInstance as the | |
1265 // parent frame. | |
1266 GURL about_blank_url("about:blank"); | |
1267 std::string script = base::StringPrintf( | |
1268 "setTimeout(function() {" | |
1269 "var iframe = document.getElementById('test');" | |
1270 "iframe.onload = function() { document.title = 'LOADED'; };" | |
1271 "iframe.src=\"%s\";" | |
1272 "},0);", | |
1273 about_blank_url.spec().c_str()); | |
1274 base::string16 passed_string(base::UTF8ToUTF16("LOADED")); | |
1275 TitleWatcher title_watcher(shell()->web_contents(), passed_string); | |
1276 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | |
1277 EXPECT_EQ(title_watcher.WaitAndGetTitle(), passed_string); | |
1278 EXPECT_TRUE(observer.last_navigation_succeeded()); | |
1279 EXPECT_EQ(about_blank_url, observer.last_navigation_url()); | |
1280 | |
1281 // Ensure that we have navigated using the top level process. | |
1282 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | |
1283 root->child_at(0)->current_frame_host()->GetSiteInstance()); | |
1284 } | |
1285 | |
1286 // Ensure that navigating subframes in --site-per-process mode properly fires | 1249 // Ensure that navigating subframes in --site-per-process mode properly fires |
1287 // the DidStopLoading event on WebContentsObserver. | 1250 // the DidStopLoading event on WebContentsObserver. |
1288 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteDidStopLoading) { | 1251 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteDidStopLoading) { |
1289 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 1252 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
1290 NavigateToURL(shell(), main_url); | 1253 NavigateToURL(shell(), main_url); |
1291 | 1254 |
1292 // It is safe to obtain the root frame tree node here, as it doesn't change. | 1255 // It is safe to obtain the root frame tree node here, as it doesn't change. |
1293 FrameTreeNode* root = | 1256 FrameTreeNode* root = |
1294 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 1257 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
1295 GetFrameTree()->root(); | 1258 GetFrameTree()->root(); |
(...skipping 15 matching lines...) Expand all Loading... |
1311 params.frame_tree_node_id = child->frame_tree_node_id(); | 1274 params.frame_tree_node_id = child->frame_tree_node_id(); |
1312 child->navigator()->GetController()->LoadURLWithParams(params); | 1275 child->navigator()->GetController()->LoadURLWithParams(params); |
1313 nav_observer.Wait(); | 1276 nav_observer.Wait(); |
1314 | 1277 |
1315 // Verify that the navigation succeeded and the expected URL was loaded. | 1278 // Verify that the navigation succeeded and the expected URL was loaded. |
1316 EXPECT_TRUE(observer.last_navigation_succeeded()); | 1279 EXPECT_TRUE(observer.last_navigation_succeeded()); |
1317 EXPECT_EQ(url, observer.last_navigation_url()); | 1280 EXPECT_EQ(url, observer.last_navigation_url()); |
1318 } | 1281 } |
1319 | 1282 |
1320 } // namespace content | 1283 } // namespace content |
OLD | NEW |