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