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

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

Issue 6731060: Move WebUIFactory to chrome/, try 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/stl_util-inl.h" 5 #include "base/stl_util-inl.h"
6 #include "base/string16.h" 6 #include "base/string16.h"
7 #include "chrome/browser/renderer_host/browser_render_process_host.h" 7 #include "chrome/browser/renderer_host/browser_render_process_host.h"
8 #include "chrome/common/chrome_constants.h" 8 #include "chrome/common/chrome_constants.h"
9 #include "chrome/common/render_messages.h" 9 #include "chrome/common/render_messages.h"
10 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
11 #include "chrome/test/testing_profile.h" 11 #include "chrome/test/testing_profile.h"
12 #include "content/browser/browsing_instance.h" 12 #include "content/browser/browsing_instance.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "content/browser/browsing_instance.h"
15 #include "content/browser/child_process_security_policy.h" 13 #include "content/browser/child_process_security_policy.h"
14 #include "content/browser/content_browser_client.h"
16 #include "content/browser/renderer_host/render_view_host.h" 15 #include "content/browser/renderer_host/render_view_host.h"
16 #include "content/browser/renderer_host/test_render_view_host.h"
17 #include "content/browser/site_instance.h" 17 #include "content/browser/site_instance.h"
18 #include "content/browser/renderer_host/test_render_view_host.h"
19 #include "content/browser/tab_contents/navigation_entry.h" 18 #include "content/browser/tab_contents/navigation_entry.h"
20 #include "content/browser/tab_contents/tab_contents.h" 19 #include "content/browser/tab_contents/tab_contents.h"
21 20 #include "content/browser/webui/empty_web_ui_factory.h"
22 class SiteInstanceTest : public testing::Test { 21 #include "content/common/content_client.h"
23 private: 22 #include "testing/gtest/include/gtest/gtest.h"
24 MessageLoopForUI message_loop_;
25 };
26 23
27 namespace { 24 namespace {
28 25
26 // TODO(estade): this shouldn't need to be chrome:, but it does (or else GURL
27 // doesn't think that the webui URLs have a host). Figure out where this is
28 // coming from and fix it.
29 const char kWebUIScheme[] = "chrome";
30
31 class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory {
32 public:
33 virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const {
34 return HasWebUIScheme(url);
35 }
36 virtual bool HasWebUIScheme(const GURL& url) const {
37 return url.SchemeIs(kWebUIScheme);
38 }
39 };
40
41 class SiteInstanceTestBrowserClient : public content::ContentBrowserClient {
42 public:
43 virtual content::WebUIFactory* GetWebUIFactory() {
44 return &factory_;
45 }
46
47 private:
48 SiteInstanceTestWebUIFactory factory_;
49 };
50
51 class SiteInstanceTest : public testing::Test {
52 public:
53 virtual void SetUp() {
54 content::GetContentClient()->set_browser(&browser_client_);
55 }
56
57 private:
58 MessageLoopForUI message_loop_;
59
60 SiteInstanceTestBrowserClient browser_client_;
61 };
62
29 class TestBrowsingInstance : public BrowsingInstance { 63 class TestBrowsingInstance : public BrowsingInstance {
30 public: 64 public:
31 TestBrowsingInstance(Profile* profile, int* deleteCounter) 65 TestBrowsingInstance(Profile* profile, int* deleteCounter)
32 : BrowsingInstance(profile), 66 : BrowsingInstance(profile),
33 use_process_per_site(false), 67 use_process_per_site(false),
34 deleteCounter_(deleteCounter) { 68 deleteCounter_(deleteCounter) {
35 } 69 }
36 70
37 // Overrides BrowsingInstance::ShouldUseProcessPerSite so that we can test 71 // Overrides BrowsingInstance::ShouldUseProcessPerSite so that we can test
38 // both alternatives without using command-line switches. 72 // both alternatives without using command-line switches.
39 bool ShouldUseProcessPerSite(const GURL& url) { 73 bool ShouldUseProcessPerSite(const GURL& url) {
40 return use_process_per_site; 74 return use_process_per_site;
41 } 75 }
42 76
43 // Set by individual tests. 77 // Set by individual tests.
44 bool use_process_per_site; 78 bool use_process_per_site;
45 79
46 private: 80 private:
47 ~TestBrowsingInstance() { 81 ~TestBrowsingInstance() {
48 (*deleteCounter_)++; 82 (*deleteCounter_)++;
49 } 83 }
50 84
51 int* deleteCounter_; 85 int* deleteCounter_;
52 }; 86 };
53 87
54
55 class TestSiteInstance : public SiteInstance { 88 class TestSiteInstance : public SiteInstance {
56 public: 89 public:
57 static TestSiteInstance* CreateTestSiteInstance(Profile* profile, 90 static TestSiteInstance* CreateTestSiteInstance(Profile* profile,
58 int* siteDeleteCounter, 91 int* siteDeleteCounter,
59 int* browsingDeleteCounter) { 92 int* browsingDeleteCounter) {
60 TestBrowsingInstance* browsing_instance = 93 TestBrowsingInstance* browsing_instance =
61 new TestBrowsingInstance(profile, browsingDeleteCounter); 94 new TestBrowsingInstance(profile, browsingDeleteCounter);
62 return new TestSiteInstance(browsing_instance, siteDeleteCounter); 95 return new TestSiteInstance(browsing_instance, siteDeleteCounter);
63 } 96 }
64 97
65 private: 98 private:
66 TestSiteInstance(BrowsingInstance* browsing_instance, int* deleteCounter) 99 TestSiteInstance(BrowsingInstance* browsing_instance, int* deleteCounter)
67 : SiteInstance(browsing_instance), deleteCounter_(deleteCounter) {} 100 : SiteInstance(browsing_instance), deleteCounter_(deleteCounter) {}
68 ~TestSiteInstance() { 101 ~TestSiteInstance() {
69 (*deleteCounter_)++; 102 (*deleteCounter_)++;
70 } 103 }
71 104
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 467
435 scoped_refptr<SiteInstance> extension2_instance( 468 scoped_refptr<SiteInstance> extension2_instance(
436 CreateSiteInstance(&rph_factory, GURL("chrome-extension://baz/bar"))); 469 CreateSiteInstance(&rph_factory, GURL("chrome-extension://baz/bar")));
437 470
438 scoped_ptr<RenderProcessHost> extension_host( 471 scoped_ptr<RenderProcessHost> extension_host(
439 extension1_instance->GetProcess()); 472 extension1_instance->GetProcess());
440 EXPECT_EQ(extension1_instance->GetProcess(), 473 EXPECT_EQ(extension1_instance->GetProcess(),
441 extension2_instance->GetProcess()); 474 extension2_instance->GetProcess());
442 475
443 // Create some WebUI instances and make sure they share a process. 476 // Create some WebUI instances and make sure they share a process.
444 scoped_refptr<SiteInstance> dom1_instance( 477 scoped_refptr<SiteInstance> webui1_instance(
445 CreateSiteInstance(&rph_factory, GURL("chrome://newtab"))); 478 CreateSiteInstance(&rph_factory,
446 policy->GrantWebUIBindings(dom1_instance->GetProcess()->id()); 479 GURL(kWebUIScheme + std::string("://newtab"))));
480 policy->GrantWebUIBindings(webui1_instance->GetProcess()->id());
447 481
448 scoped_refptr<SiteInstance> dom2_instance( 482 scoped_refptr<SiteInstance> webui2_instance(
449 CreateSiteInstance(&rph_factory, GURL("chrome://history"))); 483 CreateSiteInstance(&rph_factory,
484 GURL(kWebUIScheme + std::string("://history"))));
450 485
451 scoped_ptr<RenderProcessHost> dom_host(dom1_instance->GetProcess()); 486 scoped_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess());
452 EXPECT_EQ(dom1_instance->GetProcess(), dom2_instance->GetProcess()); 487 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess());
453 488
454 // Make sure none of differing privilege processes are mixed. 489 // Make sure none of differing privilege processes are mixed.
455 EXPECT_NE(extension1_instance->GetProcess(), dom1_instance->GetProcess()); 490 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess());
456 491
457 for (size_t i = 0; i < chrome::kMaxRendererProcessCount; ++i) { 492 for (size_t i = 0; i < chrome::kMaxRendererProcessCount; ++i) {
458 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); 493 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]);
459 EXPECT_NE(dom1_instance->GetProcess(), hosts[i]); 494 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]);
460 } 495 }
461 496
462 STLDeleteContainerPointers(hosts.begin(), hosts.end()); 497 STLDeleteContainerPointers(hosts.begin(), hosts.end());
463 } 498 }
464 499
465 // Test to ensure that profiles that derive from each other share site 500 // Test to ensure that profiles that derive from each other share site
466 // information. 501 // information.
467 TEST_F(SiteInstanceTest, GetSiteInstanceMap) { 502 TEST_F(SiteInstanceTest, GetSiteInstanceMap) {
468 int deleteCounter = 0; 503 int deleteCounter = 0;
469 504
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 GURL("chrome-extension://baz/bar"))); 556 GURL("chrome-extension://baz/bar")));
522 EXPECT_EQ(s5a, s5b); 557 EXPECT_EQ(s5a, s5b);
523 558
524 // The derived profiles with the different sites. 559 // The derived profiles with the different sites.
525 scoped_refptr<SiteInstance> s6a(instance1->GetSiteInstanceForURL( 560 scoped_refptr<SiteInstance> s6a(instance1->GetSiteInstanceForURL(
526 GURL("chrome-extension://baz/bar"))); 561 GURL("chrome-extension://baz/bar")));
527 scoped_refptr<SiteInstance> s6b(instance3->GetSiteInstanceForURL( 562 scoped_refptr<SiteInstance> s6b(instance3->GetSiteInstanceForURL(
528 GURL("chrome-extension://foo/boo"))); 563 GURL("chrome-extension://foo/boo")));
529 EXPECT_NE(s6a, s6b); 564 EXPECT_NE(s6a, s6b);
530 } 565 }
OLDNEW
« no previous file with comments | « content/browser/site_instance.cc ('k') | content/browser/tab_contents/render_view_host_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698