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.get()); |
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> BuildProfileForTesting( | |
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 scoped_refptr<history::TopSites>(top_sites); | |
Bernhard Bauer
2015/01/06 11:10:31
If this scoped_refptr<history::TopSites> can be au
Bernhard Bauer
2015/01/08 10:22:04
Just make_scoped_refptr; The compiler will pick th
| |
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 TopSitesFactory::GetInstance()->SetTestingFactory( | |
468 this, BuildProfileForTesting); | |
469 | |
456 #if defined(ENABLE_SUPERVISED_USERS) | 470 #if defined(ENABLE_SUPERVISED_USERS) |
457 if (!IsOffTheRecord()) { | 471 if (!IsOffTheRecord()) { |
458 SupervisedUserSettingsService* settings_service = | 472 SupervisedUserSettingsService* settings_service = |
459 SupervisedUserSettingsServiceFactory::GetForProfile(this); | 473 SupervisedUserSettingsServiceFactory::GetForProfile(this); |
460 TestingPrefStore* store = new TestingPrefStore(); | 474 TestingPrefStore* store = new TestingPrefStore(); |
461 settings_service->Init(store); | 475 settings_service->Init(store); |
462 store->SetInitializationCompleted(); | 476 store->SetInitializationCompleted(); |
463 } | 477 } |
464 #endif | 478 #endif |
465 | 479 |
(...skipping 25 matching lines...) Expand all Loading... | |
491 // Any objects holding live URLFetchers should be deleted before teardown. | 505 // Any objects holding live URLFetchers should be deleted before teardown. |
492 TemplateURLFetcherFactory::ShutdownForProfile(this); | 506 TemplateURLFetcherFactory::ShutdownForProfile(this); |
493 | 507 |
494 MaybeSendDestroyedNotification(); | 508 MaybeSendDestroyedNotification(); |
495 | 509 |
496 browser_context_dependency_manager_->DestroyBrowserContextServices(this); | 510 browser_context_dependency_manager_->DestroyBrowserContextServices(this); |
497 | 511 |
498 if (host_content_settings_map_.get()) | 512 if (host_content_settings_map_.get()) |
499 host_content_settings_map_->ShutdownOnUIThread(); | 513 host_content_settings_map_->ShutdownOnUIThread(); |
500 | 514 |
501 DestroyTopSites(); | |
502 | |
503 if (pref_proxy_config_tracker_.get()) | 515 if (pref_proxy_config_tracker_.get()) |
504 pref_proxy_config_tracker_->DetachFromPrefService(); | 516 pref_proxy_config_tracker_->DetachFromPrefService(); |
505 // Failing a post == leaks == heapcheck failure. Make that an immediate test | 517 // Failing a post == leaks == heapcheck failure. Make that an immediate test |
506 // failure. | 518 // failure. |
507 if (resource_context_) { | 519 if (resource_context_) { |
508 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, | 520 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, |
509 resource_context_)); | 521 resource_context_)); |
510 resource_context_ = NULL; | 522 resource_context_ = NULL; |
511 content::RunAllPendingInMessageLoop(BrowserThread::IO); | 523 content::RunAllPendingInMessageLoop(BrowserThread::IO); |
512 } | 524 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 // our destroy task. | 574 // our destroy task. |
563 base::MessageLoop::current()->Run(); | 575 base::MessageLoop::current()->Run(); |
564 | 576 |
565 // Make sure we don't have any event pending that could disrupt the next | 577 // Make sure we don't have any event pending that could disrupt the next |
566 // test. | 578 // test. |
567 base::MessageLoop::current()->PostTask(FROM_HERE, | 579 base::MessageLoop::current()->PostTask(FROM_HERE, |
568 base::MessageLoop::QuitClosure()); | 580 base::MessageLoop::QuitClosure()); |
569 base::MessageLoop::current()->Run(); | 581 base::MessageLoop::current()->Run(); |
570 } | 582 } |
571 | 583 |
572 void TestingProfile::CreateTopSites() { | |
573 DestroyTopSites(); | |
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 } | |
594 | |
595 void TestingProfile::CreateBookmarkModel(bool delete_file) { | 584 void TestingProfile::CreateBookmarkModel(bool delete_file) { |
596 if (delete_file) { | 585 if (delete_file) { |
597 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); | 586 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); |
598 base::DeleteFile(path, false); | 587 base::DeleteFile(path, false); |
599 } | 588 } |
600 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory( | 589 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory( |
601 this, BuildChromeHistoryClient); | 590 this, BuildChromeHistoryClient); |
602 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory( | 591 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory( |
603 this, BuildChromeBookmarkClient); | 592 this, BuildChromeBookmarkClient); |
604 // This creates the BookmarkModel. | 593 // This creates the BookmarkModel. |
(...skipping 22 matching lines...) Expand all Loading... | |
627 run_loop.Run(); | 616 run_loop.Run(); |
628 index->set_restore_cache_observer(NULL); | 617 index->set_restore_cache_observer(NULL); |
629 DCHECK(index->restored()); | 618 DCHECK(index->restored()); |
630 } | 619 } |
631 | 620 |
632 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? | 621 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? |
633 void TestingProfile::BlockUntilTopSitesLoaded() { | 622 void TestingProfile::BlockUntilTopSitesLoaded() { |
634 scoped_refptr<content::MessageLoopRunner> runner = | 623 scoped_refptr<content::MessageLoopRunner> runner = |
635 new content::MessageLoopRunner; | 624 new content::MessageLoopRunner; |
636 WaitTopSitesLoadedObserver observer(runner.get()); | 625 WaitTopSitesLoadedObserver observer(runner.get()); |
637 top_sites_->AddObserver(&observer); | 626 scoped_refptr<history::TopSites> top_site = |
Bernhard Bauer
2015/01/06 11:10:31
Nit: |top_sites|
Jitu( very slow this week)
2015/01/08 09:38:25
Done.
| |
627 TopSitesFactory::GetForProfile(this); | |
628 top_site->AddObserver(&observer); | |
638 runner->Run(); | 629 runner->Run(); |
639 top_sites_->RemoveObserver(&observer); | 630 top_site->RemoveObserver(&observer); |
640 } | 631 } |
641 | 632 |
642 void TestingProfile::SetGuestSession(bool guest) { | 633 void TestingProfile::SetGuestSession(bool guest) { |
643 guest_session_ = guest; | 634 guest_session_ = guest; |
644 } | 635 } |
645 | 636 |
646 base::FilePath TestingProfile::GetPath() const { | 637 base::FilePath TestingProfile::GetPath() const { |
647 return profile_path_; | 638 return profile_path_; |
648 } | 639 } |
649 | 640 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 this, profile_policy_connector_.get()); | 778 this, profile_policy_connector_.get()); |
788 CHECK_EQ(profile_policy_connector_.get(), | 779 CHECK_EQ(profile_policy_connector_.get(), |
789 policy::ProfilePolicyConnectorFactory::GetForProfile(this)); | 780 policy::ProfilePolicyConnectorFactory::GetForProfile(this)); |
790 } | 781 } |
791 | 782 |
792 PrefService* TestingProfile::GetPrefs() { | 783 PrefService* TestingProfile::GetPrefs() { |
793 DCHECK(prefs_); | 784 DCHECK(prefs_); |
794 return prefs_.get(); | 785 return prefs_.get(); |
795 } | 786 } |
796 | 787 |
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() { | 788 DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() { |
806 return NULL; | 789 return NULL; |
807 } | 790 } |
808 | 791 |
809 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { | 792 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { |
810 return GetDefaultStoragePartition(this)->GetURLRequestContext(); | 793 return GetDefaultStoragePartition(this)->GetURLRequestContext(); |
811 } | 794 } |
812 | 795 |
813 net::URLRequestContextGetter* TestingProfile::CreateRequestContext( | 796 net::URLRequestContextGetter* TestingProfile::CreateRequestContext( |
814 content::ProtocolHandlerMap* protocol_handlers, | 797 content::ProtocolHandlerMap* protocol_handlers, |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1064 #if defined(ENABLE_EXTENSIONS) | 1047 #if defined(ENABLE_EXTENSIONS) |
1065 extension_policy_, | 1048 extension_policy_, |
1066 #endif | 1049 #endif |
1067 pref_service_.Pass(), | 1050 pref_service_.Pass(), |
1068 original_profile, | 1051 original_profile, |
1069 guest_session_, | 1052 guest_session_, |
1070 supervised_user_id_, | 1053 supervised_user_id_, |
1071 policy_service_.Pass(), | 1054 policy_service_.Pass(), |
1072 testing_factories_); | 1055 testing_factories_); |
1073 } | 1056 } |
OLD | NEW |