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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
10 #include "content/browser/browsing_instance.h" | 10 #include "content/browser/browsing_instance.h" |
11 #include "content/browser/child_process_security_policy_impl.h" | 11 #include "content/browser/child_process_security_policy_impl.h" |
12 #include "content/browser/frame_host/navigation_entry_impl.h" | 12 #include "content/browser/frame_host/navigation_entry_impl.h" |
13 #include "content/browser/renderer_host/render_process_host_impl.h" | 13 #include "content/browser/renderer_host/render_process_host_impl.h" |
14 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
15 #include "content/browser/site_instance_impl.h" | 15 #include "content/browser/site_instance_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/browser/webui/content_web_ui_controller_factory.h" | 17 #include "content/browser/webui/content_web_ui_controller_factory.h" |
18 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 18 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
19 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
20 #include "content/public/common/content_constants.h" | 20 #include "content/public/common/content_constants.h" |
21 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
| 22 #include "content/public/common/site_isolation_policy.h" |
22 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
23 #include "content/public/common/url_utils.h" | 24 #include "content/public/common/url_utils.h" |
24 #include "content/public/test/mock_render_process_host.h" | 25 #include "content/public/test/mock_render_process_host.h" |
25 #include "content/public/test/test_browser_context.h" | 26 #include "content/public/test/test_browser_context.h" |
26 #include "content/public/test/test_browser_thread.h" | 27 #include "content/public/test/test_browser_thread.h" |
27 #include "content/test/test_content_browser_client.h" | 28 #include "content/test/test_content_browser_client.h" |
28 #include "content/test/test_content_client.h" | 29 #include "content/test/test_content_client.h" |
29 #include "content/test/test_render_view_host.h" | 30 #include "content/test/test_render_view_host.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "url/url_util.h" | 32 #include "url/url_util.h" |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 const GURL& url) { | 563 const GURL& url) { |
563 return static_cast<SiteInstanceImpl*>( | 564 return static_cast<SiteInstanceImpl*>( |
564 SiteInstance::CreateForURL(browser_context, url)); | 565 SiteInstance::CreateForURL(browser_context, url)); |
565 } | 566 } |
566 | 567 |
567 // Test to ensure that pages that require certain privileges are grouped | 568 // Test to ensure that pages that require certain privileges are grouped |
568 // in processes with similar pages. | 569 // in processes with similar pages. |
569 TEST_F(SiteInstanceTest, ProcessSharingByType) { | 570 TEST_F(SiteInstanceTest, ProcessSharingByType) { |
570 // This test shouldn't run with --site-per-process mode, which prohibits | 571 // This test shouldn't run with --site-per-process mode, which prohibits |
571 // the renderer process reuse this test explicitly exercises. | 572 // the renderer process reuse this test explicitly exercises. |
572 const base::CommandLine& command_line = | 573 if (SiteIsolationPolicy::AreAllSitesIsolatedForTesting()) |
573 *base::CommandLine::ForCurrentProcess(); | |
574 if (command_line.HasSwitch(switches::kSitePerProcess)) | |
575 return; | 574 return; |
576 | 575 |
577 // On Android by default the number of renderer hosts is unlimited and process | 576 // On Android by default the number of renderer hosts is unlimited and process |
578 // sharing doesn't happen. We set the override so that the test can run | 577 // sharing doesn't happen. We set the override so that the test can run |
579 // everywhere. | 578 // everywhere. |
580 RenderProcessHost::SetMaxRendererProcessCount(kMaxRendererProcessCount); | 579 RenderProcessHost::SetMaxRendererProcessCount(kMaxRendererProcessCount); |
581 | 580 |
582 ChildProcessSecurityPolicyImpl* policy = | 581 ChildProcessSecurityPolicyImpl* policy = |
583 ChildProcessSecurityPolicyImpl::GetInstance(); | 582 ChildProcessSecurityPolicyImpl::GetInstance(); |
584 | 583 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 EXPECT_FALSE(webui_instance2->HasWrongProcessForURL(webui_url)); | 684 EXPECT_FALSE(webui_instance2->HasWrongProcessForURL(webui_url)); |
686 EXPECT_TRUE( | 685 EXPECT_TRUE( |
687 webui_instance2->HasWrongProcessForURL(GURL("http://google.com"))); | 686 webui_instance2->HasWrongProcessForURL(GURL("http://google.com"))); |
688 | 687 |
689 DrainMessageLoops(); | 688 DrainMessageLoops(); |
690 } | 689 } |
691 | 690 |
692 // Test to ensure that HasWrongProcessForURL behaves properly even when | 691 // Test to ensure that HasWrongProcessForURL behaves properly even when |
693 // --site-per-process is used (http://crbug.com/160671). | 692 // --site-per-process is used (http://crbug.com/160671). |
694 TEST_F(SiteInstanceTest, HasWrongProcessForURLInSitePerProcess) { | 693 TEST_F(SiteInstanceTest, HasWrongProcessForURLInSitePerProcess) { |
695 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 694 SiteIsolationPolicy::IsolateAllSitesForTesting( |
696 switches::kSitePerProcess); | 695 base::CommandLine::ForCurrentProcess()); |
697 | 696 |
698 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 697 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
699 scoped_ptr<RenderProcessHost> host; | 698 scoped_ptr<RenderProcessHost> host; |
700 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( | 699 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( |
701 SiteInstance::Create(browser_context.get()))); | 700 SiteInstance::Create(browser_context.get()))); |
702 | 701 |
703 instance->SetSite(GURL("http://evernote.com/")); | 702 instance->SetSite(GURL("http://evernote.com/")); |
704 EXPECT_TRUE(instance->HasSite()); | 703 EXPECT_TRUE(instance->HasSite()); |
705 | 704 |
706 // Check prior to "assigning" a process to the instance, which is expected | 705 // Check prior to "assigning" a process to the instance, which is expected |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 EXPECT_TRUE(instance->GetSiteURL().is_empty()); | 777 EXPECT_TRUE(instance->GetSiteURL().is_empty()); |
779 host.reset(instance->GetProcess()); | 778 host.reset(instance->GetProcess()); |
780 | 779 |
781 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( | 780 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( |
782 browser_context.get(), GURL())); | 781 browser_context.get(), GURL())); |
783 | 782 |
784 DrainMessageLoops(); | 783 DrainMessageLoops(); |
785 } | 784 } |
786 | 785 |
787 } // namespace content | 786 } // namespace content |
OLD | NEW |