[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] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 14 | #include "base/run_loop.h" |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 15 | #include "base/string_number_conversions.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 16 | #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 17 | #include "chrome/browser/bookmarks/bookmark_model.h" |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 18 | #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
[email protected] | 1459fb6 | 2011-05-25 19:03:27 | [diff] [blame] | 19 | #include "chrome/browser/browser_process.h" |
[email protected] | 9d01a6a | 2010-11-30 12:03:33 | [diff] [blame] | 20 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 9b4d241c9 | 2012-06-29 19:48:31 | [diff] [blame] | 21 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
[email protected] | 2f69b38 | 2011-02-19 00:34:25 | [diff] [blame] | 22 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 23 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 24 | #include "chrome/browser/extensions/extension_system.h" |
| 25 | #include "chrome/browser/extensions/extension_system_factory.h" |
| 26 | #include "chrome/browser/extensions/test_extension_system.h" |
[email protected] | ee2ed42c | 2011-04-28 22:19:14 | [diff] [blame] | 27 | #include "chrome/browser/favicon/favicon_service.h" |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 28 | #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 29 | #include "chrome/browser/history/history.h" |
[email protected] | 075ae73 | 2009-02-11 23:58:31 | [diff] [blame] | 30 | #include "chrome/browser/history/history_backend.h" |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 31 | #include "chrome/browser/history/history_service_factory.h" |
[email protected] | 572f40c9b | 2012-07-06 20:35:33 | [diff] [blame] | 32 | #include "chrome/browser/history/shortcuts_backend.h" |
| 33 | #include "chrome/browser/history/shortcuts_backend_factory.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 34 | #include "chrome/browser/history/top_sites.h" |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 35 | #include "chrome/browser/net/proxy_service_factory.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 36 | #include "chrome/browser/notifications/desktop_notification_service.h" |
[email protected] | dcb72d5 | 2011-04-13 12:36:53 | [diff] [blame] | 37 | #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 38 | #include "chrome/browser/prefs/browser_prefs.h" |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 39 | #include "chrome/browser/prefs/testing_pref_store.h" |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 40 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 5cdcd15 | 2011-03-31 22:48:52 | [diff] [blame] | 41 | #include "chrome/browser/profiles/profile_dependency_manager.h" |
[email protected] | ee78d8a | 2012-03-15 16:53:48 | [diff] [blame] | 42 | #include "chrome/browser/protector/protector_service_factory.h" |
[email protected] | 16bd088b | 2012-04-03 08:12:12 | [diff] [blame] | 43 | #include "chrome/browser/search_engines/template_url_fetcher_factory.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 44 | #include "chrome/browser/speech/chrome_speech_recognition_preferences.h" |
[email protected] | 810ffba | 2012-06-12 01:07:48 | [diff] [blame] | 45 | #include "chrome/browser/webdata/web_data_service.h" |
[email protected] | d07edd4 | 2012-05-14 23:49:46 | [diff] [blame] | 46 | #include "chrome/browser/webdata/web_data_service_factory.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 47 | #include "chrome/common/chrome_constants.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 48 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 9e33d7e | 2011-09-30 16:43:54 | [diff] [blame] | 49 | #include "chrome/common/chrome_switches.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 50 | #include "chrome/common/url_constants.h" |
[email protected] | 7bc6068 | 2011-07-29 20:55:59 | [diff] [blame] | 51 | #include "chrome/test/base/bookmark_load_observer.h" |
[email protected] | 8ad3636e | 2011-08-01 22:31:40 | [diff] [blame] | 52 | #include "chrome/test/base/testing_pref_service.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 53 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 54 | #include "content/public/browser/browser_thread.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 55 | #include "content/public/browser/notification_service.h" |
[email protected] | 08a932d5 | 2012-06-03 21:42:12 | [diff] [blame] | 56 | #include "content/public/test/mock_resource_context.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 57 | #include "net/cookies/cookie_monster.h" |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 58 | #include "net/url_request/url_request_context.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 59 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | d2db029 | 2011-01-26 20:23:44 | [diff] [blame] | 60 | #include "net/url_request/url_request_test_util.h" |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 61 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | 248ce19 | 2011-02-10 15:26:34 | [diff] [blame] | 62 | |
[email protected] | 21d3a88 | 2012-05-31 14:41:55 | [diff] [blame] | 63 | #if defined(ENABLE_CONFIGURATION_POLICY) |
| 64 | #include "chrome/browser/policy/policy_service_impl.h" |
| 65 | #else |
| 66 | #include "chrome/browser/policy/policy_service_stub.h" |
| 67 | #endif // defined(ENABLE_CONFIGURATION_POLICY) |
| 68 | |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 69 | #if defined(OS_CHROMEOS) |
| 70 | #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 71 | #endif // defined(OS_CHROMEOS) |
| 72 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 73 | using base::Time; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 74 | using content::BrowserThread; |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 75 | using content::DownloadManagerDelegate; |
[email protected] | 3c88741 | 2010-04-19 20:30:23 | [diff] [blame] | 76 | using testing::NiceMock; |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 77 | using testing::Return; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 78 | |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 79 | namespace { |
| 80 | |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 81 | // Task used to make sure history has finished processing a request. Intended |
| 82 | // for use with BlockUntilHistoryProcessesPendingRequests. |
| 83 | |
| 84 | class QuittingHistoryDBTask : public HistoryDBTask { |
| 85 | public: |
| 86 | QuittingHistoryDBTask() {} |
| 87 | |
| 88 | virtual bool RunOnDBThread(history::HistoryBackend* backend, |
| 89 | history::HistoryDatabase* db) { |
| 90 | return true; |
| 91 | } |
| 92 | |
| 93 | virtual void DoneRunOnMainThread() { |
| 94 | MessageLoop::current()->Quit(); |
| 95 | } |
| 96 | |
| 97 | private: |
[email protected] | 7991a23 | 2009-11-06 01:55:48 | [diff] [blame] | 98 | ~QuittingHistoryDBTask() {} |
| 99 | |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 100 | DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask); |
| 101 | }; |
| 102 | |
[email protected] | aeb53f0 | 2011-01-15 00:21:34 | [diff] [blame] | 103 | class TestExtensionURLRequestContext : public net::URLRequestContext { |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 104 | public: |
| 105 | TestExtensionURLRequestContext() { |
| 106 | net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); |
| 107 | const char* schemes[] = {chrome::kExtensionScheme}; |
| 108 | cookie_monster->SetCookieableSchemes(schemes, 1); |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 109 | set_cookie_store(cookie_monster); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 110 | } |
[email protected] | 7b2720b | 2012-04-25 16:59:11 | [diff] [blame] | 111 | |
[email protected] | 7b2720b | 2012-04-25 16:59:11 | [diff] [blame] | 112 | virtual ~TestExtensionURLRequestContext() {} |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 113 | }; |
| 114 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 115 | class TestExtensionURLRequestContextGetter |
| 116 | : public net::URLRequestContextGetter { |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 117 | public: |
[email protected] | aeb53f0 | 2011-01-15 00:21:34 | [diff] [blame] | 118 | virtual net::URLRequestContext* GetURLRequestContext() { |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 119 | if (!context_.get()) |
| 120 | context_.reset(new TestExtensionURLRequestContext()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 121 | return context_.get(); |
| 122 | } |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 123 | virtual scoped_refptr<base::SingleThreadTaskRunner> |
| 124 | GetNetworkTaskRunner() const OVERRIDE { |
[email protected] | 0c7d74f | 2010-10-11 11:55:26 | [diff] [blame] | 125 | return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
[email protected] | 83a7d2eb | 2010-05-03 21:46:19 | [diff] [blame] | 126 | } |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 127 | |
[email protected] | 13ed17f8 | 2012-04-06 02:27:18 | [diff] [blame] | 128 | protected: |
| 129 | virtual ~TestExtensionURLRequestContextGetter() {} |
| 130 | |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 131 | private: |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 132 | scoped_ptr<net::URLRequestContext> context_; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 133 | }; |
| 134 | |
[email protected] | abc7724 | 2012-03-16 04:32:31 | [diff] [blame] | 135 | ProfileKeyedService* CreateTestDesktopNotificationService(Profile* profile) { |
[email protected] | 29cebbd | 2012-06-06 21:43:42 | [diff] [blame] | 136 | #if defined(ENABLE_NOTIFICATIONS) |
[email protected] | dcb72d5 | 2011-04-13 12:36:53 | [diff] [blame] | 137 | return new DesktopNotificationService(profile, NULL); |
[email protected] | 29cebbd | 2012-06-06 21:43:42 | [diff] [blame] | 138 | #else |
| 139 | return NULL; |
| 140 | #endif |
[email protected] | dcb72d5 | 2011-04-13 12:36:53 | [diff] [blame] | 141 | } |
| 142 | |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 143 | } // namespace |
| 144 | |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 145 | TestingProfile::TestingProfile() |
[email protected] | ea6f7657 | 2008-12-18 00:09:55 | [diff] [blame] | 146 | : start_time_(Time::Now()), |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 147 | testing_prefs_(NULL), |
[email protected] | 5bb2f52 | 2011-03-25 19:04:44 | [diff] [blame] | 148 | incognito_(false), |
[email protected] | 5cdcd15 | 2011-03-31 22:48:52 | [diff] [blame] | 149 | last_session_exited_cleanly_(true), |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 150 | profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
| 151 | delegate_(NULL) { |
[email protected] | f9dec948 | 2010-08-20 20:42:19 | [diff] [blame] | 152 | if (!temp_dir_.CreateUniqueTempDir()) { |
| 153 | LOG(ERROR) << "Failed to create unique temporary directory."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 154 | |
[email protected] | f9dec948 | 2010-08-20 20:42:19 | [diff] [blame] | 155 | // Fallback logic in case we fail to create unique temporary directory. |
| 156 | FilePath system_tmp_dir; |
| 157 | bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); |
[email protected] | 848cd05e | 2008-09-19 18:33:48 | [diff] [blame] | 158 | |
[email protected] | f9dec948 | 2010-08-20 20:42:19 | [diff] [blame] | 159 | // We're severly screwed if we can't get the system temporary |
| 160 | // directory. Die now to avoid writing to the filesystem root |
| 161 | // or other bad places. |
| 162 | CHECK(success); |
| 163 | |
| 164 | FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath")); |
| 165 | file_util::Delete(fallback_dir, true); |
| 166 | file_util::CreateDirectory(fallback_dir); |
| 167 | if (!temp_dir_.Set(fallback_dir)) { |
| 168 | // That shouldn't happen, but if it does, try to recover. |
| 169 | LOG(ERROR) << "Failed to use a fallback temporary directory."; |
| 170 | |
| 171 | // We're screwed if this fails, see CHECK above. |
| 172 | CHECK(temp_dir_.Set(system_tmp_dir)); |
| 173 | } |
| 174 | } |
[email protected] | dcb72d5 | 2011-04-13 12:36:53 | [diff] [blame] | 175 | |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 176 | profile_path_ = temp_dir_.path(); |
| 177 | |
| 178 | Init(); |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 179 | FinishInit(); |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | TestingProfile::TestingProfile(const FilePath& path) |
| 183 | : start_time_(Time::Now()), |
| 184 | testing_prefs_(NULL), |
| 185 | incognito_(false), |
| 186 | last_session_exited_cleanly_(true), |
| 187 | profile_path_(path), |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 188 | profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
| 189 | delegate_(NULL) { |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 190 | Init(); |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 191 | FinishInit(); |
| 192 | } |
| 193 | |
| 194 | TestingProfile::TestingProfile(const FilePath& path, |
| 195 | Delegate* delegate) |
| 196 | : start_time_(Time::Now()), |
| 197 | testing_prefs_(NULL), |
| 198 | incognito_(false), |
| 199 | last_session_exited_cleanly_(true), |
| 200 | profile_path_(path), |
| 201 | profile_dependency_manager_(ProfileDependencyManager::GetInstance()), |
| 202 | delegate_(delegate) { |
| 203 | Init(); |
| 204 | if (delegate_) { |
| 205 | MessageLoop::current()->PostTask(FROM_HERE, |
| 206 | base::Bind(&TestingProfile::FinishInit, |
| 207 | base::Unretained(this))); |
| 208 | } else { |
| 209 | FinishInit(); |
| 210 | } |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | void TestingProfile::Init() { |
[email protected] | d41e657 | 2012-05-04 20:49:42 | [diff] [blame] | 214 | if (!file_util::PathExists(profile_path_)) |
| 215 | file_util::CreateDirectory(profile_path_); |
| 216 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame^] | 217 | extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory( |
| 218 | this, extensions::TestExtensionSystem::Build); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 219 | |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 220 | profile_dependency_manager_->CreateProfileServices(this, true); |
| 221 | |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 222 | #if defined(ENABLE_NOTIFICATIONS) |
[email protected] | dcb72d5 | 2011-04-13 12:36:53 | [diff] [blame] | 223 | // Install profile keyed service factory hooks for dummy/test services |
[email protected] | 7722653b | 2011-06-03 17:28:22 | [diff] [blame] | 224 | DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( |
| 225 | this, CreateTestDesktopNotificationService); |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 226 | #endif |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 227 | } |
[email protected] | 12463cd | 2011-07-19 09:40:20 | [diff] [blame] | 228 | |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 229 | void TestingProfile::FinishInit() { |
[email protected] | 080adba9 | 2011-12-07 19:00:40 | [diff] [blame] | 230 | DCHECK(content::NotificationService::current()); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 231 | content::NotificationService::current()->Notify( |
[email protected] | 12463cd | 2011-07-19 09:40:20 | [diff] [blame] | 232 | chrome::NOTIFICATION_PROFILE_CREATED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 233 | content::Source<Profile>(static_cast<Profile*>(this)), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 234 | content::NotificationService::NoDetails()); |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 235 | |
| 236 | if (delegate_) |
[email protected] | 00b33f80 | 2012-03-13 07:46:03 | [diff] [blame] | 237 | delegate_->OnProfileCreated(this, true, false); |
[email protected] | ab23dbe | 2010-08-12 02:10:46 | [diff] [blame] | 238 | } |
| 239 | |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 240 | TestingProfile::~TestingProfile() { |
[email protected] | 080adba9 | 2011-12-07 19:00:40 | [diff] [blame] | 241 | DCHECK(content::NotificationService::current()); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 242 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 243 | chrome::NOTIFICATION_PROFILE_DESTROYED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 244 | content::Source<Profile>(static_cast<Profile*>(this)), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 245 | content::NotificationService::NoDetails()); |
[email protected] | 5cdcd15 | 2011-03-31 22:48:52 | [diff] [blame] | 246 | |
| 247 | profile_dependency_manager_->DestroyProfileServices(this); |
| 248 | |
[email protected] | 35552dc5 | 2011-07-12 09:04:38 | [diff] [blame] | 249 | if (host_content_settings_map_) |
| 250 | host_content_settings_map_->ShutdownOnUIThread(); |
| 251 | |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 252 | DestroyTopSites(); |
[email protected] | d2879af | 2010-02-08 16:02:56 | [diff] [blame] | 253 | DestroyFaviconService(); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 254 | |
[email protected] | cc5bfd4 | 2010-11-24 14:44:02 | [diff] [blame] | 255 | if (pref_proxy_config_tracker_.get()) |
| 256 | pref_proxy_config_tracker_->DetachFromPrefService(); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 257 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 258 | |
[email protected] | d2879af | 2010-02-08 16:02:56 | [diff] [blame] | 259 | void TestingProfile::CreateFaviconService() { |
[email protected] | 04732c0e | 2011-09-16 13:21:53 | [diff] [blame] | 260 | favicon_service_.reset(new FaviconService(this)); |
[email protected] | d2879af | 2010-02-08 16:02:56 | [diff] [blame] | 261 | } |
| 262 | |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 263 | static scoped_refptr<RefcountedProfileKeyedService> BuildHistoryService( |
| 264 | Profile* profile) { |
| 265 | return new HistoryService(profile); |
| 266 | } |
| 267 | |
[email protected] | d486a085 | 2009-11-02 21:40:00 | [diff] [blame] | 268 | void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 269 | DestroyHistoryService(); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 270 | if (delete_file) { |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 271 | FilePath path = GetPath(); |
| 272 | path = path.Append(chrome::kHistoryFilename); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 273 | file_util::Delete(path, false); |
| 274 | } |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 275 | // This will create and init the history service. |
| 276 | HistoryService* history_service = static_cast<HistoryService*>( |
| 277 | HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 278 | this, BuildHistoryService).get()); |
| 279 | if (!history_service->Init(this->GetPath(), |
[email protected] | 34f2149b | 2012-06-13 08:23:23 | [diff] [blame] | 280 | BookmarkModelFactory::GetForProfile(this), |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 281 | no_db)) { |
| 282 | HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL); |
| 283 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | void TestingProfile::DestroyHistoryService() { |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 287 | scoped_refptr<HistoryService> history_service = |
[email protected] | 92a0fb77 | 2012-06-25 20:56:46 | [diff] [blame] | 288 | HistoryServiceFactory::GetForProfileIfExists(this); |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 289 | if (!history_service.get()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 290 | return; |
| 291 | |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 292 | history_service->NotifyRenderProcessHostDestruction(0); |
| 293 | history_service->SetOnBackendDestroyTask(MessageLoop::QuitClosure()); |
| 294 | history_service->Cleanup(); |
| 295 | HistoryServiceFactory::ShutdownForProfile(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 296 | |
| 297 | // Wait for the backend class to terminate before deleting the files and |
| 298 | // moving to the next test. Note: if this never terminates, somebody is |
| 299 | // probably leaking a reference to the history backend, so it never calls |
| 300 | // our destroy task. |
| 301 | MessageLoop::current()->Run(); |
| 302 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 303 | // Make sure we don't have any event pending that could disrupt the next |
| 304 | // test. |
[email protected] | 1cb1a24 | 2011-12-10 18:36:51 | [diff] [blame] | 305 | MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 306 | MessageLoop::current()->Run(); |
| 307 | } |
[email protected] | 4d0cd7ce | 2008-08-11 16:40:57 | [diff] [blame] | 308 | |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 309 | void TestingProfile::CreateTopSites() { |
| 310 | DestroyTopSites(); |
| 311 | top_sites_ = new history::TopSites(this); |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 312 | FilePath file_name = GetPath().Append(chrome::kTopSitesFilename); |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 313 | top_sites_->Init(file_name); |
| 314 | } |
| 315 | |
| 316 | void TestingProfile::DestroyTopSites() { |
| 317 | if (top_sites_.get()) { |
| 318 | top_sites_->Shutdown(); |
| 319 | top_sites_ = NULL; |
| 320 | // TopSites::Shutdown schedules some tasks (from TopSitesBackend) that need |
| 321 | // to be run to properly shutdown. Run all pending tasks now. This is |
| 322 | // normally handled by browser_process shutdown. |
| 323 | if (MessageLoop::current()) |
| 324 | MessageLoop::current()->RunAllPending(); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | void TestingProfile::DestroyFaviconService() { |
[email protected] | 04732c0e | 2011-09-16 13:21:53 | [diff] [blame] | 329 | favicon_service_.reset(); |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 330 | } |
| 331 | |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 332 | static ProfileKeyedService* BuildBookmarkModel(Profile* profile) { |
| 333 | BookmarkModel* bookmark_model = new BookmarkModel(profile); |
| 334 | bookmark_model->Load(); |
| 335 | return bookmark_model; |
| 336 | } |
| 337 | |
| 338 | |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 339 | void TestingProfile::CreateBookmarkModel(bool delete_file) { |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 340 | |
| 341 | if (delete_file) { |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 342 | FilePath path = GetPath(); |
| 343 | path = path.Append(chrome::kBookmarksFileName); |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 344 | file_util::Delete(path, false); |
| 345 | } |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 346 | // This will create a bookmark model. |
| 347 | BookmarkModel* bookmark_service = |
| 348 | static_cast<BookmarkModel*>( |
| 349 | BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse( |
| 350 | this, BuildBookmarkModel)); |
| 351 | |
| 352 | HistoryService* history_service = |
[email protected] | 92a0fb77 | 2012-06-25 20:56:46 | [diff] [blame] | 353 | HistoryServiceFactory::GetForProfileIfExists(this).get(); |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 354 | if (history_service) { |
| 355 | history_service->history_backend_->bookmark_service_ = |
| 356 | bookmark_service; |
| 357 | history_service->history_backend_->expirer_.bookmark_service_ = |
| 358 | bookmark_service; |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 359 | } |
[email protected] | 4d0cd7ce | 2008-08-11 16:40:57 | [diff] [blame] | 360 | } |
[email protected] | d2c017a | 2008-08-13 21:51:45 | [diff] [blame] | 361 | |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 362 | void TestingProfile::CreateProtocolHandlerRegistry() { |
[email protected] | 9b4d241c9 | 2012-06-29 19:48:31 | [diff] [blame] | 363 | protocol_handler_registry_ = new ProtocolHandlerRegistry(this, |
[email protected] | fd8ca52 | 2011-05-02 18:54:49 | [diff] [blame] | 364 | new ProtocolHandlerRegistry::Delegate()); |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 365 | } |
| 366 | |
[email protected] | d07edd4 | 2012-05-14 23:49:46 | [diff] [blame] | 367 | static scoped_refptr<RefcountedProfileKeyedService> BuildWebDataService( |
| 368 | Profile* profile) { |
| 369 | WebDataService* web_data_service = new WebDataService(); |
| 370 | if (web_data_service) |
| 371 | web_data_service->Init(profile->GetPath()); |
[email protected] | a5c6529 | 2012-05-25 00:50:01 | [diff] [blame] | 372 | return web_data_service; |
[email protected] | d07edd4 | 2012-05-14 23:49:46 | [diff] [blame] | 373 | } |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 374 | |
[email protected] | d07edd4 | 2012-05-14 23:49:46 | [diff] [blame] | 375 | void TestingProfile::CreateWebDataService() { |
[email protected] | a5c6529 | 2012-05-25 00:50:01 | [diff] [blame] | 376 | WebDataServiceFactory::GetInstance()->SetTestingFactory( |
[email protected] | d07edd4 | 2012-05-14 23:49:46 | [diff] [blame] | 377 | this, BuildWebDataService); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 378 | } |
| 379 | |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 380 | void TestingProfile::BlockUntilBookmarkModelLoaded() { |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 381 | DCHECK(GetBookmarkModel()); |
| 382 | if (GetBookmarkModel()->IsLoaded()) |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 383 | return; |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 384 | base::RunLoop run_loop; |
| 385 | BookmarkLoadObserver observer( |
| 386 | ui_test_utils::GetQuitTaskForRunLoop(&run_loop)); |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 387 | GetBookmarkModel()->AddObserver(&observer); |
[email protected] | 8e937c1e | 2012-06-28 22:57:30 | [diff] [blame] | 388 | run_loop.Run(); |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 389 | GetBookmarkModel()->RemoveObserver(&observer); |
| 390 | DCHECK(GetBookmarkModel()->IsLoaded()); |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 391 | } |
| 392 | |
[email protected] | 120abf13 | 2011-09-27 21:38:06 | [diff] [blame] | 393 | // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 394 | void TestingProfile::BlockUntilTopSitesLoaded() { |
[email protected] | 120abf13 | 2011-09-27 21:38:06 | [diff] [blame] | 395 | ui_test_utils::WindowedNotificationObserver top_sites_loaded_observer( |
| 396 | chrome::NOTIFICATION_TOP_SITES_LOADED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 397 | content::NotificationService::AllSources()); |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 398 | if (!GetHistoryService(Profile::EXPLICIT_ACCESS)) |
| 399 | GetTopSites()->HistoryLoaded(); |
[email protected] | 120abf13 | 2011-09-27 21:38:06 | [diff] [blame] | 400 | top_sites_loaded_observer.Wait(); |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 401 | } |
| 402 | |
[email protected] | f9dec948 | 2010-08-20 20:42:19 | [diff] [blame] | 403 | FilePath TestingProfile::GetPath() { |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 404 | return profile_path_; |
[email protected] | f9dec948 | 2010-08-20 20:42:19 | [diff] [blame] | 405 | } |
| 406 | |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 407 | TestingPrefService* TestingProfile::GetTestingPrefService() { |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 408 | if (!prefs_.get()) |
| 409 | CreateTestingPrefService(); |
| 410 | DCHECK(testing_prefs_); |
| 411 | return testing_prefs_; |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 412 | } |
| 413 | |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 414 | TestingProfile* TestingProfile::AsTestingProfile() { |
| 415 | return this; |
| 416 | } |
| 417 | |
[email protected] | 29d7025 | 2011-04-28 02:16:58 | [diff] [blame] | 418 | std::string TestingProfile::GetProfileName() { |
| 419 | return std::string("testing_profile"); |
| 420 | } |
| 421 | |
[email protected] | 27d6e85 | 2012-03-02 21:31:32 | [diff] [blame] | 422 | bool TestingProfile::IsOffTheRecord() const { |
[email protected] | 5bb2f52 | 2011-03-25 19:04:44 | [diff] [blame] | 423 | return incognito_; |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 424 | } |
| 425 | |
[email protected] | 93dba94 | 2011-02-23 22:45:01 | [diff] [blame] | 426 | void TestingProfile::SetOffTheRecordProfile(Profile* profile) { |
[email protected] | 5bb2f52 | 2011-03-25 19:04:44 | [diff] [blame] | 427 | incognito_profile_.reset(profile); |
[email protected] | 93dba94 | 2011-02-23 22:45:01 | [diff] [blame] | 428 | } |
| 429 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 430 | Profile* TestingProfile::GetOffTheRecordProfile() { |
[email protected] | 5bb2f52 | 2011-03-25 19:04:44 | [diff] [blame] | 431 | return incognito_profile_.get(); |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 432 | } |
| 433 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 434 | GAIAInfoUpdateService* TestingProfile::GetGAIAInfoUpdateService() { |
| 435 | return NULL; |
| 436 | } |
| 437 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 438 | bool TestingProfile::HasOffTheRecordProfile() { |
[email protected] | 5bb2f52 | 2011-03-25 19:04:44 | [diff] [blame] | 439 | return incognito_profile_.get() != NULL; |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | Profile* TestingProfile::GetOriginalProfile() { |
| 443 | return this; |
| 444 | } |
| 445 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 446 | VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() { |
| 447 | return NULL; |
| 448 | } |
| 449 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 450 | ExtensionService* TestingProfile::GetExtensionService() { |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame^] | 451 | return extensions::ExtensionSystem::Get(this)->extension_service(); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 452 | } |
| 453 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 454 | UserScriptMaster* TestingProfile::GetUserScriptMaster() { |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame^] | 455 | return extensions::ExtensionSystem::Get(this)->user_script_master(); |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() { |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame^] | 459 | return extensions::ExtensionSystem::Get(this)->process_manager(); |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() { |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame^] | 463 | return extensions::ExtensionSystem::Get(this)->event_router(); |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 464 | } |
| 465 | |
[email protected] | 2261e7b7 | 2011-07-12 13:43:55 | [diff] [blame] | 466 | void TestingProfile::SetExtensionSpecialStoragePolicy( |
| 467 | ExtensionSpecialStoragePolicy* extension_special_storage_policy) { |
| 468 | extension_special_storage_policy_ = extension_special_storage_policy; |
| 469 | } |
| 470 | |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 471 | ExtensionSpecialStoragePolicy* |
| 472 | TestingProfile::GetExtensionSpecialStoragePolicy() { |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 473 | if (!extension_special_storage_policy_.get()) |
[email protected] | 7c5048c | 2011-08-19 17:07:05 | [diff] [blame] | 474 | extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 475 | return extension_special_storage_policy_.get(); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 476 | } |
| 477 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 478 | FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) { |
| 479 | return favicon_service_.get(); |
| 480 | } |
| 481 | |
| 482 | HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) { |
[email protected] | 92a0fb77 | 2012-06-25 20:56:46 | [diff] [blame] | 483 | return HistoryServiceFactory::GetForProfileIfExists(this); |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() { |
[email protected] | 92a0fb77 | 2012-06-25 20:56:46 | [diff] [blame] | 487 | return HistoryServiceFactory::GetForProfileIfExists(this); |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 488 | } |
| 489 | |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 490 | net::CookieMonster* TestingProfile::GetCookieMonster() { |
| 491 | if (!GetRequestContext()) |
| 492 | return NULL; |
[email protected] | 277ec26 | 2011-03-30 21:09:40 | [diff] [blame] | 493 | return GetRequestContext()->GetURLRequestContext()->cookie_store()-> |
| 494 | GetCookieMonster(); |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 495 | } |
| 496 | |
[email protected] | 21d3a88 | 2012-05-31 14:41:55 | [diff] [blame] | 497 | policy::PolicyService* TestingProfile::GetPolicyService() { |
| 498 | if (!policy_service_.get()) { |
| 499 | #if defined(ENABLE_CONFIGURATION_POLICY) |
| 500 | policy::PolicyServiceImpl::Providers providers; |
| 501 | policy_service_.reset(new policy::PolicyServiceImpl(providers)); |
| 502 | #else |
| 503 | policy_service_.reset(new policy::PolicyServiceStub()); |
| 504 | #endif |
| 505 | } |
| 506 | return policy_service_.get(); |
| 507 | } |
| 508 | |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 509 | void TestingProfile::SetPrefService(PrefService* prefs) { |
[email protected] | ddcaa41 | 2012-03-30 19:57:29 | [diff] [blame] | 510 | #if defined(ENABLE_PROTECTOR_SERVICE) |
[email protected] | ee78d8a | 2012-03-15 16:53:48 | [diff] [blame] | 511 | // ProtectorService binds itself very closely to the PrefService at the moment |
| 512 | // of Profile creation and watches pref changes to update their backup. |
| 513 | // For tests that replace the PrefService after TestingProfile creation, |
| 514 | // ProtectorService is disabled to prevent further invalid memory accesses. |
| 515 | protector::ProtectorServiceFactory::GetInstance()-> |
| 516 | SetTestingFactory(this, NULL); |
[email protected] | ddcaa41 | 2012-03-30 19:57:29 | [diff] [blame] | 517 | #endif |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 518 | prefs_.reset(prefs); |
| 519 | } |
| 520 | |
| 521 | void TestingProfile::CreateTestingPrefService() { |
| 522 | DCHECK(!prefs_.get()); |
| 523 | testing_prefs_ = new TestingPrefService(); |
| 524 | prefs_.reset(testing_prefs_); |
| 525 | Profile::RegisterUserPrefs(prefs_.get()); |
[email protected] | 572f40c9b | 2012-07-06 20:35:33 | [diff] [blame] | 526 | chrome::RegisterUserPrefs(prefs_.get()); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 527 | } |
| 528 | |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 529 | PrefService* TestingProfile::GetPrefs() { |
| 530 | if (!prefs_.get()) { |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 531 | CreateTestingPrefService(); |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 532 | } |
| 533 | return prefs_.get(); |
| 534 | } |
| 535 | |
| 536 | history::TopSites* TestingProfile::GetTopSites() { |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 537 | return top_sites_.get(); |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 538 | } |
| 539 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 540 | history::TopSites* TestingProfile::GetTopSitesWithoutCreating() { |
| 541 | return top_sites_.get(); |
| 542 | } |
| 543 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 544 | DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() { |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 545 | return NULL; |
| 546 | } |
| 547 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 548 | net::URLRequestContextGetter* TestingProfile::GetRequestContext() { |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 549 | return request_context_.get(); |
| 550 | } |
| 551 | |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 552 | net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess( |
| 553 | int renderer_child_id) { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 554 | ExtensionService* extension_service = |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame^] | 555 | extensions::ExtensionSystem::Get(this)->extension_service(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 556 | if (extension_service) { |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 557 | const extensions::Extension* installed_app = extension_service-> |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 558 | GetInstalledAppForRenderer(renderer_child_id); |
| 559 | if (installed_app != NULL && installed_app->is_storage_isolated()) |
| 560 | return GetRequestContextForIsolatedApp(installed_app->id()); |
| 561 | } |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 562 | |
| 563 | return GetRequestContext(); |
| 564 | } |
| 565 | |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 566 | void TestingProfile::CreateRequestContext() { |
| 567 | if (!request_context_) |
[email protected] | 4473860 | 2012-03-02 22:56:01 | [diff] [blame] | 568 | request_context_ = |
| 569 | new TestURLRequestContextGetter( |
| 570 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 571 | } |
| 572 | |
[email protected] | 7c89320 | 2010-10-07 20:18:02 | [diff] [blame] | 573 | void TestingProfile::ResetRequestContext() { |
[email protected] | 3931fd8 | 2012-03-12 21:18:48 | [diff] [blame] | 574 | // Any objects holding live URLFetchers should be deleted before the request |
| 575 | // context is shut down. |
[email protected] | 16bd088b | 2012-04-03 08:12:12 | [diff] [blame] | 576 | TemplateURLFetcherFactory::ShutdownForProfile(this); |
[email protected] | 3931fd8 | 2012-03-12 21:18:48 | [diff] [blame] | 577 | |
[email protected] | 7c89320 | 2010-10-07 20:18:02 | [diff] [blame] | 578 | request_context_ = NULL; |
| 579 | } |
| 580 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 581 | net::URLRequestContextGetter* TestingProfile::GetRequestContextForMedia() { |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 582 | return NULL; |
| 583 | } |
| 584 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 585 | net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() { |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 586 | if (!extensions_request_context_) |
[email protected] | 00dea958 | 2012-05-09 15:20:05 | [diff] [blame] | 587 | extensions_request_context_ = new TestExtensionURLRequestContextGetter(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 588 | return extensions_request_context_.get(); |
| 589 | } |
| 590 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 591 | net::SSLConfigService* TestingProfile::GetSSLConfigService() { |
| 592 | return NULL; |
| 593 | } |
| 594 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 595 | net::URLRequestContextGetter* TestingProfile::GetRequestContextForIsolatedApp( |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 596 | const std::string& app_id) { |
| 597 | // We don't test isolated app storage here yet, so returning the same dummy |
| 598 | // context is sufficient for now. |
| 599 | return GetRequestContext(); |
| 600 | } |
| 601 | |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 602 | content::ResourceContext* TestingProfile::GetResourceContext() { |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 603 | if (!resource_context_.get()) |
| 604 | resource_context_.reset(new content::MockResourceContext()); |
| 605 | return resource_context_.get(); |
[email protected] | e89b77d | 2011-04-15 18:58:10 | [diff] [blame] | 606 | } |
| 607 | |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 608 | HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() { |
[email protected] | 35552dc5 | 2011-07-12 09:04:38 | [diff] [blame] | 609 | if (!host_content_settings_map_.get()) { |
[email protected] | 646c29cb6 | 2012-06-18 14:31:05 | [diff] [blame] | 610 | host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false); |
| 611 | ExtensionService* extension_service = GetExtensionService(); |
| 612 | if (extension_service) |
| 613 | host_content_settings_map_->RegisterExtensionService(extension_service); |
[email protected] | 35552dc5 | 2011-07-12 09:04:38 | [diff] [blame] | 614 | } |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 615 | return host_content_settings_map_.get(); |
| 616 | } |
| 617 | |
[email protected] | 810ddc5 | 2012-01-24 01:00:35 | [diff] [blame] | 618 | content::GeolocationPermissionContext* |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 619 | TestingProfile::GetGeolocationPermissionContext() { |
| 620 | if (!geolocation_permission_context_.get()) { |
| 621 | geolocation_permission_context_ = |
[email protected] | c476e63 | 2011-06-23 11:18:04 | [diff] [blame] | 622 | new ChromeGeolocationPermissionContext(this); |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 623 | } |
| 624 | return geolocation_permission_context_.get(); |
| 625 | } |
| 626 | |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 627 | content::SpeechRecognitionPreferences* |
| 628 | TestingProfile::GetSpeechRecognitionPreferences() { |
[email protected] | 3297132a | 2012-02-21 23:27:59 | [diff] [blame] | 629 | #if defined(ENABLE_INPUT_SPEECH) |
[email protected] | 750e957 | 2012-06-06 15:21:24 | [diff] [blame] | 630 | return ChromeSpeechRecognitionPreferences::GetForProfile(this); |
[email protected] | 3297132a | 2012-02-21 23:27:59 | [diff] [blame] | 631 | #else |
| 632 | return NULL; |
| 633 | #endif |
[email protected] | 8238dd6 | 2011-09-29 15:13:01 | [diff] [blame] | 634 | } |
| 635 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 636 | std::wstring TestingProfile::GetName() { |
| 637 | return std::wstring(); |
| 638 | } |
| 639 | |
| 640 | std::wstring TestingProfile::GetID() { |
| 641 | return id_; |
| 642 | } |
| 643 | |
| 644 | void TestingProfile::SetID(const std::wstring& id) { |
| 645 | id_ = id; |
| 646 | } |
| 647 | |
| 648 | bool TestingProfile::DidLastSessionExitCleanly() { |
| 649 | return last_session_exited_cleanly_; |
| 650 | } |
| 651 | |
| 652 | BookmarkModel* TestingProfile::GetBookmarkModel() { |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 653 | return BookmarkModelFactory::GetForProfileIfExists(this); |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | bool TestingProfile::IsSameProfile(Profile *p) { |
| 657 | return this == p; |
| 658 | } |
| 659 | |
| 660 | base::Time TestingProfile::GetStartTime() const { |
| 661 | return start_time_; |
| 662 | } |
| 663 | |
[email protected] | a6d36cc | 2011-02-23 00:39:48 | [diff] [blame] | 664 | ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() { |
| 665 | return protocol_handler_registry_.get(); |
| 666 | } |
| 667 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 668 | FilePath TestingProfile::last_selected_directory() { |
| 669 | return last_selected_directory_; |
| 670 | } |
| 671 | |
| 672 | void TestingProfile::set_last_selected_directory(const FilePath& path) { |
| 673 | last_selected_directory_ = path; |
| 674 | } |
| 675 | |
[email protected] | cc5bfd4 | 2010-11-24 14:44:02 | [diff] [blame] | 676 | PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() { |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 677 | if (!pref_proxy_config_tracker_.get()) { |
| 678 | pref_proxy_config_tracker_.reset( |
| 679 | ProxyServiceFactory::CreatePrefProxyConfigTracker(GetPrefs())); |
| 680 | } |
| 681 | return pref_proxy_config_tracker_.get(); |
[email protected] | cc5bfd4 | 2010-11-24 14:44:02 | [diff] [blame] | 682 | } |
| 683 | |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 684 | void TestingProfile::BlockUntilHistoryProcessesPendingRequests() { |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 685 | scoped_refptr<HistoryService> history_service = |
[email protected] | 92a0fb77 | 2012-06-25 20:56:46 | [diff] [blame] | 686 | HistoryServiceFactory::GetForProfileIfExists(this); |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 687 | DCHECK(history_service.get()); |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 688 | DCHECK(MessageLoop::current()); |
| 689 | |
| 690 | CancelableRequestConsumer consumer; |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 691 | history_service->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer); |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 692 | MessageLoop::current()->Run(); |
| 693 | } |
[email protected] | 345a8b7 | 2009-09-29 09:11:44 | [diff] [blame] | 694 | |
[email protected] | 8382d8c | 2011-09-15 03:43:17 | [diff] [blame] | 695 | chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() { |
| 696 | return NULL; |
| 697 | } |
| 698 | |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 699 | void TestingProfile::ClearNetworkingHistorySince(base::Time time) { |
[email protected] | 02896a8 | 2011-09-21 18:54:32 | [diff] [blame] | 700 | NOTIMPLEMENTED(); |
| 701 | } |
| 702 | |
[email protected] | 671f9c6 | 2011-10-28 19:22:07 | [diff] [blame] | 703 | GURL TestingProfile::GetHomePage() { |
| 704 | return GURL(chrome::kChromeUINewTabURL); |
| 705 | } |
| 706 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 707 | PrefService* TestingProfile::GetOffTheRecordPrefs() { |
| 708 | return NULL; |
| 709 | } |
| 710 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 711 | quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { |
| 712 | return GetExtensionSpecialStoragePolicy(); |
| 713 | } |
| 714 | |
[email protected] | 1bee6ed | 2012-03-14 06:46:36 | [diff] [blame] | 715 | bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) { |
| 716 | return true; |
| 717 | } |
[email protected] | ef92e17 | 2012-04-25 19:40:41 | [diff] [blame] | 718 | |
| 719 | base::Callback<ChromeURLDataManagerBackend*(void)> |
| 720 | TestingProfile::GetChromeURLDataManagerBackendGetter() const { |
| 721 | return base::Callback<ChromeURLDataManagerBackend*(void)>(); |
| 722 | } |