Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 // SitePerProcessBrowserTest | 278 // SitePerProcessBrowserTest |
| 279 // | 279 // |
| 280 | 280 |
| 281 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { | 281 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { |
| 282 }; | 282 }; |
| 283 | 283 |
| 284 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { | 284 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { |
| 285 return visualizer_.DepictFrameTree(node); | 285 return visualizer_.DepictFrameTree(node); |
| 286 } | 286 } |
| 287 | 287 |
| 288 void SitePerProcessBrowserTest::StartFrameAtDataURL() { | |
| 289 std::string data_url_script = | |
| 290 "var iframes = document.getElementById('test');iframes.src=" | |
| 291 "'data:text/html,dataurl';"; | |
| 292 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), data_url_script)); | |
| 293 } | |
| 294 | |
| 295 void SitePerProcessBrowserTest::SetUpCommandLine( | 288 void SitePerProcessBrowserTest::SetUpCommandLine( |
| 296 base::CommandLine* command_line) { | 289 base::CommandLine* command_line) { |
| 297 IsolateAllSitesForTesting(command_line); | 290 IsolateAllSitesForTesting(command_line); |
| 298 }; | 291 }; |
| 299 | 292 |
| 300 void SitePerProcessBrowserTest::SetUpOnMainThread() { | 293 void SitePerProcessBrowserTest::SetUpOnMainThread() { |
| 301 host_resolver()->AddRule("*", "127.0.0.1"); | 294 host_resolver()->AddRule("*", "127.0.0.1"); |
| 302 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 295 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 303 SetupCrossSiteRedirector(embedded_test_server()); | 296 SetupCrossSiteRedirector(embedded_test_server()); |
| 304 } | 297 } |
| 305 | 298 |
| 306 // Ensure that navigating subframes in --site-per-process mode works and the | 299 // Ensure that navigating subframes in --site-per-process mode works and the |
| 307 // correct documents are committed. | 300 // correct documents are committed. |
| 308 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { | 301 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframe) { |
| 309 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 302 GURL main_url(embedded_test_server()->GetURL( |
| 303 "a.com", "/cross_site_iframe_factory.html?a(a,a(a,a(a)))")); | |
| 310 NavigateToURL(shell(), main_url); | 304 NavigateToURL(shell(), main_url); |
| 311 | 305 |
| 312 // It is safe to obtain the root frame tree node here, as it doesn't change. | 306 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 313 FrameTreeNode* root = | 307 FrameTreeNode* root = |
| 314 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 308 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 315 GetFrameTree()->root(); | 309 GetFrameTree()->root(); |
| 316 | 310 |
| 317 TestNavigationObserver observer(shell()->web_contents()); | 311 TestNavigationObserver observer(shell()->web_contents()); |
| 318 | 312 |
| 319 // Load same-site page into iframe. | 313 // Load same-site page into iframe. |
| 320 FrameTreeNode* child = root->child_at(0); | 314 FrameTreeNode* child = root->child_at(0); |
| 321 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 315 GURL http_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 322 NavigateFrameToURL(child, http_url); | 316 NavigateFrameToURL(child, http_url); |
| 323 EXPECT_EQ(http_url, observer.last_navigation_url()); | 317 EXPECT_EQ(http_url, observer.last_navigation_url()); |
| 324 EXPECT_TRUE(observer.last_navigation_succeeded()); | 318 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 325 { | 319 { |
| 326 // There should be only one RenderWidgetHost when there are no | 320 // There should be only one RenderWidgetHost when there are no |
| 327 // cross-process iframes. | 321 // cross-process iframes. |
| 328 std::set<RenderWidgetHostView*> views_set = | 322 std::set<RenderWidgetHostView*> views_set = |
| 329 static_cast<WebContentsImpl*>(shell()->web_contents()) | 323 static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 330 ->GetRenderWidgetHostViewsInTree(); | 324 ->GetRenderWidgetHostViewsInTree(); |
| 331 EXPECT_EQ(1U, views_set.size()); | 325 EXPECT_EQ(1U, views_set.size()); |
| 332 } | 326 } |
| 333 | 327 |
| 334 EXPECT_EQ( | 328 EXPECT_EQ( |
| 335 " Site A\n" | 329 " Site A\n" |
| 336 " |--Site A\n" | 330 " |--Site A\n" |
| 337 " +--Site A\n" | 331 " +--Site A\n" |
| 338 " |--Site A\n" | 332 " |--Site A\n" |
| 339 " +--Site A\n" | 333 " +--Site A\n" |
| 340 " +--Site A\n" | 334 " +--Site A\n" |
| 341 "Where A = http://127.0.0.1/", | 335 "Where A = http://a.com/", |
| 342 DepictFrameTree(root)); | 336 DepictFrameTree(root)); |
| 343 | 337 |
| 344 // Load cross-site page into iframe. | 338 // Load cross-site page into iframe. |
| 345 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); | 339 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 346 NavigateFrameToURL(root->child_at(0), url); | 340 NavigateFrameToURL(root->child_at(0), url); |
| 347 // Verify that the navigation succeeded and the expected URL was loaded. | 341 // Verify that the navigation succeeded and the expected URL was loaded. |
| 348 EXPECT_TRUE(observer.last_navigation_succeeded()); | 342 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 349 EXPECT_EQ(url, observer.last_navigation_url()); | 343 EXPECT_EQ(url, observer.last_navigation_url()); |
| 350 | 344 |
| 351 // Ensure that we have created a new process for the subframe. | 345 // Ensure that we have created a new process for the subframe. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 375 proxy_to_parent->cross_process_frame_connector()->get_view_for_testing()); | 369 proxy_to_parent->cross_process_frame_connector()->get_view_for_testing()); |
| 376 EXPECT_TRUE(child->current_frame_host()->GetRenderWidgetHost()); | 370 EXPECT_TRUE(child->current_frame_host()->GetRenderWidgetHost()); |
| 377 | 371 |
| 378 EXPECT_EQ( | 372 EXPECT_EQ( |
| 379 " Site A ------------ proxies for B\n" | 373 " Site A ------------ proxies for B\n" |
| 380 " |--Site B ------- proxies for A\n" | 374 " |--Site B ------- proxies for A\n" |
| 381 " +--Site A ------- proxies for B\n" | 375 " +--Site A ------- proxies for B\n" |
| 382 " |--Site A -- proxies for B\n" | 376 " |--Site A -- proxies for B\n" |
| 383 " +--Site A -- proxies for B\n" | 377 " +--Site A -- proxies for B\n" |
| 384 " +--Site A -- proxies for B\n" | 378 " +--Site A -- proxies for B\n" |
| 385 "Where A = http://127.0.0.1/\n" | 379 "Where A = http://a.com/\n" |
| 386 " B = http://foo.com/", | 380 " B = http://foo.com/", |
| 387 DepictFrameTree(root)); | 381 DepictFrameTree(root)); |
| 388 | 382 |
| 389 // Load another cross-site page into the same iframe. | 383 // Load another cross-site page into the same iframe. |
| 390 url = embedded_test_server()->GetURL("bar.com", "/title3.html"); | 384 url = embedded_test_server()->GetURL("bar.com", "/title3.html"); |
| 391 NavigateFrameToURL(root->child_at(0), url); | 385 NavigateFrameToURL(root->child_at(0), url); |
| 392 EXPECT_TRUE(observer.last_navigation_succeeded()); | 386 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 393 EXPECT_EQ(url, observer.last_navigation_url()); | 387 EXPECT_EQ(url, observer.last_navigation_url()); |
| 394 | 388 |
| 395 // Check again that a new process is created and is different from the | 389 // Check again that a new process is created and is different from the |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 419 proxy_to_parent->cross_process_frame_connector()->get_view_for_testing()); | 413 proxy_to_parent->cross_process_frame_connector()->get_view_for_testing()); |
| 420 EXPECT_TRUE(child->current_frame_host()->GetRenderWidgetHost()); | 414 EXPECT_TRUE(child->current_frame_host()->GetRenderWidgetHost()); |
| 421 | 415 |
| 422 EXPECT_EQ( | 416 EXPECT_EQ( |
| 423 " Site A ------------ proxies for C\n" | 417 " Site A ------------ proxies for C\n" |
| 424 " |--Site C ------- proxies for A\n" | 418 " |--Site C ------- proxies for A\n" |
| 425 " +--Site A ------- proxies for C\n" | 419 " +--Site A ------- proxies for C\n" |
| 426 " |--Site A -- proxies for C\n" | 420 " |--Site A -- proxies for C\n" |
| 427 " +--Site A -- proxies for C\n" | 421 " +--Site A -- proxies for C\n" |
| 428 " +--Site A -- proxies for C\n" | 422 " +--Site A -- proxies for C\n" |
| 429 "Where A = http://127.0.0.1/\n" | 423 "Where A = http://a.com/\n" |
| 430 " C = http://bar.com/", | 424 " C = http://bar.com/", |
| 431 DepictFrameTree(root)); | 425 DepictFrameTree(root)); |
| 432 } | 426 } |
| 433 | 427 |
| 434 // Tests OOPIF rendering by checking that the RWH of the iframe generates | 428 // Tests OOPIF rendering by checking that the RWH of the iframe generates |
| 435 // OnSwapCompositorFrame message. | 429 // OnSwapCompositorFrame message. |
| 436 #if defined(OS_ANDROID) | 430 #if defined(OS_ANDROID) |
| 437 // http://crbug.com/471850 | 431 // http://crbug.com/471850 |
| 438 #define MAYBE_CompositorFrameSwapped DISABLED_CompositorFrameSwapped | 432 #define MAYBE_CompositorFrameSwapped DISABLED_CompositorFrameSwapped |
| 439 #else | 433 #else |
| 440 #define MAYBE_CompositorFrameSwapped CompositorFrameSwapped | 434 #define MAYBE_CompositorFrameSwapped CompositorFrameSwapped |
| 441 #endif | 435 #endif |
| 442 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 436 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 443 MAYBE_CompositorFrameSwapped) { | 437 MAYBE_CompositorFrameSwapped) { |
| 444 GURL main_url( | 438 GURL main_url(embedded_test_server()->GetURL( |
| 445 embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html")); | 439 "a.com", "/cross_site_iframe_factory.html?a(baz)")); |
| 446 NavigateToURL(shell(), main_url); | 440 NavigateToURL(shell(), main_url); |
| 447 | 441 |
| 448 // It is safe to obtain the root frame tree node here, as it doesn't change. | 442 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 449 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 443 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 450 ->GetFrameTree() | 444 ->GetFrameTree() |
| 451 ->root(); | 445 ->root(); |
| 452 ASSERT_EQ(1U, root->child_count()); | 446 ASSERT_EQ(1U, root->child_count()); |
| 453 | 447 |
| 454 FrameTreeNode* child_node = root->child_at(0); | 448 FrameTreeNode* child_node = root->child_at(0); |
| 455 GURL site_url(embedded_test_server()->GetURL("baz.com", "/title1.html")); | 449 GURL site_url(embedded_test_server()->GetURL( |
| 450 "baz.com", "/cross_site_iframe_factory.html?baz()")); | |
| 456 EXPECT_EQ(site_url, child_node->current_url()); | 451 EXPECT_EQ(site_url, child_node->current_url()); |
| 457 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 452 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 458 child_node->current_frame_host()->GetSiteInstance()); | 453 child_node->current_frame_host()->GetSiteInstance()); |
| 459 RenderWidgetHostViewBase* rwhv_base = static_cast<RenderWidgetHostViewBase*>( | 454 RenderWidgetHostViewBase* rwhv_base = static_cast<RenderWidgetHostViewBase*>( |
| 460 child_node->current_frame_host()->GetRenderWidgetHost()->GetView()); | 455 child_node->current_frame_host()->GetRenderWidgetHost()->GetView()); |
| 461 | 456 |
| 462 // Wait for OnSwapCompositorFrame message. | 457 // Wait for OnSwapCompositorFrame message. |
| 463 while (rwhv_base->RendererFrameNumber() <= 0) { | 458 while (rwhv_base->RendererFrameNumber() <= 0) { |
| 464 // TODO(lazyboy): Find a better way to avoid sleeping like this. See | 459 // TODO(lazyboy): Find a better way to avoid sleeping like this. See |
| 465 // http://crbug.com/405282 for details. | 460 // http://crbug.com/405282 for details. |
| 466 base::RunLoop run_loop; | 461 base::RunLoop run_loop; |
| 467 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 462 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 468 FROM_HERE, run_loop.QuitClosure(), | 463 FROM_HERE, run_loop.QuitClosure(), |
| 469 base::TimeDelta::FromMilliseconds(10)); | 464 base::TimeDelta::FromMilliseconds(10)); |
| 470 run_loop.Run(); | 465 run_loop.Run(); |
| 471 } | 466 } |
| 472 } | 467 } |
| 473 | 468 |
| 474 // Ensure that OOPIFs are deleted after navigating to a new main frame. | 469 // Ensure that OOPIFs are deleted after navigating to a new main frame. |
| 475 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CleanupCrossSiteIframe) { | 470 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CleanupCrossSiteIframe) { |
| 476 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 471 GURL main_url(embedded_test_server()->GetURL( |
| 472 "a.com", "/cross_site_iframe_factory.html?a(a,a(a,a(a)))")); | |
| 477 NavigateToURL(shell(), main_url); | 473 NavigateToURL(shell(), main_url); |
| 478 | 474 |
| 479 // It is safe to obtain the root frame tree node here, as it doesn't change. | 475 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 480 FrameTreeNode* root = | 476 FrameTreeNode* root = |
| 481 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 477 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 482 GetFrameTree()->root(); | 478 GetFrameTree()->root(); |
| 483 | 479 |
| 484 TestNavigationObserver observer(shell()->web_contents()); | 480 TestNavigationObserver observer(shell()->web_contents()); |
| 485 | 481 |
| 486 // Load a cross-site page into both iframes. | 482 // Load a cross-site page into both iframes. |
| 487 GURL foo_url = embedded_test_server()->GetURL("foo.com", "/title2.html"); | 483 GURL foo_url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 488 NavigateFrameToURL(root->child_at(0), foo_url); | 484 NavigateFrameToURL(root->child_at(0), foo_url); |
| 489 EXPECT_TRUE(observer.last_navigation_succeeded()); | 485 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 490 EXPECT_EQ(foo_url, observer.last_navigation_url()); | 486 EXPECT_EQ(foo_url, observer.last_navigation_url()); |
| 491 NavigateFrameToURL(root->child_at(1), foo_url); | 487 NavigateFrameToURL(root->child_at(1), foo_url); |
| 492 EXPECT_TRUE(observer.last_navigation_succeeded()); | 488 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 493 EXPECT_EQ(foo_url, observer.last_navigation_url()); | 489 EXPECT_EQ(foo_url, observer.last_navigation_url()); |
| 494 | 490 |
| 495 // Ensure that we have created a new process for the subframes. | 491 // Ensure that we have created a new process for the subframes. |
| 496 EXPECT_EQ( | 492 EXPECT_EQ( |
| 497 " Site A ------------ proxies for B\n" | 493 " Site A ------------ proxies for B\n" |
| 498 " |--Site B ------- proxies for A\n" | 494 " |--Site B ------- proxies for A\n" |
| 499 " +--Site B ------- proxies for A\n" | 495 " +--Site B ------- proxies for A\n" |
| 500 "Where A = http://127.0.0.1/\n" | 496 "Where A = http://a.com/\n" |
| 501 " B = http://foo.com/", | 497 " B = http://foo.com/", |
| 502 DepictFrameTree(root)); | 498 DepictFrameTree(root)); |
| 503 | 499 |
| 504 int subframe_process_id = root->child_at(0) | 500 int subframe_process_id = root->child_at(0) |
| 505 ->current_frame_host() | 501 ->current_frame_host() |
| 506 ->GetSiteInstance() | 502 ->GetSiteInstance() |
| 507 ->GetProcess() | 503 ->GetProcess() |
| 508 ->GetID(); | 504 ->GetID(); |
| 509 int subframe_rvh_id = root->child_at(0) | 505 int subframe_rvh_id = root->child_at(0) |
| 510 ->current_frame_host() | 506 ->current_frame_host() |
| 511 ->render_view_host() | 507 ->render_view_host() |
| 512 ->GetRoutingID(); | 508 ->GetRoutingID(); |
| 513 EXPECT_TRUE(RenderViewHost::FromID(subframe_process_id, subframe_rvh_id)); | 509 EXPECT_TRUE(RenderViewHost::FromID(subframe_process_id, subframe_rvh_id)); |
| 514 | 510 |
| 515 // Use Javascript in the parent to remove one of the frames and ensure that | 511 // Use Javascript in the parent to remove one of the frames and ensure that |
| 516 // the subframe goes away. | 512 // the subframe goes away. |
| 517 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 513 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
| 518 "document.body.removeChild(" | 514 "document.body.removeChild(" |
| 519 "document.querySelectorAll('iframe')[0])")); | 515 "document.querySelectorAll('iframe')[0])")); |
| 520 ASSERT_EQ(1U, root->child_count()); | 516 ASSERT_EQ(1U, root->child_count()); |
| 521 | 517 |
| 522 // Load a new same-site page in the top-level frame and ensure the other | 518 // Load a new same-site page in the top-level frame and ensure the other |
| 523 // subframe goes away. | 519 // subframe goes away. |
| 524 GURL new_url(embedded_test_server()->GetURL("/title1.html")); | 520 GURL new_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 525 NavigateToURL(shell(), new_url); | 521 NavigateToURL(shell(), new_url); |
| 526 ASSERT_EQ(0U, root->child_count()); | 522 ASSERT_EQ(0U, root->child_count()); |
| 527 | 523 |
| 528 // Ensure the RVH for the subframe gets cleaned up when the frame goes away. | 524 // Ensure the RVH for the subframe gets cleaned up when the frame goes away. |
| 529 EXPECT_FALSE(RenderViewHost::FromID(subframe_process_id, subframe_rvh_id)); | 525 EXPECT_FALSE(RenderViewHost::FromID(subframe_process_id, subframe_rvh_id)); |
| 530 } | 526 } |
| 531 | 527 |
| 532 // Ensure that root frames cannot be detached. | 528 // Ensure that root frames cannot be detached. |
| 533 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, RestrictFrameDetach) { | 529 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, RestrictFrameDetach) { |
| 534 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 530 GURL main_url(embedded_test_server()->GetURL( |
| 531 "a.com", "/cross_site_iframe_factory.html?a(a,a(a,a(a)))")); | |
| 535 NavigateToURL(shell(), main_url); | 532 NavigateToURL(shell(), main_url); |
| 536 | 533 |
| 537 // It is safe to obtain the root frame tree node here, as it doesn't change. | 534 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 538 FrameTreeNode* root = | 535 FrameTreeNode* root = |
| 539 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 536 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 540 GetFrameTree()->root(); | 537 GetFrameTree()->root(); |
| 541 | 538 |
| 542 TestNavigationObserver observer(shell()->web_contents()); | 539 TestNavigationObserver observer(shell()->web_contents()); |
| 543 | 540 |
| 544 // Load cross-site pages into both iframes. | 541 // Load cross-site pages into both iframes. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 559 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), foo_site_instance); | 556 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), foo_site_instance); |
| 560 FrameTreeNode* bar_child = root->child_at(1); | 557 FrameTreeNode* bar_child = root->child_at(1); |
| 561 SiteInstance* bar_site_instance = | 558 SiteInstance* bar_site_instance = |
| 562 bar_child->current_frame_host()->GetSiteInstance(); | 559 bar_child->current_frame_host()->GetSiteInstance(); |
| 563 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), bar_site_instance); | 560 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), bar_site_instance); |
| 564 | 561 |
| 565 EXPECT_EQ( | 562 EXPECT_EQ( |
| 566 " Site A ------------ proxies for B C\n" | 563 " Site A ------------ proxies for B C\n" |
| 567 " |--Site B ------- proxies for A C\n" | 564 " |--Site B ------- proxies for A C\n" |
| 568 " +--Site C ------- proxies for A B\n" | 565 " +--Site C ------- proxies for A B\n" |
| 569 "Where A = http://127.0.0.1/\n" | 566 "Where A = http://a.com/\n" |
| 570 " B = http://foo.com/\n" | 567 " B = http://foo.com/\n" |
| 571 " C = http://bar.com/", | 568 " C = http://bar.com/", |
| 572 DepictFrameTree(root)); | 569 DepictFrameTree(root)); |
| 573 | 570 |
| 574 // Simulate an attempt to detach the root frame from foo_site_instance. This | 571 // Simulate an attempt to detach the root frame from foo_site_instance. This |
| 575 // should kill foo_site_instance's process. | 572 // should kill foo_site_instance's process. |
| 576 RenderFrameProxyHost* foo_mainframe_rfph = | 573 RenderFrameProxyHost* foo_mainframe_rfph = |
| 577 root->render_manager()->GetRenderFrameProxyHost(foo_site_instance); | 574 root->render_manager()->GetRenderFrameProxyHost(foo_site_instance); |
| 578 content::RenderProcessHostWatcher foo_terminated( | 575 content::RenderProcessHostWatcher foo_terminated( |
| 579 foo_mainframe_rfph->GetProcess(), | 576 foo_mainframe_rfph->GetProcess(), |
| 580 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 577 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 581 FrameHostMsg_Detach evil_msg2(foo_mainframe_rfph->GetRoutingID()); | 578 FrameHostMsg_Detach evil_msg2(foo_mainframe_rfph->GetRoutingID()); |
| 582 IPC::IpcSecurityTestUtil::PwnMessageReceived( | 579 IPC::IpcSecurityTestUtil::PwnMessageReceived( |
| 583 foo_mainframe_rfph->GetProcess()->GetChannel(), evil_msg2); | 580 foo_mainframe_rfph->GetProcess()->GetChannel(), evil_msg2); |
| 584 foo_terminated.Wait(); | 581 foo_terminated.Wait(); |
| 585 | 582 |
| 586 EXPECT_EQ( | 583 EXPECT_EQ( |
| 587 " Site A ------------ proxies for B C\n" | 584 " Site A ------------ proxies for B C\n" |
| 588 " |--Site B ------- proxies for A C\n" | 585 " |--Site B ------- proxies for A C\n" |
| 589 " +--Site C ------- proxies for A B\n" | 586 " +--Site C ------- proxies for A B\n" |
| 590 "Where A = http://127.0.0.1/\n" | 587 "Where A = http://a.com/\n" |
| 591 " B = http://foo.com/ (no process)\n" | 588 " B = http://foo.com/ (no process)\n" |
| 592 " C = http://bar.com/", | 589 " C = http://bar.com/", |
| 593 DepictFrameTree(root)); | 590 DepictFrameTree(root)); |
| 594 } | 591 } |
| 595 | 592 |
| 596 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 593 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateRemoteFrame) { |
| 597 NavigateRemoteFrame) { | 594 GURL main_url(embedded_test_server()->GetURL( |
| 598 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 595 "a.com", "/cross_site_iframe_factory.html?a(a,a(a,a(a)))")); |
| 599 NavigateToURL(shell(), main_url); | 596 NavigateToURL(shell(), main_url); |
| 600 | 597 |
| 601 // It is safe to obtain the root frame tree node here, as it doesn't change. | 598 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 602 FrameTreeNode* root = | 599 FrameTreeNode* root = |
| 603 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 600 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 604 GetFrameTree()->root(); | 601 GetFrameTree()->root(); |
| 605 | 602 |
| 606 TestNavigationObserver observer(shell()->web_contents()); | 603 TestNavigationObserver observer(shell()->web_contents()); |
| 607 | 604 |
| 608 // Load same-site page into iframe. | 605 // Load same-site page into iframe. |
| 609 FrameTreeNode* child = root->child_at(0); | 606 FrameTreeNode* child = root->child_at(0); |
| 610 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 607 GURL http_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 611 NavigateFrameToURL(child, http_url); | 608 NavigateFrameToURL(child, http_url); |
| 612 EXPECT_EQ(http_url, observer.last_navigation_url()); | 609 EXPECT_EQ(http_url, observer.last_navigation_url()); |
| 613 EXPECT_TRUE(observer.last_navigation_succeeded()); | 610 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 614 | 611 |
| 615 // Load cross-site page into iframe. | 612 // Load cross-site page into iframe. |
| 616 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); | 613 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 617 NavigateFrameToURL(root->child_at(0), url); | 614 NavigateFrameToURL(root->child_at(0), url); |
| 618 EXPECT_TRUE(observer.last_navigation_succeeded()); | 615 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 619 EXPECT_EQ(url, observer.last_navigation_url()); | 616 EXPECT_EQ(url, observer.last_navigation_url()); |
| 620 | 617 |
| 621 // Ensure that we have created a new process for the subframe. | 618 // Ensure that we have created a new process for the subframe. |
| 622 ASSERT_EQ(2U, root->child_count()); | 619 EXPECT_EQ( |
| 620 " Site A ------------ proxies for B\n" | |
| 621 " |--Site B ------- proxies for A\n" | |
| 622 " +--Site A ------- proxies for B\n" | |
| 623 " |--Site A -- proxies for B\n" | |
| 624 " +--Site A -- proxies for B\n" | |
| 625 " +--Site A -- proxies for B\n" | |
| 626 "Where A = http://a.com/\n" | |
| 627 " B = http://foo.com/", | |
| 628 DepictFrameTree(root)); | |
| 623 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance(); | 629 SiteInstance* site_instance = child->current_frame_host()->GetSiteInstance(); |
| 624 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); | 630 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site_instance); |
| 625 | 631 |
| 626 // Emulate the main frame changing the src of the iframe such that it | 632 // Emulate the main frame changing the src of the iframe such that it |
| 627 // navigates cross-site. | 633 // navigates cross-site. |
| 628 url = embedded_test_server()->GetURL("bar.com", "/title3.html"); | 634 url = embedded_test_server()->GetURL("bar.com", "/title3.html"); |
| 629 NavigateIframeToURL(shell()->web_contents(), "test", url); | 635 NavigateIframeToURL(shell()->web_contents(), "child-0", url); |
| 630 EXPECT_TRUE(observer.last_navigation_succeeded()); | 636 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 631 EXPECT_EQ(url, observer.last_navigation_url()); | 637 EXPECT_EQ(url, observer.last_navigation_url()); |
| 632 | 638 |
| 633 // Check again that a new process is created and is different from the | 639 // Check again that a new process is created and is different from the |
| 634 // top level one and the previous one. | 640 // top level one and the previous one. |
| 635 ASSERT_EQ(2U, root->child_count()); | 641 EXPECT_EQ( |
| 636 child = root->child_at(0); | 642 " Site A ------------ proxies for C\n" |
| 637 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 643 " |--Site C ------- proxies for A\n" |
| 638 child->current_frame_host()->GetSiteInstance()); | 644 " +--Site A ------- proxies for C\n" |
| 639 EXPECT_NE(site_instance, | 645 " |--Site A -- proxies for C\n" |
| 640 child->current_frame_host()->GetSiteInstance()); | 646 " +--Site A -- proxies for C\n" |
| 647 " +--Site A -- proxies for C\n" | |
| 648 "Where A = http://a.com/\n" | |
| 649 " C = http://bar.com/", | |
| 650 DepictFrameTree(root)); | |
| 641 | 651 |
| 642 // Navigate back to the parent's origin and ensure we return to the | 652 // Navigate back to the parent's origin and ensure we return to the |
| 643 // parent's process. | 653 // parent's process. |
| 644 NavigateFrameToURL(child, http_url); | 654 NavigateFrameToURL(child, http_url); |
| 645 EXPECT_EQ(http_url, observer.last_navigation_url()); | 655 EXPECT_EQ(http_url, observer.last_navigation_url()); |
| 646 EXPECT_TRUE(observer.last_navigation_succeeded()); | 656 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 647 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 657 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
| 648 child->current_frame_host()->GetSiteInstance()); | 658 child->current_frame_host()->GetSiteInstance()); |
| 649 } | 659 } |
| 650 | 660 |
| 651 #if defined(OS_WIN) | |
| 652 // http://crbug.com/465722 | |
| 653 #define MAYBE_NavigateRemoteFrameToBlankAndDataURLs \ | |
| 654 DISABLED_NavigateRemoteFrameToBlankAndDataURLs | |
| 655 #else | |
| 656 #define MAYBE_NavigateRemoteFrameToBlankAndDataURLs \ | |
| 657 NavigateRemoteFrameToBlankAndDataURLs | |
| 658 #endif | |
| 659 | |
| 660 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 661 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 661 MAYBE_NavigateRemoteFrameToBlankAndDataURLs) { | 662 NavigateRemoteFrameToBlankAndDataURLs) { |
|
Charlie Reis
2015/08/27 21:14:48
Sure, we can give re-enabling this a try to see if
| |
| 662 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 663 GURL main_url(embedded_test_server()->GetURL( |
| 664 "a.com", "/cross_site_iframe_factory.html?a(a,a(a))")); | |
| 663 NavigateToURL(shell(), main_url); | 665 NavigateToURL(shell(), main_url); |
| 664 | 666 |
| 665 // It is safe to obtain the root frame tree node here, as it doesn't change. | 667 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 666 FrameTreeNode* root = | 668 FrameTreeNode* root = |
| 667 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 669 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 668 GetFrameTree()->root(); | 670 GetFrameTree()->root(); |
| 669 | 671 |
| 670 TestNavigationObserver observer(shell()->web_contents()); | 672 TestNavigationObserver observer(shell()->web_contents()); |
| 671 | 673 |
| 672 // Load same-site page into iframe. | 674 // Load same-site page into iframe. |
| 673 FrameTreeNode* child = root->child_at(0); | 675 FrameTreeNode* child = root->child_at(0); |
| 674 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 676 GURL http_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 675 NavigateFrameToURL(child, http_url); | 677 NavigateFrameToURL(child, http_url); |
| 676 EXPECT_EQ(http_url, observer.last_navigation_url()); | 678 EXPECT_EQ(http_url, observer.last_navigation_url()); |
| 677 EXPECT_TRUE(observer.last_navigation_succeeded()); | 679 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 680 EXPECT_EQ( | |
| 681 " Site A\n" | |
| 682 " |--Site A\n" | |
| 683 " +--Site A\n" | |
| 684 " +--Site A\n" | |
| 685 "Where A = http://a.com/", | |
| 686 DepictFrameTree(root)); | |
| 678 | 687 |
| 679 // Load cross-site page into iframe. | 688 // Load cross-site page into iframe. |
| 680 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); | 689 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 681 NavigateFrameToURL(root->child_at(0), url); | 690 NavigateFrameToURL(root->child_at(0), url); |
| 682 EXPECT_TRUE(observer.last_navigation_succeeded()); | 691 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 683 EXPECT_EQ(url, observer.last_navigation_url()); | 692 EXPECT_EQ(url, observer.last_navigation_url()); |
| 684 ASSERT_EQ(2U, root->child_count()); | 693 EXPECT_EQ( |
| 685 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 694 " Site A ------------ proxies for B\n" |
| 686 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 695 " |--Site B ------- proxies for A\n" |
| 696 " +--Site A ------- proxies for B\n" | |
| 697 " +--Site A -- proxies for B\n" | |
| 698 "Where A = http://a.com/\n" | |
| 699 " B = http://foo.com/", | |
| 700 DepictFrameTree(root)); | |
| 687 | 701 |
| 688 // Navigate iframe to a data URL. The navigation happens from a script in the | 702 // Navigate iframe to a data URL. The navigation happens from a script in the |
| 689 // parent frame, so the data URL should be committed in the same SiteInstance | 703 // parent frame, so the data URL should be committed in the same SiteInstance |
| 690 // as the parent frame. | 704 // as the parent frame. |
| 691 GURL data_url("data:text/html,dataurl"); | 705 GURL data_url("data:text/html,dataurl"); |
| 692 NavigateIframeToURL(shell()->web_contents(), "test", data_url); | 706 NavigateIframeToURL(shell()->web_contents(), "child-0", data_url); |
| 693 EXPECT_TRUE(observer.last_navigation_succeeded()); | 707 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 694 EXPECT_EQ(data_url, observer.last_navigation_url()); | 708 EXPECT_EQ(data_url, observer.last_navigation_url()); |
| 695 | 709 |
| 696 // Ensure that we have navigated using the top level process. | 710 // Ensure that we have navigated using the top level process. |
| 697 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 711 EXPECT_EQ( |
| 698 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 712 " Site A\n" |
| 713 " |--Site A\n" | |
| 714 " +--Site A\n" | |
| 715 " +--Site A\n" | |
| 716 "Where A = http://a.com/", | |
| 717 DepictFrameTree(root)); | |
| 699 | 718 |
| 700 // Load cross-site page into iframe. | 719 // Load cross-site page into iframe. |
| 701 url = embedded_test_server()->GetURL("bar.com", "/title2.html"); | 720 url = embedded_test_server()->GetURL("bar.com", "/title2.html"); |
| 702 NavigateFrameToURL(root->child_at(0), url); | 721 NavigateFrameToURL(root->child_at(0), url); |
| 703 EXPECT_TRUE(observer.last_navigation_succeeded()); | 722 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 704 EXPECT_EQ(url, observer.last_navigation_url()); | 723 EXPECT_EQ(url, observer.last_navigation_url()); |
| 705 ASSERT_EQ(2U, root->child_count()); | 724 EXPECT_EQ( |
| 706 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 725 " Site A ------------ proxies for C\n" |
| 707 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 726 " |--Site C ------- proxies for A\n" |
| 727 " +--Site A ------- proxies for C\n" | |
| 728 " +--Site A -- proxies for C\n" | |
| 729 "Where A = http://a.com/\n" | |
| 730 " C = http://bar.com/", | |
| 731 DepictFrameTree(root)); | |
| 708 | 732 |
| 709 // Navigate iframe to about:blank. The navigation happens from a script in the | 733 // Navigate iframe to about:blank. The navigation happens from a script in the |
| 710 // parent frame, so it should be committed in the same SiteInstance as the | 734 // parent frame, so it should be committed in the same SiteInstance as the |
| 711 // parent frame. | 735 // parent frame. |
| 712 GURL about_blank_url("about:blank"); | 736 GURL about_blank_url("about:blank"); |
| 713 NavigateIframeToURL(shell()->web_contents(), "test", about_blank_url); | 737 NavigateIframeToURL(shell()->web_contents(), "child-0", about_blank_url); |
| 714 EXPECT_TRUE(observer.last_navigation_succeeded()); | 738 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 715 EXPECT_EQ(about_blank_url, observer.last_navigation_url()); | 739 EXPECT_EQ(about_blank_url, observer.last_navigation_url()); |
| 716 | 740 |
| 717 // Ensure that we have navigated using the top level process. | 741 // Ensure that we have navigated using the top level process. |
| 718 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 742 EXPECT_EQ( |
| 719 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 743 " Site A\n" |
| 744 " |--Site A\n" | |
| 745 " +--Site A\n" | |
| 746 " +--Site A\n" | |
| 747 "Where A = http://a.com/", | |
| 748 DepictFrameTree(root)); | |
| 720 } | 749 } |
| 721 | 750 |
| 722 // This test checks that killing a renderer process of a remote frame | 751 // This test checks that killing a renderer process of a remote frame |
| 723 // and then navigating some other frame to the same SiteInstance of the killed | 752 // and then navigating some other frame to the same SiteInstance of the killed |
| 724 // process works properly. | 753 // process works properly. |
| 725 // This can be illustrated as follows, | 754 // This can be illustrated as follows, |
| 726 // where 1/2/3 are FrameTreeNode-s and A/B are processes and B* is the killed | 755 // where 1/2/3 are FrameTreeNode-s and A/B are processes and B* is the killed |
| 727 // B process: | 756 // B process: |
| 728 // | 757 // |
| 729 // 1 A A A | 758 // 1 A A A |
| 730 // / \ -> / \ -> Kill B -> / \ -> Navigate 3 to B -> / \ . | 759 // / \ -> / \ -> Kill B -> / \ -> Navigate 3 to B -> / \ . |
| 731 // 2 3 B A B* A B* B | 760 // 2 3 B A B* A B* B |
| 732 // | 761 // |
| 733 // Initially, node1.proxy_hosts_ = {B} | 762 // Initially, node1.proxy_hosts_ = {B} |
| 734 // After we kill B, we make sure B stays in node1.proxy_hosts_, then we navigate | 763 // After we kill B, we make sure B stays in node1.proxy_hosts_, then we navigate |
| 735 // 3 to B and we expect that to complete normally. | 764 // 3 to B and we expect that to complete normally. |
| 736 // See http://crbug.com/432107. | 765 // See http://crbug.com/432107. |
| 737 // | 766 // |
| 738 // Note that due to http://crbug.com/450681, node2 cannot be re-navigated to | 767 // Note that due to http://crbug.com/450681, node2 cannot be re-navigated to |
| 739 // site B and stays in not rendered state. | 768 // site B and stays in not rendered state. |
| 740 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 769 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 741 NavigateRemoteFrameToKilledProcess) { | 770 NavigateRemoteFrameToKilledProcess) { |
| 742 GURL main_url(embedded_test_server()->GetURL( | 771 GURL main_url(embedded_test_server()->GetURL( |
| 743 "/frame_tree/page_with_two_frames.html")); | 772 "foo.com", "/cross_site_iframe_factory.html?foo.com(bar.com, foo.com)")); |
| 744 NavigateToURL(shell(), main_url); | 773 NavigateToURL(shell(), main_url); |
| 745 | 774 |
| 746 // It is safe to obtain the root frame tree node here, as it doesn't change. | 775 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 747 FrameTreeNode* root = | 776 FrameTreeNode* root = |
| 748 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 777 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 749 GetFrameTree()->root(); | 778 GetFrameTree()->root(); |
| 750 | 779 |
| 751 TestNavigationObserver observer(shell()->web_contents()); | 780 TestNavigationObserver observer(shell()->web_contents()); |
| 752 ASSERT_EQ(2U, root->child_count()); | 781 ASSERT_EQ(2U, root->child_count()); |
| 753 | 782 |
| 754 // Make sure node2 points to the correct cross-site page. | 783 // Make sure node2 points to the correct cross-site page. |
| 755 GURL site_b_url = embedded_test_server()->GetURL("bar.com", "/title1.html"); | 784 GURL site_b_url = embedded_test_server()->GetURL( |
| 785 "bar.com", "/cross_site_iframe_factory.html?bar.com()"); | |
| 756 FrameTreeNode* node2 = root->child_at(0); | 786 FrameTreeNode* node2 = root->child_at(0); |
| 757 EXPECT_EQ(site_b_url, node2->current_url()); | 787 EXPECT_EQ(site_b_url, node2->current_url()); |
| 758 | 788 |
| 759 // Kill that cross-site renderer. | 789 // Kill that cross-site renderer. |
| 760 RenderProcessHost* child_process = | 790 RenderProcessHost* child_process = |
| 761 node2->current_frame_host()->GetProcess(); | 791 node2->current_frame_host()->GetProcess(); |
| 762 RenderProcessHostWatcher crash_observer( | 792 RenderProcessHostWatcher crash_observer( |
| 763 child_process, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 793 child_process, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 764 child_process->Shutdown(0, false); | 794 child_process->Shutdown(0, false); |
| 765 crash_observer.Wait(); | 795 crash_observer.Wait(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 783 // | 813 // |
| 784 // Initially, node1.proxy_hosts_ = {B, C} | 814 // Initially, node1.proxy_hosts_ = {B, C} |
| 785 // After we kill B, we make sure B stays in node1.proxy_hosts_, but | 815 // After we kill B, we make sure B stays in node1.proxy_hosts_, but |
| 786 // C gets cleared from node1.proxy_hosts_. | 816 // C gets cleared from node1.proxy_hosts_. |
| 787 // | 817 // |
| 788 // Note that due to http://crbug.com/450681, node2 cannot be re-navigated to | 818 // Note that due to http://crbug.com/450681, node2 cannot be re-navigated to |
| 789 // site B and stays in not rendered state. | 819 // site B and stays in not rendered state. |
| 790 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 820 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 791 NavigateRemoteFrameToKilledProcessWithSubtree) { | 821 NavigateRemoteFrameToKilledProcessWithSubtree) { |
| 792 GURL main_url(embedded_test_server()->GetURL( | 822 GURL main_url(embedded_test_server()->GetURL( |
| 793 "a.com", "/frame_tree/page_with_two_frames_nested.html")); | 823 "a.com", "/cross_site_iframe_factory.html?a(bar(baz), a)")); |
| 794 NavigateToURL(shell(), main_url); | 824 NavigateToURL(shell(), main_url); |
| 795 | 825 |
| 796 // It is safe to obtain the root frame tree node here, as it doesn't change. | 826 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 797 FrameTreeNode* root = | 827 FrameTreeNode* root = |
| 798 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 828 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 799 GetFrameTree()->root(); | 829 GetFrameTree()->root(); |
| 800 TestNavigationObserver observer(shell()->web_contents()); | 830 TestNavigationObserver observer(shell()->web_contents()); |
| 801 | 831 |
| 802 ASSERT_EQ(2U, root->child_count()); | 832 ASSERT_EQ(2U, root->child_count()); |
| 803 | 833 |
| 804 GURL site_b_url( | 834 GURL site_b_url(embedded_test_server()->GetURL( |
| 805 embedded_test_server()->GetURL( | 835 "bar.com", "/cross_site_iframe_factory.html?bar(baz())")); |
| 806 "bar.com", "/frame_tree/page_with_one_frame.html")); | |
| 807 // We can't use a TestNavigationObserver to verify the URL here, | 836 // We can't use a TestNavigationObserver to verify the URL here, |
| 808 // since the frame has children that may have clobbered it in the observer. | 837 // since the frame has children that may have clobbered it in the observer. |
| 809 EXPECT_EQ(site_b_url, root->child_at(0)->current_url()); | 838 EXPECT_EQ(site_b_url, root->child_at(0)->current_url()); |
| 810 | 839 |
| 811 // Ensure that a new process is created for node2. | 840 // Ensure that a new process is created for node2. |
| 812 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 841 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 813 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 842 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 814 // Ensure that a new process is *not* created for node3. | 843 // Ensure that a new process is *not* created for node3. |
| 815 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), | 844 EXPECT_EQ(shell()->web_contents()->GetSiteInstance(), |
| 816 root->child_at(1)->current_frame_host()->GetSiteInstance()); | 845 root->child_at(1)->current_frame_host()->GetSiteInstance()); |
| 817 | 846 |
| 818 ASSERT_EQ(1U, root->child_at(0)->child_count()); | 847 ASSERT_EQ(1U, root->child_at(0)->child_count()); |
| 819 | 848 |
| 820 // Make sure node4 points to the correct cross-site page. | 849 // Make sure node4 points to the correct cross-site page. |
| 821 FrameTreeNode* node4 = root->child_at(0)->child_at(0); | 850 FrameTreeNode* node4 = root->child_at(0)->child_at(0); |
| 822 GURL site_c_url(embedded_test_server()->GetURL("baz.com", "/title1.html")); | 851 GURL site_c_url(embedded_test_server()->GetURL( |
| 852 "baz.com", "/cross_site_iframe_factory.html?baz()")); | |
| 823 EXPECT_EQ(site_c_url, node4->current_url()); | 853 EXPECT_EQ(site_c_url, node4->current_url()); |
| 824 | 854 |
| 825 // |site_instance_c| is expected to go away once we kill |child_process_b| | 855 // |site_instance_c| is expected to go away once we kill |child_process_b| |
| 826 // below, so create a local scope so we can extend the lifetime of | 856 // below, so create a local scope so we can extend the lifetime of |
| 827 // |site_instance_c| with a refptr. | 857 // |site_instance_c| with a refptr. |
| 828 { | 858 { |
| 829 // Initially each frame has proxies for the other sites. | 859 // Initially each frame has proxies for the other sites. |
| 830 EXPECT_EQ( | 860 EXPECT_EQ( |
| 831 " Site A ------------ proxies for B C\n" | 861 " Site A ------------ proxies for B C\n" |
| 832 " |--Site B ------- proxies for A C\n" | 862 " |--Site B ------- proxies for A C\n" |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1186 "Where A = http://a.com/\n" | 1216 "Where A = http://a.com/\n" |
| 1187 " B = http://bar.com/ (no process)", | 1217 " B = http://bar.com/ (no process)", |
| 1188 DepictFrameTree(root)); | 1218 DepictFrameTree(root)); |
| 1189 | 1219 |
| 1190 EXPECT_EQ(0U, site_instance_c->active_frame_count()); | 1220 EXPECT_EQ(0U, site_instance_c->active_frame_count()); |
| 1191 } | 1221 } |
| 1192 | 1222 |
| 1193 // Crash a subframe and ensures its children are cleared from the FrameTree. | 1223 // Crash a subframe and ensures its children are cleared from the FrameTree. |
| 1194 // See http://crbug.com/338508. | 1224 // See http://crbug.com/338508. |
| 1195 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrashSubframe) { | 1225 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrashSubframe) { |
| 1196 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 1226 GURL main_url(embedded_test_server()->GetURL( |
| 1227 "a.com", "/cross_site_iframe_factory.html?a(b)")); | |
| 1197 NavigateToURL(shell(), main_url); | 1228 NavigateToURL(shell(), main_url); |
| 1198 | 1229 |
| 1199 StartFrameAtDataURL(); | |
|
Charlie Reis
2015/08/27 21:14:48
Nice. I'm not sure if the motivation for this met
| |
| 1200 | |
| 1201 // Load cross-site page into iframe. | |
| 1202 EXPECT_TRUE(NavigateIframeToURL( | |
| 1203 shell()->web_contents(), "test", | |
| 1204 embedded_test_server()->GetURL("/cross-site/foo.com/title2.html"))); | |
| 1205 | |
| 1206 // Check the subframe process. | 1230 // Check the subframe process. |
| 1207 FrameTreeNode* root = | 1231 FrameTreeNode* root = |
| 1208 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 1232 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 1209 GetFrameTree()->root(); | 1233 GetFrameTree()->root(); |
| 1210 ASSERT_EQ(2U, root->child_count()); | 1234 EXPECT_EQ( |
| 1235 " Site A ------------ proxies for B\n" | |
| 1236 " +--Site B ------- proxies for A\n" | |
| 1237 "Where A = http://a.com/\n" | |
| 1238 " B = http://b.com/", | |
| 1239 DepictFrameTree(root)); | |
| 1211 FrameTreeNode* child = root->child_at(0); | 1240 FrameTreeNode* child = root->child_at(0); |
| 1212 EXPECT_EQ(main_url, root->current_url()); | |
| 1213 EXPECT_EQ("foo.com", child->current_url().host()); | |
| 1214 EXPECT_EQ("/title2.html", child->current_url().path()); | |
| 1215 | |
| 1216 EXPECT_TRUE( | 1241 EXPECT_TRUE( |
| 1217 child->current_frame_host()->render_view_host()->IsRenderViewLive()); | 1242 child->current_frame_host()->render_view_host()->IsRenderViewLive()); |
| 1218 EXPECT_TRUE(child->current_frame_host()->IsRenderFrameLive()); | 1243 EXPECT_TRUE(child->current_frame_host()->IsRenderFrameLive()); |
| 1219 | 1244 |
| 1220 // Crash the subframe process. | 1245 // Crash the subframe process. |
| 1221 RenderProcessHost* root_process = root->current_frame_host()->GetProcess(); | 1246 RenderProcessHost* root_process = root->current_frame_host()->GetProcess(); |
| 1222 RenderProcessHost* child_process = child->current_frame_host()->GetProcess(); | 1247 RenderProcessHost* child_process = child->current_frame_host()->GetProcess(); |
| 1223 { | 1248 { |
| 1224 RenderProcessHostWatcher crash_observer( | 1249 RenderProcessHostWatcher crash_observer( |
| 1225 child_process, | 1250 child_process, |
| 1226 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 1251 RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 1227 child_process->Shutdown(0, false); | 1252 child_process->Shutdown(0, false); |
| 1228 crash_observer.Wait(); | 1253 crash_observer.Wait(); |
| 1229 } | 1254 } |
| 1230 | 1255 |
| 1231 // Ensure that the child frame still exists but has been cleared. | 1256 // Ensure that the child frame still exists but has been cleared. |
| 1232 EXPECT_EQ(2U, root->child_count()); | 1257 EXPECT_EQ( |
| 1258 " Site A ------------ proxies for B\n" | |
| 1259 " +--Site B ------- proxies for A\n" | |
| 1260 "Where A = http://a.com/\n" | |
| 1261 " B = http://b.com/ (no process)", | |
| 1262 DepictFrameTree(root)); | |
| 1263 EXPECT_EQ(1U, root->child_count()); | |
| 1233 EXPECT_EQ(main_url, root->current_url()); | 1264 EXPECT_EQ(main_url, root->current_url()); |
| 1234 EXPECT_EQ(GURL(), child->current_url()); | 1265 EXPECT_EQ(GURL(), child->current_url()); |
| 1235 | 1266 |
| 1236 EXPECT_FALSE( | 1267 EXPECT_FALSE( |
| 1237 child->current_frame_host()->render_view_host()->IsRenderViewLive()); | 1268 child->current_frame_host()->render_view_host()->IsRenderViewLive()); |
| 1238 EXPECT_FALSE(child->current_frame_host()->IsRenderFrameLive()); | 1269 EXPECT_FALSE(child->current_frame_host()->IsRenderFrameLive()); |
| 1239 EXPECT_FALSE(child->current_frame_host()->render_frame_created_); | 1270 EXPECT_FALSE(child->current_frame_host()->render_frame_created_); |
| 1240 | 1271 |
| 1241 // Now crash the top-level page to clear the child frame. | 1272 // Now crash the top-level page to clear the child frame. |
| 1242 { | 1273 { |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1503 // DidFailProvisionalLoad when navigating to client_redirect_http_url. | 1534 // DidFailProvisionalLoad when navigating to client_redirect_http_url. |
| 1504 EXPECT_EQ(observer.last_navigation_url(), client_redirect_http_url); | 1535 EXPECT_EQ(observer.last_navigation_url(), client_redirect_http_url); |
| 1505 EXPECT_FALSE(observer.last_navigation_succeeded()); | 1536 EXPECT_FALSE(observer.last_navigation_succeeded()); |
| 1506 } | 1537 } |
| 1507 } | 1538 } |
| 1508 | 1539 |
| 1509 // Ensure that when navigating a frame cross-process RenderFrameProxyHosts are | 1540 // Ensure that when navigating a frame cross-process RenderFrameProxyHosts are |
| 1510 // created in the FrameTree skipping the subtree of the navigating frame. | 1541 // created in the FrameTree skipping the subtree of the navigating frame. |
| 1511 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 1542 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 1512 ProxyCreationSkipsSubtree) { | 1543 ProxyCreationSkipsSubtree) { |
| 1513 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 1544 GURL main_url(embedded_test_server()->GetURL( |
| 1545 "a.com", "/cross_site_iframe_factory.html?a(a,a(a,a(a)))")); | |
| 1514 NavigateToURL(shell(), main_url); | 1546 NavigateToURL(shell(), main_url); |
| 1515 | 1547 |
| 1516 // It is safe to obtain the root frame tree node here, as it doesn't change. | 1548 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 1517 FrameTreeNode* root = | 1549 FrameTreeNode* root = |
| 1518 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 1550 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 1519 GetFrameTree()->root(); | 1551 GetFrameTree()->root(); |
| 1520 | 1552 |
| 1521 EXPECT_TRUE(root->child_at(1) != NULL); | 1553 EXPECT_TRUE(root->child_at(1) != NULL); |
| 1522 EXPECT_EQ(2U, root->child_at(1)->child_count()); | 1554 EXPECT_EQ(2U, root->child_at(1)->child_count()); |
| 1523 | 1555 |
| 1524 { | 1556 { |
| 1525 // Load same-site page into iframe. | 1557 // Load same-site page into iframe. |
| 1526 TestNavigationObserver observer(shell()->web_contents()); | 1558 TestNavigationObserver observer(shell()->web_contents()); |
| 1527 GURL http_url(embedded_test_server()->GetURL("/title1.html")); | 1559 GURL http_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 1528 NavigateFrameToURL(root->child_at(0), http_url); | 1560 NavigateFrameToURL(root->child_at(0), http_url); |
| 1529 EXPECT_EQ(http_url, observer.last_navigation_url()); | 1561 EXPECT_EQ(http_url, observer.last_navigation_url()); |
| 1530 EXPECT_TRUE(observer.last_navigation_succeeded()); | 1562 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1531 EXPECT_EQ( | 1563 EXPECT_EQ( |
| 1532 " Site A\n" | 1564 " Site A\n" |
| 1533 " |--Site A\n" | 1565 " |--Site A\n" |
| 1534 " +--Site A\n" | 1566 " +--Site A\n" |
| 1535 " |--Site A\n" | 1567 " |--Site A\n" |
| 1536 " +--Site A\n" | 1568 " +--Site A\n" |
| 1537 " +--Site A\n" | 1569 " +--Site A\n" |
| 1538 "Where A = http://127.0.0.1/", | 1570 "Where A = http://a.com/", |
| 1539 DepictFrameTree(root)); | 1571 DepictFrameTree(root)); |
| 1540 } | 1572 } |
| 1541 | 1573 |
| 1542 // Create the cross-site URL to navigate to. | 1574 // Create the cross-site URL to navigate to. |
| 1543 GURL cross_site_url = | 1575 GURL cross_site_url = |
| 1544 embedded_test_server()->GetURL("foo.com", "/frame_tree/1-1.html"); | 1576 embedded_test_server()->GetURL("foo.com", "/frame_tree/1-1.html"); |
| 1545 | 1577 |
| 1546 // Load cross-site page into the second iframe without waiting for the | 1578 // Load cross-site page into the second iframe without waiting for the |
| 1547 // navigation to complete. Once LoadURLWithParams returns, we would expect | 1579 // navigation to complete. Once LoadURLWithParams returns, we would expect |
| 1548 // proxies to have been created in the frame tree, but children of the | 1580 // proxies to have been created in the frame tree, but children of the |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1572 } | 1604 } |
| 1573 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site); | 1605 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site); |
| 1574 | 1606 |
| 1575 std::string tree = base::StringPrintf( | 1607 std::string tree = base::StringPrintf( |
| 1576 " Site A ------------ proxies for B\n" | 1608 " Site A ------------ proxies for B\n" |
| 1577 " |--Site A ------- proxies for B\n" | 1609 " |--Site A ------- proxies for B\n" |
| 1578 " +--Site A (B %s)\n" | 1610 " +--Site A (B %s)\n" |
| 1579 " |--Site A\n" | 1611 " |--Site A\n" |
| 1580 " +--Site A\n" | 1612 " +--Site A\n" |
| 1581 " +--Site A\n" | 1613 " +--Site A\n" |
| 1582 "Where A = http://127.0.0.1/\n" | 1614 "Where A = http://a.com/\n" |
| 1583 " B = http://foo.com/", | 1615 " B = http://foo.com/", |
| 1584 cross_site_rfh_type.c_str()); | 1616 cross_site_rfh_type.c_str()); |
| 1585 EXPECT_EQ(tree, DepictFrameTree(root)); | 1617 EXPECT_EQ(tree, DepictFrameTree(root)); |
| 1586 | 1618 |
| 1587 // Now that the verification is done, run the message loop and wait for the | 1619 // Now that the verification is done, run the message loop and wait for the |
| 1588 // navigation to complete. | 1620 // navigation to complete. |
| 1589 navigation_observer.Wait(); | 1621 navigation_observer.Wait(); |
| 1590 EXPECT_FALSE(child->render_manager()->pending_frame_host()); | 1622 EXPECT_FALSE(child->render_manager()->pending_frame_host()); |
| 1591 EXPECT_TRUE(observer.last_navigation_succeeded()); | 1623 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1592 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); | 1624 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
| 1593 | 1625 |
| 1594 EXPECT_EQ( | 1626 EXPECT_EQ( |
| 1595 " Site A ------------ proxies for B\n" | 1627 " Site A ------------ proxies for B\n" |
| 1596 " |--Site A ------- proxies for B\n" | 1628 " |--Site A ------- proxies for B\n" |
| 1597 " +--Site B ------- proxies for A\n" | 1629 " +--Site B ------- proxies for A\n" |
| 1598 "Where A = http://127.0.0.1/\n" | 1630 "Where A = http://a.com/\n" |
| 1599 " B = http://foo.com/", | 1631 " B = http://foo.com/", |
| 1600 DepictFrameTree(root)); | 1632 DepictFrameTree(root)); |
| 1601 } | 1633 } |
| 1602 | 1634 |
| 1603 // Load another cross-site page into the same iframe. | 1635 // Load another cross-site page into the same iframe. |
| 1604 cross_site_url = embedded_test_server()->GetURL("bar.com", "/title2.html"); | 1636 cross_site_url = embedded_test_server()->GetURL("bar.com", "/title2.html"); |
| 1605 { | 1637 { |
| 1606 // Perform the same checks as the first cross-site navigation, since | 1638 // Perform the same checks as the first cross-site navigation, since |
| 1607 // there have been issues in subsequent cross-site navigations. Also ensure | 1639 // there have been issues in subsequent cross-site navigations. Also ensure |
| 1608 // that the SiteInstance has properly changed. | 1640 // that the SiteInstance has properly changed. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1624 } else { | 1656 } else { |
| 1625 site2 = child->render_manager()->pending_frame_host()->GetSiteInstance(); | 1657 site2 = child->render_manager()->pending_frame_host()->GetSiteInstance(); |
| 1626 } | 1658 } |
| 1627 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site2); | 1659 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), site2); |
| 1628 EXPECT_NE(site, site2); | 1660 EXPECT_NE(site, site2); |
| 1629 | 1661 |
| 1630 std::string tree = base::StringPrintf( | 1662 std::string tree = base::StringPrintf( |
| 1631 " Site A ------------ proxies for B C\n" | 1663 " Site A ------------ proxies for B C\n" |
| 1632 " |--Site A ------- proxies for B C\n" | 1664 " |--Site A ------- proxies for B C\n" |
| 1633 " +--Site B (C %s) -- proxies for A\n" | 1665 " +--Site B (C %s) -- proxies for A\n" |
| 1634 "Where A = http://127.0.0.1/\n" | 1666 "Where A = http://a.com/\n" |
| 1635 " B = http://foo.com/\n" | 1667 " B = http://foo.com/\n" |
| 1636 " C = http://bar.com/", | 1668 " C = http://bar.com/", |
| 1637 cross_site_rfh_type.c_str()); | 1669 cross_site_rfh_type.c_str()); |
| 1638 EXPECT_EQ(tree, DepictFrameTree(root)); | 1670 EXPECT_EQ(tree, DepictFrameTree(root)); |
| 1639 | 1671 |
| 1640 navigation_observer.Wait(); | 1672 navigation_observer.Wait(); |
| 1641 EXPECT_TRUE(observer.last_navigation_succeeded()); | 1673 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 1642 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); | 1674 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
| 1643 EXPECT_EQ(0U, child->child_count()); | 1675 EXPECT_EQ(0U, child->child_count()); |
| 1644 } | 1676 } |
| (...skipping 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2988 success = false; | 3020 success = false; |
| 2989 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 3021 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 2990 popup_root->child_at(1)->current_frame_host(), | 3022 popup_root->child_at(1)->current_frame_host(), |
| 2991 "window.domAutomationController.send(" | 3023 "window.domAutomationController.send(" |
| 2992 " window.opener === window.opener.parent.frames['frame1']);", | 3024 " window.opener === window.opener.parent.frames['frame1']);", |
| 2993 &success)); | 3025 &success)); |
| 2994 EXPECT_TRUE(success); | 3026 EXPECT_TRUE(success); |
| 2995 } | 3027 } |
| 2996 | 3028 |
| 2997 } // namespace content | 3029 } // namespace content |
| OLD | NEW |