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