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