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