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

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

Issue 815983002: Topsites become keyedService based. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years, 11 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
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 "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
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_service_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
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 TopSitesServiceFactory::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(
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 449
447 browser_context_dependency_manager_->CreateBrowserContextServicesForTest( 450 browser_context_dependency_manager_->CreateBrowserContextServicesForTest(
448 this); 451 this);
449 452
450 #if defined(ENABLE_NOTIFICATIONS) 453 #if defined(ENABLE_NOTIFICATIONS)
451 // Install profile keyed service factory hooks for dummy/test services 454 // Install profile keyed service factory hooks for dummy/test services
452 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( 455 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
453 this, CreateTestDesktopNotificationService); 456 this, CreateTestDesktopNotificationService);
454 #endif 457 #endif
455 458
459 CreateTopSitesService();
460
456 #if defined(ENABLE_SUPERVISED_USERS) 461 #if defined(ENABLE_SUPERVISED_USERS)
457 if (!IsOffTheRecord()) { 462 if (!IsOffTheRecord()) {
458 SupervisedUserSettingsService* settings_service = 463 SupervisedUserSettingsService* settings_service =
459 SupervisedUserSettingsServiceFactory::GetForProfile(this); 464 SupervisedUserSettingsServiceFactory::GetForProfile(this);
460 TestingPrefStore* store = new TestingPrefStore(); 465 TestingPrefStore* store = new TestingPrefStore();
461 settings_service->Init(store); 466 settings_service->Init(store);
462 store->SetInitializationCompleted(); 467 store->SetInitializationCompleted();
463 } 468 }
464 #endif 469 #endif
465 470
(...skipping 25 matching lines...) Expand all
491 // Any objects holding live URLFetchers should be deleted before teardown. 496 // Any objects holding live URLFetchers should be deleted before teardown.
492 TemplateURLFetcherFactory::ShutdownForProfile(this); 497 TemplateURLFetcherFactory::ShutdownForProfile(this);
493 498
494 MaybeSendDestroyedNotification(); 499 MaybeSendDestroyedNotification();
495 500
496 browser_context_dependency_manager_->DestroyBrowserContextServices(this); 501 browser_context_dependency_manager_->DestroyBrowserContextServices(this);
497 502
498 if (host_content_settings_map_.get()) 503 if (host_content_settings_map_.get())
499 host_content_settings_map_->ShutdownOnUIThread(); 504 host_content_settings_map_->ShutdownOnUIThread();
500 505
501 DestroyTopSites();
502
503 if (pref_proxy_config_tracker_.get()) 506 if (pref_proxy_config_tracker_.get())
504 pref_proxy_config_tracker_->DetachFromPrefService(); 507 pref_proxy_config_tracker_->DetachFromPrefService();
505 // Failing a post == leaks == heapcheck failure. Make that an immediate test 508 // Failing a post == leaks == heapcheck failure. Make that an immediate test
506 // failure. 509 // failure.
507 if (resource_context_) { 510 if (resource_context_) {
508 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, 511 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
509 resource_context_)); 512 resource_context_));
510 resource_context_ = NULL; 513 resource_context_ = NULL;
511 content::RunAllPendingInMessageLoop(BrowserThread::IO); 514 content::RunAllPendingInMessageLoop(BrowserThread::IO);
512 } 515 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 // our destroy task. 565 // our destroy task.
563 base::MessageLoop::current()->Run(); 566 base::MessageLoop::current()->Run();
564 567
565 // Make sure we don't have any event pending that could disrupt the next 568 // Make sure we don't have any event pending that could disrupt the next
566 // test. 569 // test.
567 base::MessageLoop::current()->PostTask(FROM_HERE, 570 base::MessageLoop::current()->PostTask(FROM_HERE,
568 base::MessageLoop::QuitClosure()); 571 base::MessageLoop::QuitClosure());
569 base::MessageLoop::current()->Run(); 572 base::MessageLoop::current()->Run();
570 } 573 }
571 574
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) { 575 void TestingProfile::CreateBookmarkModel(bool delete_file) {
596 if (delete_file) { 576 if (delete_file) {
597 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); 577 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName);
598 base::DeleteFile(path, false); 578 base::DeleteFile(path, false);
599 } 579 }
600 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory( 580 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory(
601 this, BuildChromeHistoryClient); 581 this, BuildChromeHistoryClient);
602 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory( 582 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory(
603 this, BuildChromeBookmarkClient); 583 this, BuildChromeBookmarkClient);
604 // This creates the BookmarkModel. 584 // This creates the BookmarkModel.
605 ignore_result(BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse( 585 ignore_result(BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
606 this, BuildBookmarkModel)); 586 this, BuildBookmarkModel));
607 } 587 }
608 588
589 void TestingProfile::CreateTopSitesService(history::TopSites* top_sites) {
590 TopSitesServiceFactory::GetInstance()->SetTestingFactory(
591 this,
592 &TopSitesServiceFactory::CreateCustomTopSitesServiceFactory(&top_sites));
sdefresne 2014/12/29 09:48:14 Please move this testing factory function (TopSite
Jitu( very slow this week) 2014/12/30 10:09:03 Done.
593 }
594
595 void TestingProfile::CreateTopSitesService() {
596 TopSitesServiceFactory::GetInstance()->SetTestingFactory(
597 this, &TopSitesServiceFactory::BuildProfileForTesting(this));
sdefresne 2014/12/29 09:48:14 Please move this testing factory function (TopSite
Jitu( very slow this week) 2014/12/30 10:09:03 Done.
598 }
599
609 void TestingProfile::CreateWebDataService() { 600 void TestingProfile::CreateWebDataService() {
610 WebDataServiceFactory::GetInstance()->SetTestingFactory( 601 WebDataServiceFactory::GetInstance()->SetTestingFactory(
611 this, BuildWebDataService); 602 this, BuildWebDataService);
612 } 603 }
613 604
614 void TestingProfile::BlockUntilHistoryIndexIsRefreshed() { 605 void TestingProfile::BlockUntilHistoryIndexIsRefreshed() {
615 // Only get the history service if it actually exists since the caller of the 606 // Only get the history service if it actually exists since the caller of the
616 // test should explicitly call CreateHistoryService to build it. 607 // test should explicitly call CreateHistoryService to build it.
617 HistoryService* history_service = 608 HistoryService* history_service =
618 HistoryServiceFactory::GetForProfileWithoutCreating(this); 609 HistoryServiceFactory::GetForProfileWithoutCreating(this);
619 DCHECK(history_service); 610 DCHECK(history_service);
620 history::InMemoryURLIndex* index = history_service->InMemoryIndex(); 611 history::InMemoryURLIndex* index = history_service->InMemoryIndex();
621 if (!index || index->restored()) 612 if (!index || index->restored())
622 return; 613 return;
623 base::RunLoop run_loop; 614 base::RunLoop run_loop;
624 HistoryIndexRestoreObserver observer( 615 HistoryIndexRestoreObserver observer(
625 content::GetQuitTaskForRunLoop(&run_loop)); 616 content::GetQuitTaskForRunLoop(&run_loop));
626 index->set_restore_cache_observer(&observer); 617 index->set_restore_cache_observer(&observer);
627 run_loop.Run(); 618 run_loop.Run();
628 index->set_restore_cache_observer(NULL); 619 index->set_restore_cache_observer(NULL);
629 DCHECK(index->restored()); 620 DCHECK(index->restored());
630 } 621 }
631 622
632 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? 623 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded?
633 void TestingProfile::BlockUntilTopSitesLoaded() { 624 void TestingProfile::BlockUntilTopSitesLoaded() {
634 scoped_refptr<content::MessageLoopRunner> runner = 625 scoped_refptr<content::MessageLoopRunner> runner =
635 new content::MessageLoopRunner; 626 new content::MessageLoopRunner;
636 WaitTopSitesLoadedObserver observer(runner.get()); 627 WaitTopSitesLoadedObserver observer(runner.get());
637 top_sites_->AddObserver(&observer); 628 scoped_refptr<history::TopSites> top_site =
629 TopSitesServiceFactory::GetForProfile(this);
630 top_site->AddObserver(&observer);
638 runner->Run(); 631 runner->Run();
639 top_sites_->RemoveObserver(&observer); 632 top_site->RemoveObserver(&observer);
640 } 633 }
641 634
642 void TestingProfile::SetGuestSession(bool guest) { 635 void TestingProfile::SetGuestSession(bool guest) {
643 guest_session_ = guest; 636 guest_session_ = guest;
644 } 637 }
645 638
646 base::FilePath TestingProfile::GetPath() const { 639 base::FilePath TestingProfile::GetPath() const {
647 return profile_path_; 640 return profile_path_;
648 } 641 }
649 642
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 this, profile_policy_connector_.get()); 780 this, profile_policy_connector_.get());
788 CHECK_EQ(profile_policy_connector_.get(), 781 CHECK_EQ(profile_policy_connector_.get(),
789 policy::ProfilePolicyConnectorFactory::GetForProfile(this)); 782 policy::ProfilePolicyConnectorFactory::GetForProfile(this));
790 } 783 }
791 784
792 PrefService* TestingProfile::GetPrefs() { 785 PrefService* TestingProfile::GetPrefs() {
793 DCHECK(prefs_); 786 DCHECK(prefs_);
794 return prefs_.get(); 787 return prefs_.get();
795 } 788 }
796 789
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() { 790 DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
806 return NULL; 791 return NULL;
807 } 792 }
808 793
809 net::URLRequestContextGetter* TestingProfile::GetRequestContext() { 794 net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
810 return GetDefaultStoragePartition(this)->GetURLRequestContext(); 795 return GetDefaultStoragePartition(this)->GetURLRequestContext();
811 } 796 }
812 797
813 net::URLRequestContextGetter* TestingProfile::CreateRequestContext( 798 net::URLRequestContextGetter* TestingProfile::CreateRequestContext(
814 content::ProtocolHandlerMap* protocol_handlers, 799 content::ProtocolHandlerMap* protocol_handlers,
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 #if defined(ENABLE_EXTENSIONS) 1049 #if defined(ENABLE_EXTENSIONS)
1065 extension_policy_, 1050 extension_policy_,
1066 #endif 1051 #endif
1067 pref_service_.Pass(), 1052 pref_service_.Pass(),
1068 original_profile, 1053 original_profile,
1069 guest_session_, 1054 guest_session_,
1070 supervised_user_id_, 1055 supervised_user_id_,
1071 policy_service_.Pass(), 1056 policy_service_.Pass(),
1072 testing_factories_); 1057 testing_factories_);
1073 } 1058 }
OLDNEW
« chrome/browser/thumbnails/thumbnail_service_unittest.cc ('K') | « chrome/test/base/testing_profile.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698