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