Correctly integrate StoragePartition into TestingProfile.
Until this CL, TestingProfile had 3 distinct URLRequestContexts it would return to the user: one via profile->GetDefaultStoragePartition()->GetRequestContext(), one via profile->GetRequestContext(), and one via profile->GetResourceContext->GetRequestContext(). All of these had different cookie stores. This CL unified them so they all return the one from profile->GetDefaultStoragePartition()->GetRequestContext(). This correctly mimics how production code works.
Doing this had a bunch of implications:
(1) Removes TestingProfile::CreateRequestContext()/ResetRequestContext()
(2) Changes MockRequestContext to share the URLRequestContext with TestingProfile.
(3) TestingProfile now requires all BrowserThreads.
Point (3) effectively adds TestBrowserThreadBundle into a bunch more spots. Because of that, we also have the following changes:
(a) AshTestBase now has a TestBrowserThreadBundle
(b) Removed a bunch of real threads from tests.
(c) TemplateUrlService has reworked synchronization semantics.
(d) Removed MultiThreadTestHelper.
(e) Added TestingIOThread class + testing API in IOThread to mock out various IO thread tasks which enervated with the new TestBrowserThreadBundle.
TBR=bauerb,brettw,isherman,joth,jyasskin,mattm,mmenke,mnissler,pkasting,rkc,rlp,satorux,tim,xians,joth
BUG=159193
Review URL: https://chromiumcodereview.appspot.com/17127002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213272 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index 2704bc7c..3a3c019 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -170,6 +170,7 @@
last_session_exited_cleanly_(true),
browser_context_dependency_manager_(
BrowserContextDependencyManager::GetInstance()),
+ resource_context_(NULL),
delegate_(NULL) {
CreateTempProfileDir();
profile_path_ = temp_dir_.path();
@@ -187,6 +188,7 @@
profile_path_(path),
browser_context_dependency_manager_(
BrowserContextDependencyManager::GetInstance()),
+ resource_context_(NULL),
delegate_(NULL) {
Init();
FinishInit();
@@ -202,6 +204,7 @@
profile_path_(path),
browser_context_dependency_manager_(
BrowserContextDependencyManager::GetInstance()),
+ resource_context_(NULL),
delegate_(delegate) {
Init();
if (delegate_) {
@@ -228,6 +231,7 @@
profile_path_(path),
browser_context_dependency_manager_(
BrowserContextDependencyManager::GetInstance()),
+ resource_context_(NULL),
delegate_(delegate) {
// If no profile path was supplied, create one.
@@ -320,6 +324,9 @@
}
TestingProfile::~TestingProfile() {
+ // Any objects holding live URLFetchers should be deleted before teardown.
+ TemplateURLFetcherFactory::ShutdownForProfile(this);
+
MaybeSendDestroyedNotification();
browser_context_dependency_manager_->DestroyBrowserContextServices(this);
@@ -331,6 +338,14 @@
if (pref_proxy_config_tracker_.get())
pref_proxy_config_tracker_->DetachFromPrefService();
+ // Failing a post == leaks == heapcheck failure. Make that an immediate test
+ // failure.
+ if (resource_context_) {
+ CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
+ resource_context_));
+ resource_context_ = NULL;
+ content::RunAllPendingInMessageLoop(BrowserThread::IO);
+ }
}
static BrowserContextKeyedService* BuildFaviconService(
@@ -596,12 +611,13 @@
}
net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
- return request_context_.get();
+ return GetDefaultStoragePartition(this)->GetURLRequestContext();
}
net::URLRequestContextGetter* TestingProfile::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers) {
- return request_context_.get();
+ return new net::TestURLRequestContextGetter(
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
}
net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
@@ -611,20 +627,6 @@
return rph->GetStoragePartition()->GetURLRequestContext();
}
-void TestingProfile::CreateRequestContext() {
- if (!request_context_.get())
- request_context_ = new net::TestURLRequestContextGetter(
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
-}
-
-void TestingProfile::ResetRequestContext() {
- // Any objects holding live URLFetchers should be deleted before the request
- // context is shut down.
- TemplateURLFetcherFactory::ShutdownForProfile(this);
-
- request_context_ = NULL;
-}
-
net::URLRequestContextGetter* TestingProfile::GetMediaRequestContext() {
return NULL;
}
@@ -674,9 +676,9 @@
}
content::ResourceContext* TestingProfile::GetResourceContext() {
- if (!resource_context_.get())
- resource_context_.reset(new content::MockResourceContext());
- return resource_context_.get();
+ if (!resource_context_)
+ resource_context_ = new content::MockResourceContext();
+ return resource_context_;
}
HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {