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 "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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 web_data_service->Init(profile->GetPath()); | 413 web_data_service->Init(profile->GetPath()); |
414 return web_data_service; | 414 return web_data_service; |
415 } | 415 } |
416 | 416 |
417 void TestingProfile::CreateWebDataService() { | 417 void TestingProfile::CreateWebDataService() { |
418 WebDataServiceFactory::GetInstance()->SetTestingFactory( | 418 WebDataServiceFactory::GetInstance()->SetTestingFactory( |
419 this, BuildWebDataService); | 419 this, BuildWebDataService); |
420 } | 420 } |
421 | 421 |
422 void TestingProfile::BlockUntilBookmarkModelLoaded() { | 422 void TestingProfile::BlockUntilBookmarkModelLoaded() { |
423 DCHECK(GetBookmarkModel()); | 423 // Only get the bookmark model if it actually exists since the caller of the |
424 if (GetBookmarkModel()->IsLoaded()) | 424 // test should explicitly call CreateBookmarkModel to build it. |
| 425 BookmarkModel* bookmark_model = |
| 426 BookmarkModelFactory::GetForProfileIfExists(this); |
| 427 DCHECK(bookmark_model); |
| 428 if (bookmark_model->IsLoaded()) |
425 return; | 429 return; |
426 base::RunLoop run_loop; | 430 base::RunLoop run_loop; |
427 BookmarkLoadObserver observer(content::GetQuitTaskForRunLoop(&run_loop)); | 431 BookmarkLoadObserver observer(content::GetQuitTaskForRunLoop(&run_loop)); |
428 GetBookmarkModel()->AddObserver(&observer); | 432 bookmark_model->AddObserver(&observer); |
429 run_loop.Run(); | 433 run_loop.Run(); |
430 GetBookmarkModel()->RemoveObserver(&observer); | 434 bookmark_model->RemoveObserver(&observer); |
431 DCHECK(GetBookmarkModel()->IsLoaded()); | 435 DCHECK(bookmark_model->IsLoaded()); |
432 } | 436 } |
433 | 437 |
434 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? | 438 // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? |
435 void TestingProfile::BlockUntilTopSitesLoaded() { | 439 void TestingProfile::BlockUntilTopSitesLoaded() { |
436 content::WindowedNotificationObserver top_sites_loaded_observer( | 440 content::WindowedNotificationObserver top_sites_loaded_observer( |
437 chrome::NOTIFICATION_TOP_SITES_LOADED, | 441 chrome::NOTIFICATION_TOP_SITES_LOADED, |
438 content::NotificationService::AllSources()); | 442 content::NotificationService::AllSources()); |
439 if (!GetHistoryService(Profile::EXPLICIT_ACCESS)) | 443 if (!HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS)) |
440 GetTopSites()->HistoryLoaded(); | 444 GetTopSites()->HistoryLoaded(); |
441 top_sites_loaded_observer.Wait(); | 445 top_sites_loaded_observer.Wait(); |
442 } | 446 } |
443 | 447 |
444 FilePath TestingProfile::GetPath() { | 448 FilePath TestingProfile::GetPath() { |
445 return profile_path_; | 449 return profile_path_; |
446 } | 450 } |
447 | 451 |
448 TestingPrefService* TestingProfile::GetTestingPrefService() { | 452 TestingPrefService* TestingProfile::GetTestingPrefService() { |
449 if (!prefs_.get()) | 453 if (!prefs_.get()) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 TestingProfile::GetExtensionSpecialStoragePolicy() { | 517 TestingProfile::GetExtensionSpecialStoragePolicy() { |
514 if (!extension_special_storage_policy_.get()) | 518 if (!extension_special_storage_policy_.get()) |
515 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL); | 519 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL); |
516 return extension_special_storage_policy_.get(); | 520 return extension_special_storage_policy_.get(); |
517 } | 521 } |
518 | 522 |
519 FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) { | 523 FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) { |
520 return favicon_service_.get(); | 524 return favicon_service_.get(); |
521 } | 525 } |
522 | 526 |
523 HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) { | |
524 return HistoryServiceFactory::GetForProfileIfExists(this, access); | |
525 } | |
526 | |
527 HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() { | |
528 return HistoryServiceFactory::GetForProfileWithoutCreating(this); | |
529 } | |
530 | |
531 net::CookieMonster* TestingProfile::GetCookieMonster() { | 527 net::CookieMonster* TestingProfile::GetCookieMonster() { |
532 if (!GetRequestContext()) | 528 if (!GetRequestContext()) |
533 return NULL; | 529 return NULL; |
534 return GetRequestContext()->GetURLRequestContext()->cookie_store()-> | 530 return GetRequestContext()->GetURLRequestContext()->cookie_store()-> |
535 GetCookieMonster(); | 531 GetCookieMonster(); |
536 } | 532 } |
537 | 533 |
538 policy::UserCloudPolicyManager* TestingProfile::GetUserCloudPolicyManager() { | 534 policy::UserCloudPolicyManager* TestingProfile::GetUserCloudPolicyManager() { |
539 return user_cloud_policy_manager_.get(); | 535 return user_cloud_policy_manager_.get(); |
540 } | 536 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 } | 695 } |
700 | 696 |
701 void TestingProfile::SetID(const std::wstring& id) { | 697 void TestingProfile::SetID(const std::wstring& id) { |
702 id_ = id; | 698 id_ = id; |
703 } | 699 } |
704 | 700 |
705 bool TestingProfile::DidLastSessionExitCleanly() { | 701 bool TestingProfile::DidLastSessionExitCleanly() { |
706 return last_session_exited_cleanly_; | 702 return last_session_exited_cleanly_; |
707 } | 703 } |
708 | 704 |
709 BookmarkModel* TestingProfile::GetBookmarkModel() { | |
710 return BookmarkModelFactory::GetForProfileIfExists(this); | |
711 } | |
712 | |
713 bool TestingProfile::IsSameProfile(Profile *p) { | 705 bool TestingProfile::IsSameProfile(Profile *p) { |
714 return this == p; | 706 return this == p; |
715 } | 707 } |
716 | 708 |
717 base::Time TestingProfile::GetStartTime() const { | 709 base::Time TestingProfile::GetStartTime() const { |
718 return start_time_; | 710 return start_time_; |
719 } | 711 } |
720 | 712 |
721 ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() { | 713 ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() { |
722 return NULL; | 714 return NULL; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 build_called_ = true; | 805 build_called_ = true; |
814 return scoped_ptr<TestingProfile>(new TestingProfile( | 806 return scoped_ptr<TestingProfile>(new TestingProfile( |
815 path_, | 807 path_, |
816 delegate_, | 808 delegate_, |
817 extension_policy_, | 809 extension_policy_, |
818 pref_service_.Pass(), | 810 pref_service_.Pass(), |
819 user_cloud_policy_manager_.Pass())); | 811 user_cloud_policy_manager_.Pass())); |
820 } | 812 } |
821 | 813 |
822 | 814 |
OLD | NEW |