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