| 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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 // Load a cross-site page into both iframes. | 452 // Load a cross-site page into both iframes. |
| 453 GURL foo_url = embedded_test_server()->GetURL("foo.com", "/title2.html"); | 453 GURL foo_url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 454 NavigateFrameToURL(root->child_at(0), foo_url); | 454 NavigateFrameToURL(root->child_at(0), foo_url); |
| 455 EXPECT_TRUE(observer.last_navigation_succeeded()); | 455 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 456 EXPECT_EQ(foo_url, observer.last_navigation_url()); | 456 EXPECT_EQ(foo_url, observer.last_navigation_url()); |
| 457 NavigateFrameToURL(root->child_at(1), foo_url); | 457 NavigateFrameToURL(root->child_at(1), foo_url); |
| 458 EXPECT_TRUE(observer.last_navigation_succeeded()); | 458 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 459 EXPECT_EQ(foo_url, observer.last_navigation_url()); | 459 EXPECT_EQ(foo_url, observer.last_navigation_url()); |
| 460 | 460 |
| 461 // Ensure that we have created a new process for the subframes. | 461 // Ensure that we have created a new process for the subframes. |
| 462 RenderFrameHostImpl* child1_rfh = root->child_at(0)->current_frame_host(); | |
| 463 RenderFrameHostImpl* child2_rfh = root->child_at(1)->current_frame_host(); | |
| 464 ASSERT_EQ(2U, root->child_count()); | 462 ASSERT_EQ(2U, root->child_count()); |
| 465 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 463 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 466 child1_rfh->GetSiteInstance()); | 464 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 467 EXPECT_EQ(child1_rfh->GetSiteInstance(), child2_rfh->GetSiteInstance()); | 465 EXPECT_EQ(root->child_at(0)->current_frame_host()->GetSiteInstance(), |
| 468 | 466 root->child_at(1)->current_frame_host()->GetSiteInstance()); |
| 469 int subframe_process_id = | |
| 470 child1_rfh->GetSiteInstance()->GetProcess()->GetID(); | |
| 471 int subframe_rvh_id = child1_rfh->render_view_host()->GetRoutingID(); | |
| 472 EXPECT_TRUE(RenderViewHost::FromID(subframe_process_id, subframe_rvh_id)); | |
| 473 | 467 |
| 474 // Use Javascript in the parent to remove one of the frames and ensure that | 468 // Use Javascript in the parent to remove one of the frames and ensure that |
| 475 // the subframe goes away. | 469 // the subframe goes away. |
| 476 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 470 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
| 477 "document.body.removeChild(" | 471 "document.body.removeChild(" |
| 478 "document.querySelectorAll('iframe')[0])")); | 472 "document.querySelectorAll('iframe')[0])")); |
| 479 ASSERT_EQ(1U, root->child_count()); | 473 ASSERT_EQ(1U, root->child_count()); |
| 480 | 474 |
| 481 // Load a new same-site page in the top-level frame and ensure the other | 475 // Load a new same-site page in the top-level frame and ensure the other |
| 482 // subframe goes away. | 476 // subframe goes away. |
| 483 GURL new_url(embedded_test_server()->GetURL("/title1.html")); | 477 GURL new_url(embedded_test_server()->GetURL("/title1.html")); |
| 484 NavigateToURL(shell(), new_url); | 478 NavigateToURL(shell(), new_url); |
| 485 ASSERT_EQ(0U, root->child_count()); | 479 ASSERT_EQ(0U, root->child_count()); |
| 486 | |
| 487 // Ensure the RVH for the subframe gets cleaned up when the frame goes away. | |
| 488 EXPECT_FALSE(RenderViewHost::FromID(subframe_process_id, subframe_rvh_id)); | |
| 489 } | 480 } |
| 490 | 481 |
| 491 // Ensure that root frames cannot be detached. | 482 // Ensure that root frames cannot be detached. |
| 492 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, RestrictFrameDetach) { | 483 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, RestrictFrameDetach) { |
| 493 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); | 484 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); |
| 494 NavigateToURL(shell(), main_url); | 485 NavigateToURL(shell(), main_url); |
| 495 | 486 |
| 496 // It is safe to obtain the root frame tree node here, as it doesn't change. | 487 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 497 FrameTreeNode* root = | 488 FrameTreeNode* root = |
| 498 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 489 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| (...skipping 1970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2469 " |--Site A\n" | 2460 " |--Site A\n" |
| 2470 " +--Site A\n" | 2461 " +--Site A\n" |
| 2471 " |--Site A\n" | 2462 " |--Site A\n" |
| 2472 " +--Site A\n" | 2463 " +--Site A\n" |
| 2473 " +--Site A\n" | 2464 " +--Site A\n" |
| 2474 "Where A = http://127.0.0.1/", | 2465 "Where A = http://127.0.0.1/", |
| 2475 DepictFrameTree(root)); | 2466 DepictFrameTree(root)); |
| 2476 } | 2467 } |
| 2477 | 2468 |
| 2478 } // namespace content | 2469 } // namespace content |
| OLD | NEW |