[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | a4ff9eae | 2011-08-01 19:58:16 | [diff] [blame] | 5 | #include "chrome/test/base/testing_profile.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | a42b559 | 2009-09-03 16:52:23 | [diff] [blame] | 7 | #include "build/build_config.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 8 | |
| 9 | #include "base/base_paths.h" |
[email protected] | e3e43d9 | 2010-02-26 22:02:38 | [diff] [blame] | 10 | #include "base/command_line.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 11 | #include "base/file_util.h" |
[email protected] | 83a7d2eb | 2010-05-03 21:46:19 | [diff] [blame] | 12 | #include "base/message_loop_proxy.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 13 | #include "base/path_service.h" |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 14 | #include "base/string_number_conversions.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 15 | #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 16 | #include "chrome/browser/bookmarks/bookmark_model.h" |
[email protected] | 1459fb6 | 2011-05-25 19:03:27 | [diff] [blame] | 17 | #include "chrome/browser/browser_process.h" |
[email protected] | 9d01a6a | 2010-11-30 12:03:33 | [diff] [blame] | 18 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 19 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
[email protected] | 2bb5130 | 2011-02-18 22:39:27 | [diff] [blame] | 20 | #include "chrome/browser/extensions/extension_pref_value_map.h" |
[email protected] | 2f69b38 | 2011-02-19 00:34:25 | [diff] [blame] | 21 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 22 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | ee2ed42c | 2011-04-28 22:19:14 | [diff] [blame] | 23 | #include "chrome/browser/favicon/favicon_service.h" |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 24 | #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 25 | #include "chrome/browser/history/history.h" |
[email protected] | 075ae73 | 2009-02-11 23:58:31 | [diff] [blame] | 26 | #include "chrome/browser/history/history_backend.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 27 | #include "chrome/browser/history/top_sites.h" |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 28 | #include "chrome/browser/net/proxy_service_factory.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 29 | #include "chrome/browser/notifications/desktop_notification_service.h" |
[email protected] | dcb72d5 | 2011-04-13 12:36:53 | [diff] [blame] | 30 | #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 31 | #include "chrome/browser/prefs/browser_prefs.h" |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 32 | #include "chrome/browser/prefs/testing_pref_store.h" |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 33 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 5cdcd15 | 2011-03-31 22:48:52 | [diff] [blame] | 34 | #include "chrome/browser/profiles/profile_dependency_manager.h" |
[email protected] | fb9d1f4 | 2010-10-06 23:17:59 | [diff] [blame] | 35 | #include "chrome/browser/search_engines/template_url_fetcher.h" |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 36 | #include "chrome/browser/search_engines/template_url_service.h" |
| 37 | #include "chrome/browser/search_engines/template_url_service_factory.h" |
[email protected] | 99e652f | 2012-01-22 04:05:07 | [diff] [blame] | 38 | #include "chrome/browser/signin/token_service.h" |
[email protected] | 8238dd6 | 2011-09-29 15:13:01 | [diff] [blame] | 39 | #include "chrome/browser/speech/chrome_speech_input_preferences.h" |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 40 | #include "chrome/browser/sync/profile_sync_service_mock.h" |
[email protected] | fd42ac30f | 2011-02-27 19:33:36 | [diff] [blame] | 41 | #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 42 | #include "chrome/common/chrome_constants.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 43 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 9e33d7e | 2011-09-30 16:43:54 | [diff] [blame] | 44 | #include "chrome/common/chrome_switches.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 45 | #include "chrome/common/url_constants.h" |
[email protected] | 7bc6068 | 2011-07-29 20:55:59 | [diff] [blame] | 46 | #include "chrome/test/base/bookmark_load_observer.h" |
[email protected] | aecb6ca | 2011-07-29 22:56:14 | [diff] [blame] | 47 | #include "chrome/test/base/test_url_request_context_getter.h" |
[email protected] | 8ad3636e | 2011-08-01 22:31:40 | [diff] [blame] | 48 | #include "chrome/test/base/testing_pref_service.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 49 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 567812d | 2011-02-24 17:40:50 | [diff] [blame] | 50 | #include "content/browser/in_process_webkit/webkit_context.h" |
[email protected] | e89b77d | 2011-04-15 18:58:10 | [diff] [blame] | 51 | #include "content/browser/mock_resource_context.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 52 | #include "content/public/browser/browser_thread.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 53 | #include "content/public/browser/notification_service.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 54 | #include "net/base/cookie_monster.h" |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 55 | #include "net/url_request/url_request_context.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 56 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | d2db029 | 2011-01-26 20:23:44 | [diff] [blame] | 57 | #include "net/url_request/url_request_test_util.h" |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 58 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | 2f351cb | 2009-11-09 23:43:34 | [diff] [blame] | 59 | #include "webkit/database/database_tracker.h" |
[email protected] | de5480fa | 2011-05-26 22:07:36 | [diff] [blame] | 60 | #include "webkit/fileapi/file_system_context.h" |
[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 61 | #include "webkit/fileapi/file_system_options.h" |
[email protected] | 9470417 | 2011-08-01 16:23:40 | [diff] [blame] | 62 | #include "webkit/quota/mock_quota_manager.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 63 | #include "webkit/quota/quota_manager.h" |
[email protected] | 248ce19 | 2011-02-10 15:26:34 | [diff] [blame] | 64 | |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 65 | #if defined(OS_CHROMEOS) |
| 66 | #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 67 | #endif // defined(OS_CHROMEOS) |
| 68 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 69 | using base::Time; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 70 | using content::BrowserThread; |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 71 | using content::DownloadManager; |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 72 | using content::HostZoomMap; |
[email protected] | 3c88741 | 2010-04-19 20:30:23 | [diff] [blame] | 73 | using testing::NiceMock; |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 74 | using testing::Return; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 75 | |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 76 | namespace { |
| 77 | |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 78 | // Task used to make sure history has finished processing a request. Intended |
| 79 | // for use with BlockUntilHistoryProcessesPendingRequests. |
| 80 | |
| 81 | class QuittingHistoryDBTask : public HistoryDBTask { |
| 82 | public: |
| 83 | QuittingHistoryDBTask() {} |
| 84 | |
| 85 | virtual bool RunOnDBThread(history::HistoryBackend* backend, |
| 86 | history::HistoryDatabase* db) { |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | virtual void DoneRunOnMainThread() { |
| 91 | MessageLoop::current()->Quit(); |
| 92 | } |
| 93 | |
| 94 | private: |
[email protected] | 7991a23 | 2009-11-06 01:55:48 | [diff] [blame] | 95 | ~QuittingHistoryDBTask() {} |
| 96 | |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 97 | DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask); |
| 98 | }; |
| 99 | |
[email protected] | aeb53f0 | 2011-01-15 00:21:34 | [diff] [blame] | 100 | class TestExtensionURLRequestContext : public net::URLRequestContext { |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 101 | public: |
| 102 | TestExtensionURLRequestContext() { |
| 103 | net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); |
| 104 | const char* schemes[] = {chrome::kExtensionScheme}; |
| 105 | cookie_monster->SetCookieableSchemes(schemes, 1); |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 106 | set_cookie_store(cookie_monster); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 107 | } |
| 108 | }; |
| 109 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 110 | class TestExtensionURLRequestContextGetter |
| 111 | : public net::URLRequestContextGetter { |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 112 | public: |
[email protected] | aeb53f0 | 2011-01-15 00:21:34 | [diff] [blame] | 113 | virtual net::URLRequestContext* GetURLRequestContext() { |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 114 | if (!context_) |
| 115 | context_ = new TestExtensionURLRequestContext(); |
| 116 | return context_.get(); |
| 117 | } |
[email protected] | 00ed48f | 2010-10-22 22:19:24 | [diff] [blame] | 118 | virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { |
[email protected] | 0c7d74f | 2010-10-11 11:55:26 | [diff] [blame] | 119 | return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
[email protected] | 83a7d2eb | 2010-05-03 21:46:19 | [diff] [blame] | 120 | } |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 121 | |
| 122 | private: |
[email protected] | aeb53f0 | 2011-01-15 00:21:34 | [diff] [blame] | 123 | scoped_refptr<net::URLRequestContext> context_; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 124 | }; |
| 125 | |
[email protected] | 67e7999 | 2012-02-13 20:47:58 | [diff] [blame] | 126 | ProfileKeyedBase* CreateTestDesktopNotificationService(Profile* profile) { |
[email protected] | dcb72d5 | 2011-04-13 12:36:53 | [diff] [blame] | 127 | return new DesktopNotificationService(profile, NULL); |
| 128 | } |
| 129 | |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 130 | } // namespace |
| 131 | |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 132 | TestingProfile::TestingProfile() |
[email protected] | ea6f7657 | 2008-12-18 00:09:55 | [diff] [blame] | 133 | : start_time_(Time::Now()), |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 134 | testing_prefs_(NULL), |
[email protected] | 5bb2f52 | 2011-03-25 19:04:44 | [diff] [blame] | 135 | incognito_(false), |
[email protected] | 5cdcd15 | 2011-03-31 22:48:52 | [diff] [blame] | 136 | last_session_exited_cleanly_(true), |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 137 | profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
| 138 | delegate_(NULL) { |
[email protected] | f9dec948 | 2010-08-20 20:42:19 | [diff] [blame] | 139 | if (!temp_dir_.CreateUniqueTempDir()) { |
| 140 | LOG(ERROR) << "Failed to create unique temporary directory."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 141 | |
[email protected] | f9dec948 | 2010-08-20 20:42:19 | [diff] [blame] | 142 | // Fallback logic in case we fail to create unique temporary directory. |
| 143 | FilePath system_tmp_dir; |
| 144 | bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); |
[email protected] | 848cd05e | 2008-09-19 18:33:48 | [diff] [blame] | 145 | |
[email protected] | f9dec948 | 2010-08-20 20:42:19 | [diff] [blame] | 146 | // We're severly screwed if we can't get the system temporary |
| 147 | // directory. Die now to avoid writing to the filesystem root |
| 148 | // or other bad places. |
| 149 | CHECK(success); |
| 150 | |
| 151 | FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath")); |
| 152 | file_util::Delete(fallback_dir, true); |
| 153 | file_util::CreateDirectory(fallback_dir); |
| 154 | if (!temp_dir_.Set(fallback_dir)) { |
| 155 | // That shouldn't happen, but if it does, try to recover. |
| 156 | LOG(ERROR) << "Failed to use a fallback temporary directory."; |
| 157 | |
| 158 | // We're screwed if this fails, see CHECK above. |
| 159 | CHECK(temp_dir_.Set(system_tmp_dir)); |
| 160 | } |
| 161 | } |
[email protected] | dcb72d5 | 2011-04-13 12:36:53 | [diff] [blame] | 162 | |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 163 | profile_path_ = temp_dir_.path(); |
| 164 | |
| 165 | Init(); |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 166 | FinishInit(); |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | TestingProfile::TestingProfile(const FilePath& path) |
| 170 | : start_time_(Time::Now()), |
| 171 | testing_prefs_(NULL), |
| 172 | incognito_(false), |
| 173 | last_session_exited_cleanly_(true), |
| 174 | profile_path_(path), |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 175 | profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
| 176 | delegate_(NULL) { |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 177 | Init(); |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 178 | FinishInit(); |
| 179 | } |
| 180 | |
| 181 | TestingProfile::TestingProfile(const FilePath& path, |
| 182 | Delegate* delegate) |
| 183 | : start_time_(Time::Now()), |
| 184 | testing_prefs_(NULL), |
| 185 | incognito_(false), |
| 186 | last_session_exited_cleanly_(true), |
| 187 | profile_path_(path), |
| 188 | profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
| 189 | delegate_(delegate) { |
| 190 | Init(); |
| 191 | if (delegate_) { |
| 192 | MessageLoop::current()->PostTask(FROM_HERE, |
| 193 | base::Bind(&TestingProfile::FinishInit, |
| 194 | base::Unretained(this))); |
| 195 | } else { |
| 196 | FinishInit(); |
| 197 | } |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | void TestingProfile::Init() { |
| 201 | profile_dependency_manager_->CreateProfileServices(this, true); |
| 202 | |
[email protected] | dcb72d5 | 2011-04-13 12:36:53 | [diff] [blame] | 203 | // Install profile keyed service factory hooks for dummy/test services |
[email protected] | 7722653b | 2011-06-03 17:28:22 | [diff] [blame] | 204 | DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( |
| 205 | this, CreateTestDesktopNotificationService); |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 206 | } |
[email protected] | 12463cd | 2011-07-19 09:40:20 | [diff] [blame] | 207 | |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 208 | void TestingProfile::FinishInit() { |
[email protected] | 080adba9 | 2011-12-07 19:00:40 | [diff] [blame] | 209 | DCHECK(content::NotificationService::current()); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 210 | content::NotificationService::current()->Notify( |
[email protected] | 12463cd | 2011-07-19 09:40:20 | [diff] [blame] | 211 | chrome::NOTIFICATION_PROFILE_CREATED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 212 | content::Source<Profile>(static_cast<Profile*>(this)), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 213 | content::NotificationService::NoDetails()); |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 214 | |
| 215 | if (delegate_) |
| 216 | delegate_->OnProfileCreated(this, true); |
[email protected] | ab23dbe | 2010-08-12 02:10:46 | [diff] [blame] | 217 | } |
| 218 | |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 219 | TestingProfile::~TestingProfile() { |
[email protected] | 080adba9 | 2011-12-07 19:00:40 | [diff] [blame] | 220 | DCHECK(content::NotificationService::current()); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 221 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 222 | chrome::NOTIFICATION_PROFILE_DESTROYED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 223 | content::Source<Profile>(static_cast<Profile*>(this)), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 224 | content::NotificationService::NoDetails()); |
[email protected] | 5cdcd15 | 2011-03-31 22:48:52 | [diff] [blame] | 225 | |
| 226 | profile_dependency_manager_->DestroyProfileServices(this); |
| 227 | |
[email protected] | 35552dc5 | 2011-07-12 09:04:38 | [diff] [blame] | 228 | if (host_content_settings_map_) |
| 229 | host_content_settings_map_->ShutdownOnUIThread(); |
| 230 | |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 231 | DestroyTopSites(); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 232 | DestroyHistoryService(); |
[email protected] | d2879af | 2010-02-08 16:02:56 | [diff] [blame] | 233 | // FaviconService depends on HistoryServce so destroying it later. |
| 234 | DestroyFaviconService(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 235 | DestroyWebDataService(); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 236 | |
[email protected] | cc5bfd4 | 2010-11-24 14:44:02 | [diff] [blame] | 237 | if (pref_proxy_config_tracker_.get()) |
| 238 | pref_proxy_config_tracker_->DetachFromPrefService(); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 239 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 240 | |
[email protected] | d2879af | 2010-02-08 16:02:56 | [diff] [blame] | 241 | void TestingProfile::CreateFaviconService() { |
[email protected] | 04732c0e | 2011-09-16 13:21:53 | [diff] [blame] | 242 | favicon_service_.reset(new FaviconService(this)); |
[email protected] | d2879af | 2010-02-08 16:02:56 | [diff] [blame] | 243 | } |
| 244 | |
[email protected] | d486a085 | 2009-11-02 21:40:00 | [diff] [blame] | 245 | void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 246 | DestroyHistoryService(); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 247 | if (delete_file) { |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 248 | FilePath path = GetPath(); |
| 249 | path = path.Append(chrome::kHistoryFilename); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 250 | file_util::Delete(path, false); |
| 251 | } |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 252 | history_service_ = new HistoryService(this); |
[email protected] | d486a085 | 2009-11-02 21:40:00 | [diff] [blame] | 253 | history_service_->Init(GetPath(), bookmark_bar_model_.get(), no_db); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | void TestingProfile::DestroyHistoryService() { |
| 257 | if (!history_service_.get()) |
| 258 | return; |
| 259 | |
| 260 | history_service_->NotifyRenderProcessHostDestruction(0); |
[email protected] | 1cb1a24 | 2011-12-10 18:36:51 | [diff] [blame] | 261 | history_service_->SetOnBackendDestroyTask(MessageLoop::QuitClosure()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 262 | history_service_->Cleanup(); |
| 263 | history_service_ = NULL; |
| 264 | |
| 265 | // Wait for the backend class to terminate before deleting the files and |
| 266 | // moving to the next test. Note: if this never terminates, somebody is |
| 267 | // probably leaking a reference to the history backend, so it never calls |
| 268 | // our destroy task. |
| 269 | MessageLoop::current()->Run(); |
| 270 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 271 | // Make sure we don't have any event pending that could disrupt the next |
| 272 | // test. |
[email protected] | 1cb1a24 | 2011-12-10 18:36:51 | [diff] [blame] | 273 | MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 274 | MessageLoop::current()->Run(); |
| 275 | } |
[email protected] | 4d0cd7ce | 2008-08-11 16:40:57 | [diff] [blame] | 276 | |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 277 | void TestingProfile::CreateTopSites() { |
| 278 | DestroyTopSites(); |
| 279 | top_sites_ = new history::TopSites(this); |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 280 | FilePath file_name = GetPath().Append(chrome::kTopSitesFilename); |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 281 | top_sites_->Init(file_name); |
| 282 | } |
| 283 | |
| 284 | void TestingProfile::DestroyTopSites() { |
| 285 | if (top_sites_.get()) { |
| 286 | top_sites_->Shutdown(); |
| 287 | top_sites_ = NULL; |
| 288 | // TopSites::Shutdown schedules some tasks (from TopSitesBackend) that need |
| 289 | // to be run to properly shutdown. Run all pending tasks now. This is |
| 290 | // normally handled by browser_process shutdown. |
| 291 | if (MessageLoop::current()) |
| 292 | MessageLoop::current()->RunAllPending(); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | void TestingProfile::DestroyFaviconService() { |
[email protected] | 04732c0e | 2011-09-16 13:21:53 | [diff] [blame] | 297 | favicon_service_.reset(); |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 298 | } |
| 299 | |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 300 | void TestingProfile::CreateBookmarkModel(bool delete_file) { |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 301 | // Nuke the model first, that way we're sure it's done writing to disk. |
| 302 | bookmark_bar_model_.reset(NULL); |
| 303 | |
| 304 | if (delete_file) { |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 305 | FilePath path = GetPath(); |
| 306 | path = path.Append(chrome::kBookmarksFileName); |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 307 | file_util::Delete(path, false); |
| 308 | } |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 309 | bookmark_bar_model_.reset(new BookmarkModel(this)); |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 310 | if (history_service_.get()) { |
| 311 | history_service_->history_backend_->bookmark_service_ = |
| 312 | bookmark_bar_model_.get(); |
| 313 | history_service_->history_backend_->expirer_.bookmark_service_ = |
| 314 | bookmark_bar_model_.get(); |
| 315 | } |
| 316 | bookmark_bar_model_->Load(); |
[email protected] | 4d0cd7ce | 2008-08-11 16:40:57 | [diff] [blame] | 317 | } |
[email protected] | d2c017a | 2008-08-13 21:51:45 | [diff] [blame] | 318 | |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame] | 319 | void TestingProfile::CreateAutocompleteClassifier() { |
| 320 | autocomplete_classifier_.reset(new AutocompleteClassifier(this)); |
| 321 | } |
| 322 | |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 323 | void TestingProfile::CreateProtocolHandlerRegistry() { |
[email protected] | fd8ca52 | 2011-05-02 18:54:49 | [diff] [blame] | 324 | protocol_handler_registry_ = new ProtocolHandlerRegistry(this, |
| 325 | new ProtocolHandlerRegistry::Delegate()); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 326 | } |
| 327 | |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 328 | void TestingProfile::CreateWebDataService(bool delete_file) { |
| 329 | if (web_data_service_.get()) |
| 330 | web_data_service_->Shutdown(); |
| 331 | |
| 332 | if (delete_file) { |
| 333 | FilePath path = GetPath(); |
| 334 | path = path.Append(chrome::kWebDataFilename); |
| 335 | file_util::Delete(path, false); |
| 336 | } |
| 337 | |
| 338 | web_data_service_ = new WebDataService; |
| 339 | if (web_data_service_.get()) |
| 340 | web_data_service_->Init(GetPath()); |
| 341 | } |
| 342 | |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 343 | void TestingProfile::BlockUntilBookmarkModelLoaded() { |
| 344 | DCHECK(bookmark_bar_model_.get()); |
| 345 | if (bookmark_bar_model_->IsLoaded()) |
| 346 | return; |
| 347 | BookmarkLoadObserver observer; |
| 348 | bookmark_bar_model_->AddObserver(&observer); |
| 349 | MessageLoop::current()->Run(); |
| 350 | bookmark_bar_model_->RemoveObserver(&observer); |
| 351 | DCHECK(bookmark_bar_model_->IsLoaded()); |
| 352 | } |
| 353 | |
[email protected] | 120abf13 | 2011-09-27 21:38:06 | [diff] [blame] | 354 | // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 355 | void TestingProfile::BlockUntilTopSitesLoaded() { |
[email protected] | 120abf13 | 2011-09-27 21:38:06 | [diff] [blame] | 356 | ui_test_utils::WindowedNotificationObserver top_sites_loaded_observer( |
| 357 | chrome::NOTIFICATION_TOP_SITES_LOADED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 358 | content::NotificationService::AllSources()); |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 359 | if (!GetHistoryService(Profile::EXPLICIT_ACCESS)) |
| 360 | GetTopSites()->HistoryLoaded(); |
[email protected] | 120abf13 | 2011-09-27 21:38:06 | [diff] [blame] | 361 | top_sites_loaded_observer.Wait(); |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 362 | } |
| 363 | |
[email protected] | fb9d1f4 | 2010-10-06 23:17:59 | [diff] [blame] | 364 | void TestingProfile::CreateTemplateURLFetcher() { |
| 365 | template_url_fetcher_.reset(new TemplateURLFetcher(this)); |
| 366 | } |
| 367 | |
[email protected] | 67e7999 | 2012-02-13 20:47:58 | [diff] [blame] | 368 | static ProfileKeyedBase* BuildTemplateURLService(Profile* profile) { |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 369 | return new TemplateURLService(profile); |
[email protected] | fb9d1f4 | 2010-10-06 23:17:59 | [diff] [blame] | 370 | } |
| 371 | |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 372 | void TestingProfile::CreateTemplateURLService() { |
| 373 | TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 374 | this, BuildTemplateURLService); |
[email protected] | d2c017a | 2008-08-13 21:51:45 | [diff] [blame] | 375 | } |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 376 | |
[email protected] | 66d2216 | 2011-11-22 03:47:31 | [diff] [blame] | 377 | void TestingProfile::BlockUntilTemplateURLServiceLoaded() { |
| 378 | TemplateURLService* turl_model = |
| 379 | TemplateURLServiceFactory::GetForProfile(this); |
| 380 | if (turl_model->loaded()) |
| 381 | return; |
| 382 | |
| 383 | ui_test_utils::WindowedNotificationObserver turl_service_load_observer( |
| 384 | chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
| 385 | content::NotificationService::AllSources()); |
| 386 | turl_model->Load(); |
| 387 | turl_service_load_observer.Wait(); |
| 388 | } |
| 389 | |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 390 | void TestingProfile::CreateExtensionProcessManager() { |
| 391 | extension_process_manager_.reset(ExtensionProcessManager::Create(this)); |
| 392 | } |
| 393 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 394 | ExtensionService* TestingProfile::CreateExtensionService( |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 395 | const CommandLine* command_line, |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 396 | const FilePath& install_directory, |
| 397 | bool autoupdate_enabled) { |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 398 | // Extension pref store, created for use by |extension_prefs_|. |
| 399 | |
| 400 | extension_pref_value_map_.reset(new ExtensionPrefValueMap); |
[email protected] | 9e33d7e | 2011-09-30 16:43:54 | [diff] [blame] | 401 | |
| 402 | bool extensions_disabled = |
| 403 | command_line && command_line->HasSwitch(switches::kDisableExtensions); |
| 404 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 405 | // Note that the GetPrefs() creates a TestingPrefService, therefore |
| 406 | // the extension controlled pref values set in extension_prefs_ |
| 407 | // are not reflected in the pref service. One would need to |
| 408 | // inject a new ExtensionPrefStore(extension_pref_value_map_.get(), false). |
| 409 | extension_prefs_.reset( |
| 410 | new ExtensionPrefs(GetPrefs(), |
| 411 | install_directory, |
| 412 | extension_pref_value_map_.get())); |
[email protected] | 9e33d7e | 2011-09-30 16:43:54 | [diff] [blame] | 413 | extension_prefs_->Init(extensions_disabled); |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 414 | extension_service_.reset(new ExtensionService(this, |
| 415 | command_line, |
| 416 | install_directory, |
| 417 | extension_prefs_.get(), |
| 418 | autoupdate_enabled, |
| 419 | true)); |
| 420 | return extension_service_.get(); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 421 | } |
| 422 | |
[email protected] | f9dec948 | 2010-08-20 20:42:19 | [diff] [blame] | 423 | FilePath TestingProfile::GetPath() { |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 424 | return profile_path_; |
[email protected] | f9dec948 | 2010-08-20 20:42:19 | [diff] [blame] | 425 | } |
| 426 | |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 427 | TestingPrefService* TestingProfile::GetTestingPrefService() { |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 428 | if (!prefs_.get()) |
| 429 | CreateTestingPrefService(); |
| 430 | DCHECK(testing_prefs_); |
| 431 | return testing_prefs_; |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 432 | } |
| 433 | |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 434 | TestingProfile* TestingProfile::AsTestingProfile() { |
| 435 | return this; |
| 436 | } |
| 437 | |
[email protected] | 29d7025 | 2011-04-28 02:16:58 | [diff] [blame] | 438 | std::string TestingProfile::GetProfileName() { |
| 439 | return std::string("testing_profile"); |
| 440 | } |
| 441 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 442 | bool TestingProfile::IsOffTheRecord() { |
[email protected] | 5bb2f52 | 2011-03-25 19:04:44 | [diff] [blame] | 443 | return incognito_; |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 444 | } |
| 445 | |
[email protected] | 93dba94 | 2011-02-23 22:45:01 | [diff] [blame] | 446 | void TestingProfile::SetOffTheRecordProfile(Profile* profile) { |
[email protected] | 5bb2f52 | 2011-03-25 19:04:44 | [diff] [blame] | 447 | incognito_profile_.reset(profile); |
[email protected] | 93dba94 | 2011-02-23 22:45:01 | [diff] [blame] | 448 | } |
| 449 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 450 | Profile* TestingProfile::GetOffTheRecordProfile() { |
[email protected] | 5bb2f52 | 2011-03-25 19:04:44 | [diff] [blame] | 451 | return incognito_profile_.get(); |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 452 | } |
| 453 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 454 | GAIAInfoUpdateService* TestingProfile::GetGAIAInfoUpdateService() { |
| 455 | return NULL; |
| 456 | } |
| 457 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 458 | bool TestingProfile::HasOffTheRecordProfile() { |
[email protected] | 5bb2f52 | 2011-03-25 19:04:44 | [diff] [blame] | 459 | return incognito_profile_.get() != NULL; |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | Profile* TestingProfile::GetOriginalProfile() { |
| 463 | return this; |
| 464 | } |
| 465 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 466 | VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() { |
| 467 | return NULL; |
| 468 | } |
| 469 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 470 | ExtensionService* TestingProfile::GetExtensionService() { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 471 | return extension_service_.get(); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 472 | } |
| 473 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 474 | UserScriptMaster* TestingProfile::GetUserScriptMaster() { |
| 475 | return NULL; |
| 476 | } |
| 477 | |
| 478 | ExtensionDevToolsManager* TestingProfile::GetExtensionDevToolsManager() { |
| 479 | return NULL; |
| 480 | } |
| 481 | |
| 482 | ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() { |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 483 | return extension_process_manager_.get(); |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | ExtensionMessageService* TestingProfile::GetExtensionMessageService() { |
| 487 | return NULL; |
| 488 | } |
| 489 | |
| 490 | ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() { |
| 491 | return NULL; |
| 492 | } |
| 493 | |
[email protected] | 2261e7b7 | 2011-07-12 13:43:55 | [diff] [blame] | 494 | void TestingProfile::SetExtensionSpecialStoragePolicy( |
| 495 | ExtensionSpecialStoragePolicy* extension_special_storage_policy) { |
| 496 | extension_special_storage_policy_ = extension_special_storage_policy; |
| 497 | } |
| 498 | |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 499 | ExtensionSpecialStoragePolicy* |
| 500 | TestingProfile::GetExtensionSpecialStoragePolicy() { |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 501 | if (!extension_special_storage_policy_.get()) |
[email protected] | 7c5048c | 2011-08-19 17:07:05 | [diff] [blame] | 502 | extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 503 | return extension_special_storage_policy_.get(); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 504 | } |
| 505 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 506 | FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) { |
| 507 | return favicon_service_.get(); |
| 508 | } |
| 509 | |
| 510 | HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) { |
| 511 | return history_service_.get(); |
| 512 | } |
| 513 | |
| 514 | HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() { |
| 515 | return history_service_.get(); |
| 516 | } |
| 517 | |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 518 | net::CookieMonster* TestingProfile::GetCookieMonster() { |
| 519 | if (!GetRequestContext()) |
| 520 | return NULL; |
[email protected] | 277ec26 | 2011-03-30 21:09:40 | [diff] [blame] | 521 | return GetRequestContext()->GetURLRequestContext()->cookie_store()-> |
| 522 | GetCookieMonster(); |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 523 | } |
| 524 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 525 | AutocompleteClassifier* TestingProfile::GetAutocompleteClassifier() { |
| 526 | return autocomplete_classifier_.get(); |
| 527 | } |
| 528 | |
[email protected] | c620fd5 | 2011-07-22 18:33:29 | [diff] [blame] | 529 | history::ShortcutsBackend* TestingProfile::GetShortcutsBackend() { |
| 530 | return NULL; |
| 531 | } |
| 532 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 533 | WebDataService* TestingProfile::GetWebDataService(ServiceAccessType access) { |
| 534 | return web_data_service_.get(); |
| 535 | } |
| 536 | |
| 537 | WebDataService* TestingProfile::GetWebDataServiceWithoutCreating() { |
| 538 | return web_data_service_.get(); |
| 539 | } |
| 540 | |
| 541 | PasswordStore* TestingProfile::GetPasswordStore(ServiceAccessType access) { |
| 542 | return NULL; |
| 543 | } |
| 544 | |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 545 | void TestingProfile::SetPrefService(PrefService* prefs) { |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 546 | prefs_.reset(prefs); |
| 547 | } |
| 548 | |
| 549 | void TestingProfile::CreateTestingPrefService() { |
| 550 | DCHECK(!prefs_.get()); |
| 551 | testing_prefs_ = new TestingPrefService(); |
| 552 | prefs_.reset(testing_prefs_); |
| 553 | Profile::RegisterUserPrefs(prefs_.get()); |
[email protected] | 2f9d8132 | 2011-02-21 09:55:43 | [diff] [blame] | 554 | browser::RegisterUserPrefs(prefs_.get()); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 555 | } |
| 556 | |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 557 | PrefService* TestingProfile::GetPrefs() { |
| 558 | if (!prefs_.get()) { |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 559 | CreateTestingPrefService(); |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 560 | } |
| 561 | return prefs_.get(); |
| 562 | } |
| 563 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 564 | TemplateURLFetcher* TestingProfile::GetTemplateURLFetcher() { |
| 565 | return template_url_fetcher_.get(); |
| 566 | } |
| 567 | |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 568 | history::TopSites* TestingProfile::GetTopSites() { |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 569 | return top_sites_.get(); |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 570 | } |
| 571 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 572 | history::TopSites* TestingProfile::GetTopSitesWithoutCreating() { |
| 573 | return top_sites_.get(); |
| 574 | } |
| 575 | |
| 576 | DownloadManager* TestingProfile::GetDownloadManager() { |
| 577 | return NULL; |
| 578 | } |
| 579 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 580 | net::URLRequestContextGetter* TestingProfile::GetRequestContext() { |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 581 | return request_context_.get(); |
| 582 | } |
| 583 | |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 584 | net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess( |
| 585 | int renderer_child_id) { |
| 586 | if (extension_service_.get()) { |
| 587 | const Extension* installed_app = extension_service_-> |
| 588 | GetInstalledAppForRenderer(renderer_child_id); |
| 589 | if (installed_app != NULL && installed_app->is_storage_isolated()) |
| 590 | return GetRequestContextForIsolatedApp(installed_app->id()); |
| 591 | } |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 592 | |
| 593 | return GetRequestContext(); |
| 594 | } |
| 595 | |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 596 | void TestingProfile::CreateRequestContext() { |
| 597 | if (!request_context_) |
| 598 | request_context_ = new TestURLRequestContextGetter(); |
| 599 | } |
| 600 | |
[email protected] | 7c89320 | 2010-10-07 20:18:02 | [diff] [blame] | 601 | void TestingProfile::ResetRequestContext() { |
| 602 | request_context_ = NULL; |
| 603 | } |
| 604 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 605 | net::URLRequestContextGetter* TestingProfile::GetRequestContextForMedia() { |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 606 | return NULL; |
| 607 | } |
| 608 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 609 | net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() { |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 610 | if (!extensions_request_context_) |
| 611 | extensions_request_context_ = new TestExtensionURLRequestContextGetter(); |
| 612 | return extensions_request_context_.get(); |
| 613 | } |
| 614 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 615 | net::SSLConfigService* TestingProfile::GetSSLConfigService() { |
| 616 | return NULL; |
| 617 | } |
| 618 | |
| 619 | UserStyleSheetWatcher* TestingProfile::GetUserStyleSheetWatcher() { |
| 620 | return NULL; |
| 621 | } |
| 622 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 623 | net::URLRequestContextGetter* TestingProfile::GetRequestContextForIsolatedApp( |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 624 | const std::string& app_id) { |
| 625 | // We don't test isolated app storage here yet, so returning the same dummy |
| 626 | // context is sufficient for now. |
| 627 | return GetRequestContext(); |
| 628 | } |
| 629 | |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 630 | content::ResourceContext* TestingProfile::GetResourceContext() { |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame^] | 631 | if (!resource_context_.get()) |
| 632 | resource_context_.reset(new content::MockResourceContext()); |
| 633 | return resource_context_.get(); |
[email protected] | e89b77d | 2011-04-15 18:58:10 | [diff] [blame] | 634 | } |
| 635 | |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 636 | HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() { |
[email protected] | 35552dc5 | 2011-07-12 09:04:38 | [diff] [blame] | 637 | if (!host_content_settings_map_.get()) { |
| 638 | host_content_settings_map_ = new HostContentSettingsMap( |
| 639 | GetPrefs(), GetExtensionService(), false); |
| 640 | } |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 641 | return host_content_settings_map_.get(); |
| 642 | } |
| 643 | |
[email protected] | 810ddc5 | 2012-01-24 01:00:35 | [diff] [blame] | 644 | content::GeolocationPermissionContext* |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 645 | TestingProfile::GetGeolocationPermissionContext() { |
| 646 | if (!geolocation_permission_context_.get()) { |
| 647 | geolocation_permission_context_ = |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 648 | new ChromeGeolocationPermissionContext(this); |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 649 | } |
| 650 | return geolocation_permission_context_.get(); |
| 651 | } |
| 652 | |
[email protected] | 2ee0c3f | 2012-02-13 00:28:36 | [diff] [blame] | 653 | content::SpeechInputPreferences* TestingProfile::GetSpeechInputPreferences() { |
[email protected] | 8238dd6 | 2011-09-29 15:13:01 | [diff] [blame] | 654 | if (!speech_input_preferences_.get()) |
| 655 | speech_input_preferences_ = new ChromeSpeechInputPreferences(GetPrefs()); |
| 656 | return speech_input_preferences_.get(); |
| 657 | } |
| 658 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 659 | HostZoomMap* TestingProfile::GetHostZoomMap() { |
| 660 | return NULL; |
| 661 | } |
| 662 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 663 | std::wstring TestingProfile::GetName() { |
| 664 | return std::wstring(); |
| 665 | } |
| 666 | |
| 667 | std::wstring TestingProfile::GetID() { |
| 668 | return id_; |
| 669 | } |
| 670 | |
| 671 | void TestingProfile::SetID(const std::wstring& id) { |
| 672 | id_ = id; |
| 673 | } |
| 674 | |
| 675 | bool TestingProfile::DidLastSessionExitCleanly() { |
| 676 | return last_session_exited_cleanly_; |
| 677 | } |
| 678 | |
| 679 | BookmarkModel* TestingProfile::GetBookmarkModel() { |
| 680 | return bookmark_bar_model_.get(); |
| 681 | } |
| 682 | |
| 683 | bool TestingProfile::IsSameProfile(Profile *p) { |
| 684 | return this == p; |
| 685 | } |
| 686 | |
| 687 | base::Time TestingProfile::GetStartTime() const { |
| 688 | return start_time_; |
| 689 | } |
| 690 | |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 691 | ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() { |
| 692 | return protocol_handler_registry_.get(); |
| 693 | } |
| 694 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 695 | WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() { |
| 696 | return NULL; |
| 697 | } |
| 698 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 699 | FilePath TestingProfile::last_selected_directory() { |
| 700 | return last_selected_directory_; |
| 701 | } |
| 702 | |
| 703 | void TestingProfile::set_last_selected_directory(const FilePath& path) { |
| 704 | last_selected_directory_ = path; |
| 705 | } |
| 706 | |
[email protected] | cc5bfd4 | 2010-11-24 14:44:02 | [diff] [blame] | 707 | PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() { |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 708 | if (!pref_proxy_config_tracker_.get()) { |
| 709 | pref_proxy_config_tracker_.reset( |
| 710 | ProxyServiceFactory::CreatePrefProxyConfigTracker(GetPrefs())); |
| 711 | } |
| 712 | return pref_proxy_config_tracker_.get(); |
[email protected] | cc5bfd4 | 2010-11-24 14:44:02 | [diff] [blame] | 713 | } |
| 714 | |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 715 | void TestingProfile::BlockUntilHistoryProcessesPendingRequests() { |
| 716 | DCHECK(history_service_.get()); |
| 717 | DCHECK(MessageLoop::current()); |
| 718 | |
| 719 | CancelableRequestConsumer consumer; |
| 720 | history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer); |
| 721 | MessageLoop::current()->Run(); |
| 722 | } |
[email protected] | 345a8b7 | 2009-09-29 09:11:44 | [diff] [blame] | 723 | |
[email protected] | 8e4c2961 | 2010-07-14 01:24:45 | [diff] [blame] | 724 | TokenService* TestingProfile::GetTokenService() { |
| 725 | if (!token_service_.get()) { |
| 726 | token_service_.reset(new TokenService()); |
| 727 | } |
| 728 | return token_service_.get(); |
| 729 | } |
| 730 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 731 | ExtensionInfoMap* TestingProfile::GetExtensionInfoMap() { |
| 732 | return NULL; |
| 733 | } |
| 734 | |
| 735 | PromoCounter* TestingProfile::GetInstantPromoCounter() { |
| 736 | return NULL; |
| 737 | } |
| 738 | |
[email protected] | 248ce19 | 2011-02-10 15:26:34 | [diff] [blame] | 739 | ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() { |
| 740 | if (!chrome_url_data_manager_.get()) |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 741 | chrome_url_data_manager_.reset( |
| 742 | new ChromeURLDataManager( |
| 743 | base::Callback<ChromeURLDataManagerBackend*(void)>())); |
[email protected] | 248ce19 | 2011-02-10 15:26:34 | [diff] [blame] | 744 | return chrome_url_data_manager_.get(); |
| 745 | } |
| 746 | |
[email protected] | 8382d8c | 2011-09-15 03:43:17 | [diff] [blame] | 747 | chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() { |
| 748 | return NULL; |
| 749 | } |
| 750 | |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 751 | void TestingProfile::ClearNetworkingHistorySince(base::Time time) { |
[email protected] | 02896a8 | 2011-09-21 18:54:32 | [diff] [blame] | 752 | NOTIMPLEMENTED(); |
| 753 | } |
| 754 | |
[email protected] | 671f9c6 | 2011-10-28 19:22:07 | [diff] [blame] | 755 | GURL TestingProfile::GetHomePage() { |
| 756 | return GURL(chrome::kChromeUINewTabURL); |
| 757 | } |
| 758 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 759 | PrefService* TestingProfile::GetOffTheRecordPrefs() { |
| 760 | return NULL; |
| 761 | } |
| 762 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 763 | quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { |
| 764 | return GetExtensionSpecialStoragePolicy(); |
| 765 | } |
| 766 | |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 767 | void TestingProfile::DestroyWebDataService() { |
| 768 | if (!web_data_service_.get()) |
| 769 | return; |
| 770 | |
| 771 | web_data_service_->Shutdown(); |
| 772 | } |