| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/testing_profile.h" | 5 #include "chrome/test/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" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 17 #include "chrome/browser/content_settings/host_content_settings_map.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 18 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 18 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 19 #include "chrome/browser/extensions/extension_pref_value_map.h" | 19 #include "chrome/browser/extensions/extension_pref_value_map.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 21 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 22 #include "chrome/browser/favicon_service.h" | 22 #include "chrome/browser/favicon_service.h" |
| 23 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 23 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| 24 #include "chrome/browser/history/history.h" | 24 #include "chrome/browser/history/history.h" |
| 25 #include "chrome/browser/history/history_backend.h" | 25 #include "chrome/browser/history/history_backend.h" |
| 26 #include "chrome/browser/history/top_sites.h" | 26 #include "chrome/browser/history/top_sites.h" |
| 27 #include "chrome/browser/net/gaia/token_service.h" | 27 #include "chrome/browser/net/gaia/token_service.h" |
| 28 #include "chrome/browser/net/pref_proxy_config_service.h" | 28 #include "chrome/browser/net/pref_proxy_config_service.h" |
| 29 #include "chrome/browser/notifications/desktop_notification_service.h" | 29 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 30 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 30 #include "chrome/browser/prefs/browser_prefs.h" | 31 #include "chrome/browser/prefs/browser_prefs.h" |
| 31 #include "chrome/browser/prefs/testing_pref_store.h" | 32 #include "chrome/browser/prefs/testing_pref_store.h" |
| 32 #include "chrome/browser/prerender/prerender_manager.h" | 33 #include "chrome/browser/prerender/prerender_manager.h" |
| 33 #include "chrome/browser/profiles/profile_dependency_manager.h" | 34 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 34 #include "chrome/browser/search_engines/template_url_fetcher.h" | 35 #include "chrome/browser/search_engines/template_url_fetcher.h" |
| 35 #include "chrome/browser/search_engines/template_url_model.h" | 36 #include "chrome/browser/search_engines/template_url_model.h" |
| 36 #include "chrome/browser/sessions/session_service.h" | 37 #include "chrome/browser/sessions/session_service.h" |
| 37 #include "chrome/browser/sync/profile_sync_service_mock.h" | 38 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 38 #include "chrome/browser/ui/find_bar/find_bar_state.h" | 39 #include "chrome/browser/ui/find_bar/find_bar_state.h" |
| 39 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 40 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 return context_.get(); | 135 return context_.get(); |
| 135 } | 136 } |
| 136 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { | 137 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { |
| 137 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 138 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| 138 } | 139 } |
| 139 | 140 |
| 140 private: | 141 private: |
| 141 scoped_refptr<net::URLRequestContext> context_; | 142 scoped_refptr<net::URLRequestContext> context_; |
| 142 }; | 143 }; |
| 143 | 144 |
| 145 ProfileKeyedService* CreateTestDesktopNotificationService(Profile* profile) { |
| 146 return new DesktopNotificationService(profile, NULL); |
| 147 } |
| 148 |
| 144 } // namespace | 149 } // namespace |
| 145 | 150 |
| 146 TestingProfile::TestingProfile() | 151 TestingProfile::TestingProfile() |
| 147 : start_time_(Time::Now()), | 152 : start_time_(Time::Now()), |
| 148 testing_prefs_(NULL), | 153 testing_prefs_(NULL), |
| 149 incognito_(false), | 154 incognito_(false), |
| 150 last_session_exited_cleanly_(true), | 155 last_session_exited_cleanly_(true), |
| 151 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { | 156 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { |
| 152 if (!temp_dir_.CreateUniqueTempDir()) { | 157 if (!temp_dir_.CreateUniqueTempDir()) { |
| 153 LOG(ERROR) << "Failed to create unique temporary directory."; | 158 LOG(ERROR) << "Failed to create unique temporary directory."; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 165 file_util::Delete(fallback_dir, true); | 170 file_util::Delete(fallback_dir, true); |
| 166 file_util::CreateDirectory(fallback_dir); | 171 file_util::CreateDirectory(fallback_dir); |
| 167 if (!temp_dir_.Set(fallback_dir)) { | 172 if (!temp_dir_.Set(fallback_dir)) { |
| 168 // That shouldn't happen, but if it does, try to recover. | 173 // That shouldn't happen, but if it does, try to recover. |
| 169 LOG(ERROR) << "Failed to use a fallback temporary directory."; | 174 LOG(ERROR) << "Failed to use a fallback temporary directory."; |
| 170 | 175 |
| 171 // We're screwed if this fails, see CHECK above. | 176 // We're screwed if this fails, see CHECK above. |
| 172 CHECK(temp_dir_.Set(system_tmp_dir)); | 177 CHECK(temp_dir_.Set(system_tmp_dir)); |
| 173 } | 178 } |
| 174 } | 179 } |
| 180 |
| 181 // Install profile keyed service factory hooks for dummy/test services |
| 182 DesktopNotificationServiceFactory::GetInstance()->set_test_factory( |
| 183 &CreateTestDesktopNotificationService); |
| 184 DesktopNotificationServiceFactory::GetInstance()->ForceAssociationBetween( |
| 185 this, NULL); |
| 175 } | 186 } |
| 176 | 187 |
| 177 TestingProfile::~TestingProfile() { | 188 TestingProfile::~TestingProfile() { |
| 178 NotificationService::current()->Notify( | 189 NotificationService::current()->Notify( |
| 179 NotificationType::PROFILE_DESTROYED, | 190 NotificationType::PROFILE_DESTROYED, |
| 180 Source<Profile>(static_cast<Profile*>(this)), | 191 Source<Profile>(static_cast<Profile*>(this)), |
| 181 NotificationService::NoDetails()); | 192 NotificationService::NoDetails()); |
| 182 | 193 |
| 183 profile_dependency_manager_->DestroyProfileServices(this); | 194 profile_dependency_manager_->DestroyProfileServices(this); |
| 184 | 195 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 return temp_dir_.path(); | 366 return temp_dir_.path(); |
| 356 } | 367 } |
| 357 | 368 |
| 358 TestingPrefService* TestingProfile::GetTestingPrefService() { | 369 TestingPrefService* TestingProfile::GetTestingPrefService() { |
| 359 if (!prefs_.get()) | 370 if (!prefs_.get()) |
| 360 CreateTestingPrefService(); | 371 CreateTestingPrefService(); |
| 361 DCHECK(testing_prefs_); | 372 DCHECK(testing_prefs_); |
| 362 return testing_prefs_; | 373 return testing_prefs_; |
| 363 } | 374 } |
| 364 | 375 |
| 365 void TestingProfile::SetProfileDependencyManager( | |
| 366 ProfileDependencyManager* manager) { | |
| 367 profile_dependency_manager_ = manager; | |
| 368 } | |
| 369 | |
| 370 ProfileId TestingProfile::GetRuntimeId() { | 376 ProfileId TestingProfile::GetRuntimeId() { |
| 371 return reinterpret_cast<ProfileId>(this); | 377 return reinterpret_cast<ProfileId>(this); |
| 372 } | 378 } |
| 373 | 379 |
| 374 bool TestingProfile::IsOffTheRecord() { | 380 bool TestingProfile::IsOffTheRecord() { |
| 375 return incognito_; | 381 return incognito_; |
| 376 } | 382 } |
| 377 | 383 |
| 378 void TestingProfile::SetOffTheRecordProfile(Profile* profile) { | 384 void TestingProfile::SetOffTheRecordProfile(Profile* profile) { |
| 379 incognito_profile_.reset(profile); | 385 incognito_profile_.reset(profile); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() { | 692 WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() { |
| 687 return NULL; | 693 return NULL; |
| 688 } | 694 } |
| 689 | 695 |
| 690 NTPResourceCache* TestingProfile::GetNTPResourceCache() { | 696 NTPResourceCache* TestingProfile::GetNTPResourceCache() { |
| 691 if (!ntp_resource_cache_.get()) | 697 if (!ntp_resource_cache_.get()) |
| 692 ntp_resource_cache_.reset(new NTPResourceCache(this)); | 698 ntp_resource_cache_.reset(new NTPResourceCache(this)); |
| 693 return ntp_resource_cache_.get(); | 699 return ntp_resource_cache_.get(); |
| 694 } | 700 } |
| 695 | 701 |
| 696 DesktopNotificationService* TestingProfile::GetDesktopNotificationService() { | |
| 697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 698 if (!desktop_notification_service_.get()) { | |
| 699 desktop_notification_service_.reset(new DesktopNotificationService( | |
| 700 this, NULL)); | |
| 701 } | |
| 702 return desktop_notification_service_.get(); | |
| 703 } | |
| 704 | |
| 705 BackgroundContentsService* | 702 BackgroundContentsService* |
| 706 TestingProfile::GetBackgroundContentsService() const { | 703 TestingProfile::GetBackgroundContentsService() const { |
| 707 return NULL; | 704 return NULL; |
| 708 } | 705 } |
| 709 | 706 |
| 710 StatusTray* TestingProfile::GetStatusTray() { | 707 StatusTray* TestingProfile::GetStatusTray() { |
| 711 return NULL; | 708 return NULL; |
| 712 } | 709 } |
| 713 | 710 |
| 714 FilePath TestingProfile::last_selected_directory() { | 711 FilePath TestingProfile::last_selected_directory() { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 } | 805 } |
| 809 | 806 |
| 810 DerivedTestingProfile::DerivedTestingProfile(Profile* profile) | 807 DerivedTestingProfile::DerivedTestingProfile(Profile* profile) |
| 811 : original_profile_(profile) {} | 808 : original_profile_(profile) {} |
| 812 | 809 |
| 813 DerivedTestingProfile::~DerivedTestingProfile() {} | 810 DerivedTestingProfile::~DerivedTestingProfile() {} |
| 814 | 811 |
| 815 ProfileId DerivedTestingProfile::GetRuntimeId() { | 812 ProfileId DerivedTestingProfile::GetRuntimeId() { |
| 816 return original_profile_->GetRuntimeId(); | 813 return original_profile_->GetRuntimeId(); |
| 817 } | 814 } |
| OLD | NEW |