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