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