| 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" |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_blank, url_foo)); | 398 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_blank, url_foo)); |
| 399 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_blank, url_foo_https)); | 399 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_blank, url_foo_https)); |
| 400 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_blank, url_foo_port)); | 400 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_blank, url_foo_port)); |
| 401 | 401 |
| 402 DrainMessageLoops(); | 402 DrainMessageLoops(); |
| 403 } | 403 } |
| 404 | 404 |
| 405 // Test to ensure that there is only one SiteInstance per site in a given | 405 // Test to ensure that there is only one SiteInstance per site in a given |
| 406 // BrowsingInstance, when process-per-site is not in use. | 406 // BrowsingInstance, when process-per-site is not in use. |
| 407 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { | 407 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { |
| 408 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( | 408 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 409 switches::kProcessPerSite)); | 409 switches::kProcessPerSite)); |
| 410 int delete_counter = 0; | 410 int delete_counter = 0; |
| 411 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 411 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 412 TestBrowsingInstance* browsing_instance = | 412 TestBrowsingInstance* browsing_instance = |
| 413 new TestBrowsingInstance(browser_context.get(), &delete_counter); | 413 new TestBrowsingInstance(browser_context.get(), &delete_counter); |
| 414 | 414 |
| 415 const GURL url_a1("http://www.google.com/1.html"); | 415 const GURL url_a1("http://www.google.com/1.html"); |
| 416 scoped_refptr<SiteInstanceImpl> site_instance_a1( | 416 scoped_refptr<SiteInstanceImpl> site_instance_a1( |
| 417 static_cast<SiteInstanceImpl*>( | 417 static_cast<SiteInstanceImpl*>( |
| 418 browsing_instance->GetSiteInstanceForURL(url_a1))); | 418 browsing_instance->GetSiteInstanceForURL(url_a1))); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 472 |
| 473 // browsing_instances will be deleted when their SiteInstances are deleted. | 473 // browsing_instances will be deleted when their SiteInstances are deleted. |
| 474 // The processes will be unregistered when the RPH scoped_ptrs go away. | 474 // The processes will be unregistered when the RPH scoped_ptrs go away. |
| 475 | 475 |
| 476 DrainMessageLoops(); | 476 DrainMessageLoops(); |
| 477 } | 477 } |
| 478 | 478 |
| 479 // Test to ensure that there is only one RenderProcessHost per site for an | 479 // Test to ensure that there is only one RenderProcessHost per site for an |
| 480 // entire BrowserContext, if process-per-site is in use. | 480 // entire BrowserContext, if process-per-site is in use. |
| 481 TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInBrowserContext) { | 481 TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInBrowserContext) { |
| 482 CommandLine::ForCurrentProcess()->AppendSwitch( | 482 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 483 switches::kProcessPerSite); | 483 switches::kProcessPerSite); |
| 484 int delete_counter = 0; | 484 int delete_counter = 0; |
| 485 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 485 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 486 TestBrowsingInstance* browsing_instance = | 486 TestBrowsingInstance* browsing_instance = |
| 487 new TestBrowsingInstance(browser_context.get(), &delete_counter); | 487 new TestBrowsingInstance(browser_context.get(), &delete_counter); |
| 488 | 488 |
| 489 const GURL url_a1("http://www.google.com/1.html"); | 489 const GURL url_a1("http://www.google.com/1.html"); |
| 490 scoped_refptr<SiteInstanceImpl> site_instance_a1( | 490 scoped_refptr<SiteInstanceImpl> site_instance_a1( |
| 491 static_cast<SiteInstanceImpl*>( | 491 static_cast<SiteInstanceImpl*>( |
| 492 browsing_instance->GetSiteInstanceForURL(url_a1))); | 492 browsing_instance->GetSiteInstanceForURL(url_a1))); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 const GURL& url) { | 563 const GURL& url) { |
| 564 return static_cast<SiteInstanceImpl*>( | 564 return static_cast<SiteInstanceImpl*>( |
| 565 SiteInstance::CreateForURL(browser_context, url)); | 565 SiteInstance::CreateForURL(browser_context, url)); |
| 566 } | 566 } |
| 567 | 567 |
| 568 // Test to ensure that pages that require certain privileges are grouped | 568 // Test to ensure that pages that require certain privileges are grouped |
| 569 // in processes with similar pages. | 569 // in processes with similar pages. |
| 570 TEST_F(SiteInstanceTest, ProcessSharingByType) { | 570 TEST_F(SiteInstanceTest, ProcessSharingByType) { |
| 571 // This test shouldn't run with --site-per-process mode, since it doesn't | 571 // This test shouldn't run with --site-per-process mode, since it doesn't |
| 572 // allow render process reuse, which this test explicitly exercises. | 572 // allow render process reuse, which this test explicitly exercises. |
| 573 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) | 573 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 574 switches::kSitePerProcess)) |
| 574 return; | 575 return; |
| 575 | 576 |
| 576 // On Android by default the number of renderer hosts is unlimited and process | 577 // On Android by default the number of renderer hosts is unlimited and process |
| 577 // sharing doesn't happen. We set the override so that the test can run | 578 // sharing doesn't happen. We set the override so that the test can run |
| 578 // everywhere. | 579 // everywhere. |
| 579 RenderProcessHost::SetMaxRendererProcessCount(kMaxRendererProcessCount); | 580 RenderProcessHost::SetMaxRendererProcessCount(kMaxRendererProcessCount); |
| 580 | 581 |
| 581 ChildProcessSecurityPolicyImpl* policy = | 582 ChildProcessSecurityPolicyImpl* policy = |
| 582 ChildProcessSecurityPolicyImpl::GetInstance(); | 583 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 583 | 584 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 EXPECT_FALSE(webui_instance2->HasWrongProcessForURL(webui_url)); | 684 EXPECT_FALSE(webui_instance2->HasWrongProcessForURL(webui_url)); |
| 684 EXPECT_TRUE( | 685 EXPECT_TRUE( |
| 685 webui_instance2->HasWrongProcessForURL(GURL("http://google.com"))); | 686 webui_instance2->HasWrongProcessForURL(GURL("http://google.com"))); |
| 686 | 687 |
| 687 DrainMessageLoops(); | 688 DrainMessageLoops(); |
| 688 } | 689 } |
| 689 | 690 |
| 690 // Test to ensure that HasWrongProcessForURL behaves properly even when | 691 // Test to ensure that HasWrongProcessForURL behaves properly even when |
| 691 // --site-per-process is used (http://crbug.com/160671). | 692 // --site-per-process is used (http://crbug.com/160671). |
| 692 TEST_F(SiteInstanceTest, HasWrongProcessForURLInSitePerProcess) { | 693 TEST_F(SiteInstanceTest, HasWrongProcessForURLInSitePerProcess) { |
| 693 CommandLine::ForCurrentProcess()->AppendSwitch( | 694 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 694 switches::kSitePerProcess); | 695 switches::kSitePerProcess); |
| 695 | 696 |
| 696 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 697 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 697 scoped_ptr<RenderProcessHost> host; | 698 scoped_ptr<RenderProcessHost> host; |
| 698 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( | 699 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( |
| 699 SiteInstance::Create(browser_context.get()))); | 700 SiteInstance::Create(browser_context.get()))); |
| 700 | 701 |
| 701 instance->SetSite(GURL("http://evernote.com/")); | 702 instance->SetSite(GURL("http://evernote.com/")); |
| 702 EXPECT_TRUE(instance->HasSite()); | 703 EXPECT_TRUE(instance->HasSite()); |
| 703 | 704 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 EXPECT_TRUE(host2.get() != NULL); | 758 EXPECT_TRUE(host2.get() != NULL); |
| 758 EXPECT_TRUE(instance2->HasProcess()); | 759 EXPECT_TRUE(instance2->HasProcess()); |
| 759 EXPECT_NE(host.get(), host2.get()); | 760 EXPECT_NE(host.get(), host2.get()); |
| 760 | 761 |
| 761 DrainMessageLoops(); | 762 DrainMessageLoops(); |
| 762 } | 763 } |
| 763 | 764 |
| 764 // Test that we do not register processes with empty sites for process-per-site | 765 // Test that we do not register processes with empty sites for process-per-site |
| 765 // mode. | 766 // mode. |
| 766 TEST_F(SiteInstanceTest, NoProcessPerSiteForEmptySite) { | 767 TEST_F(SiteInstanceTest, NoProcessPerSiteForEmptySite) { |
| 767 CommandLine::ForCurrentProcess()->AppendSwitch( | 768 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 768 switches::kProcessPerSite); | 769 switches::kProcessPerSite); |
| 769 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 770 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 770 scoped_ptr<RenderProcessHost> host; | 771 scoped_ptr<RenderProcessHost> host; |
| 771 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( | 772 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( |
| 772 SiteInstance::Create(browser_context.get()))); | 773 SiteInstance::Create(browser_context.get()))); |
| 773 | 774 |
| 774 instance->SetSite(GURL()); | 775 instance->SetSite(GURL()); |
| 775 EXPECT_TRUE(instance->HasSite()); | 776 EXPECT_TRUE(instance->HasSite()); |
| 776 EXPECT_TRUE(instance->GetSiteURL().is_empty()); | 777 EXPECT_TRUE(instance->GetSiteURL().is_empty()); |
| 777 host.reset(instance->GetProcess()); | 778 host.reset(instance->GetProcess()); |
| 778 | 779 |
| 779 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( | 780 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( |
| 780 browser_context.get(), GURL())); | 781 browser_context.get(), GURL())); |
| 781 | 782 |
| 782 DrainMessageLoops(); | 783 DrainMessageLoops(); |
| 783 } | 784 } |
| 784 | 785 |
| 785 } // namespace content | 786 } // namespace content |
| OLD | NEW |