Index: content/browser/site_instance_impl_unittest.cc |
=================================================================== |
--- content/browser/site_instance_impl_unittest.cc (revision 164121) |
+++ content/browser/site_instance_impl_unittest.cc (working copy) |
@@ -28,7 +28,17 @@ |
#include "googleurl/src/url_util.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-namespace content { |
+using content::BrowserContext; |
+using content::BrowserThread; |
+using content::BrowserThreadImpl; |
+using content::MockRenderProcessHost; |
+using content::MockRenderProcessHostFactory; |
+using content::NavigationEntry; |
+using content::NavigationEntryImpl; |
+using content::SiteInstance; |
+using content::WebContentsImpl; |
+using content::WebUI; |
+using content::WebUIController; |
namespace { |
@@ -36,7 +46,8 @@ |
const char kPrivilegedScheme[] = "privileged"; |
-class SiteInstanceTestWebUIControllerFactory : public WebUIControllerFactory { |
+class SiteInstanceTestWebUIControllerFactory |
+ : public content::WebUIControllerFactory { |
public: |
virtual WebUIController* CreateWebUIControllerForURL( |
WebUI* web_ui, const GURL& url) const OVERRIDE { |
@@ -48,11 +59,11 @@ |
} |
virtual bool UseWebUIForURL(BrowserContext* browser_context, |
const GURL& url) const OVERRIDE { |
- return GetContentClient()->HasWebUIScheme(url); |
+ return content::GetContentClient()->HasWebUIScheme(url); |
} |
virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, |
const GURL& url) const OVERRIDE { |
- return GetContentClient()->HasWebUIScheme(url); |
+ return content::GetContentClient()->HasWebUIScheme(url); |
} |
virtual bool IsURLAcceptableForWebUI( |
BrowserContext* browser_context, |
@@ -72,17 +83,18 @@ |
} |
}; |
-class SiteInstanceTestBrowserClient : public TestContentBrowserClient { |
+class SiteInstanceTestBrowserClient : public content::TestContentBrowserClient { |
public: |
SiteInstanceTestBrowserClient() |
: privileged_process_id_(-1) { |
} |
- virtual WebUIControllerFactory* GetWebUIControllerFactory() OVERRIDE { |
+ virtual content::WebUIControllerFactory* |
+ GetWebUIControllerFactory() OVERRIDE { |
return &factory_; |
} |
- virtual bool IsSuitableHost(RenderProcessHost* process_host, |
+ virtual bool IsSuitableHost(content::RenderProcessHost* process_host, |
const GURL& site_url) OVERRIDE { |
return (privileged_process_id_ == process_host->GetID()) == |
site_url.SchemeIs(kPrivilegedScheme); |
@@ -101,28 +113,28 @@ |
public: |
SiteInstanceTest() |
: ui_thread_(BrowserThread::UI, &message_loop_), |
- file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, |
+ file_user_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING, |
&message_loop_), |
- io_thread_(BrowserThread::IO, &message_loop_), |
+ io_thread_(content::BrowserThread::IO, &message_loop_), |
old_client_(NULL), |
old_browser_client_(NULL) { |
} |
virtual void SetUp() { |
- old_client_ = GetContentClient(); |
- old_browser_client_ = GetContentClient()->browser(); |
- SetContentClient(&client_); |
- GetContentClient()->set_browser_for_testing(&browser_client_); |
+ old_client_ = content::GetContentClient(); |
+ old_browser_client_ = content::GetContentClient()->browser(); |
+ content::SetContentClient(&client_); |
+ content::GetContentClient()->set_browser_for_testing(&browser_client_); |
url_util::AddStandardScheme(kPrivilegedScheme); |
url_util::AddStandardScheme(chrome::kChromeUIScheme); |
} |
virtual void TearDown() { |
// Ensure that no RenderProcessHosts are left over after the tests. |
- EXPECT_TRUE(RenderProcessHost::AllHostsIterator().IsAtEnd()); |
+ EXPECT_TRUE(content::RenderProcessHost::AllHostsIterator().IsAtEnd()); |
- GetContentClient()->set_browser_for_testing(old_browser_client_); |
- SetContentClient(old_client_); |
+ content::GetContentClient()->set_browser_for_testing(old_browser_client_); |
+ content::SetContentClient(old_client_); |
// http://crbug.com/143565 found SiteInstanceTest leaking an |
// AppCacheDatabase. This happens because some part of the test indirectly |
@@ -150,14 +162,14 @@ |
private: |
MessageLoopForUI message_loop_; |
- TestBrowserThread ui_thread_; |
- TestBrowserThread file_user_blocking_thread_; |
- TestBrowserThread io_thread_; |
+ content::TestBrowserThread ui_thread_; |
+ content::TestBrowserThread file_user_blocking_thread_; |
+ content::TestBrowserThread io_thread_; |
SiteInstanceTestClient client_; |
SiteInstanceTestBrowserClient browser_client_; |
- ContentClient* old_client_; |
- ContentBrowserClient* old_browser_client_; |
+ content::ContentClient* old_client_; |
+ content::ContentBrowserClient* old_browser_client_; |
}; |
// Subclass of BrowsingInstance that updates a counter when deleted and |
@@ -212,7 +224,7 @@ |
TEST_F(SiteInstanceTest, SiteInstanceDestructor) { |
// The existence of this object will cause WebContentsImpl to create our |
// test one instead of the real one. |
- RenderViewHostTestEnabler rvh_test_enabler; |
+ content::RenderViewHostTestEnabler rvh_test_enabler; |
int site_delete_counter = 0; |
int browsing_delete_counter = 0; |
const GURL url("test:foo"); |
@@ -224,7 +236,8 @@ |
EXPECT_EQ(0, site_delete_counter); |
NavigationEntryImpl* e1 = new NavigationEntryImpl( |
- instance, 0, url, Referrer(), string16(), PAGE_TRANSITION_LINK, false); |
+ instance, 0, url, content::Referrer(), string16(), |
+ content::PAGE_TRANSITION_LINK, false); |
// Redundantly setting e1's SiteInstance shouldn't affect the ref count. |
e1->set_site_instance(instance); |
@@ -232,7 +245,8 @@ |
// Add a second reference |
NavigationEntryImpl* e2 = new NavigationEntryImpl( |
- instance, 0, url, Referrer(), string16(), PAGE_TRANSITION_LINK, false); |
+ instance, 0, url, content::Referrer(), string16(), |
+ content::PAGE_TRANSITION_LINK, false); |
// Now delete both entries and be sure the SiteInstance goes away. |
delete e1; |
@@ -245,7 +259,8 @@ |
// browsing_instance is now deleted |
// Ensure that instances are deleted when their RenderViewHosts are gone. |
- scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
+ scoped_ptr<content::TestBrowserContext> browser_context( |
+ new content::TestBrowserContext()); |
instance = |
TestSiteInstance::CreateTestSiteInstance(browser_context.get(), |
&site_delete_counter, |
@@ -284,7 +299,8 @@ |
&browsing_delete_counter); |
NavigationEntryImpl* e1 = new NavigationEntryImpl( |
- instance1, 0, url, Referrer(), string16(), PAGE_TRANSITION_LINK, false); |
+ instance1, 0, url, content::Referrer(), string16(), |
+ content::PAGE_TRANSITION_LINK, false); |
// Clone the entry |
NavigationEntryImpl* e2 = new NavigationEntryImpl(*e1); |
@@ -311,8 +327,9 @@ |
// Test to ensure GetProcess returns and creates processes correctly. |
TEST_F(SiteInstanceTest, GetProcess) { |
// Ensure that GetProcess returns a process. |
- scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
- scoped_ptr<RenderProcessHost> host1; |
+ scoped_ptr<content::TestBrowserContext> browser_context( |
+ new content::TestBrowserContext()); |
+ scoped_ptr<content::RenderProcessHost> host1; |
scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( |
SiteInstance::Create(browser_context.get()))); |
host1.reset(instance->GetProcess()); |
@@ -321,7 +338,7 @@ |
// Ensure that GetProcess creates a new process. |
scoped_refptr<SiteInstanceImpl> instance2(static_cast<SiteInstanceImpl*>( |
SiteInstance::Create(browser_context.get()))); |
- scoped_ptr<RenderProcessHost> host2(instance2->GetProcess()); |
+ scoped_ptr<content::RenderProcessHost> host2(instance2->GetProcess()); |
EXPECT_TRUE(host2.get() != NULL); |
EXPECT_NE(host1.get(), host2.get()); |
@@ -412,7 +429,8 @@ |
ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( |
switches::kProcessPerSite)); |
int delete_counter = 0; |
- scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
+ scoped_ptr<content::TestBrowserContext> browser_context( |
+ new content::TestBrowserContext()); |
TestBrowsingInstance* browsing_instance = |
new TestBrowsingInstance(browser_context.get(), &delete_counter); |
@@ -455,8 +473,9 @@ |
// The two SiteInstances for http://google.com should not use the same process |
// if process-per-site is not enabled. |
- scoped_ptr<RenderProcessHost> process_a1(site_instance_a1->GetProcess()); |
- scoped_ptr<RenderProcessHost> process_a2_2( |
+ scoped_ptr<content::RenderProcessHost> process_a1( |
+ site_instance_a1->GetProcess()); |
+ scoped_ptr<content::RenderProcessHost> process_a2_2( |
site_instance_a2_2->GetProcess()); |
EXPECT_NE(process_a1.get(), process_a2_2.get()); |
@@ -486,7 +505,8 @@ |
CommandLine::ForCurrentProcess()->AppendSwitch( |
switches::kProcessPerSite); |
int delete_counter = 0; |
- scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
+ scoped_ptr<content::TestBrowserContext> browser_context( |
+ new content::TestBrowserContext()); |
TestBrowsingInstance* browsing_instance = |
new TestBrowsingInstance(browser_context.get(), &delete_counter); |
@@ -495,7 +515,7 @@ |
static_cast<SiteInstanceImpl*>( |
browsing_instance->GetSiteInstanceForURL(url_a1))); |
EXPECT_TRUE(site_instance_a1.get() != NULL); |
- scoped_ptr<RenderProcessHost> process_a1( |
+ scoped_ptr<content::RenderProcessHost> process_a1( |
site_instance_a1->GetProcess()); |
// A separate site should create a separate SiteInstance. |
@@ -531,14 +551,15 @@ |
// A visit to the original site in a new BrowsingInstance (different browser |
// context) should return a different SiteInstance with a different process. |
- scoped_ptr<TestBrowserContext> browser_context2(new TestBrowserContext()); |
+ scoped_ptr<content::TestBrowserContext> browser_context2( |
+ new content::TestBrowserContext()); |
TestBrowsingInstance* browsing_instance3 = |
new TestBrowsingInstance(browser_context2.get(), &delete_counter); |
scoped_refptr<SiteInstanceImpl> site_instance_a2_3( |
static_cast<SiteInstanceImpl*>( |
browsing_instance3->GetSiteInstanceForURL(url_a2))); |
EXPECT_TRUE(site_instance_a2_3.get() != NULL); |
- scoped_ptr<RenderProcessHost> process_a2_3( |
+ scoped_ptr<content::RenderProcessHost> process_a2_3( |
site_instance_a2_3->GetProcess()); |
EXPECT_NE(site_instance_a1.get(), site_instance_a2_3.get()); |
EXPECT_NE(process_a1.get(), process_a2_3.get()); |
@@ -565,9 +586,10 @@ |
DrainMessageLoops(); |
} |
-static SiteInstanceImpl* CreateSiteInstance(BrowserContext* browser_context, |
- RenderProcessHostFactory* factory, |
- const GURL& url) { |
+static SiteInstanceImpl* CreateSiteInstance( |
+ content::BrowserContext* browser_context, |
+ content::RenderProcessHostFactory* factory, |
+ const GURL& url) { |
SiteInstanceImpl* instance = |
reinterpret_cast<SiteInstanceImpl*>( |
SiteInstance::CreateForURL(browser_context, url)); |
@@ -583,9 +605,10 @@ |
ChildProcessSecurityPolicyImpl::GetInstance(); |
// Make a bunch of mock renderers so that we hit the limit. |
- scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
+ scoped_ptr<content::TestBrowserContext> browser_context( |
+ new content::TestBrowserContext()); |
std::vector<MockRenderProcessHost*> hosts; |
- for (size_t i = 0; i < kMaxRendererProcessCount; ++i) |
+ for (size_t i = 0; i < content::kMaxRendererProcessCount; ++i) |
hosts.push_back(new MockRenderProcessHost(browser_context.get())); |
// Create some extension instances and make sure they share a process. |
@@ -598,7 +621,7 @@ |
CreateSiteInstance(browser_context.get(), &rph_factory, |
GURL(kPrivilegedScheme + std::string("://baz/bar")))); |
- scoped_ptr<RenderProcessHost> extension_host( |
+ scoped_ptr<content::RenderProcessHost> extension_host( |
extension1_instance->GetProcess()); |
EXPECT_EQ(extension1_instance->GetProcess(), |
extension2_instance->GetProcess()); |
@@ -613,13 +636,14 @@ |
browser_context.get(), &rph_factory, |
GURL(chrome::kChromeUIScheme + std::string("://history")))); |
- scoped_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess()); |
+ scoped_ptr<content::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(), webui1_instance->GetProcess()); |
- for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { |
+ for (size_t i = 0; i < content::kMaxRendererProcessCount; ++i) { |
EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); |
EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); |
} |
@@ -632,8 +656,9 @@ |
// Test to ensure that HasWrongProcessForURL behaves properly for different |
// types of URLs. |
TEST_F(SiteInstanceTest, HasWrongProcessForURL) { |
- scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
- scoped_ptr<RenderProcessHost> host; |
+ scoped_ptr<content::TestBrowserContext> browser_context( |
+ new content::TestBrowserContext()); |
+ scoped_ptr<content::RenderProcessHost> host; |
scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( |
SiteInstance::Create(browser_context.get()))); |
@@ -661,5 +686,3 @@ |
DrainMessageLoops(); |
} |
- |
-} // namespace content |