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