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

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

Issue 2921063003: Fix process reuse for dedicated processes when over process limit. (Closed)
Patch Set: Rebase Created 3 years, 5 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "content/browser/child_process_security_policy_impl.h" 6 #include "content/browser/child_process_security_policy_impl.h"
7 #include "content/browser/web_contents/web_contents_impl.h" 7 #include "content/browser/web_contents/web_contents_impl.h"
8 #include "content/public/browser/render_process_host.h" 8 #include "content/public/browser/render_process_host.h"
9 #include "content/public/common/content_switches.h" 9 #include "content/public/common/content_switches.h"
10 #include "content/public/test/browser_test_utils.h" 10 #include "content/public/test/browser_test_utils.h"
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 346
347 EXPECT_TRUE(ExecuteScript(web_contents(), "document.cookie = 'foo=bar';")); 347 EXPECT_TRUE(ExecuteScript(web_contents(), "document.cookie = 'foo=bar';"));
348 348
349 std::string cookie; 349 std::string cookie;
350 EXPECT_TRUE(ExecuteScriptAndExtractString( 350 EXPECT_TRUE(ExecuteScriptAndExtractString(
351 web_contents(), "window.domAutomationController.send(document.cookie);", 351 web_contents(), "window.domAutomationController.send(document.cookie);",
352 &cookie)); 352 &cookie));
353 EXPECT_EQ("foo=bar", cookie); 353 EXPECT_EQ("foo=bar", cookie);
354 } 354 }
355 355
356 // Check that isolated origins won't be placed into processes for other sites
357 // when over the process limit.
358 IN_PROC_BROWSER_TEST_F(IsolatedOriginTest, ProcessLimit) {
359 // Set the process limit to 1.
360 RenderProcessHost::SetMaxRendererProcessCount(1);
361
362 // Navigate to an unisolated foo.com URL with an iframe.
363 GURL foo_url(
364 embedded_test_server()->GetURL("www.foo.com", "/page_with_iframe.html"));
365 EXPECT_TRUE(NavigateToURL(shell(), foo_url));
366 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
367 RenderProcessHost* foo_process = root->current_frame_host()->GetProcess();
368 FrameTreeNode* child = root->child_at(0);
369
370 // Navigate iframe to an isolated origin.
371 GURL isolated_foo_url(
372 embedded_test_server()->GetURL("isolated.foo.com", "/title2.html"));
373 NavigateIframeToURL(web_contents(), "test_iframe", isolated_foo_url);
374
375 // Ensure that the subframe was rendered in a new process.
376 EXPECT_NE(child->current_frame_host()->GetProcess(), foo_process);
377
378 // Sanity-check IsSuitableHost values for the current processes.
379 BrowserContext* browser_context = web_contents()->GetBrowserContext();
380 auto is_suitable_host = [browser_context](RenderProcessHost* process,
381 GURL url) {
382 return RenderProcessHostImpl::IsSuitableHost(
383 process, browser_context,
384 SiteInstance::GetSiteForURL(browser_context, url));
385 };
386 EXPECT_TRUE(is_suitable_host(foo_process, foo_url));
387 EXPECT_FALSE(is_suitable_host(foo_process, isolated_foo_url));
388 EXPECT_TRUE(is_suitable_host(child->current_frame_host()->GetProcess(),
389 isolated_foo_url));
390 EXPECT_FALSE(
391 is_suitable_host(child->current_frame_host()->GetProcess(), foo_url));
392
393 // Open a new, unrelated tab and navigate it to isolated.foo.com. This
394 // should use a new, unrelated SiteInstance that reuses the existing isolated
395 // origin process from first tab's subframe.
396 Shell* new_shell = CreateBrowser();
397 EXPECT_TRUE(NavigateToURL(new_shell, isolated_foo_url));
398 scoped_refptr<SiteInstance> isolated_foo_instance(
399 new_shell->web_contents()->GetMainFrame()->GetSiteInstance());
400 RenderProcessHost* isolated_foo_process = isolated_foo_instance->GetProcess();
401 EXPECT_NE(child->current_frame_host()->GetSiteInstance(),
402 isolated_foo_instance);
403 EXPECT_FALSE(isolated_foo_instance->IsRelatedSiteInstance(
404 child->current_frame_host()->GetSiteInstance()));
405 // TODO(alexmos): with --site-per-process, this won't currently reuse the
406 // subframe process, because the new SiteInstance will initialize its
407 // process while it still has no site (during CreateBrowser()), and since
408 // dedicated processes can't currently be reused for a SiteInstance with no
409 // site, this creates a new process. The subsequent navigation to
410 // |isolated_foo_url| stays in that new process without consulting whether it
411 // can now reuse a different process. This should be fixed; see
412 // https://crbug.com/513036. Without --site-per-process, this works because
413 // the site-less SiteInstance is allowed to reuse the first tab's foo.com
414 // process (which isn't dedicated), and then it swaps to the isolated.foo.com
415 // process during navigation.
416 if (!AreAllSitesIsolatedForTesting())
417 EXPECT_EQ(child->current_frame_host()->GetProcess(), isolated_foo_process);
418
419 // Navigate iframe on the first tab to a non-isolated site. This should swap
420 // processes so that it does not reuse the isolated origin's process.
421 NavigateIframeToURL(
422 web_contents(), "test_iframe",
423 embedded_test_server()->GetURL("www.foo.com", "/title1.html"));
424 EXPECT_EQ(foo_process, child->current_frame_host()->GetProcess());
425 EXPECT_NE(isolated_foo_process, child->current_frame_host()->GetProcess());
426
427 // Navigate iframe back to isolated origin. See that it reuses the
428 // |new_shell| process.
429 NavigateIframeToURL(web_contents(), "test_iframe", isolated_foo_url);
430 EXPECT_NE(foo_process, child->current_frame_host()->GetProcess());
431 EXPECT_EQ(isolated_foo_process, child->current_frame_host()->GetProcess());
432
433 // Navigate iframe to a different isolated origin. Ensure that this creates
434 // a third process.
435 GURL isolated_bar_url(
436 embedded_test_server()->GetURL("isolated.bar.com", "/title3.html"));
437 NavigateIframeToURL(web_contents(), "test_iframe", isolated_bar_url);
438 RenderProcessHost* isolated_bar_process =
439 child->current_frame_host()->GetProcess();
440 EXPECT_NE(foo_process, isolated_bar_process);
441 EXPECT_NE(isolated_foo_process, isolated_bar_process);
442
443 // The new process should only be suitable to host isolated.bar.com, not
444 // regular web URLs or other isolated origins.
445 EXPECT_TRUE(is_suitable_host(isolated_bar_process, isolated_bar_url));
446 EXPECT_FALSE(is_suitable_host(isolated_bar_process, foo_url));
447 EXPECT_FALSE(is_suitable_host(isolated_bar_process, isolated_foo_url));
448
449 // Navigate second tab (currently at isolated.foo.com) to the
450 // second isolated origin, and see that it switches processes.
451 EXPECT_TRUE(NavigateToURL(new_shell, isolated_bar_url));
452 EXPECT_NE(foo_process,
453 new_shell->web_contents()->GetMainFrame()->GetProcess());
454 EXPECT_NE(isolated_foo_process,
455 new_shell->web_contents()->GetMainFrame()->GetProcess());
456 EXPECT_EQ(isolated_bar_process,
457 new_shell->web_contents()->GetMainFrame()->GetProcess());
458
459 // Navigate second tab to a non-isolated URL and see that it goes back into
460 // the www.foo.com process, and that it does not share processes with any
461 // isolated origins.
462 EXPECT_TRUE(NavigateToURL(new_shell, foo_url));
463 EXPECT_EQ(foo_process,
464 new_shell->web_contents()->GetMainFrame()->GetProcess());
465 EXPECT_NE(isolated_foo_process,
466 new_shell->web_contents()->GetMainFrame()->GetProcess());
467 EXPECT_NE(isolated_bar_process,
468 new_shell->web_contents()->GetMainFrame()->GetProcess());
469 }
470
356 } // namespace content 471 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/child_process_security_policy_impl.cc ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698