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