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

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

Issue 1129123004: Don't treat http://gpu as a WebUI url (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CONTENT_EXPORT Created 5 years, 7 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
« no previous file with comments | « no previous file | content/browser/web_contents/web_contents_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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/web_ui_controller_factory_registry.h" 18 #include "content/browser/webui/web_ui_controller_factory_registry.h"
18 #include "content/public/common/content_client.h" 19 #include "content/public/common/content_client.h"
19 #include "content/public/common/content_constants.h" 20 #include "content/public/common/content_constants.h"
20 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
21 #include "content/public/common/url_constants.h" 22 #include "content/public/common/url_constants.h"
22 #include "content/public/common/url_utils.h" 23 #include "content/public/common/url_utils.h"
23 #include "content/public/test/mock_render_process_host.h" 24 #include "content/public/test/mock_render_process_host.h"
24 #include "content/public/test/test_browser_context.h" 25 #include "content/public/test/test_browser_context.h"
25 #include "content/public/test/test_browser_thread.h" 26 #include "content/public/test/test_browser_thread.h"
26 #include "content/test/test_content_browser_client.h" 27 #include "content/test/test_content_browser_client.h"
27 #include "content/test/test_content_client.h" 28 #include "content/test/test_content_client.h"
28 #include "content/test/test_render_view_host.h" 29 #include "content/test/test_render_view_host.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
30 #include "url/url_util.h" 31 #include "url/url_util.h"
31 32
32 namespace content { 33 namespace content {
33 namespace { 34 namespace {
34 35
35 const char kPrivilegedScheme[] = "privileged"; 36 const char kPrivilegedScheme[] = "privileged";
36 37
37 class SiteInstanceTestWebUIControllerFactory : public WebUIControllerFactory {
38 public:
39 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui,
40 const GURL& url) const override {
41 return NULL;
42 }
43 WebUI::TypeID GetWebUIType(BrowserContext* browser_context,
44 const GURL& url) const override {
45 return WebUI::kNoWebUI;
46 }
47 bool UseWebUIForURL(BrowserContext* browser_context,
48 const GURL& url) const override {
49 return HasWebUIScheme(url);
50 }
51 bool UseWebUIBindingsForURL(BrowserContext* browser_context,
52 const GURL& url) const override {
53 return HasWebUIScheme(url);
54 }
55 };
56
57 class SiteInstanceTestBrowserClient : public TestContentBrowserClient { 38 class SiteInstanceTestBrowserClient : public TestContentBrowserClient {
58 public: 39 public:
59 SiteInstanceTestBrowserClient() 40 SiteInstanceTestBrowserClient()
60 : privileged_process_id_(-1) { 41 : privileged_process_id_(-1) {
61 WebUIControllerFactory::RegisterFactory(&factory_); 42 WebUIControllerFactory::RegisterFactory(
43 ContentWebUIControllerFactory::GetInstance());
62 } 44 }
63 45
64 ~SiteInstanceTestBrowserClient() override { 46 ~SiteInstanceTestBrowserClient() override {
65 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); 47 WebUIControllerFactory::UnregisterFactoryForTesting(
48 ContentWebUIControllerFactory::GetInstance());
66 } 49 }
67 50
68 bool IsSuitableHost(RenderProcessHost* process_host, 51 bool IsSuitableHost(RenderProcessHost* process_host,
69 const GURL& site_url) override { 52 const GURL& site_url) override {
70 return (privileged_process_id_ == process_host->GetID()) == 53 return (privileged_process_id_ == process_host->GetID()) ==
71 site_url.SchemeIs(kPrivilegedScheme); 54 site_url.SchemeIs(kPrivilegedScheme);
72 } 55 }
73 56
74 void set_privileged_process_id(int process_id) { 57 void set_privileged_process_id(int process_id) {
75 privileged_process_id_ = process_id; 58 privileged_process_id_ = process_id;
76 } 59 }
77 60
78 private: 61 private:
79 SiteInstanceTestWebUIControllerFactory factory_;
80 int privileged_process_id_; 62 int privileged_process_id_;
81 }; 63 };
82 64
83 class SiteInstanceTest : public testing::Test { 65 class SiteInstanceTest : public testing::Test {
84 public: 66 public:
85 SiteInstanceTest() 67 SiteInstanceTest()
86 : ui_thread_(BrowserThread::UI, &message_loop_), 68 : ui_thread_(BrowserThread::UI, &message_loop_),
87 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, 69 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING,
88 &message_loop_), 70 &message_loop_),
89 io_thread_(BrowserThread::IO, &message_loop_), 71 io_thread_(BrowserThread::IO, &message_loop_),
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 CreateSiteInstance(browser_context.get(), 600 CreateSiteInstance(browser_context.get(),
619 GURL(kPrivilegedScheme + std::string("://baz/bar")))); 601 GURL(kPrivilegedScheme + std::string("://baz/bar"))));
620 602
621 scoped_ptr<RenderProcessHost> extension_host( 603 scoped_ptr<RenderProcessHost> extension_host(
622 extension1_instance->GetProcess()); 604 extension1_instance->GetProcess());
623 EXPECT_EQ(extension1_instance->GetProcess(), 605 EXPECT_EQ(extension1_instance->GetProcess(),
624 extension2_instance->GetProcess()); 606 extension2_instance->GetProcess());
625 607
626 // Create some WebUI instances and make sure they share a process. 608 // Create some WebUI instances and make sure they share a process.
627 scoped_refptr<SiteInstanceImpl> webui1_instance(CreateSiteInstance( 609 scoped_refptr<SiteInstanceImpl> webui1_instance(CreateSiteInstance(
628 browser_context.get(), GURL(kChromeUIScheme + std::string("://newtab")))); 610 browser_context.get(), GURL(kChromeUIScheme + std::string("://gpu"))));
629 policy->GrantWebUIBindings(webui1_instance->GetProcess()->GetID()); 611 policy->GrantWebUIBindings(webui1_instance->GetProcess()->GetID());
630 612
631 scoped_refptr<SiteInstanceImpl> webui2_instance( 613 scoped_refptr<SiteInstanceImpl> webui2_instance(CreateSiteInstance(
632 CreateSiteInstance(browser_context.get(), 614 browser_context.get(),
633 GURL(kChromeUIScheme + std::string("://history")))); 615 GURL(kChromeUIScheme + std::string("://media-internals"))));
634 616
635 scoped_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess()); 617 scoped_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess());
636 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); 618 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess());
637 619
638 // Make sure none of differing privilege processes are mixed. 620 // Make sure none of differing privilege processes are mixed.
639 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); 621 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess());
640 622
641 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { 623 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) {
642 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); 624 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]);
643 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); 625 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]);
(...skipping 26 matching lines...) Expand all
670 // The call to GetProcess actually creates a new real process, which works 652 // The call to GetProcess actually creates a new real process, which works
671 // fine, but might be a cause for problems in different contexts. 653 // fine, but might be a cause for problems in different contexts.
672 host.reset(instance->GetProcess()); 654 host.reset(instance->GetProcess());
673 EXPECT_TRUE(host.get() != NULL); 655 EXPECT_TRUE(host.get() != NULL);
674 EXPECT_TRUE(instance->HasProcess()); 656 EXPECT_TRUE(instance->HasProcess());
675 657
676 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); 658 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com")));
677 EXPECT_FALSE(instance->HasWrongProcessForURL( 659 EXPECT_FALSE(instance->HasWrongProcessForURL(
678 GURL("javascript:alert(document.location.href);"))); 660 GURL("javascript:alert(document.location.href);")));
679 661
680 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); 662 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://gpu")));
681 663
682 // Test that WebUI SiteInstances reject normal web URLs. 664 // Test that WebUI SiteInstances reject normal web URLs.
683 const GURL webui_url("chrome://settings"); 665 const GURL webui_url("chrome://gpu");
684 scoped_refptr<SiteInstanceImpl> webui_instance(static_cast<SiteInstanceImpl*>( 666 scoped_refptr<SiteInstanceImpl> webui_instance(static_cast<SiteInstanceImpl*>(
685 SiteInstance::Create(browser_context.get()))); 667 SiteInstance::Create(browser_context.get())));
686 webui_instance->SetSite(webui_url); 668 webui_instance->SetSite(webui_url);
687 scoped_ptr<RenderProcessHost> webui_host(webui_instance->GetProcess()); 669 scoped_ptr<RenderProcessHost> webui_host(webui_instance->GetProcess());
688 670
689 // Simulate granting WebUI bindings for the process. 671 // Simulate granting WebUI bindings for the process.
690 ChildProcessSecurityPolicyImpl::GetInstance()->GrantWebUIBindings( 672 ChildProcessSecurityPolicyImpl::GetInstance()->GrantWebUIBindings(
691 webui_host->GetID()); 673 webui_host->GetID());
692 674
693 EXPECT_TRUE(webui_instance->HasProcess()); 675 EXPECT_TRUE(webui_instance->HasProcess());
694 EXPECT_FALSE(webui_instance->HasWrongProcessForURL(webui_url)); 676 EXPECT_FALSE(webui_instance->HasWrongProcessForURL(webui_url));
695 EXPECT_TRUE(webui_instance->HasWrongProcessForURL(GURL("http://google.com"))); 677 EXPECT_TRUE(webui_instance->HasWrongProcessForURL(GURL("http://google.com")));
678 EXPECT_TRUE(webui_instance->HasWrongProcessForURL(GURL("http://gpu")));
696 679
697 // WebUI uses process-per-site, so another instance will use the same process 680 // WebUI uses process-per-site, so another instance will use the same process
698 // even if we haven't called GetProcess yet. Make sure HasWrongProcessForURL 681 // even if we haven't called GetProcess yet. Make sure HasWrongProcessForURL
699 // doesn't crash (http://crbug.com/137070). 682 // doesn't crash (http://crbug.com/137070).
700 scoped_refptr<SiteInstanceImpl> webui_instance2( 683 scoped_refptr<SiteInstanceImpl> webui_instance2(
701 static_cast<SiteInstanceImpl*>( 684 static_cast<SiteInstanceImpl*>(
702 SiteInstance::Create(browser_context.get()))); 685 SiteInstance::Create(browser_context.get())));
703 webui_instance2->SetSite(webui_url); 686 webui_instance2->SetSite(webui_url);
704 EXPECT_FALSE(webui_instance2->HasWrongProcessForURL(webui_url)); 687 EXPECT_FALSE(webui_instance2->HasWrongProcessForURL(webui_url));
705 EXPECT_TRUE( 688 EXPECT_TRUE(
(...skipping 23 matching lines...) Expand all
729 // The call to GetProcess actually creates a new real process, which works 712 // The call to GetProcess actually creates a new real process, which works
730 // fine, but might be a cause for problems in different contexts. 713 // fine, but might be a cause for problems in different contexts.
731 host.reset(instance->GetProcess()); 714 host.reset(instance->GetProcess());
732 EXPECT_TRUE(host.get() != NULL); 715 EXPECT_TRUE(host.get() != NULL);
733 EXPECT_TRUE(instance->HasProcess()); 716 EXPECT_TRUE(instance->HasProcess());
734 717
735 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); 718 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com")));
736 EXPECT_FALSE(instance->HasWrongProcessForURL( 719 EXPECT_FALSE(instance->HasWrongProcessForURL(
737 GURL("javascript:alert(document.location.href);"))); 720 GURL("javascript:alert(document.location.href);")));
738 721
739 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); 722 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://gpu")));
740 723
741 DrainMessageLoops(); 724 DrainMessageLoops();
742 } 725 }
743 726
744 // Test that we do not reuse a process in process-per-site mode if it has the 727 // Test that we do not reuse a process in process-per-site mode if it has the
745 // wrong bindings for its URL. http://crbug.com/174059. 728 // wrong bindings for its URL. http://crbug.com/174059.
746 TEST_F(SiteInstanceTest, ProcessPerSiteWithWrongBindings) { 729 TEST_F(SiteInstanceTest, ProcessPerSiteWithWrongBindings) {
747 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); 730 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext());
748 scoped_ptr<RenderProcessHost> host; 731 scoped_ptr<RenderProcessHost> host;
749 scoped_ptr<RenderProcessHost> host2; 732 scoped_ptr<RenderProcessHost> host2;
750 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( 733 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>(
751 SiteInstance::Create(browser_context.get()))); 734 SiteInstance::Create(browser_context.get())));
752 735
753 EXPECT_FALSE(instance->HasSite()); 736 EXPECT_FALSE(instance->HasSite());
754 EXPECT_TRUE(instance->GetSiteURL().is_empty()); 737 EXPECT_TRUE(instance->GetSiteURL().is_empty());
755 738
756 // Simulate navigating to a WebUI URL in a process that does not have WebUI 739 // Simulate navigating to a WebUI URL in a process that does not have WebUI
757 // bindings. This already requires bypassing security checks. 740 // bindings. This already requires bypassing security checks.
758 const GURL webui_url("chrome://settings"); 741 const GURL webui_url("chrome://gpu");
759 instance->SetSite(webui_url); 742 instance->SetSite(webui_url);
760 EXPECT_TRUE(instance->HasSite()); 743 EXPECT_TRUE(instance->HasSite());
761 744
762 // The call to GetProcess actually creates a new real process. 745 // The call to GetProcess actually creates a new real process.
763 host.reset(instance->GetProcess()); 746 host.reset(instance->GetProcess());
764 EXPECT_TRUE(host.get() != NULL); 747 EXPECT_TRUE(host.get() != NULL);
765 EXPECT_TRUE(instance->HasProcess()); 748 EXPECT_TRUE(instance->HasProcess());
766 749
767 // Without bindings, this should look like the wrong process. 750 // Without bindings, this should look like the wrong process.
768 EXPECT_TRUE(instance->HasWrongProcessForURL(webui_url)); 751 EXPECT_TRUE(instance->HasWrongProcessForURL(webui_url));
(...skipping 28 matching lines...) Expand all
797 EXPECT_TRUE(instance->GetSiteURL().is_empty()); 780 EXPECT_TRUE(instance->GetSiteURL().is_empty());
798 host.reset(instance->GetProcess()); 781 host.reset(instance->GetProcess());
799 782
800 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( 783 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite(
801 browser_context.get(), GURL())); 784 browser_context.get(), GURL()));
802 785
803 DrainMessageLoops(); 786 DrainMessageLoops();
804 } 787 }
805 788
806 } // namespace content 789 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/web_contents/web_contents_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698