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