| 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 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 32 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 33 #include "chrome/browser/prefs/browser_prefs.h" | 33 #include "chrome/browser/prefs/browser_prefs.h" |
| 34 #include "chrome/browser/prefs/testing_pref_store.h" | 34 #include "chrome/browser/prefs/testing_pref_store.h" |
| 35 #include "chrome/browser/prerender/prerender_manager.h" | 35 #include "chrome/browser/prerender/prerender_manager.h" |
| 36 #include "chrome/browser/profiles/profile_dependency_manager.h" | 36 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 37 #include "chrome/browser/protector/protector_service_factory.h" | 37 #include "chrome/browser/protector/protector_service_factory.h" |
| 38 #include "chrome/browser/search_engines/template_url_fetcher_factory.h" | 38 #include "chrome/browser/search_engines/template_url_fetcher_factory.h" |
| 39 #include "chrome/browser/search_engines/template_url_service.h" | 39 #include "chrome/browser/search_engines/template_url_service.h" |
| 40 #include "chrome/browser/search_engines/template_url_service_factory.h" | 40 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 41 #include "chrome/browser/speech/chrome_speech_recognition_preferences.h" | 41 #include "chrome/browser/speech/chrome_speech_recognition_preferences.h" |
| 42 #include "chrome/browser/sync/profile_sync_service_mock.h" | 42 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 43 #include "chrome/common/chrome_constants.h" | 43 #include "chrome/common/chrome_constants.h" |
| 44 #include "chrome/common/chrome_notification_types.h" | 44 #include "chrome/common/chrome_notification_types.h" |
| 45 #include "chrome/common/chrome_switches.h" | 45 #include "chrome/common/chrome_switches.h" |
| 46 #include "chrome/common/url_constants.h" | 46 #include "chrome/common/url_constants.h" |
| 47 #include "chrome/test/base/bookmark_load_observer.h" | 47 #include "chrome/test/base/bookmark_load_observer.h" |
| 48 #include "chrome/test/base/testing_pref_service.h" | 48 #include "chrome/test/base/testing_pref_service.h" |
| 49 #include "chrome/test/base/ui_test_utils.h" | 49 #include "chrome/test/base/ui_test_utils.h" |
| 50 #include "content/public/browser/browser_thread.h" | 50 #include "content/public/browser/browser_thread.h" |
| 51 #include "content/public/browser/notification_service.h" | 51 #include "content/public/browser/notification_service.h" |
| 52 #include "content/test/mock_resource_context.h" | 52 #include "content/test/mock_resource_context.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 232 |
| 233 profile_dependency_manager_->DestroyProfileServices(this); | 233 profile_dependency_manager_->DestroyProfileServices(this); |
| 234 | 234 |
| 235 if (host_content_settings_map_) | 235 if (host_content_settings_map_) |
| 236 host_content_settings_map_->ShutdownOnUIThread(); | 236 host_content_settings_map_->ShutdownOnUIThread(); |
| 237 | 237 |
| 238 DestroyTopSites(); | 238 DestroyTopSites(); |
| 239 DestroyHistoryService(); | 239 DestroyHistoryService(); |
| 240 // FaviconService depends on HistoryServce so destroying it later. | 240 // FaviconService depends on HistoryServce so destroying it later. |
| 241 DestroyFaviconService(); | 241 DestroyFaviconService(); |
| 242 DestroyWebDataService(); | |
| 243 | 242 |
| 244 if (pref_proxy_config_tracker_.get()) | 243 if (pref_proxy_config_tracker_.get()) |
| 245 pref_proxy_config_tracker_->DetachFromPrefService(); | 244 pref_proxy_config_tracker_->DetachFromPrefService(); |
| 246 } | 245 } |
| 247 | 246 |
| 248 void TestingProfile::CreateFaviconService() { | 247 void TestingProfile::CreateFaviconService() { |
| 249 favicon_service_.reset(new FaviconService(this)); | 248 favicon_service_.reset(new FaviconService(this)); |
| 250 } | 249 } |
| 251 | 250 |
| 252 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { | 251 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 324 |
| 326 void TestingProfile::CreateAutocompleteClassifier() { | 325 void TestingProfile::CreateAutocompleteClassifier() { |
| 327 autocomplete_classifier_.reset(new AutocompleteClassifier(this)); | 326 autocomplete_classifier_.reset(new AutocompleteClassifier(this)); |
| 328 } | 327 } |
| 329 | 328 |
| 330 void TestingProfile::CreateProtocolHandlerRegistry() { | 329 void TestingProfile::CreateProtocolHandlerRegistry() { |
| 331 protocol_handler_registry_ = new ProtocolHandlerRegistry(this, | 330 protocol_handler_registry_ = new ProtocolHandlerRegistry(this, |
| 332 new ProtocolHandlerRegistry::Delegate()); | 331 new ProtocolHandlerRegistry::Delegate()); |
| 333 } | 332 } |
| 334 | 333 |
| 335 void TestingProfile::CreateWebDataService(bool delete_file) { | 334 static scoped_refptr<RefcountedProfileKeyedService> BuildWebDataService( |
| 336 if (web_data_service_.get()) | 335 Profile* profile) { |
| 337 web_data_service_->Shutdown(); | 336 WebDataService* web_data_service = new WebDataService(); |
| 337 if (web_data_service) |
| 338 web_data_service->Init(profile->GetPath()); |
| 339 return scoped_refptr<WebDataService>(web_data_service); |
| 340 } |
| 338 | 341 |
| 339 if (delete_file) { | 342 void TestingProfile::CreateWebDataService() { |
| 340 FilePath path = GetPath(); | 343 WebDataServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 341 path = path.Append(chrome::kWebDataFilename); | 344 this, BuildWebDataService); |
| 342 file_util::Delete(path, false); | |
| 343 } | |
| 344 | |
| 345 web_data_service_ = new WebDataService; | |
| 346 if (web_data_service_.get()) | |
| 347 web_data_service_->Init(GetPath()); | |
| 348 } | 345 } |
| 349 | 346 |
| 350 void TestingProfile::BlockUntilBookmarkModelLoaded() { | 347 void TestingProfile::BlockUntilBookmarkModelLoaded() { |
| 351 DCHECK(bookmark_bar_model_.get()); | 348 DCHECK(bookmark_bar_model_.get()); |
| 352 if (bookmark_bar_model_->IsLoaded()) | 349 if (bookmark_bar_model_->IsLoaded()) |
| 353 return; | 350 return; |
| 354 BookmarkLoadObserver observer; | 351 BookmarkLoadObserver observer; |
| 355 bookmark_bar_model_->AddObserver(&observer); | 352 bookmark_bar_model_->AddObserver(&observer); |
| 356 MessageLoop::current()->Run(); | 353 MessageLoop::current()->Run(); |
| 357 bookmark_bar_model_->RemoveObserver(&observer); | 354 bookmark_bar_model_->RemoveObserver(&observer); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 } | 482 } |
| 486 | 483 |
| 487 AutocompleteClassifier* TestingProfile::GetAutocompleteClassifier() { | 484 AutocompleteClassifier* TestingProfile::GetAutocompleteClassifier() { |
| 488 return autocomplete_classifier_.get(); | 485 return autocomplete_classifier_.get(); |
| 489 } | 486 } |
| 490 | 487 |
| 491 history::ShortcutsBackend* TestingProfile::GetShortcutsBackend() { | 488 history::ShortcutsBackend* TestingProfile::GetShortcutsBackend() { |
| 492 return NULL; | 489 return NULL; |
| 493 } | 490 } |
| 494 | 491 |
| 495 WebDataService* TestingProfile::GetWebDataService(ServiceAccessType access) { | |
| 496 return web_data_service_.get(); | |
| 497 } | |
| 498 | |
| 499 WebDataService* TestingProfile::GetWebDataServiceWithoutCreating() { | |
| 500 return web_data_service_.get(); | |
| 501 } | |
| 502 | |
| 503 void TestingProfile::SetPrefService(PrefService* prefs) { | 492 void TestingProfile::SetPrefService(PrefService* prefs) { |
| 504 #if defined(ENABLE_PROTECTOR_SERVICE) | 493 #if defined(ENABLE_PROTECTOR_SERVICE) |
| 505 // ProtectorService binds itself very closely to the PrefService at the moment | 494 // ProtectorService binds itself very closely to the PrefService at the moment |
| 506 // of Profile creation and watches pref changes to update their backup. | 495 // of Profile creation and watches pref changes to update their backup. |
| 507 // For tests that replace the PrefService after TestingProfile creation, | 496 // For tests that replace the PrefService after TestingProfile creation, |
| 508 // ProtectorService is disabled to prevent further invalid memory accesses. | 497 // ProtectorService is disabled to prevent further invalid memory accesses. |
| 509 protector::ProtectorServiceFactory::GetInstance()-> | 498 protector::ProtectorServiceFactory::GetInstance()-> |
| 510 SetTestingFactory(this, NULL); | 499 SetTestingFactory(this, NULL); |
| 511 #endif | 500 #endif |
| 512 prefs_.reset(prefs); | 501 prefs_.reset(prefs); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 } | 687 } |
| 699 | 688 |
| 700 PrefService* TestingProfile::GetOffTheRecordPrefs() { | 689 PrefService* TestingProfile::GetOffTheRecordPrefs() { |
| 701 return NULL; | 690 return NULL; |
| 702 } | 691 } |
| 703 | 692 |
| 704 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { | 693 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { |
| 705 return GetExtensionSpecialStoragePolicy(); | 694 return GetExtensionSpecialStoragePolicy(); |
| 706 } | 695 } |
| 707 | 696 |
| 708 void TestingProfile::DestroyWebDataService() { | |
| 709 if (!web_data_service_.get()) | |
| 710 return; | |
| 711 | |
| 712 web_data_service_->Shutdown(); | |
| 713 } | |
| 714 | |
| 715 bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) { | 697 bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) { |
| 716 return true; | 698 return true; |
| 717 } | 699 } |
| 718 | 700 |
| 719 base::Callback<ChromeURLDataManagerBackend*(void)> | 701 base::Callback<ChromeURLDataManagerBackend*(void)> |
| 720 TestingProfile::GetChromeURLDataManagerBackendGetter() const { | 702 TestingProfile::GetChromeURLDataManagerBackendGetter() const { |
| 721 return base::Callback<ChromeURLDataManagerBackend*(void)>(); | 703 return base::Callback<ChromeURLDataManagerBackend*(void)>(); |
| 722 } | 704 } |
| OLD | NEW |