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

Side by Side Diff: chrome/test/base/testing_profile.cc

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix InstantNTP test. Created 7 years, 5 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
« no previous file with comments | « chrome/test/base/testing_profile.h ('k') | chrome/test/base/ui_test_utils.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 "chrome/test/base/testing_profile.h" 5 #include "chrome/test/base/testing_profile.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 #endif 163 #endif
164 164
165 TestingProfile::TestingProfile() 165 TestingProfile::TestingProfile()
166 : start_time_(Time::Now()), 166 : start_time_(Time::Now()),
167 testing_prefs_(NULL), 167 testing_prefs_(NULL),
168 incognito_(false), 168 incognito_(false),
169 original_profile_(NULL), 169 original_profile_(NULL),
170 last_session_exited_cleanly_(true), 170 last_session_exited_cleanly_(true),
171 browser_context_dependency_manager_( 171 browser_context_dependency_manager_(
172 BrowserContextDependencyManager::GetInstance()), 172 BrowserContextDependencyManager::GetInstance()),
173 resource_context_(NULL),
173 delegate_(NULL) { 174 delegate_(NULL) {
174 CreateTempProfileDir(); 175 CreateTempProfileDir();
175 profile_path_ = temp_dir_.path(); 176 profile_path_ = temp_dir_.path();
176 177
177 Init(); 178 Init();
178 FinishInit(); 179 FinishInit();
179 } 180 }
180 181
181 TestingProfile::TestingProfile(const base::FilePath& path) 182 TestingProfile::TestingProfile(const base::FilePath& path)
182 : start_time_(Time::Now()), 183 : start_time_(Time::Now()),
183 testing_prefs_(NULL), 184 testing_prefs_(NULL),
184 incognito_(false), 185 incognito_(false),
185 original_profile_(NULL), 186 original_profile_(NULL),
186 last_session_exited_cleanly_(true), 187 last_session_exited_cleanly_(true),
187 profile_path_(path), 188 profile_path_(path),
188 browser_context_dependency_manager_( 189 browser_context_dependency_manager_(
189 BrowserContextDependencyManager::GetInstance()), 190 BrowserContextDependencyManager::GetInstance()),
191 resource_context_(NULL),
190 delegate_(NULL) { 192 delegate_(NULL) {
191 Init(); 193 Init();
192 FinishInit(); 194 FinishInit();
193 } 195 }
194 196
195 TestingProfile::TestingProfile(const base::FilePath& path, 197 TestingProfile::TestingProfile(const base::FilePath& path,
196 Delegate* delegate) 198 Delegate* delegate)
197 : start_time_(Time::Now()), 199 : start_time_(Time::Now()),
198 testing_prefs_(NULL), 200 testing_prefs_(NULL),
199 incognito_(false), 201 incognito_(false),
200 original_profile_(NULL), 202 original_profile_(NULL),
201 last_session_exited_cleanly_(true), 203 last_session_exited_cleanly_(true),
202 profile_path_(path), 204 profile_path_(path),
203 browser_context_dependency_manager_( 205 browser_context_dependency_manager_(
204 BrowserContextDependencyManager::GetInstance()), 206 BrowserContextDependencyManager::GetInstance()),
207 resource_context_(NULL),
205 delegate_(delegate) { 208 delegate_(delegate) {
206 Init(); 209 Init();
207 if (delegate_) { 210 if (delegate_) {
208 base::MessageLoop::current()->PostTask( 211 base::MessageLoop::current()->PostTask(
209 FROM_HERE, 212 FROM_HERE,
210 base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); 213 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
211 } else { 214 } else {
212 FinishInit(); 215 FinishInit();
213 } 216 }
214 } 217 }
215 218
216 TestingProfile::TestingProfile( 219 TestingProfile::TestingProfile(
217 const base::FilePath& path, 220 const base::FilePath& path,
218 Delegate* delegate, 221 Delegate* delegate,
219 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, 222 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy,
220 scoped_ptr<PrefServiceSyncable> prefs) 223 scoped_ptr<PrefServiceSyncable> prefs)
221 : start_time_(Time::Now()), 224 : start_time_(Time::Now()),
222 prefs_(prefs.release()), 225 prefs_(prefs.release()),
223 testing_prefs_(NULL), 226 testing_prefs_(NULL),
224 incognito_(false), 227 incognito_(false),
225 original_profile_(NULL), 228 original_profile_(NULL),
226 last_session_exited_cleanly_(true), 229 last_session_exited_cleanly_(true),
227 extension_special_storage_policy_(extension_policy), 230 extension_special_storage_policy_(extension_policy),
228 profile_path_(path), 231 profile_path_(path),
229 browser_context_dependency_manager_( 232 browser_context_dependency_manager_(
230 BrowserContextDependencyManager::GetInstance()), 233 BrowserContextDependencyManager::GetInstance()),
234 resource_context_(NULL),
231 delegate_(delegate) { 235 delegate_(delegate) {
232 236
233 // If no profile path was supplied, create one. 237 // If no profile path was supplied, create one.
234 if (profile_path_.empty()) { 238 if (profile_path_.empty()) {
235 CreateTempProfileDir(); 239 CreateTempProfileDir();
236 profile_path_ = temp_dir_.path(); 240 profile_path_ = temp_dir_.path();
237 } 241 }
238 242
239 Init(); 243 Init();
240 // If caller supplied a delegate, delay the FinishInit invocation until other 244 // If caller supplied a delegate, delay the FinishInit invocation until other
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 content::NotificationService::current()->Notify( 317 content::NotificationService::current()->Notify(
314 chrome::NOTIFICATION_PROFILE_CREATED, 318 chrome::NOTIFICATION_PROFILE_CREATED,
315 content::Source<Profile>(static_cast<Profile*>(this)), 319 content::Source<Profile>(static_cast<Profile*>(this)),
316 content::NotificationService::NoDetails()); 320 content::NotificationService::NoDetails());
317 321
318 if (delegate_) 322 if (delegate_)
319 delegate_->OnProfileCreated(this, true, false); 323 delegate_->OnProfileCreated(this, true, false);
320 } 324 }
321 325
322 TestingProfile::~TestingProfile() { 326 TestingProfile::~TestingProfile() {
327 // Any objects holding live URLFetchers should be deleted before teardown.
328 TemplateURLFetcherFactory::ShutdownForProfile(this);
329
323 MaybeSendDestroyedNotification(); 330 MaybeSendDestroyedNotification();
324 331
325 browser_context_dependency_manager_->DestroyBrowserContextServices(this); 332 browser_context_dependency_manager_->DestroyBrowserContextServices(this);
326 333
327 if (host_content_settings_map_.get()) 334 if (host_content_settings_map_.get())
328 host_content_settings_map_->ShutdownOnUIThread(); 335 host_content_settings_map_->ShutdownOnUIThread();
329 336
330 DestroyTopSites(); 337 DestroyTopSites();
331 338
332 if (pref_proxy_config_tracker_.get()) 339 if (pref_proxy_config_tracker_.get())
333 pref_proxy_config_tracker_->DetachFromPrefService(); 340 pref_proxy_config_tracker_->DetachFromPrefService();
341 // Failing a post == leaks == heapcheck failure. Make that an immediate test
342 // failure.
343 if (resource_context_) {
344 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
345 resource_context_));
346 resource_context_ = NULL;
347 content::RunAllPendingInMessageLoop(BrowserThread::IO);
348 }
334 } 349 }
335 350
336 static BrowserContextKeyedService* BuildFaviconService( 351 static BrowserContextKeyedService* BuildFaviconService(
337 content::BrowserContext* profile) { 352 content::BrowserContext* profile) {
338 return new FaviconService( 353 return new FaviconService(
339 HistoryServiceFactory::GetForProfileWithoutCreating( 354 HistoryServiceFactory::GetForProfileWithoutCreating(
340 static_cast<Profile*>(profile))); 355 static_cast<Profile*>(profile)));
341 } 356 }
342 357
343 void TestingProfile::CreateFaviconService() { 358 void TestingProfile::CreateFaviconService() {
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 604
590 history::TopSites* TestingProfile::GetTopSitesWithoutCreating() { 605 history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
591 return top_sites_.get(); 606 return top_sites_.get();
592 } 607 }
593 608
594 DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() { 609 DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
595 return NULL; 610 return NULL;
596 } 611 }
597 612
598 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { 613 net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
599 return request_context_.get(); 614 return GetDefaultStoragePartition(this)->GetURLRequestContext();
600 } 615 }
601 616
602 net::URLRequestContextGetter* TestingProfile::CreateRequestContext( 617 net::URLRequestContextGetter* TestingProfile::CreateRequestContext(
603 content::ProtocolHandlerMap* protocol_handlers) { 618 content::ProtocolHandlerMap* protocol_handlers) {
604 return request_context_.get(); 619 return new net::TestURLRequestContextGetter(
620 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
605 } 621 }
606 622
607 net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess( 623 net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
608 int renderer_child_id) { 624 int renderer_child_id) {
609 content::RenderProcessHost* rph = content::RenderProcessHost::FromID( 625 content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
610 renderer_child_id); 626 renderer_child_id);
611 return rph->GetStoragePartition()->GetURLRequestContext(); 627 return rph->GetStoragePartition()->GetURLRequestContext();
612 } 628 }
613 629
614 void TestingProfile::CreateRequestContext() {
615 if (!request_context_.get())
616 request_context_ = new net::TestURLRequestContextGetter(
617 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
618 }
619
620 void TestingProfile::ResetRequestContext() {
621 // Any objects holding live URLFetchers should be deleted before the request
622 // context is shut down.
623 TemplateURLFetcherFactory::ShutdownForProfile(this);
624
625 request_context_ = NULL;
626 }
627
628 net::URLRequestContextGetter* TestingProfile::GetMediaRequestContext() { 630 net::URLRequestContextGetter* TestingProfile::GetMediaRequestContext() {
629 return NULL; 631 return NULL;
630 } 632 }
631 633
632 net::URLRequestContextGetter* 634 net::URLRequestContextGetter*
633 TestingProfile::GetMediaRequestContextForRenderProcess( 635 TestingProfile::GetMediaRequestContextForRenderProcess(
634 int renderer_child_id) { 636 int renderer_child_id) {
635 return NULL; 637 return NULL;
636 } 638 }
637 639
(...skipping 29 matching lines...) Expand all
667 TestingProfile::CreateRequestContextForStoragePartition( 669 TestingProfile::CreateRequestContextForStoragePartition(
668 const base::FilePath& partition_path, 670 const base::FilePath& partition_path,
669 bool in_memory, 671 bool in_memory,
670 content::ProtocolHandlerMap* protocol_handlers) { 672 content::ProtocolHandlerMap* protocol_handlers) {
671 // We don't test storage partitions here yet, so returning the same dummy 673 // We don't test storage partitions here yet, so returning the same dummy
672 // context is sufficient for now. 674 // context is sufficient for now.
673 return GetRequestContext(); 675 return GetRequestContext();
674 } 676 }
675 677
676 content::ResourceContext* TestingProfile::GetResourceContext() { 678 content::ResourceContext* TestingProfile::GetResourceContext() {
677 if (!resource_context_.get()) 679 if (!resource_context_)
678 resource_context_.reset(new content::MockResourceContext()); 680 resource_context_ = new content::MockResourceContext();
679 return resource_context_.get(); 681 return resource_context_;
680 } 682 }
681 683
682 HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() { 684 HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
683 if (!host_content_settings_map_.get()) { 685 if (!host_content_settings_map_.get()) {
684 host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false); 686 host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false);
685 #if defined(ENABLE_EXTENSIONS) 687 #if defined(ENABLE_EXTENSIONS)
686 ExtensionService* extension_service = GetExtensionService(); 688 ExtensionService* extension_service = GetExtensionService();
687 if (extension_service) 689 if (extension_service)
688 host_content_settings_map_->RegisterExtensionService(extension_service); 690 host_content_settings_map_->RegisterExtensionService(extension_service);
689 #endif 691 #endif
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 810
809 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { 811 scoped_ptr<TestingProfile> TestingProfile::Builder::Build() {
810 DCHECK(!build_called_); 812 DCHECK(!build_called_);
811 build_called_ = true; 813 build_called_ = true;
812 return scoped_ptr<TestingProfile>(new TestingProfile( 814 return scoped_ptr<TestingProfile>(new TestingProfile(
813 path_, 815 path_,
814 delegate_, 816 delegate_,
815 extension_policy_, 817 extension_policy_,
816 pref_service_.Pass())); 818 pref_service_.Pass()));
817 } 819 }
OLDNEW
« no previous file with comments | « chrome/test/base/testing_profile.h ('k') | chrome/test/base/ui_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698