Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" | 21 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" |
| 22 #include "chrome/browser/favicon/favicon_service.h" | 22 #include "chrome/browser/favicon/favicon_service.h" |
| 23 #include "chrome/browser/favicon/favicon_service_factory.h" | 23 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 24 #include "chrome/browser/history/chrome_history_client.h" | 24 #include "chrome/browser/history/chrome_history_client.h" |
| 25 #include "chrome/browser/history/chrome_history_client_factory.h" | 25 #include "chrome/browser/history/chrome_history_client_factory.h" |
| 26 #include "chrome/browser/history/history_backend.h" | 26 #include "chrome/browser/history/history_backend.h" |
| 27 #include "chrome/browser/history/history_db_task.h" | 27 #include "chrome/browser/history/history_db_task.h" |
| 28 #include "chrome/browser/history/history_service.h" | 28 #include "chrome/browser/history/history_service.h" |
| 29 #include "chrome/browser/history/history_service_factory.h" | 29 #include "chrome/browser/history/history_service_factory.h" |
| 30 #include "chrome/browser/history/top_sites.h" | 30 #include "chrome/browser/history/top_sites.h" |
| 31 #include "chrome/browser/history/top_sites_impl.h" | |
| 32 #include "chrome/browser/history/top_sites_factory.h" | |
| 31 #include "chrome/browser/history/web_history_service_factory.h" | 33 #include "chrome/browser/history/web_history_service_factory.h" |
| 32 #include "chrome/browser/net/pref_proxy_config_tracker.h" | 34 #include "chrome/browser/net/pref_proxy_config_tracker.h" |
| 33 #include "chrome/browser/net/proxy_service_factory.h" | 35 #include "chrome/browser/net/proxy_service_factory.h" |
| 34 #include "chrome/browser/notifications/desktop_notification_service.h" | 36 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 35 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 37 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 36 #include "chrome/browser/policy/profile_policy_connector.h" | 38 #include "chrome/browser/policy/profile_policy_connector.h" |
| 37 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 39 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 38 #include "chrome/browser/prefs/browser_prefs.h" | 40 #include "chrome/browser/prefs/browser_prefs.h" |
| 39 #include "chrome/browser/prefs/pref_service_syncable.h" | 41 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 40 #include "chrome/browser/prerender/prerender_manager.h" | 42 #include "chrome/browser/prerender/prerender_manager.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 } | 218 } |
| 217 | 219 |
| 218 KeyedService* BuildChromeBookmarkClient( | 220 KeyedService* BuildChromeBookmarkClient( |
| 219 content::BrowserContext* context) { | 221 content::BrowserContext* context) { |
| 220 return new ChromeBookmarkClient(static_cast<Profile*>(context)); | 222 return new ChromeBookmarkClient(static_cast<Profile*>(context)); |
| 221 } | 223 } |
| 222 | 224 |
| 223 KeyedService* BuildChromeHistoryClient( | 225 KeyedService* BuildChromeHistoryClient( |
| 224 content::BrowserContext* context) { | 226 content::BrowserContext* context) { |
| 225 Profile* profile = static_cast<Profile*>(context); | 227 Profile* profile = static_cast<Profile*>(context); |
| 228 scoped_refptr<history::TopSites> top_sites = | |
| 229 TopSitesFactory::GetForProfile(profile); | |
| 226 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile), | 230 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile), |
| 227 profile, | 231 profile, top_sites); |
| 228 profile->GetTopSites()); | |
| 229 } | 232 } |
| 230 | 233 |
| 231 void TestProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type, | 234 void TestProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type, |
| 232 sql::InitStatus status) { | 235 sql::InitStatus status) { |
| 233 NOTREACHED(); | 236 NOTREACHED(); |
| 234 } | 237 } |
| 235 | 238 |
| 236 KeyedService* BuildWebDataService(content::BrowserContext* context) { | 239 KeyedService* BuildWebDataService(content::BrowserContext* context) { |
| 237 const base::FilePath& context_path = context->GetPath(); | 240 const base::FilePath& context_path = context->GetPath(); |
| 238 return new WebDataServiceWrapper( | 241 return new WebDataServiceWrapper( |
| 239 context_path, g_browser_process->GetApplicationLocale(), | 242 context_path, g_browser_process->GetApplicationLocale(), |
| 240 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | 243 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), |
| 241 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 244 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
| 242 sync_start_util::GetFlareForSyncableService(context_path), | 245 sync_start_util::GetFlareForSyncableService(context_path), |
| 243 &TestProfileErrorCallback); | 246 &TestProfileErrorCallback); |
| 244 } | 247 } |
| 245 | 248 |
| 249 scoped_refptr<RefcountedKeyedService> BuildTopSites( | |
|
sdefresne
2015/01/12 17:24:24
It looks like TopSitesFactory::BuildInstanceForPro
sdefresne
2015/01/14 21:31:47
Please also test keeping TestingProfile::CreateTop
| |
| 250 content::BrowserContext* profile) { | |
| 251 history::TopSitesImpl* top_sites = | |
| 252 new history::TopSitesImpl(static_cast<Profile*>(profile)); | |
| 253 top_sites->Init(profile->GetPath().Append(chrome::kTopSitesFilename)); | |
| 254 return make_scoped_refptr(top_sites); | |
| 255 } | |
| 256 | |
| 246 } // namespace | 257 } // namespace |
| 247 | 258 |
| 248 // static | 259 // static |
| 249 #if defined(OS_CHROMEOS) | 260 #if defined(OS_CHROMEOS) |
| 250 // Must be kept in sync with | 261 // Must be kept in sync with |
| 251 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. | 262 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. |
| 252 const char TestingProfile::kTestUserProfileDir[] = "test-user"; | 263 const char TestingProfile::kTestUserProfileDir[] = "test-user"; |
| 253 #else | 264 #else |
| 254 const char TestingProfile::kTestUserProfileDir[] = "Default"; | 265 const char TestingProfile::kTestUserProfileDir[] = "Default"; |
| 255 #endif | 266 #endif |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 | 457 |
| 447 browser_context_dependency_manager_->CreateBrowserContextServicesForTest( | 458 browser_context_dependency_manager_->CreateBrowserContextServicesForTest( |
| 448 this); | 459 this); |
| 449 | 460 |
| 450 #if defined(ENABLE_NOTIFICATIONS) | 461 #if defined(ENABLE_NOTIFICATIONS) |
| 451 // Install profile keyed service factory hooks for dummy/test services | 462 // Install profile keyed service factory hooks for dummy/test services |
| 452 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( | 463 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( |
| 453 this, CreateTestDesktopNotificationService); | 464 this, CreateTestDesktopNotificationService); |
| 454 #endif | 465 #endif |
| 455 | 466 |
| 467 CreateTopSites(); | |
| 468 | |
| 456 #if defined(ENABLE_SUPERVISED_USERS) | 469 #if defined(ENABLE_SUPERVISED_USERS) |
| 457 if (!IsOffTheRecord()) { | 470 if (!IsOffTheRecord()) { |
| 458 SupervisedUserSettingsService* settings_service = | 471 SupervisedUserSettingsService* settings_service = |
| 459 SupervisedUserSettingsServiceFactory::GetForProfile(this); | 472 SupervisedUserSettingsServiceFactory::GetForProfile(this); |
| 460 TestingPrefStore* store = new TestingPrefStore(); | 473 TestingPrefStore* store = new TestingPrefStore(); |
| 461 settings_service->Init(store); | 474 settings_service->Init(store); |
| 462 store->SetInitializationCompleted(); | 475 store->SetInitializationCompleted(); |
| 463 } | 476 } |
| 464 #endif | 477 #endif |
| 465 | 478 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 491 // Any objects holding live URLFetchers should be deleted before teardown. | 504 // Any objects holding live URLFetchers should be deleted before teardown. |
| 492 TemplateURLFetcherFactory::ShutdownForProfile(this); | 505 TemplateURLFetcherFactory::ShutdownForProfile(this); |
| 493 | 506 |
| 494 MaybeSendDestroyedNotification(); | 507 MaybeSendDestroyedNotification(); |
| 495 | 508 |
| 496 browser_context_dependency_manager_->DestroyBrowserContextServices(this); | 509 browser_context_dependency_manager_->DestroyBrowserContextServices(this); |
| 497 | 510 |
| 498 if (host_content_settings_map_.get()) | 511 if (host_content_settings_map_.get()) |
| 499 host_content_settings_map_->ShutdownOnUIThread(); | 512 host_content_settings_map_->ShutdownOnUIThread(); |
| 500 | 513 |
| 501 DestroyTopSites(); | |
| 502 | |
| 503 if (pref_proxy_config_tracker_.get()) | 514 if (pref_proxy_config_tracker_.get()) |
| 504 pref_proxy_config_tracker_->DetachFromPrefService(); | 515 pref_proxy_config_tracker_->DetachFromPrefService(); |
| 505 // Failing a post == leaks == heapcheck failure. Make that an immediate test | 516 // Failing a post == leaks == heapcheck failure. Make that an immediate test |
| 506 // failure. | 517 // failure. |
| 507 if (resource_context_) { | 518 if (resource_context_) { |
| 508 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, | 519 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, |
| 509 resource_context_)); | 520 resource_context_)); |
| 510 resource_context_ = NULL; | 521 resource_context_ = NULL; |
| 511 content::RunAllPendingInMessageLoop(BrowserThread::IO); | 522 content::RunAllPendingInMessageLoop(BrowserThread::IO); |
| 512 } | 523 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 base::MessageLoop::current()->Run(); | 574 base::MessageLoop::current()->Run(); |
| 564 | 575 |
| 565 // Make sure we don't have any event pending that could disrupt the next | 576 // Make sure we don't have any event pending that could disrupt the next |
| 566 // test. | 577 // test. |
| 567 base::MessageLoop::current()->PostTask(FROM_HERE, | 578 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 568 base::MessageLoop::QuitClosure()); | 579 base::MessageLoop::QuitClosure()); |
| 569 base::MessageLoop::current()->Run(); | 580 base::MessageLoop::current()->Run(); |
| 570 } | 581 } |
| 571 | 582 |
| 572 void TestingProfile::CreateTopSites() { | 583 void TestingProfile::CreateTopSites() { |
| 573 DestroyTopSites(); | 584 TopSitesFactory::GetInstance()->SetTestingFactory(this, BuildTopSites); |
| 574 top_sites_ = history::TopSites::Create( | |
| 575 this, GetPath().Append(chrome::kTopSitesFilename)); | |
| 576 } | |
| 577 | |
| 578 void TestingProfile::SetTopSites(history::TopSites* top_sites) { | |
| 579 DestroyTopSites(); | |
| 580 top_sites_ = top_sites; | |
| 581 } | |
| 582 | |
| 583 void TestingProfile::DestroyTopSites() { | |
| 584 if (top_sites_.get()) { | |
| 585 top_sites_->Shutdown(); | |
| 586 top_sites_ = NULL; | |
| 587 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that | |
| 588 // need to be run to properly shutdown. Run all pending tasks now. This is | |
| 589 // normally handled by browser_process shutdown. | |
| 590 if (base::MessageLoop::current()) | |
| 591 base::MessageLoop::current()->RunUntilIdle(); | |
| 592 } | |
| 593 } | 585 } |
| 594 | 586 |
| 595 void TestingProfile::CreateBookmarkModel(bool delete_file) { | 587 void TestingProfile::CreateBookmarkModel(bool delete_file) { |
| 596 if (delete_file) { | 588 if (delete_file) { |
| 597 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); | 589 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); |
| 598 base::DeleteFile(path, false); | 590 base::DeleteFile(path, false); |
| 599 } | 591 } |
| 600 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory( | 592 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory( |
| 601 this, BuildChromeHistoryClient); | 593 this, BuildChromeHistoryClient); |
| 602 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory( | 594 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory( |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 627 run_loop.Run(); | 619 run_loop.Run(); |
| 628 index->set_restore_cache_observer(NULL); | 620 index->set_restore_cache_observer(NULL); |
| 629 DCHECK(index->restored()); | 621 DCHECK(index->restored()); |
| 630 } | 622 } |
| 631 | 623 |
| 632 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? | 624 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? |
| 633 void TestingProfile::BlockUntilTopSitesLoaded() { | 625 void TestingProfile::BlockUntilTopSitesLoaded() { |
| 634 scoped_refptr<content::MessageLoopRunner> runner = | 626 scoped_refptr<content::MessageLoopRunner> runner = |
| 635 new content::MessageLoopRunner; | 627 new content::MessageLoopRunner; |
| 636 WaitTopSitesLoadedObserver observer(runner.get()); | 628 WaitTopSitesLoadedObserver observer(runner.get()); |
| 637 top_sites_->AddObserver(&observer); | 629 scoped_refptr<history::TopSites> top_sites = |
| 630 TopSitesFactory::GetForProfile(this); | |
| 631 top_sites->AddObserver(&observer); | |
| 638 runner->Run(); | 632 runner->Run(); |
| 639 top_sites_->RemoveObserver(&observer); | 633 top_sites->RemoveObserver(&observer); |
| 640 } | 634 } |
| 641 | 635 |
| 642 void TestingProfile::SetGuestSession(bool guest) { | 636 void TestingProfile::SetGuestSession(bool guest) { |
| 643 guest_session_ = guest; | 637 guest_session_ = guest; |
| 644 } | 638 } |
| 645 | 639 |
| 646 base::FilePath TestingProfile::GetPath() const { | 640 base::FilePath TestingProfile::GetPath() const { |
| 647 return profile_path_; | 641 return profile_path_; |
| 648 } | 642 } |
| 649 | 643 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 787 this, profile_policy_connector_.get()); | 781 this, profile_policy_connector_.get()); |
| 788 CHECK_EQ(profile_policy_connector_.get(), | 782 CHECK_EQ(profile_policy_connector_.get(), |
| 789 policy::ProfilePolicyConnectorFactory::GetForProfile(this)); | 783 policy::ProfilePolicyConnectorFactory::GetForProfile(this)); |
| 790 } | 784 } |
| 791 | 785 |
| 792 PrefService* TestingProfile::GetPrefs() { | 786 PrefService* TestingProfile::GetPrefs() { |
| 793 DCHECK(prefs_); | 787 DCHECK(prefs_); |
| 794 return prefs_.get(); | 788 return prefs_.get(); |
| 795 } | 789 } |
| 796 | 790 |
| 797 history::TopSites* TestingProfile::GetTopSites() { | |
| 798 return top_sites_.get(); | |
| 799 } | |
| 800 | |
| 801 history::TopSites* TestingProfile::GetTopSitesWithoutCreating() { | |
| 802 return top_sites_.get(); | |
| 803 } | |
| 804 | |
| 805 DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() { | 791 DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() { |
| 806 return NULL; | 792 return NULL; |
| 807 } | 793 } |
| 808 | 794 |
| 809 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { | 795 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { |
| 810 return GetDefaultStoragePartition(this)->GetURLRequestContext(); | 796 return GetDefaultStoragePartition(this)->GetURLRequestContext(); |
| 811 } | 797 } |
| 812 | 798 |
| 813 net::URLRequestContextGetter* TestingProfile::CreateRequestContext( | 799 net::URLRequestContextGetter* TestingProfile::CreateRequestContext( |
| 814 content::ProtocolHandlerMap* protocol_handlers, | 800 content::ProtocolHandlerMap* protocol_handlers, |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1064 #if defined(ENABLE_EXTENSIONS) | 1050 #if defined(ENABLE_EXTENSIONS) |
| 1065 extension_policy_, | 1051 extension_policy_, |
| 1066 #endif | 1052 #endif |
| 1067 pref_service_.Pass(), | 1053 pref_service_.Pass(), |
| 1068 original_profile, | 1054 original_profile, |
| 1069 guest_session_, | 1055 guest_session_, |
| 1070 supervised_user_id_, | 1056 supervised_user_id_, |
| 1071 policy_service_.Pass(), | 1057 policy_service_.Pass(), |
| 1072 testing_factories_); | 1058 testing_factories_); |
| 1073 } | 1059 } |
| OLD | NEW |