[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame] | 1 | // Copyright (c) 2010 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] | e3e43d9 | 2010-02-26 22:02:38 | [diff] [blame] | 8 | #include "base/command_line.h" |
[email protected] | 83a7d2eb | 2010-05-03 21:46:19 | [diff] [blame] | 9 | #include "base/message_loop_proxy.h" |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame^] | 10 | #include "base/string_number_conversions.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 11 | #include "chrome/common/url_constants.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 12 | #include "chrome/browser/bookmarks/bookmark_model.h" |
[email protected] | 156ed27b | 2009-11-23 18:31:25 | [diff] [blame] | 13 | #include "chrome/browser/dom_ui/ntp_resource_cache.h" |
[email protected] | 075ae73 | 2009-02-11 23:58:31 | [diff] [blame] | 14 | #include "chrome/browser/history/history_backend.h" |
[email protected] | 8e4c2961 | 2010-07-14 01:24:45 | [diff] [blame] | 15 | #include "chrome/browser/net/gaia/token_service.h" |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 16 | #include "chrome/browser/sessions/session_service.h" |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 17 | #include "chrome/browser/sync/profile_sync_service_mock.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 18 | #include "chrome/common/chrome_constants.h" |
[email protected] | 68d2a05f | 2010-05-07 21:39:55 | [diff] [blame] | 19 | #include "chrome/common/net/url_request_context_getter.h" |
[email protected] | d2879af | 2010-02-08 16:02:56 | [diff] [blame] | 20 | #include "chrome/common/notification_service.h" |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 21 | #include "net/url_request/url_request_context.h" |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 22 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | 2f351cb | 2009-11-09 23:43:34 | [diff] [blame] | 23 | #include "webkit/database/database_tracker.h" |
[email protected] | 4bcac78 | 2009-02-10 02:48:27 | [diff] [blame] | 24 | |
[email protected] | a42b559 | 2009-09-03 16:52:23 | [diff] [blame] | 25 | #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) |
| 26 | #include "chrome/browser/gtk/gtk_theme_provider.h" |
| 27 | #endif |
| 28 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 29 | using base::Time; |
[email protected] | 3c88741 | 2010-04-19 20:30:23 | [diff] [blame] | 30 | using testing::NiceMock; |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 31 | using testing::Return; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 32 | |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 33 | namespace { |
| 34 | |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 35 | // Task used to make sure history has finished processing a request. Intended |
| 36 | // for use with BlockUntilHistoryProcessesPendingRequests. |
| 37 | |
| 38 | class QuittingHistoryDBTask : public HistoryDBTask { |
| 39 | public: |
| 40 | QuittingHistoryDBTask() {} |
| 41 | |
| 42 | virtual bool RunOnDBThread(history::HistoryBackend* backend, |
| 43 | history::HistoryDatabase* db) { |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | virtual void DoneRunOnMainThread() { |
| 48 | MessageLoop::current()->Quit(); |
| 49 | } |
| 50 | |
| 51 | private: |
[email protected] | 7991a23 | 2009-11-06 01:55:48 | [diff] [blame] | 52 | ~QuittingHistoryDBTask() {} |
| 53 | |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 54 | DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask); |
| 55 | }; |
| 56 | |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 57 | // BookmarkLoadObserver is used when blocking until the BookmarkModel |
| 58 | // finishes loading. As soon as the BookmarkModel finishes loading the message |
| 59 | // loop is quit. |
| 60 | class BookmarkLoadObserver : public BookmarkModelObserver { |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 61 | public: |
| 62 | BookmarkLoadObserver() {} |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 63 | virtual void Loaded(BookmarkModel* model) { |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 64 | MessageLoop::current()->Quit(); |
| 65 | } |
| 66 | |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 67 | virtual void BookmarkNodeMoved(BookmarkModel* model, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 68 | const BookmarkNode* old_parent, |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 69 | int old_index, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 70 | const BookmarkNode* new_parent, |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 71 | int new_index) {} |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 72 | virtual void BookmarkNodeAdded(BookmarkModel* model, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 73 | const BookmarkNode* parent, |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 74 | int index) {} |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 75 | virtual void BookmarkNodeRemoved(BookmarkModel* model, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 76 | const BookmarkNode* parent, |
[email protected] | 6696502 | 2009-07-15 17:20:01 | [diff] [blame] | 77 | int old_index, |
| 78 | const BookmarkNode* node) {} |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 79 | virtual void BookmarkNodeChanged(BookmarkModel* model, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 80 | const BookmarkNode* node) {} |
[email protected] | 58b359d | 2009-02-27 22:05:08 | [diff] [blame] | 81 | virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 82 | const BookmarkNode* node) {} |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 83 | virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 84 | const BookmarkNode* node) {} |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 85 | |
| 86 | private: |
| 87 | DISALLOW_COPY_AND_ASSIGN(BookmarkLoadObserver); |
| 88 | }; |
| 89 | |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 90 | // This context is used to assist testing the CookieMonster by providing a |
| 91 | // valid CookieStore. This can probably be expanded to test other aspects of |
| 92 | // the context as well. |
| 93 | class TestURLRequestContext : public URLRequestContext { |
| 94 | public: |
| 95 | TestURLRequestContext() { |
[email protected] | 0f7066e | 2010-03-25 08:31:47 | [diff] [blame] | 96 | cookie_store_ = new net::CookieMonster(NULL, NULL); |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 97 | } |
| 98 | }; |
| 99 | |
| 100 | // Used to return a dummy context (normally the context is on the IO thread). |
| 101 | // The one here can be run on the main test thread. Note that this can lead to |
| 102 | // a leak if your test does not have a ChromeThread::IO in it because |
| 103 | // URLRequestContextGetter is defined as a ReferenceCounted object with a |
[email protected] | 83a7d2eb | 2010-05-03 21:46:19 | [diff] [blame] | 104 | // special trait that deletes it on the IO thread. |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 105 | class TestURLRequestContextGetter : public URLRequestContextGetter { |
| 106 | public: |
| 107 | virtual URLRequestContext* GetURLRequestContext() { |
| 108 | if (!context_) |
| 109 | context_ = new TestURLRequestContext(); |
| 110 | return context_.get(); |
| 111 | } |
[email protected] | 656475d | 2010-05-06 18:34:24 | [diff] [blame] | 112 | virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() { |
[email protected] | 83a7d2eb | 2010-05-03 21:46:19 | [diff] [blame] | 113 | return ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO); |
| 114 | } |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 115 | |
| 116 | private: |
| 117 | scoped_refptr<URLRequestContext> context_; |
| 118 | }; |
| 119 | |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 120 | class TestExtensionURLRequestContext : public URLRequestContext { |
| 121 | public: |
| 122 | TestExtensionURLRequestContext() { |
| 123 | net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); |
| 124 | const char* schemes[] = {chrome::kExtensionScheme}; |
| 125 | cookie_monster->SetCookieableSchemes(schemes, 1); |
| 126 | cookie_store_ = cookie_monster; |
| 127 | } |
| 128 | }; |
| 129 | |
| 130 | class TestExtensionURLRequestContextGetter : public URLRequestContextGetter { |
| 131 | public: |
| 132 | virtual URLRequestContext* GetURLRequestContext() { |
| 133 | if (!context_) |
| 134 | context_ = new TestExtensionURLRequestContext(); |
| 135 | return context_.get(); |
| 136 | } |
[email protected] | 656475d | 2010-05-06 18:34:24 | [diff] [blame] | 137 | virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() { |
[email protected] | 83a7d2eb | 2010-05-03 21:46:19 | [diff] [blame] | 138 | return ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO); |
| 139 | } |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 140 | |
| 141 | private: |
| 142 | scoped_refptr<URLRequestContext> context_; |
| 143 | }; |
| 144 | |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 145 | } // namespace |
| 146 | |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 147 | TestingProfile::TestingProfile() |
[email protected] | ea6f7657 | 2008-12-18 00:09:55 | [diff] [blame] | 148 | : start_time_(Time::Now()), |
[email protected] | a42b559 | 2009-09-03 16:52:23 | [diff] [blame] | 149 | created_theme_provider_(false), |
[email protected] | ea6f7657 | 2008-12-18 00:09:55 | [diff] [blame] | 150 | has_history_service_(false), |
| 151 | off_the_record_(false), |
| 152 | last_session_exited_cleanly_(true) { |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 153 | PathService::Get(base::DIR_TEMP, &path_); |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 154 | path_ = path_.Append(FILE_PATH_LITERAL("TestingProfilePath")); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 155 | file_util::Delete(path_, true); |
| 156 | file_util::CreateDirectory(path_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 157 | } |
| 158 | |
[email protected] | 848cd05e | 2008-09-19 18:33:48 | [diff] [blame] | 159 | TestingProfile::TestingProfile(int count) |
[email protected] | ea6f7657 | 2008-12-18 00:09:55 | [diff] [blame] | 160 | : start_time_(Time::Now()), |
[email protected] | a6caa7e | 2009-09-25 21:03:51 | [diff] [blame] | 161 | created_theme_provider_(false), |
[email protected] | ea6f7657 | 2008-12-18 00:09:55 | [diff] [blame] | 162 | has_history_service_(false), |
| 163 | off_the_record_(false), |
| 164 | last_session_exited_cleanly_(true) { |
[email protected] | 848cd05e | 2008-09-19 18:33:48 | [diff] [blame] | 165 | PathService::Get(base::DIR_TEMP, &path_); |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 166 | path_ = path_.Append(FILE_PATH_LITERAL("TestingProfilePath")); |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame^] | 167 | path_ = path_.AppendASCII(base::IntToString(count)); |
[email protected] | 848cd05e | 2008-09-19 18:33:48 | [diff] [blame] | 168 | file_util::Delete(path_, true); |
| 169 | file_util::CreateDirectory(path_); |
| 170 | } |
| 171 | |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 172 | TestingProfile::~TestingProfile() { |
[email protected] | d2879af | 2010-02-08 16:02:56 | [diff] [blame] | 173 | NotificationService::current()->Notify( |
| 174 | NotificationType::PROFILE_DESTROYED, |
| 175 | Source<Profile>(this), |
| 176 | NotificationService::NoDetails()); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 177 | DestroyHistoryService(); |
[email protected] | d2879af | 2010-02-08 16:02:56 | [diff] [blame] | 178 | // FaviconService depends on HistoryServce so destroying it later. |
| 179 | DestroyFaviconService(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 180 | DestroyWebDataService(); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 181 | file_util::Delete(path_, true); |
| 182 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 183 | |
[email protected] | d2879af | 2010-02-08 16:02:56 | [diff] [blame] | 184 | void TestingProfile::CreateFaviconService() { |
| 185 | favicon_service_ = NULL; |
| 186 | favicon_service_ = new FaviconService(this); |
| 187 | } |
| 188 | |
[email protected] | d486a085 | 2009-11-02 21:40:00 | [diff] [blame] | 189 | void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 190 | if (history_service_.get()) |
| 191 | history_service_->Cleanup(); |
| 192 | |
| 193 | history_service_ = NULL; |
| 194 | |
| 195 | if (delete_file) { |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 196 | FilePath path = GetPath(); |
| 197 | path = path.Append(chrome::kHistoryFilename); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 198 | file_util::Delete(path, false); |
| 199 | } |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 200 | history_service_ = new HistoryService(this); |
[email protected] | d486a085 | 2009-11-02 21:40:00 | [diff] [blame] | 201 | history_service_->Init(GetPath(), bookmark_bar_model_.get(), no_db); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 202 | } |
| 203 | |
[email protected] | d2879af | 2010-02-08 16:02:56 | [diff] [blame] | 204 | void TestingProfile::DestroyFaviconService() { |
| 205 | if (!favicon_service_.get()) |
| 206 | return; |
| 207 | favicon_service_ = NULL; |
| 208 | } |
| 209 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 210 | void TestingProfile::DestroyHistoryService() { |
| 211 | if (!history_service_.get()) |
| 212 | return; |
| 213 | |
| 214 | history_service_->NotifyRenderProcessHostDestruction(0); |
| 215 | history_service_->SetOnBackendDestroyTask(new MessageLoop::QuitTask); |
| 216 | history_service_->Cleanup(); |
| 217 | history_service_ = NULL; |
| 218 | |
| 219 | // Wait for the backend class to terminate before deleting the files and |
| 220 | // moving to the next test. Note: if this never terminates, somebody is |
| 221 | // probably leaking a reference to the history backend, so it never calls |
| 222 | // our destroy task. |
| 223 | MessageLoop::current()->Run(); |
| 224 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 225 | // Make sure we don't have any event pending that could disrupt the next |
| 226 | // test. |
| 227 | MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); |
| 228 | MessageLoop::current()->Run(); |
| 229 | } |
[email protected] | 4d0cd7ce | 2008-08-11 16:40:57 | [diff] [blame] | 230 | |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 231 | void TestingProfile::CreateBookmarkModel(bool delete_file) { |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 232 | // Nuke the model first, that way we're sure it's done writing to disk. |
| 233 | bookmark_bar_model_.reset(NULL); |
| 234 | |
| 235 | if (delete_file) { |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 236 | FilePath path = GetPath(); |
| 237 | path = path.Append(chrome::kBookmarksFileName); |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 238 | file_util::Delete(path, false); |
| 239 | } |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 240 | bookmark_bar_model_.reset(new BookmarkModel(this)); |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 241 | if (history_service_.get()) { |
| 242 | history_service_->history_backend_->bookmark_service_ = |
| 243 | bookmark_bar_model_.get(); |
| 244 | history_service_->history_backend_->expirer_.bookmark_service_ = |
| 245 | bookmark_bar_model_.get(); |
| 246 | } |
| 247 | bookmark_bar_model_->Load(); |
[email protected] | 4d0cd7ce | 2008-08-11 16:40:57 | [diff] [blame] | 248 | } |
[email protected] | d2c017a | 2008-08-13 21:51:45 | [diff] [blame] | 249 | |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame] | 250 | void TestingProfile::CreateAutocompleteClassifier() { |
| 251 | autocomplete_classifier_.reset(new AutocompleteClassifier(this)); |
| 252 | } |
| 253 | |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 254 | void TestingProfile::CreateWebDataService(bool delete_file) { |
| 255 | if (web_data_service_.get()) |
| 256 | web_data_service_->Shutdown(); |
| 257 | |
| 258 | if (delete_file) { |
| 259 | FilePath path = GetPath(); |
| 260 | path = path.Append(chrome::kWebDataFilename); |
| 261 | file_util::Delete(path, false); |
| 262 | } |
| 263 | |
| 264 | web_data_service_ = new WebDataService; |
| 265 | if (web_data_service_.get()) |
| 266 | web_data_service_->Init(GetPath()); |
| 267 | } |
| 268 | |
[email protected] | d364c65 | 2008-08-29 19:46:56 | [diff] [blame] | 269 | void TestingProfile::BlockUntilBookmarkModelLoaded() { |
| 270 | DCHECK(bookmark_bar_model_.get()); |
| 271 | if (bookmark_bar_model_->IsLoaded()) |
| 272 | return; |
| 273 | BookmarkLoadObserver observer; |
| 274 | bookmark_bar_model_->AddObserver(&observer); |
| 275 | MessageLoop::current()->Run(); |
| 276 | bookmark_bar_model_->RemoveObserver(&observer); |
| 277 | DCHECK(bookmark_bar_model_->IsLoaded()); |
| 278 | } |
| 279 | |
[email protected] | d2c017a | 2008-08-13 21:51:45 | [diff] [blame] | 280 | void TestingProfile::CreateTemplateURLModel() { |
| 281 | template_url_model_.reset(new TemplateURLModel(this)); |
| 282 | } |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 283 | |
[email protected] | a42b559 | 2009-09-03 16:52:23 | [diff] [blame] | 284 | void TestingProfile::UseThemeProvider(BrowserThemeProvider* theme_provider) { |
| 285 | theme_provider->Init(this); |
| 286 | created_theme_provider_ = true; |
[email protected] | 761962c | 2009-09-25 00:18:15 | [diff] [blame] | 287 | theme_provider_.reset(theme_provider); |
[email protected] | a42b559 | 2009-09-03 16:52:23 | [diff] [blame] | 288 | } |
| 289 | |
[email protected] | 2f351cb | 2009-11-09 23:43:34 | [diff] [blame] | 290 | webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() { |
| 291 | if (!db_tracker_) |
[email protected] | fe615f3 | 2010-06-13 09:08:41 | [diff] [blame] | 292 | db_tracker_ = new webkit_database::DatabaseTracker(GetPath(), false); |
[email protected] | 2f351cb | 2009-11-09 23:43:34 | [diff] [blame] | 293 | return db_tracker_; |
| 294 | } |
| 295 | |
[email protected] | a42b559 | 2009-09-03 16:52:23 | [diff] [blame] | 296 | void TestingProfile::InitThemes() { |
| 297 | if (!created_theme_provider_) { |
| 298 | #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) |
[email protected] | 761962c | 2009-09-25 00:18:15 | [diff] [blame] | 299 | theme_provider_.reset(new GtkThemeProvider); |
[email protected] | a42b559 | 2009-09-03 16:52:23 | [diff] [blame] | 300 | #else |
[email protected] | 761962c | 2009-09-25 00:18:15 | [diff] [blame] | 301 | theme_provider_.reset(new BrowserThemeProvider); |
[email protected] | a42b559 | 2009-09-03 16:52:23 | [diff] [blame] | 302 | #endif |
[email protected] | 761962c | 2009-09-25 00:18:15 | [diff] [blame] | 303 | theme_provider_->Init(this); |
[email protected] | a42b559 | 2009-09-03 16:52:23 | [diff] [blame] | 304 | created_theme_provider_ = true; |
[email protected] | a42b559 | 2009-09-03 16:52:23 | [diff] [blame] | 305 | } |
[email protected] | 7668808 | 2009-05-16 07:04:42 | [diff] [blame] | 306 | } |
| 307 | |
[email protected] | 812b3a3 | 2010-01-08 05:36:04 | [diff] [blame] | 308 | URLRequestContextGetter* TestingProfile::GetRequestContext() { |
| 309 | return request_context_.get(); |
| 310 | } |
| 311 | |
| 312 | void TestingProfile::CreateRequestContext() { |
| 313 | if (!request_context_) |
| 314 | request_context_ = new TestURLRequestContextGetter(); |
| 315 | } |
| 316 | |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 317 | URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() { |
| 318 | if (!extensions_request_context_) |
| 319 | extensions_request_context_ = new TestExtensionURLRequestContextGetter(); |
| 320 | return extensions_request_context_.get(); |
| 321 | } |
| 322 | |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 323 | void TestingProfile::set_session_service(SessionService* session_service) { |
| 324 | session_service_ = session_service; |
| 325 | } |
| 326 | |
[email protected] | 156ed27b | 2009-11-23 18:31:25 | [diff] [blame] | 327 | NTPResourceCache* TestingProfile::GetNTPResourceCache() { |
| 328 | if (!ntp_resource_cache_.get()) |
| 329 | ntp_resource_cache_.reset(new NTPResourceCache(this)); |
| 330 | return ntp_resource_cache_.get(); |
| 331 | } |
| 332 | |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 333 | void TestingProfile::BlockUntilHistoryProcessesPendingRequests() { |
| 334 | DCHECK(history_service_.get()); |
| 335 | DCHECK(MessageLoop::current()); |
| 336 | |
| 337 | CancelableRequestConsumer consumer; |
| 338 | history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer); |
| 339 | MessageLoop::current()->Run(); |
| 340 | } |
[email protected] | 345a8b7 | 2009-09-29 09:11:44 | [diff] [blame] | 341 | |
[email protected] | 8e4c2961 | 2010-07-14 01:24:45 | [diff] [blame] | 342 | TokenService* TestingProfile::GetTokenService() { |
| 343 | if (!token_service_.get()) { |
| 344 | token_service_.reset(new TokenService()); |
| 345 | } |
| 346 | return token_service_.get(); |
| 347 | } |
| 348 | |
[email protected] | 345a8b7 | 2009-09-29 09:11:44 | [diff] [blame] | 349 | ProfileSyncService* TestingProfile::GetProfileSyncService() { |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 350 | if (!profile_sync_service_.get()) { |
[email protected] | 3c88741 | 2010-04-19 20:30:23 | [diff] [blame] | 351 | // Use a NiceMock here since we are really using the mock as a |
| 352 | // fake. Test cases that want to set expectations on a |
| 353 | // ProfileSyncService should use the ProfileMock and have this |
| 354 | // method return their own mock instance. |
| 355 | profile_sync_service_.reset(new NiceMock<ProfileSyncServiceMock>()); |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 356 | } |
[email protected] | 345a8b7 | 2009-09-29 09:11:44 | [diff] [blame] | 357 | return profile_sync_service_.get(); |
[email protected] | 345a8b7 | 2009-09-29 09:11:44 | [diff] [blame] | 358 | } |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 359 | |
| 360 | void TestingProfile::DestroyWebDataService() { |
| 361 | if (!web_data_service_.get()) |
| 362 | return; |
| 363 | |
| 364 | web_data_service_->Shutdown(); |
| 365 | } |