Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(588)

Side by Side Diff: content/browser/site_per_process_browsertest.cc

Issue 1039403002: OOPIF: Remove the FrameTreeNode when a RemoteFrame is detached. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable ActiveTab test on FYI bot Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "content/browser/frame_host/frame_tree.h" 11 #include "content/browser/frame_host/frame_tree.h"
12 #include "content/browser/frame_host/navigator.h" 12 #include "content/browser/frame_host/navigator.h"
13 #include "content/browser/frame_host/render_frame_proxy_host.h" 13 #include "content/browser/frame_host/render_frame_proxy_host.h"
14 #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"
15 #include "content/browser/renderer_host/render_view_host_impl.h" 15 #include "content/browser/renderer_host/render_view_host_impl.h"
16 #include "content/browser/web_contents/web_contents_impl.h" 16 #include "content/browser/web_contents/web_contents_impl.h"
17 #include "content/common/frame_messages.h"
17 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/notification_types.h" 20 #include "content/public/browser/notification_types.h"
20 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
21 #include "content/public/test/browser_test_utils.h" 22 #include "content/public/test/browser_test_utils.h"
22 #include "content/public/test/content_browser_test_utils.h" 23 #include "content/public/test/content_browser_test_utils.h"
23 #include "content/public/test/test_navigation_observer.h" 24 #include "content/public/test/test_navigation_observer.h"
24 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
25 #include "content/shell/browser/shell.h" 26 #include "content/shell/browser/shell.h"
26 #include "content/test/content_browser_test_utils_internal.h" 27 #include "content/test/content_browser_test_utils_internal.h"
27 #include "content/test/test_frame_navigation_observer.h" 28 #include "content/test/test_frame_navigation_observer.h"
29 #include "ipc/ipc_security_test_util.h"
28 #include "net/dns/mock_host_resolver.h" 30 #include "net/dns/mock_host_resolver.h"
29 #include "net/test/embedded_test_server/embedded_test_server.h" 31 #include "net/test/embedded_test_server/embedded_test_server.h"
30 32
31 namespace content { 33 namespace content {
32 34
33 class RedirectNotificationObserver : public NotificationObserver { 35 class RedirectNotificationObserver : public NotificationObserver {
34 public: 36 public:
35 // Register to listen for notifications of the given type from either a 37 // Register to listen for notifications of the given type from either a
36 // specific source, or from all sources if |source| is 38 // specific source, or from all sources if |source| is
37 // NotificationService::AllSources(). 39 // NotificationService::AllSources().
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // TODO(lazyboy): Find a better way to avoid sleeping like this. See 316 // TODO(lazyboy): Find a better way to avoid sleeping like this. See
315 // http://crbug.com/405282 for details. 317 // http://crbug.com/405282 for details.
316 base::RunLoop run_loop; 318 base::RunLoop run_loop;
317 base::MessageLoop::current()->PostDelayedTask( 319 base::MessageLoop::current()->PostDelayedTask(
318 FROM_HERE, run_loop.QuitClosure(), 320 FROM_HERE, run_loop.QuitClosure(),
319 base::TimeDelta::FromMilliseconds(10)); 321 base::TimeDelta::FromMilliseconds(10));
320 run_loop.Run(); 322 run_loop.Run();
321 } 323 }
322 } 324 }
323 325
326 // Ensure that OOPIFs are deleted after navigating to a new main frame.
327 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CleanupCrossSiteIframe) {
328 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html"));
329 NavigateToURL(shell(), main_url);
330
331 // It is safe to obtain the root frame tree node here, as it doesn't change.
332 FrameTreeNode* root =
333 static_cast<WebContentsImpl*>(shell()->web_contents())->
334 GetFrameTree()->root();
335
336 TestNavigationObserver observer(shell()->web_contents());
337
338 // Load a cross-site page into both iframes.
339 GURL foo_url = embedded_test_server()->GetURL("foo.com", "/title2.html");
340 NavigateFrameToURL(root->child_at(0), foo_url);
341 EXPECT_TRUE(observer.last_navigation_succeeded());
342 EXPECT_EQ(foo_url, observer.last_navigation_url());
343 NavigateFrameToURL(root->child_at(1), foo_url);
344 EXPECT_TRUE(observer.last_navigation_succeeded());
345 EXPECT_EQ(foo_url, observer.last_navigation_url());
346
347 // Ensure that we have created a new process for the subframes.
348 ASSERT_EQ(2U, root->child_count());
349 EXPECT_NE(shell()->web_contents()->GetSiteInstance(),
350 root->child_at(0)->current_frame_host()->GetSiteInstance());
351 EXPECT_EQ(root->child_at(0)->current_frame_host()->GetSiteInstance(),
352 root->child_at(1)->current_frame_host()->GetSiteInstance());
353
354 // Use Javascript in the parent to remove one of the frames and ensure that
355 // the subframe goes away.
356 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
357 "document.body.removeChild("
358 "document.querySelectorAll('iframe')[0])"));
359 ASSERT_EQ(1U, root->child_count());
360
361 // Load a new same-site page in the top-level frame and ensure the other
362 // subframe goes away.
363 GURL new_url(embedded_test_server()->GetURL("/title1.html"));
364 NavigateToURL(shell(), new_url);
365 ASSERT_EQ(0U, root->child_count());
366 }
367
368 // Ensure that root frames cannot be detached.
369 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, RestrictFrameDetach) {
370 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html"));
371 NavigateToURL(shell(), main_url);
372
373 // It is safe to obtain the root frame tree node here, as it doesn't change.
374 FrameTreeNode* root =
375 static_cast<WebContentsImpl*>(shell()->web_contents())->
376 GetFrameTree()->root();
377
378 TestNavigationObserver observer(shell()->web_contents());
379
380 // Load cross-site pages into both iframes.
381 GURL foo_url = embedded_test_server()->GetURL("foo.com", "/title2.html");
382 NavigateFrameToURL(root->child_at(0), foo_url);
383 EXPECT_TRUE(observer.last_navigation_succeeded());
384 EXPECT_EQ(foo_url, observer.last_navigation_url());
385 GURL bar_url = embedded_test_server()->GetURL("bar.com", "/title2.html");
386 NavigateFrameToURL(root->child_at(1), bar_url);
387 EXPECT_TRUE(observer.last_navigation_succeeded());
388 EXPECT_EQ(bar_url, observer.last_navigation_url());
389
390 // Ensure that we have created new processes for the subframes.
391 ASSERT_EQ(2U, root->child_count());
392 FrameTreeNode* foo_child = root->child_at(0);
393 SiteInstance* foo_site_instance =
394 foo_child->current_frame_host()->GetSiteInstance();
395 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), foo_site_instance);
396 FrameTreeNode* bar_child = root->child_at(1);
397 SiteInstance* bar_site_instance =
398 bar_child->current_frame_host()->GetSiteInstance();
399 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), bar_site_instance);
400
401 // Simulate an attempt to detach the root frame from foo_site_instance. This
402 // should kill foo_site_instance's process.
403 RenderFrameProxyHost* foo_mainframe_rfph =
404 root->render_manager()->GetRenderFrameProxyHost(foo_site_instance);
405 content::RenderProcessHostWatcher foo_terminated(
406 foo_mainframe_rfph->GetProcess(),
407 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
408 FrameHostMsg_Detach evil_msg2(foo_mainframe_rfph->GetRoutingID());
409 IPC::IpcSecurityTestUtil::PwnMessageReceived(
410 foo_mainframe_rfph->GetProcess()->GetChannel(), evil_msg2);
411 foo_terminated.Wait();
412 }
413
324 // Disabled for flaky crashing: crbug.com/446575 414 // Disabled for flaky crashing: crbug.com/446575
325 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, 415 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest,
326 NavigateRemoteFrame) { 416 NavigateRemoteFrame) {
327 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html")); 417 GURL main_url(embedded_test_server()->GetURL("/site_per_process_main.html"));
328 NavigateToURL(shell(), main_url); 418 NavigateToURL(shell(), main_url);
329 419
330 // It is safe to obtain the root frame tree node here, as it doesn't change. 420 // It is safe to obtain the root frame tree node here, as it doesn't change.
331 FrameTreeNode* root = 421 FrameTreeNode* root =
332 static_cast<WebContentsImpl*>(shell()->web_contents())-> 422 static_cast<WebContentsImpl*>(shell()->web_contents())->
333 GetFrameTree()->root(); 423 GetFrameTree()->root();
(...skipping 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 TitleWatcher title_watcher(shell()->web_contents(), expected_title); 1815 TitleWatcher title_watcher(shell()->web_contents(), expected_title);
1726 TestNavigationObserver observer(shell()->web_contents()); 1816 TestNavigationObserver observer(shell()->web_contents());
1727 NavigateFrameToURL(root->child_at(0), foo_url); 1817 NavigateFrameToURL(root->child_at(0), foo_url);
1728 EXPECT_TRUE(observer.last_navigation_succeeded()); 1818 EXPECT_TRUE(observer.last_navigation_succeeded());
1729 EXPECT_EQ(foo_url, observer.last_navigation_url()); 1819 EXPECT_EQ(foo_url, observer.last_navigation_url());
1730 EXPECT_EQ(title_watcher.WaitAndGetTitle(), expected_title); 1820 EXPECT_EQ(title_watcher.WaitAndGetTitle(), expected_title);
1731 } 1821 }
1732 } 1822 }
1733 1823
1734 } // namespace content 1824 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_proxy_host.cc ('k') | content/renderer/render_frame_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698