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