[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] | 76ae8a6 | 2013-05-10 05:34:22 | [diff] [blame] | 12 | #include "base/message_loop/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] | 81d4978 | 2013-07-12 01:50:52 | [diff] [blame] | 21 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 9d01a6a | 2010-11-30 12:03:33 | [diff] [blame] | 22 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 2f69b38 | 2011-02-19 00:34:25 | [diff] [blame] | 23 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 24 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 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] | a50e16a | 2013-04-25 14:07:17 | [diff] [blame] | 38 | #include "chrome/browser/history/web_history_service_factory.h" |
[email protected] | 53c5b0f | 2013-07-22 10:54:11 | [diff] [blame] | 39 | #include "chrome/browser/net/pref_proxy_config_tracker.h" |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 40 | #include "chrome/browser/net/proxy_service_factory.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 41 | #include "chrome/browser/notifications/desktop_notification_service.h" |
[email protected] | dcb72d5 | 2011-04-13 12:36:53 | [diff] [blame] | 42 | #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
[email protected] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 43 | #include "chrome/browser/policy/profile_policy_connector.h" |
| 44 | #include "chrome/browser/policy/profile_policy_connector_factory.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 45 | #include "chrome/browser/prefs/browser_prefs.h" |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 46 | #include "chrome/browser/prefs/pref_service_syncable.h" |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 47 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 48 | #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 49 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 27ddfed2 | 2012-10-30 23:22:43 | [diff] [blame] | 50 | #include "chrome/browser/profiles/storage_partition_descriptor.h" |
[email protected] | 16bd088b | 2012-04-03 08:12:12 | [diff] [blame] | 51 | #include "chrome/browser/search_engines/template_url_fetcher_factory.h" |
[email protected] | 810ffba | 2012-06-12 01:07:48 | [diff] [blame] | 52 | #include "chrome/browser/webdata/web_data_service.h" |
[email protected] | d07edd4 | 2012-05-14 23:49:46 | [diff] [blame] | 53 | #include "chrome/browser/webdata/web_data_service_factory.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 54 | #include "chrome/common/chrome_constants.h" |
[email protected] | 9e33d7e | 2011-09-30 16:43:54 | [diff] [blame] | 55 | #include "chrome/common/chrome_switches.h" |
[email protected] | e000daf | 2013-07-31 16:50:58 | [diff] [blame] | 56 | #include "chrome/common/pref_names.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 57 | #include "chrome/common/url_constants.h" |
[email protected] | 18a15ca8 | 2012-08-30 00:28:16 | [diff] [blame] | 58 | #include "chrome/test/base/history_index_restore_observer.h" |
[email protected] | 7688968a | 2013-02-12 21:45:13 | [diff] [blame] | 59 | #include "chrome/test/base/testing_pref_service_syncable.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 60 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 0dd6f203 | 2013-05-20 23:33:40 | [diff] [blame] | 61 | #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" |
[email protected] | 76b4b15 | 2013-12-08 21:10:04 | [diff] [blame] | 62 | #include "components/policy/core/common/policy_service.h" |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 63 | #include "components/user_prefs/user_prefs.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 64 | #include "content/public/browser/browser_thread.h" |
[email protected] | 7c4b66b | 2014-01-04 12:28:13 | [diff] [blame] | 65 | #include "content/public/browser/cookie_store_factory.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 66 | #include "content/public/browser/notification_service.h" |
[email protected] | fb29e6cf | 2012-07-12 21:27:20 | [diff] [blame] | 67 | #include "content/public/browser/render_process_host.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 68 | #include "content/public/browser/storage_partition.h" |
[email protected] | 08a932d5 | 2012-06-03 21:42:12 | [diff] [blame] | 69 | #include "content/public/test/mock_resource_context.h" |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 70 | #include "content/public/test/test_utils.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 71 | #include "extensions/browser/extension_system.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 72 | #include "extensions/common/constants.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 73 | #include "net/cookies/cookie_monster.h" |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 74 | #include "net/url_request/url_request_context.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 75 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | d2db029 | 2011-01-26 20:23:44 | [diff] [blame] | 76 | #include "net/url_request/url_request_test_util.h" |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 77 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | 248ce19 | 2011-02-10 15:26:34 | [diff] [blame] | 78 | |
[email protected] | 21d3a88 | 2012-05-31 14:41:55 | [diff] [blame] | 79 | #if defined(ENABLE_CONFIGURATION_POLICY) |
[email protected] | eb83c39 | 2013-11-07 12:53:24 | [diff] [blame] | 80 | #include "chrome/browser/policy/schema_registry_service.h" |
| 81 | #include "chrome/browser/policy/schema_registry_service_factory.h" |
[email protected] | f20a3a2 | 2013-12-03 16:12:37 | [diff] [blame] | 82 | #include "components/policy/core/common/configuration_policy_provider.h" |
[email protected] | 76b4b15 | 2013-12-08 21:10:04 | [diff] [blame] | 83 | #include "components/policy/core/common/policy_service_impl.h" |
[email protected] | eb83c39 | 2013-11-07 12:53:24 | [diff] [blame] | 84 | #include "components/policy/core/common/schema.h" |
[email protected] | 21d3a88 | 2012-05-31 14:41:55 | [diff] [blame] | 85 | #else |
[email protected] | 76b4b15 | 2013-12-08 21:10:04 | [diff] [blame] | 86 | #include "components/policy/core/common/policy_service_stub.h" |
[email protected] | 21d3a88 | 2012-05-31 14:41:55 | [diff] [blame] | 87 | #endif // defined(ENABLE_CONFIGURATION_POLICY) |
| 88 | |
[email protected] | e148048 | 2013-09-11 11:49:58 | [diff] [blame] | 89 | #if defined(ENABLE_MANAGED_USERS) |
| 90 | #include "chrome/browser/managed_mode/managed_user_settings_service.h" |
| 91 | #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" |
| 92 | #endif |
| 93 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 94 | using base::Time; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 95 | using content::BrowserThread; |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 96 | using content::DownloadManagerDelegate; |
[email protected] | 3c88741 | 2010-04-19 20:30:23 | [diff] [blame] | 97 | using testing::NiceMock; |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 98 | using testing::Return; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 99 | |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 100 | namespace { |
| 101 | |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 102 | // Task used to make sure history has finished processing a request. Intended |
| 103 | // for use with BlockUntilHistoryProcessesPendingRequests. |
| 104 | |
[email protected] | d891f52 | 2013-02-08 03:24:41 | [diff] [blame] | 105 | class QuittingHistoryDBTask : public history::HistoryDBTask { |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 106 | public: |
| 107 | QuittingHistoryDBTask() {} |
| 108 | |
| 109 | virtual bool RunOnDBThread(history::HistoryBackend* backend, |
[email protected] | be9826e6 | 2013-02-07 02:00:58 | [diff] [blame] | 110 | history::HistoryDatabase* db) OVERRIDE { |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 111 | return true; |
| 112 | } |
| 113 | |
[email protected] | be9826e6 | 2013-02-07 02:00:58 | [diff] [blame] | 114 | virtual void DoneRunOnMainThread() OVERRIDE { |
[email protected] | bb024fe | 2013-05-10 21:33:26 | [diff] [blame] | 115 | base::MessageLoop::current()->Quit(); |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | private: |
[email protected] | be9826e6 | 2013-02-07 02:00:58 | [diff] [blame] | 119 | virtual ~QuittingHistoryDBTask() {} |
[email protected] | 7991a23 | 2009-11-06 01:55:48 | [diff] [blame] | 120 | |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 121 | DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask); |
| 122 | }; |
| 123 | |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 124 | class TestExtensionURLRequestContext : public net::URLRequestContext { |
| 125 | public: |
| 126 | TestExtensionURLRequestContext() { |
[email protected] | 7c4b66b | 2014-01-04 12:28:13 | [diff] [blame] | 127 | net::CookieMonster* cookie_monster = |
[email protected] | 9a6c2aa | 2014-01-11 22:39:39 | [diff] [blame] | 128 | content::CreateCookieStore(content::CookieStoreConfig())-> |
| 129 | GetCookieMonster(); |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 130 | const char* schemes[] = {extensions::kExtensionScheme}; |
| 131 | cookie_monster->SetCookieableSchemes(schemes, 1); |
| 132 | set_cookie_store(cookie_monster); |
| 133 | } |
| 134 | |
| 135 | virtual ~TestExtensionURLRequestContext() {} |
| 136 | }; |
| 137 | |
| 138 | class TestExtensionURLRequestContextGetter |
| 139 | : public net::URLRequestContextGetter { |
| 140 | public: |
| 141 | virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { |
| 142 | if (!context_.get()) |
| 143 | context_.reset(new TestExtensionURLRequestContext()); |
| 144 | return context_.get(); |
| 145 | } |
| 146 | virtual scoped_refptr<base::SingleThreadTaskRunner> |
| 147 | GetNetworkTaskRunner() const OVERRIDE { |
| 148 | return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| 149 | } |
| 150 | |
| 151 | protected: |
| 152 | virtual ~TestExtensionURLRequestContextGetter() {} |
| 153 | |
| 154 | private: |
| 155 | scoped_ptr<net::URLRequestContext> context_; |
| 156 | }; |
| 157 | |
[email protected] | 1d51882f | 2013-11-12 01:59:02 | [diff] [blame] | 158 | #if defined(ENABLE_NOTIFICATIONS) |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 159 | BrowserContextKeyedService* CreateTestDesktopNotificationService( |
[email protected] | c7fa436 | 2013-04-26 18:09:02 | [diff] [blame] | 160 | content::BrowserContext* profile) { |
[email protected] | c7fa436 | 2013-04-26 18:09:02 | [diff] [blame] | 161 | return new DesktopNotificationService(static_cast<Profile*>(profile), NULL); |
[email protected] | dcb72d5 | 2011-04-13 12:36:53 | [diff] [blame] | 162 | } |
[email protected] | 1d51882f | 2013-11-12 01:59:02 | [diff] [blame] | 163 | #endif |
[email protected] | dcb72d5 | 2011-04-13 12:36:53 | [diff] [blame] | 164 | |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 165 | } // namespace |
| 166 | |
[email protected] | 89dbb177 | 2012-07-17 13:47:25 | [diff] [blame] | 167 | // static |
| 168 | #if defined(OS_CHROMEOS) |
| 169 | // Must be kept in sync with |
| 170 | // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. |
[email protected] | 0f13fe8d | 2013-11-19 08:25:00 | [diff] [blame] | 171 | const char TestingProfile::kTestUserProfileDir[] = "test-user"; |
[email protected] | 89dbb177 | 2012-07-17 13:47:25 | [diff] [blame] | 172 | #else |
| 173 | const char TestingProfile::kTestUserProfileDir[] = "Default"; |
| 174 | #endif |
| 175 | |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 176 | TestingProfile::TestingProfile() |
[email protected] | ea6f7657 | 2008-12-18 00:09:55 | [diff] [blame] | 177 | : start_time_(Time::Now()), |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 178 | testing_prefs_(NULL), |
[email protected] | 5bb2f52 | 2011-03-25 19:04:44 | [diff] [blame] | 179 | incognito_(false), |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 180 | force_incognito_(false), |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 181 | original_profile_(NULL), |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 182 | guest_session_(false), |
[email protected] | 5cdcd15 | 2011-03-31 22:48:52 | [diff] [blame] | 183 | last_session_exited_cleanly_(true), |
[email protected] | f0901a2 | 2013-05-27 21:37:53 | [diff] [blame] | 184 | browser_context_dependency_manager_( |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 185 | BrowserContextDependencyManager::GetInstance()), |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 186 | resource_context_(NULL), |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 187 | delegate_(NULL) { |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 188 | CreateTempProfileDir(); |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 189 | profile_path_ = temp_dir_.path(); |
| 190 | |
| 191 | Init(); |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 192 | FinishInit(); |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 193 | } |
| 194 | |
[email protected] | 152ea30 | 2013-02-11 04:08:40 | [diff] [blame] | 195 | TestingProfile::TestingProfile(const base::FilePath& path) |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 196 | : start_time_(Time::Now()), |
| 197 | testing_prefs_(NULL), |
| 198 | incognito_(false), |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 199 | force_incognito_(false), |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 200 | original_profile_(NULL), |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 201 | guest_session_(false), |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 202 | last_session_exited_cleanly_(true), |
| 203 | profile_path_(path), |
[email protected] | f0901a2 | 2013-05-27 21:37:53 | [diff] [blame] | 204 | browser_context_dependency_manager_( |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 205 | BrowserContextDependencyManager::GetInstance()), |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 206 | resource_context_(NULL), |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 207 | delegate_(NULL) { |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 208 | Init(); |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 209 | FinishInit(); |
| 210 | } |
| 211 | |
[email protected] | 152ea30 | 2013-02-11 04:08:40 | [diff] [blame] | 212 | TestingProfile::TestingProfile(const base::FilePath& path, |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 213 | Delegate* delegate) |
| 214 | : start_time_(Time::Now()), |
| 215 | testing_prefs_(NULL), |
| 216 | incognito_(false), |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 217 | force_incognito_(false), |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 218 | original_profile_(NULL), |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 219 | guest_session_(false), |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 220 | last_session_exited_cleanly_(true), |
| 221 | profile_path_(path), |
[email protected] | f0901a2 | 2013-05-27 21:37:53 | [diff] [blame] | 222 | browser_context_dependency_manager_( |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 223 | BrowserContextDependencyManager::GetInstance()), |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 224 | resource_context_(NULL), |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 225 | delegate_(delegate) { |
| 226 | Init(); |
| 227 | if (delegate_) { |
[email protected] | bb024fe | 2013-05-10 21:33:26 | [diff] [blame] | 228 | base::MessageLoop::current()->PostTask( |
| 229 | FROM_HERE, |
| 230 | base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 231 | } else { |
| 232 | FinishInit(); |
| 233 | } |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 234 | } |
| 235 | |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 236 | TestingProfile::TestingProfile( |
[email protected] | 152ea30 | 2013-02-11 04:08:40 | [diff] [blame] | 237 | const base::FilePath& path, |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 238 | Delegate* delegate, |
| 239 | scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 240 | scoped_ptr<PrefServiceSyncable> prefs, |
| 241 | bool incognito, |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 242 | bool guest_session, |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 243 | const std::string& managed_user_id, |
[email protected] | a43b9a8 | 2013-11-28 16:56:41 | [diff] [blame] | 244 | scoped_ptr<policy::PolicyService> policy_service, |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 245 | const TestingFactories& factories) |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 246 | : start_time_(Time::Now()), |
| 247 | prefs_(prefs.release()), |
| 248 | testing_prefs_(NULL), |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 249 | incognito_(incognito), |
| 250 | force_incognito_(false), |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 251 | original_profile_(NULL), |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 252 | guest_session_(guest_session), |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 253 | managed_user_id_(managed_user_id), |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 254 | last_session_exited_cleanly_(true), |
| 255 | extension_special_storage_policy_(extension_policy), |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 256 | profile_path_(path), |
[email protected] | f0901a2 | 2013-05-27 21:37:53 | [diff] [blame] | 257 | browser_context_dependency_manager_( |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 258 | BrowserContextDependencyManager::GetInstance()), |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 259 | resource_context_(NULL), |
[email protected] | a43b9a8 | 2013-11-28 16:56:41 | [diff] [blame] | 260 | delegate_(delegate), |
| 261 | policy_service_(policy_service.release()) { |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 262 | |
| 263 | // If no profile path was supplied, create one. |
| 264 | if (profile_path_.empty()) { |
| 265 | CreateTempProfileDir(); |
| 266 | profile_path_ = temp_dir_.path(); |
| 267 | } |
| 268 | |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 269 | // Set any testing factories prior to initializing the services. |
| 270 | for (TestingFactories::const_iterator it = factories.begin(); |
| 271 | it != factories.end(); ++it) { |
| 272 | it->first->SetTestingFactory(this, it->second); |
| 273 | } |
| 274 | |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 275 | Init(); |
| 276 | // If caller supplied a delegate, delay the FinishInit invocation until other |
| 277 | // tasks have run. |
| 278 | // TODO(atwilson): See if this is still required once we convert the current |
| 279 | // users of the constructor that takes a Delegate* param. |
| 280 | if (delegate_) { |
[email protected] | bb024fe | 2013-05-10 21:33:26 | [diff] [blame] | 281 | base::MessageLoop::current()->PostTask( |
| 282 | FROM_HERE, |
| 283 | base::Bind(&TestingProfile::FinishInit, base::Unretained(this))); |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 284 | } else { |
| 285 | FinishInit(); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | void TestingProfile::CreateTempProfileDir() { |
| 290 | if (!temp_dir_.CreateUniqueTempDir()) { |
| 291 | LOG(ERROR) << "Failed to create unique temporary directory."; |
| 292 | |
| 293 | // Fallback logic in case we fail to create unique temporary directory. |
[email protected] | 152ea30 | 2013-02-11 04:08:40 | [diff] [blame] | 294 | base::FilePath system_tmp_dir; |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 295 | bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir); |
| 296 | |
| 297 | // We're severly screwed if we can't get the system temporary |
| 298 | // directory. Die now to avoid writing to the filesystem root |
| 299 | // or other bad places. |
| 300 | CHECK(success); |
| 301 | |
[email protected] | 152ea30 | 2013-02-11 04:08:40 | [diff] [blame] | 302 | base::FilePath fallback_dir( |
| 303 | system_tmp_dir.AppendASCII("TestingProfilePath")); |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 304 | base::DeleteFile(fallback_dir, true); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 305 | base::CreateDirectory(fallback_dir); |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 306 | if (!temp_dir_.Set(fallback_dir)) { |
| 307 | // That shouldn't happen, but if it does, try to recover. |
| 308 | LOG(ERROR) << "Failed to use a fallback temporary directory."; |
| 309 | |
| 310 | // We're screwed if this fails, see CHECK above. |
| 311 | CHECK(temp_dir_.Set(system_tmp_dir)); |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 316 | void TestingProfile::Init() { |
[email protected] | bf390cb | 2013-08-06 02:48:08 | [diff] [blame] | 317 | // If threads have been initialized, we should be on the UI thread. |
[email protected] | 33d0624 | 2013-08-12 05:20:30 | [diff] [blame] | 318 | DCHECK(!content::BrowserThread::IsThreadInitialized( |
| 319 | content::BrowserThread::UI) || |
| 320 | content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
[email protected] | bf390cb | 2013-08-06 02:48:08 | [diff] [blame] | 321 | |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 322 | // Normally this would happen during browser startup, but for tests |
| 323 | // we need to trigger creation of Profile-related services. |
| 324 | ChromeBrowserMainExtraPartsProfiles:: |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 325 | EnsureBrowserContextKeyedServiceFactoriesBuilt(); |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 326 | |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 327 | if (prefs_.get()) |
[email protected] | c7141feb | 2013-06-11 13:00:16 | [diff] [blame] | 328 | user_prefs::UserPrefs::Set(this, prefs_.get()); |
[email protected] | c7fa436 | 2013-04-26 18:09:02 | [diff] [blame] | 329 | else |
| 330 | CreateTestingPrefService(); |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 331 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 332 | if (!base::PathExists(profile_path_)) |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 333 | base::CreateDirectory(profile_path_); |
[email protected] | d41e657 | 2012-05-04 20:49:42 | [diff] [blame] | 334 | |
[email protected] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 335 | // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl |
| 336 | // anymore, after converting the PrefService to a PKS. Until then it must |
| 337 | // be associated with a TestingProfile too. |
[email protected] | eb83c39 | 2013-11-07 12:53:24 | [diff] [blame] | 338 | if (!IsOffTheRecord()) |
| 339 | CreateProfilePolicyConnector(); |
[email protected] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 340 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 341 | extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory( |
| 342 | this, extensions::TestExtensionSystem::Build); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 343 | |
[email protected] | d45c5d5 | 2013-12-04 23:41:16 | [diff] [blame] | 344 | // If no original profile was specified for this profile: register preferences |
| 345 | // even if this is an incognito profile - this allows tests to create a |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 346 | // standalone incognito profile while still having prefs registered. |
[email protected] | d45c5d5 | 2013-12-04 23:41:16 | [diff] [blame] | 347 | if (!IsOffTheRecord() || !original_profile_) { |
| 348 | user_prefs::PrefRegistrySyncable* pref_registry = |
| 349 | static_cast<user_prefs::PrefRegistrySyncable*>( |
| 350 | prefs_->DeprecatedGetPrefRegistry()); |
| 351 | browser_context_dependency_manager_-> |
| 352 | RegisterProfilePrefsForServices(this, pref_registry); |
| 353 | } |
| 354 | |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 355 | browser_context_dependency_manager_->CreateBrowserContextServicesForTest( |
[email protected] | d45c5d5 | 2013-12-04 23:41:16 | [diff] [blame] | 356 | this); |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 357 | |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 358 | #if defined(ENABLE_NOTIFICATIONS) |
[email protected] | dcb72d5 | 2011-04-13 12:36:53 | [diff] [blame] | 359 | // Install profile keyed service factory hooks for dummy/test services |
[email protected] | 7722653b | 2011-06-03 17:28:22 | [diff] [blame] | 360 | DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory( |
| 361 | this, CreateTestDesktopNotificationService); |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 362 | #endif |
[email protected] | e148048 | 2013-09-11 11:49:58 | [diff] [blame] | 363 | |
| 364 | #if defined(ENABLE_MANAGED_USERS) |
| 365 | ManagedUserSettingsService* settings_service = |
| 366 | ManagedUserSettingsServiceFactory::GetForProfile(this); |
| 367 | TestingPrefStore* store = new TestingPrefStore(); |
| 368 | settings_service->Init(store); |
| 369 | store->SetInitializationCompleted(); |
| 370 | #endif |
[email protected] | d600187 | 2013-09-24 18:31:26 | [diff] [blame] | 371 | |
| 372 | profile_name_ = "testing_profile"; |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 373 | } |
[email protected] | 12463cd | 2011-07-19 09:40:20 | [diff] [blame] | 374 | |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 375 | void TestingProfile::FinishInit() { |
[email protected] | 080adba9 | 2011-12-07 19:00:40 | [diff] [blame] | 376 | DCHECK(content::NotificationService::current()); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 377 | content::NotificationService::current()->Notify( |
[email protected] | 12463cd | 2011-07-19 09:40:20 | [diff] [blame] | 378 | chrome::NOTIFICATION_PROFILE_CREATED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 379 | content::Source<Profile>(static_cast<Profile*>(this)), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 380 | content::NotificationService::NoDetails()); |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 381 | |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 382 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 383 | if (profile_manager) |
| 384 | profile_manager->InitProfileUserPrefs(this); |
| 385 | |
[email protected] | 537c108 | 2011-12-02 02:37:17 | [diff] [blame] | 386 | if (delegate_) |
[email protected] | 00b33f80 | 2012-03-13 07:46:03 | [diff] [blame] | 387 | delegate_->OnProfileCreated(this, true, false); |
[email protected] | ab23dbe | 2010-08-12 02:10:46 | [diff] [blame] | 388 | } |
| 389 | |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 390 | TestingProfile::~TestingProfile() { |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 391 | // Revert to non-incognito mode before shutdown. |
| 392 | force_incognito_ = false; |
| 393 | |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 394 | // Any objects holding live URLFetchers should be deleted before teardown. |
| 395 | TemplateURLFetcherFactory::ShutdownForProfile(this); |
| 396 | |
[email protected] | a7c4c03 | 2012-07-27 00:36:32 | [diff] [blame] | 397 | MaybeSendDestroyedNotification(); |
[email protected] | 5cdcd15 | 2011-03-31 22:48:52 | [diff] [blame] | 398 | |
[email protected] | f0901a2 | 2013-05-27 21:37:53 | [diff] [blame] | 399 | browser_context_dependency_manager_->DestroyBrowserContextServices(this); |
[email protected] | 5cdcd15 | 2011-03-31 22:48:52 | [diff] [blame] | 400 | |
[email protected] | 5c6ac84 | 2013-06-02 23:37:03 | [diff] [blame] | 401 | if (host_content_settings_map_.get()) |
[email protected] | 35552dc5 | 2011-07-12 09:04:38 | [diff] [blame] | 402 | host_content_settings_map_->ShutdownOnUIThread(); |
| 403 | |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 404 | DestroyTopSites(); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 405 | |
[email protected] | cc5bfd4 | 2010-11-24 14:44:02 | [diff] [blame] | 406 | if (pref_proxy_config_tracker_.get()) |
| 407 | pref_proxy_config_tracker_->DetachFromPrefService(); |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 408 | // Failing a post == leaks == heapcheck failure. Make that an immediate test |
| 409 | // failure. |
| 410 | if (resource_context_) { |
| 411 | CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, |
| 412 | resource_context_)); |
| 413 | resource_context_ = NULL; |
| 414 | content::RunAllPendingInMessageLoop(BrowserThread::IO); |
| 415 | } |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 416 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 417 | |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 418 | static BrowserContextKeyedService* BuildFaviconService( |
[email protected] | c7fa436 | 2013-04-26 18:09:02 | [diff] [blame] | 419 | content::BrowserContext* profile) { |
[email protected] | f718290e | 2013-11-05 07:11:58 | [diff] [blame] | 420 | return new FaviconService(static_cast<Profile*>(profile)); |
[email protected] | f3d2b31 | 2012-08-23 22:27:59 | [diff] [blame] | 421 | } |
| 422 | |
[email protected] | d2879af | 2010-02-08 16:02:56 | [diff] [blame] | 423 | void TestingProfile::CreateFaviconService() { |
[email protected] | f3d2b31 | 2012-08-23 22:27:59 | [diff] [blame] | 424 | // It is up to the caller to create the history service if one is needed. |
| 425 | FaviconServiceFactory::GetInstance()->SetTestingFactory( |
| 426 | this, BuildFaviconService); |
[email protected] | d2879af | 2010-02-08 16:02:56 | [diff] [blame] | 427 | } |
| 428 | |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 429 | static BrowserContextKeyedService* BuildHistoryService( |
[email protected] | c7fa436 | 2013-04-26 18:09:02 | [diff] [blame] | 430 | content::BrowserContext* profile) { |
| 431 | return new HistoryService(static_cast<Profile*>(profile)); |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 432 | } |
| 433 | |
[email protected] | 608e7e0 | 2013-07-24 12:23:31 | [diff] [blame] | 434 | bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 435 | DestroyHistoryService(); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 436 | if (delete_file) { |
[email protected] | 152ea30 | 2013-02-11 04:08:40 | [diff] [blame] | 437 | base::FilePath path = GetPath(); |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 438 | path = path.Append(chrome::kHistoryFilename); |
[email protected] | 608e7e0 | 2013-07-24 12:23:31 | [diff] [blame] | 439 | if (!base::DeleteFile(path, false) || base::PathExists(path)) |
| 440 | return false; |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 441 | } |
[email protected] | 7019bb6d | 2012-08-23 09:09:48 | [diff] [blame] | 442 | // This will create and init the history service. |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 443 | HistoryService* history_service = static_cast<HistoryService*>( |
| 444 | HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
[email protected] | a5894fe | 2012-11-01 14:40:56 | [diff] [blame] | 445 | this, BuildHistoryService)); |
[email protected] | 7019bb6d | 2012-08-23 09:09:48 | [diff] [blame] | 446 | if (!history_service->Init(this->GetPath(), |
| 447 | BookmarkModelFactory::GetForProfile(this), |
| 448 | no_db)) { |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 449 | HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL); |
[email protected] | 7019bb6d | 2012-08-23 09:09:48 | [diff] [blame] | 450 | } |
[email protected] | a50e16a | 2013-04-25 14:07:17 | [diff] [blame] | 451 | // Disable WebHistoryService by default, since it makes network requests. |
| 452 | WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL); |
[email protected] | 608e7e0 | 2013-07-24 12:23:31 | [diff] [blame] | 453 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | void TestingProfile::DestroyHistoryService() { |
[email protected] | a5894fe | 2012-11-01 14:40:56 | [diff] [blame] | 457 | HistoryService* history_service = |
[email protected] | 6c53704 | 2012-07-13 00:59:02 | [diff] [blame] | 458 | HistoryServiceFactory::GetForProfileWithoutCreating(this); |
[email protected] | a5894fe | 2012-11-01 14:40:56 | [diff] [blame] | 459 | if (!history_service) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 460 | return; |
| 461 | |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 462 | history_service->NotifyRenderProcessHostDestruction(0); |
[email protected] | bb024fe | 2013-05-10 21:33:26 | [diff] [blame] | 463 | history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure()); |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 464 | history_service->Cleanup(); |
| 465 | HistoryServiceFactory::ShutdownForProfile(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 466 | |
| 467 | // Wait for the backend class to terminate before deleting the files and |
| 468 | // moving to the next test. Note: if this never terminates, somebody is |
| 469 | // probably leaking a reference to the history backend, so it never calls |
| 470 | // our destroy task. |
[email protected] | bb024fe | 2013-05-10 21:33:26 | [diff] [blame] | 471 | base::MessageLoop::current()->Run(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 472 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 473 | // Make sure we don't have any event pending that could disrupt the next |
| 474 | // test. |
[email protected] | bb024fe | 2013-05-10 21:33:26 | [diff] [blame] | 475 | base::MessageLoop::current()->PostTask(FROM_HERE, |
| 476 | base::MessageLoop::QuitClosure()); |
| 477 | base::MessageLoop::current()->Run(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 478 | } |
[email protected] | 4d0cd7ce | 2008-08-11 16:40:57 | [diff] [blame] | 479 | |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 480 | void TestingProfile::CreateTopSites() { |
| 481 | DestroyTopSites(); |
[email protected] | 9a93d343 | 2013-04-29 20:52:12 | [diff] [blame] | 482 | top_sites_ = history::TopSites::Create( |
| 483 | this, GetPath().Append(chrome::kTopSitesFilename)); |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | void TestingProfile::DestroyTopSites() { |
| 487 | if (top_sites_.get()) { |
| 488 | top_sites_->Shutdown(); |
| 489 | top_sites_ = NULL; |
[email protected] | 9a93d343 | 2013-04-29 20:52:12 | [diff] [blame] | 490 | // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that |
| 491 | // need to be run to properly shutdown. Run all pending tasks now. This is |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 492 | // normally handled by browser_process shutdown. |
[email protected] | bb024fe | 2013-05-10 21:33:26 | [diff] [blame] | 493 | if (base::MessageLoop::current()) |
| 494 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 498 | static BrowserContextKeyedService* BuildBookmarkModel( |
[email protected] | c7fa436 | 2013-04-26 18:09:02 | [diff] [blame] | 499 | content::BrowserContext* context) { |
| 500 | Profile* profile = static_cast<Profile*>(context); |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 501 | BookmarkModel* bookmark_model = new BookmarkModel(profile); |
[email protected] | afecfb7 | 2013-04-18 17:17:33 | [diff] [blame] | 502 | bookmark_model->Load(profile->GetIOTaskRunner()); |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 503 | return bookmark_model; |
| 504 | } |
| 505 | |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 506 | void TestingProfile::CreateBookmarkModel(bool delete_file) { |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 507 | if (delete_file) { |
[email protected] | 8a39b47 | 2013-04-04 17:07:42 | [diff] [blame] | 508 | base::FilePath path = GetPath().Append(chrome::kBookmarksFileName); |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 509 | base::DeleteFile(path, false); |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 510 | } |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 511 | // This will create a bookmark model. |
[email protected] | 8a39b47 | 2013-04-04 17:07:42 | [diff] [blame] | 512 | BookmarkModel* bookmark_service = static_cast<BookmarkModel*>( |
| 513 | BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse( |
| 514 | this, BuildBookmarkModel)); |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 515 | |
| 516 | HistoryService* history_service = |
[email protected] | a5894fe | 2012-11-01 14:40:56 | [diff] [blame] | 517 | HistoryServiceFactory::GetForProfileWithoutCreating(this); |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 518 | if (history_service) { |
[email protected] | 8a39b47 | 2013-04-04 17:07:42 | [diff] [blame] | 519 | history_service->history_backend_->bookmark_service_ = bookmark_service; |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 520 | history_service->history_backend_->expirer_.bookmark_service_ = |
| 521 | bookmark_service; |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 522 | } |
[email protected] | 4d0cd7ce | 2008-08-11 16:40:57 | [diff] [blame] | 523 | } |
[email protected] | d2c017a | 2008-08-13 21:51:45 | [diff] [blame] | 524 | |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 525 | static BrowserContextKeyedService* BuildWebDataService( |
[email protected] | c7fa436 | 2013-04-26 18:09:02 | [diff] [blame] | 526 | content::BrowserContext* profile) { |
| 527 | return new WebDataServiceWrapper(static_cast<Profile*>(profile)); |
[email protected] | d07edd4 | 2012-05-14 23:49:46 | [diff] [blame] | 528 | } |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 529 | |
[email protected] | d07edd4 | 2012-05-14 23:49:46 | [diff] [blame] | 530 | void TestingProfile::CreateWebDataService() { |
[email protected] | a5c6529 | 2012-05-25 00:50:01 | [diff] [blame] | 531 | WebDataServiceFactory::GetInstance()->SetTestingFactory( |
[email protected] | d07edd4 | 2012-05-14 23:49:46 | [diff] [blame] | 532 | this, BuildWebDataService); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 533 | } |
| 534 | |
[email protected] | 18a15ca8 | 2012-08-30 00:28:16 | [diff] [blame] | 535 | void TestingProfile::BlockUntilHistoryIndexIsRefreshed() { |
| 536 | // Only get the history service if it actually exists since the caller of the |
| 537 | // test should explicitly call CreateHistoryService to build it. |
| 538 | HistoryService* history_service = |
| 539 | HistoryServiceFactory::GetForProfileWithoutCreating(this); |
| 540 | DCHECK(history_service); |
| 541 | history::InMemoryURLIndex* index = history_service->InMemoryIndex(); |
| 542 | if (!index || index->restored()) |
| 543 | return; |
| 544 | base::RunLoop run_loop; |
| 545 | HistoryIndexRestoreObserver observer( |
| 546 | content::GetQuitTaskForRunLoop(&run_loop)); |
| 547 | index->set_restore_cache_observer(&observer); |
| 548 | run_loop.Run(); |
| 549 | index->set_restore_cache_observer(NULL); |
| 550 | DCHECK(index->restored()); |
| 551 | } |
| 552 | |
[email protected] | 120abf13 | 2011-09-27 21:38:06 | [diff] [blame] | 553 | // TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded? |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 554 | void TestingProfile::BlockUntilTopSitesLoaded() { |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 555 | content::WindowedNotificationObserver top_sites_loaded_observer( |
[email protected] | 120abf13 | 2011-09-27 21:38:06 | [diff] [blame] | 556 | chrome::NOTIFICATION_TOP_SITES_LOADED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 557 | content::NotificationService::AllSources()); |
[email protected] | 120abf13 | 2011-09-27 21:38:06 | [diff] [blame] | 558 | top_sites_loaded_observer.Wait(); |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 559 | } |
| 560 | |
[email protected] | 4251165a | 2013-07-17 04:33:40 | [diff] [blame] | 561 | base::FilePath TestingProfile::GetPath() const { |
[email protected] | 49a2563 | 2011-08-31 17:03:48 | [diff] [blame] | 562 | return profile_path_; |
[email protected] | f9dec948 | 2010-08-20 20:42:19 | [diff] [blame] | 563 | } |
| 564 | |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 565 | scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() { |
[email protected] | bb024fe | 2013-05-10 21:33:26 | [diff] [blame] | 566 | return base::MessageLoop::current()->message_loop_proxy(); |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 567 | } |
| 568 | |
[email protected] | 5b19952 | 2012-12-22 17:24:44 | [diff] [blame] | 569 | TestingPrefServiceSyncable* TestingProfile::GetTestingPrefService() { |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 570 | if (!prefs_.get()) |
| 571 | CreateTestingPrefService(); |
| 572 | DCHECK(testing_prefs_); |
| 573 | return testing_prefs_; |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 574 | } |
| 575 | |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 576 | TestingProfile* TestingProfile::AsTestingProfile() { |
| 577 | return this; |
| 578 | } |
| 579 | |
[email protected] | 29d7025 | 2011-04-28 02:16:58 | [diff] [blame] | 580 | std::string TestingProfile::GetProfileName() { |
[email protected] | d600187 | 2013-09-24 18:31:26 | [diff] [blame] | 581 | return profile_name_; |
[email protected] | 29d7025 | 2011-04-28 02:16:58 | [diff] [blame] | 582 | } |
| 583 | |
[email protected] | 27d6e85 | 2012-03-02 21:31:32 | [diff] [blame] | 584 | bool TestingProfile::IsOffTheRecord() const { |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 585 | return force_incognito_ || incognito_; |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 586 | } |
| 587 | |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 588 | void TestingProfile::SetOffTheRecordProfile(scoped_ptr<Profile> profile) { |
| 589 | DCHECK(!IsOffTheRecord()); |
| 590 | incognito_profile_ = profile.Pass(); |
[email protected] | 93dba94 | 2011-02-23 22:45:01 | [diff] [blame] | 591 | } |
| 592 | |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 593 | void TestingProfile::SetOriginalProfile(Profile* profile) { |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 594 | DCHECK(IsOffTheRecord()); |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 595 | original_profile_ = profile; |
| 596 | } |
| 597 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 598 | Profile* TestingProfile::GetOffTheRecordProfile() { |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 599 | if (IsOffTheRecord()) |
| 600 | return this; |
[email protected] | cbed02ae | 2014-03-07 17:16:26 | [diff] [blame^] | 601 | if (!incognito_profile_) { |
| 602 | TestingProfile::Builder builder; |
| 603 | builder.SetIncognito(); |
| 604 | scoped_ptr<TestingProfile> incognito_test_profile(builder.Build()); |
| 605 | incognito_test_profile->SetOriginalProfile(this); |
| 606 | SetOffTheRecordProfile(incognito_test_profile.PassAs<Profile>()); |
| 607 | } |
[email protected] | 5bb2f52 | 2011-03-25 19:04:44 | [diff] [blame] | 608 | return incognito_profile_.get(); |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | bool TestingProfile::HasOffTheRecordProfile() { |
[email protected] | 5bb2f52 | 2011-03-25 19:04:44 | [diff] [blame] | 612 | return incognito_profile_.get() != NULL; |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | Profile* TestingProfile::GetOriginalProfile() { |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 616 | if (original_profile_) |
| 617 | return original_profile_; |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 618 | return this; |
| 619 | } |
| 620 | |
[email protected] | e000daf | 2013-07-31 16:50:58 | [diff] [blame] | 621 | bool TestingProfile::IsManaged() { |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 622 | return !managed_user_id_.empty(); |
[email protected] | e000daf | 2013-07-31 16:50:58 | [diff] [blame] | 623 | } |
| 624 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 625 | ExtensionService* TestingProfile::GetExtensionService() { |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 626 | return extensions::ExtensionSystem::Get(this)->extension_service(); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 627 | } |
| 628 | |
[email protected] | 2261e7b7 | 2011-07-12 13:43:55 | [diff] [blame] | 629 | void TestingProfile::SetExtensionSpecialStoragePolicy( |
| 630 | ExtensionSpecialStoragePolicy* extension_special_storage_policy) { |
| 631 | extension_special_storage_policy_ = extension_special_storage_policy; |
| 632 | } |
| 633 | |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 634 | ExtensionSpecialStoragePolicy* |
| 635 | TestingProfile::GetExtensionSpecialStoragePolicy() { |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 636 | if (!extension_special_storage_policy_.get()) |
[email protected] | 7c5048c | 2011-08-19 17:07:05 | [diff] [blame] | 637 | extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL); |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 638 | return extension_special_storage_policy_.get(); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 639 | } |
| 640 | |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 641 | net::CookieMonster* TestingProfile::GetCookieMonster() { |
| 642 | if (!GetRequestContext()) |
| 643 | return NULL; |
| 644 | return GetRequestContext()->GetURLRequestContext()->cookie_store()-> |
| 645 | GetCookieMonster(); |
| 646 | } |
| 647 | |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 648 | void TestingProfile::CreateTestingPrefService() { |
| 649 | DCHECK(!prefs_.get()); |
[email protected] | 5b19952 | 2012-12-22 17:24:44 | [diff] [blame] | 650 | testing_prefs_ = new TestingPrefServiceSyncable(); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 651 | prefs_.reset(testing_prefs_); |
[email protected] | c7141feb | 2013-06-11 13:00:16 | [diff] [blame] | 652 | user_prefs::UserPrefs::Set(this, prefs_.get()); |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 653 | chrome::RegisterUserProfilePrefs(testing_prefs_->registry()); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 654 | } |
| 655 | |
[email protected] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 656 | void TestingProfile::CreateProfilePolicyConnector() { |
[email protected] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 657 | #if defined(ENABLE_CONFIGURATION_POLICY) |
[email protected] | eb83c39 | 2013-11-07 12:53:24 | [diff] [blame] | 658 | schema_registry_service_ = |
| 659 | policy::SchemaRegistryServiceFactory::CreateForContext( |
| 660 | this, policy::Schema(), NULL); |
| 661 | CHECK_EQ(schema_registry_service_.get(), |
| 662 | policy::SchemaRegistryServiceFactory::GetForContext(this)); |
[email protected] | a43b9a8 | 2013-11-28 16:56:41 | [diff] [blame] | 663 | #endif // defined(ENABLE_CONFIGURATION_POLICY) |
[email protected] | eb83c39 | 2013-11-07 12:53:24 | [diff] [blame] | 664 | |
[email protected] | a43b9a8 | 2013-11-28 16:56:41 | [diff] [blame] | 665 | if (!policy_service_) { |
| 666 | #if defined(ENABLE_CONFIGURATION_POLICY) |
| 667 | std::vector<policy::ConfigurationPolicyProvider*> providers; |
[email protected] | 3352840 | 2013-12-16 18:38:32 | [diff] [blame] | 668 | policy_service_.reset(new policy::PolicyServiceImpl(providers)); |
[email protected] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 669 | #else |
[email protected] | a43b9a8 | 2013-11-28 16:56:41 | [diff] [blame] | 670 | policy_service_.reset(new policy::PolicyServiceStub()); |
[email protected] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 671 | #endif |
[email protected] | a43b9a8 | 2013-11-28 16:56:41 | [diff] [blame] | 672 | } |
[email protected] | 24a9f1c9 | 2013-11-13 12:33:37 | [diff] [blame] | 673 | profile_policy_connector_.reset(new policy::ProfilePolicyConnector()); |
[email protected] | a43b9a8 | 2013-11-28 16:56:41 | [diff] [blame] | 674 | profile_policy_connector_->InitForTesting(policy_service_.Pass()); |
[email protected] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 675 | policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting( |
| 676 | this, profile_policy_connector_.get()); |
| 677 | CHECK_EQ(profile_policy_connector_.get(), |
| 678 | policy::ProfilePolicyConnectorFactory::GetForProfile(this)); |
| 679 | } |
| 680 | |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 681 | PrefService* TestingProfile::GetPrefs() { |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 682 | if (!prefs_.get()) { |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 683 | CreateTestingPrefService(); |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 684 | } |
| 685 | return prefs_.get(); |
| 686 | } |
| 687 | |
| 688 | history::TopSites* TestingProfile::GetTopSites() { |
[email protected] | 809cc4d | 2010-10-27 15:22:54 | [diff] [blame] | 689 | return top_sites_.get(); |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 690 | } |
| 691 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 692 | history::TopSites* TestingProfile::GetTopSitesWithoutCreating() { |
| 693 | return top_sites_.get(); |
| 694 | } |
| 695 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 696 | DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() { |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 697 | return NULL; |
| 698 | } |
| 699 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 700 | net::URLRequestContextGetter* TestingProfile::GetRequestContext() { |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 701 | return GetDefaultStoragePartition(this)->GetURLRequestContext(); |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 702 | } |
| 703 | |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 704 | net::URLRequestContextGetter* TestingProfile::CreateRequestContext( |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 705 | content::ProtocolHandlerMap* protocol_handlers) { |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 706 | return new net::TestURLRequestContextGetter( |
| 707 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 708 | } |
| 709 | |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 710 | net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess( |
| 711 | int renderer_child_id) { |
[email protected] | fb29e6cf | 2012-07-12 21:27:20 | [diff] [blame] | 712 | content::RenderProcessHost* rph = content::RenderProcessHost::FromID( |
| 713 | renderer_child_id); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 714 | return rph->GetStoragePartition()->GetURLRequestContext(); |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 715 | } |
| 716 | |
[email protected] | 10705a7b | 2012-08-21 19:07:08 | [diff] [blame] | 717 | net::URLRequestContextGetter* TestingProfile::GetMediaRequestContext() { |
| 718 | return NULL; |
| 719 | } |
| 720 | |
| 721 | net::URLRequestContextGetter* |
| 722 | TestingProfile::GetMediaRequestContextForRenderProcess( |
| 723 | int renderer_child_id) { |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 724 | return NULL; |
| 725 | } |
| 726 | |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 727 | net::URLRequestContextGetter* |
| 728 | TestingProfile::GetMediaRequestContextForStoragePartition( |
[email protected] | 152ea30 | 2013-02-11 04:08:40 | [diff] [blame] | 729 | const base::FilePath& partition_path, |
[email protected] | 27ddfed2 | 2012-10-30 23:22:43 | [diff] [blame] | 730 | bool in_memory) { |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 731 | return NULL; |
| 732 | } |
| 733 | |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 734 | void TestingProfile::RequestMidiSysExPermission( |
[email protected] | 8aca725 | 2013-07-12 19:18:59 | [diff] [blame] | 735 | int render_process_id, |
| 736 | int render_view_id, |
[email protected] | 00880a0 | 2013-10-30 03:18:30 | [diff] [blame] | 737 | int bridge_id, |
[email protected] | 8aca725 | 2013-07-12 19:18:59 | [diff] [blame] | 738 | const GURL& requesting_frame, |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 739 | const MidiSysExPermissionCallback& callback) { |
[email protected] | 8aca725 | 2013-07-12 19:18:59 | [diff] [blame] | 740 | // Always reject requests for testing. |
| 741 | callback.Run(false); |
| 742 | } |
| 743 | |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 744 | void TestingProfile::CancelMidiSysExPermissionRequest( |
[email protected] | 00880a0 | 2013-10-30 03:18:30 | [diff] [blame] | 745 | int render_process_id, |
| 746 | int render_view_id, |
| 747 | int bridge_id, |
| 748 | const GURL& requesting_frame) { |
| 749 | } |
| 750 | |
[email protected] | 566755f8 | 2014-01-08 01:14:57 | [diff] [blame] | 751 | void TestingProfile::RequestProtectedMediaIdentifierPermission( |
| 752 | int render_process_id, |
| 753 | int render_view_id, |
| 754 | int bridge_id, |
| 755 | int group_id, |
| 756 | const GURL& requesting_frame, |
| 757 | const ProtectedMediaIdentifierPermissionCallback& callback) { |
| 758 | // Always reject requests for testing. |
| 759 | callback.Run(false); |
| 760 | } |
| 761 | |
| 762 | void TestingProfile::CancelProtectedMediaIdentifierPermissionRequests( |
| 763 | int group_id) { |
| 764 | } |
| 765 | |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 766 | net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() { |
| 767 | if (!extensions_request_context_.get()) |
| 768 | extensions_request_context_ = new TestExtensionURLRequestContextGetter(); |
| 769 | return extensions_request_context_.get(); |
| 770 | } |
| 771 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 772 | net::SSLConfigService* TestingProfile::GetSSLConfigService() { |
[email protected] | dc6655b | 2012-12-14 05:58:24 | [diff] [blame] | 773 | if (!GetRequestContext()) |
| 774 | return NULL; |
| 775 | return GetRequestContext()->GetURLRequestContext()->ssl_config_service(); |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 776 | } |
| 777 | |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 778 | net::URLRequestContextGetter* |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 779 | TestingProfile::CreateRequestContextForStoragePartition( |
[email protected] | 152ea30 | 2013-02-11 04:08:40 | [diff] [blame] | 780 | const base::FilePath& partition_path, |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 781 | bool in_memory, |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 782 | content::ProtocolHandlerMap* protocol_handlers) { |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 783 | // We don't test storage partitions here yet, so returning the same dummy |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 784 | // context is sufficient for now. |
| 785 | return GetRequestContext(); |
| 786 | } |
| 787 | |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 788 | content::ResourceContext* TestingProfile::GetResourceContext() { |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 789 | if (!resource_context_) |
| 790 | resource_context_ = new content::MockResourceContext(); |
| 791 | return resource_context_; |
[email protected] | e89b77d | 2011-04-15 18:58:10 | [diff] [blame] | 792 | } |
| 793 | |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 794 | HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() { |
[email protected] | 35552dc5 | 2011-07-12 09:04:38 | [diff] [blame] | 795 | if (!host_content_settings_map_.get()) { |
[email protected] | 646c29cb6 | 2012-06-18 14:31:05 | [diff] [blame] | 796 | host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false); |
[email protected] | 701550ad | 2012-09-06 23:43:29 | [diff] [blame] | 797 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | 646c29cb6 | 2012-06-18 14:31:05 | [diff] [blame] | 798 | ExtensionService* extension_service = GetExtensionService(); |
| 799 | if (extension_service) |
| 800 | host_content_settings_map_->RegisterExtensionService(extension_service); |
[email protected] | 701550ad | 2012-09-06 23:43:29 | [diff] [blame] | 801 | #endif |
[email protected] | 35552dc5 | 2011-07-12 09:04:38 | [diff] [blame] | 802 | } |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 803 | return host_content_settings_map_.get(); |
| 804 | } |
| 805 | |
[email protected] | 810ddc5 | 2012-01-24 01:00:35 | [diff] [blame] | 806 | content::GeolocationPermissionContext* |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 807 | TestingProfile::GetGeolocationPermissionContext() { |
[email protected] | a877a7d | 2013-01-08 13:40:59 | [diff] [blame] | 808 | return ChromeGeolocationPermissionContextFactory::GetForProfile(this); |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 809 | } |
| 810 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 811 | std::wstring TestingProfile::GetName() { |
| 812 | return std::wstring(); |
| 813 | } |
| 814 | |
| 815 | std::wstring TestingProfile::GetID() { |
| 816 | return id_; |
| 817 | } |
| 818 | |
| 819 | void TestingProfile::SetID(const std::wstring& id) { |
| 820 | id_ = id; |
| 821 | } |
| 822 | |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 823 | bool TestingProfile::IsSameProfile(Profile *p) { |
| 824 | return this == p; |
| 825 | } |
| 826 | |
| 827 | base::Time TestingProfile::GetStartTime() const { |
| 828 | return start_time_; |
| 829 | } |
| 830 | |
[email protected] | 152ea30 | 2013-02-11 04:08:40 | [diff] [blame] | 831 | base::FilePath TestingProfile::last_selected_directory() { |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 832 | return last_selected_directory_; |
| 833 | } |
| 834 | |
[email protected] | 152ea30 | 2013-02-11 04:08:40 | [diff] [blame] | 835 | void TestingProfile::set_last_selected_directory(const base::FilePath& path) { |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 836 | last_selected_directory_ = path; |
| 837 | } |
| 838 | |
[email protected] | cc5bfd4 | 2010-11-24 14:44:02 | [diff] [blame] | 839 | PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() { |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 840 | if (!pref_proxy_config_tracker_.get()) { |
[email protected] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 841 | // TestingProfile is used in unit tests, where local state is not available. |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 842 | pref_proxy_config_tracker_.reset( |
[email protected] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 843 | ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(GetPrefs(), |
| 844 | NULL)); |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 845 | } |
| 846 | return pref_proxy_config_tracker_.get(); |
[email protected] | cc5bfd4 | 2010-11-24 14:44:02 | [diff] [blame] | 847 | } |
| 848 | |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 849 | void TestingProfile::BlockUntilHistoryProcessesPendingRequests() { |
[email protected] | a5894fe | 2012-11-01 14:40:56 | [diff] [blame] | 850 | HistoryService* history_service = |
[email protected] | 6c53704 | 2012-07-13 00:59:02 | [diff] [blame] | 851 | HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS); |
[email protected] | a5894fe | 2012-11-01 14:40:56 | [diff] [blame] | 852 | DCHECK(history_service); |
[email protected] | bb024fe | 2013-05-10 21:33:26 | [diff] [blame] | 853 | DCHECK(base::MessageLoop::current()); |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 854 | |
| 855 | CancelableRequestConsumer consumer; |
[email protected] | f61f478 | 2012-06-08 21:54:21 | [diff] [blame] | 856 | history_service->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer); |
[email protected] | bb024fe | 2013-05-10 21:33:26 | [diff] [blame] | 857 | base::MessageLoop::current()->Run(); |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 858 | } |
[email protected] | 345a8b7 | 2009-09-29 09:11:44 | [diff] [blame] | 859 | |
[email protected] | 8382d8c | 2011-09-15 03:43:17 | [diff] [blame] | 860 | chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() { |
| 861 | return NULL; |
| 862 | } |
| 863 | |
[email protected] | e0e1fc2 | 2012-11-05 20:25:36 | [diff] [blame] | 864 | void TestingProfile::ClearNetworkingHistorySince( |
| 865 | base::Time time, |
| 866 | const base::Closure& completion) { |
| 867 | if (!completion.is_null()) { |
| 868 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion); |
| 869 | } |
[email protected] | 02896a8 | 2011-09-21 18:54:32 | [diff] [blame] | 870 | } |
| 871 | |
[email protected] | 671f9c6 | 2011-10-28 19:22:07 | [diff] [blame] | 872 | GURL TestingProfile::GetHomePage() { |
| 873 | return GURL(chrome::kChromeUINewTabURL); |
| 874 | } |
| 875 | |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 876 | PrefService* TestingProfile::GetOffTheRecordPrefs() { |
[email protected] | fadc607b6 | 2011-02-07 17:55:50 | [diff] [blame] | 877 | return NULL; |
| 878 | } |
| 879 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 880 | quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { |
| 881 | return GetExtensionSpecialStoragePolicy(); |
| 882 | } |
| 883 | |
[email protected] | 1bee6ed | 2012-03-14 06:46:36 | [diff] [blame] | 884 | bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) { |
| 885 | return true; |
| 886 | } |
[email protected] | ef92e17 | 2012-04-25 19:40:41 | [diff] [blame] | 887 | |
[email protected] | 4251165a | 2013-07-17 04:33:40 | [diff] [blame] | 888 | bool TestingProfile::IsGuestSession() const { |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 889 | return guest_session_; |
[email protected] | 4251165a | 2013-07-17 04:33:40 | [diff] [blame] | 890 | } |
[email protected] | 1101dbc5 | 2013-10-05 00:19:12 | [diff] [blame] | 891 | |
[email protected] | 6c0ca7fc | 2012-10-05 16:27:22 | [diff] [blame] | 892 | Profile::ExitType TestingProfile::GetLastSessionExitType() { |
| 893 | return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED; |
[email protected] | 2ca1ea66 | 2012-10-04 02:26:36 | [diff] [blame] | 894 | } |
| 895 | |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 896 | TestingProfile::Builder::Builder() |
| 897 | : build_called_(false), |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 898 | delegate_(NULL), |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 899 | incognito_(false), |
| 900 | guest_session_(false) { |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | TestingProfile::Builder::~Builder() { |
| 904 | } |
| 905 | |
[email protected] | 152ea30 | 2013-02-11 04:08:40 | [diff] [blame] | 906 | void TestingProfile::Builder::SetPath(const base::FilePath& path) { |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 907 | path_ = path; |
| 908 | } |
| 909 | |
| 910 | void TestingProfile::Builder::SetDelegate(Delegate* delegate) { |
| 911 | delegate_ = delegate; |
| 912 | } |
| 913 | |
| 914 | void TestingProfile::Builder::SetExtensionSpecialStoragePolicy( |
| 915 | scoped_refptr<ExtensionSpecialStoragePolicy> policy) { |
| 916 | extension_policy_ = policy; |
| 917 | } |
| 918 | |
[email protected] | 5b19952 | 2012-12-22 17:24:44 | [diff] [blame] | 919 | void TestingProfile::Builder::SetPrefService( |
| 920 | scoped_ptr<PrefServiceSyncable> prefs) { |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 921 | pref_service_ = prefs.Pass(); |
| 922 | } |
| 923 | |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 924 | void TestingProfile::Builder::SetIncognito() { |
| 925 | incognito_ = true; |
| 926 | } |
| 927 | |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 928 | void TestingProfile::Builder::SetGuestSession() { |
| 929 | guest_session_ = true; |
| 930 | } |
| 931 | |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 932 | void TestingProfile::Builder::SetManagedUserId( |
| 933 | const std::string& managed_user_id) { |
| 934 | managed_user_id_ = managed_user_id; |
| 935 | } |
| 936 | |
[email protected] | a43b9a8 | 2013-11-28 16:56:41 | [diff] [blame] | 937 | void TestingProfile::Builder::SetPolicyService( |
| 938 | scoped_ptr<policy::PolicyService> policy_service) { |
| 939 | policy_service_ = policy_service.Pass(); |
| 940 | } |
| 941 | |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 942 | void TestingProfile::Builder::AddTestingFactory( |
| 943 | BrowserContextKeyedServiceFactory* service_factory, |
[email protected] | d45c5d5 | 2013-12-04 23:41:16 | [diff] [blame] | 944 | BrowserContextKeyedServiceFactory::TestingFactoryFunction callback) { |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 945 | testing_factories_.push_back(std::make_pair(service_factory, callback)); |
| 946 | } |
| 947 | |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 948 | scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { |
| 949 | DCHECK(!build_called_); |
| 950 | build_called_ = true; |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 951 | |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 952 | return scoped_ptr<TestingProfile>(new TestingProfile( |
| 953 | path_, |
| 954 | delegate_, |
| 955 | extension_policy_, |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 956 | pref_service_.Pass(), |
| 957 | incognito_, |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 958 | guest_session_, |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 959 | managed_user_id_, |
[email protected] | a43b9a8 | 2013-11-28 16:56:41 | [diff] [blame] | 960 | policy_service_.Pass(), |
[email protected] | 9819fd0 | 2013-08-22 10:49:39 | [diff] [blame] | 961 | testing_factories_)); |
[email protected] | 5c4c89f | 2012-08-07 21:09:59 | [diff] [blame] | 962 | } |