summaryrefslogtreecommitdiffstats
path: root/content/browser/site_instance_unittest.cc
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 16:55:56 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 16:55:56 +0000
commit1fd1a5043e4de3078e3e05684a14055474da0d0b (patch)
tree25d28a7c713fd8bbda6e28bd599d4a890e6b3254 /content/browser/site_instance_unittest.cc
parent76b0f686facc70c33f2983c115933006654ee482 (diff)
downloadchromium_src-1fd1a5043e4de3078e3e05684a14055474da0d0b.zip
chromium_src-1fd1a5043e4de3078e3e05684a14055474da0d0b.tar.gz
chromium_src-1fd1a5043e4de3078e3e05684a14055474da0d0b.tar.bz2
Move WebUIFactory to chrome/, try 2.
first try was r79691 This fixes the SiteInstance unit test failure. SiteInstance has all kinds of dependencies into chrome/. This fixes the unittest just enough to get it passing without trying to refactor SiteInstance at all. BUG=77092 TEST=trybots, again Review URL: http://codereview.chromium.org/6731060 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79849 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/site_instance_unittest.cc')
-rw-r--r--content/browser/site_instance_unittest.cc67
1 files changed, 51 insertions, 16 deletions
diff --git a/content/browser/site_instance_unittest.cc b/content/browser/site_instance_unittest.cc
index 1b072aa..247dd13 100644
--- a/content/browser/site_instance_unittest.cc
+++ b/content/browser/site_instance_unittest.cc
@@ -10,21 +10,55 @@
#include "chrome/common/url_constants.h"
#include "chrome/test/testing_profile.h"
#include "content/browser/browsing_instance.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "content/browser/browsing_instance.h"
#include "content/browser/child_process_security_policy.h"
+#include "content/browser/content_browser_client.h"
#include "content/browser/renderer_host/render_view_host.h"
-#include "content/browser/site_instance.h"
#include "content/browser/renderer_host/test_render_view_host.h"
+#include "content/browser/site_instance.h"
#include "content/browser/tab_contents/navigation_entry.h"
#include "content/browser/tab_contents/tab_contents.h"
+#include "content/browser/webui/empty_web_ui_factory.h"
+#include "content/common/content_client.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+// TODO(estade): this shouldn't need to be chrome:, but it does (or else GURL
+// doesn't think that the webui URLs have a host). Figure out where this is
+// coming from and fix it.
+const char kWebUIScheme[] = "chrome";
+
+class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory {
+ public:
+ virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const {
+ return HasWebUIScheme(url);
+ }
+ virtual bool HasWebUIScheme(const GURL& url) const {
+ return url.SchemeIs(kWebUIScheme);
+ }
+};
+
+class SiteInstanceTestBrowserClient : public content::ContentBrowserClient {
+ public:
+ virtual content::WebUIFactory* GetWebUIFactory() {
+ return &factory_;
+ }
+
+ private:
+ SiteInstanceTestWebUIFactory factory_;
+};
class SiteInstanceTest : public testing::Test {
+ public:
+ virtual void SetUp() {
+ content::GetContentClient()->set_browser(&browser_client_);
+ }
+
private:
MessageLoopForUI message_loop_;
-};
-namespace {
+ SiteInstanceTestBrowserClient browser_client_;
+};
class TestBrowsingInstance : public BrowsingInstance {
public:
@@ -51,14 +85,13 @@ class TestBrowsingInstance : public BrowsingInstance {
int* deleteCounter_;
};
-
class TestSiteInstance : public SiteInstance {
public:
static TestSiteInstance* CreateTestSiteInstance(Profile* profile,
int* siteDeleteCounter,
int* browsingDeleteCounter) {
TestBrowsingInstance* browsing_instance =
- new TestBrowsingInstance(profile, browsingDeleteCounter);
+ new TestBrowsingInstance(profile, browsingDeleteCounter);
return new TestSiteInstance(browsing_instance, siteDeleteCounter);
}
@@ -441,22 +474,24 @@ TEST_F(SiteInstanceTest, ProcessSharingByType) {
extension2_instance->GetProcess());
// Create some WebUI instances and make sure they share a process.
- scoped_refptr<SiteInstance> dom1_instance(
- CreateSiteInstance(&rph_factory, GURL("chrome://newtab")));
- policy->GrantWebUIBindings(dom1_instance->GetProcess()->id());
+ scoped_refptr<SiteInstance> webui1_instance(
+ CreateSiteInstance(&rph_factory,
+ GURL(kWebUIScheme + std::string("://newtab"))));
+ policy->GrantWebUIBindings(webui1_instance->GetProcess()->id());
- scoped_refptr<SiteInstance> dom2_instance(
- CreateSiteInstance(&rph_factory, GURL("chrome://history")));
+ scoped_refptr<SiteInstance> webui2_instance(
+ CreateSiteInstance(&rph_factory,
+ GURL(kWebUIScheme + std::string("://history"))));
- scoped_ptr<RenderProcessHost> dom_host(dom1_instance->GetProcess());
- EXPECT_EQ(dom1_instance->GetProcess(), dom2_instance->GetProcess());
+ scoped_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess());
+ EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess());
// Make sure none of differing privilege processes are mixed.
- EXPECT_NE(extension1_instance->GetProcess(), dom1_instance->GetProcess());
+ EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess());
for (size_t i = 0; i < chrome::kMaxRendererProcessCount; ++i) {
EXPECT_NE(extension1_instance->GetProcess(), hosts[i]);
- EXPECT_NE(dom1_instance->GetProcess(), hosts[i]);
+ EXPECT_NE(webui1_instance->GetProcess(), hosts[i]);
}
STLDeleteContainerPointers(hosts.begin(), hosts.end());