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