| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/testing_profile.h" | 5 #include "chrome/test/testing_profile.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 10 #include "chrome/browser/dom_ui/ntp_resource_cache.h" | 10 #include "chrome/browser/dom_ui/ntp_resource_cache.h" |
| 11 #include "chrome/browser/history/history_backend.h" | 11 #include "chrome/browser/history/history_backend.h" |
| 12 #include "chrome/browser/net/url_request_context_getter.h" |
| 12 #include "chrome/browser/sync/profile_sync_service.h" | 13 #include "chrome/browser/sync/profile_sync_service.h" |
| 13 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 15 #include "net/url_request/url_request_context.h" |
| 14 #include "webkit/database/database_tracker.h" | 16 #include "webkit/database/database_tracker.h" |
| 15 | 17 |
| 16 #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) | 18 #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) |
| 17 #include "chrome/browser/gtk/gtk_theme_provider.h" | 19 #include "chrome/browser/gtk/gtk_theme_provider.h" |
| 18 #endif | 20 #endif |
| 19 | 21 |
| 20 using base::Time; | 22 using base::Time; |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 const BookmarkNode* node) {} | 71 const BookmarkNode* node) {} |
| 70 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, | 72 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, |
| 71 const BookmarkNode* node) {} | 73 const BookmarkNode* node) {} |
| 72 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, | 74 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, |
| 73 const BookmarkNode* node) {} | 75 const BookmarkNode* node) {} |
| 74 | 76 |
| 75 private: | 77 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadObserver); | 78 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadObserver); |
| 77 }; | 79 }; |
| 78 | 80 |
| 81 // This context is used to assist testing the CookieMonster by providing a |
| 82 // valid CookieStore. This can probably be expanded to test other aspects of |
| 83 // the context as well. |
| 84 class TestURLRequestContext : public URLRequestContext { |
| 85 public: |
| 86 TestURLRequestContext() { |
| 87 cookie_store_ = new net::CookieMonster(); |
| 88 } |
| 89 }; |
| 90 |
| 91 // Used to return a dummy context (normally the context is on the IO thread). |
| 92 // The one here can be run on the main test thread. Note that this can lead to |
| 93 // a leak if your test does not have a ChromeThread::IO in it because |
| 94 // URLRequestContextGetter is defined as a ReferenceCounted object with a |
| 95 // DeleteOnIOThread trait. |
| 96 class TestURLRequestContextGetter : public URLRequestContextGetter { |
| 97 public: |
| 98 virtual URLRequestContext* GetURLRequestContext() { |
| 99 if (!context_) |
| 100 context_ = new TestURLRequestContext(); |
| 101 return context_.get(); |
| 102 } |
| 103 |
| 104 private: |
| 105 scoped_refptr<URLRequestContext> context_; |
| 106 }; |
| 107 |
| 79 } // namespace | 108 } // namespace |
| 80 | 109 |
| 81 TestingProfile::TestingProfile() | 110 TestingProfile::TestingProfile() |
| 82 : start_time_(Time::Now()), | 111 : start_time_(Time::Now()), |
| 83 created_theme_provider_(false), | 112 created_theme_provider_(false), |
| 84 has_history_service_(false), | 113 has_history_service_(false), |
| 85 off_the_record_(false), | 114 off_the_record_(false), |
| 86 last_session_exited_cleanly_(true) { | 115 last_session_exited_cleanly_(true) { |
| 87 PathService::Get(base::DIR_TEMP, &path_); | 116 PathService::Get(base::DIR_TEMP, &path_); |
| 88 path_ = path_.Append(FILE_PATH_LITERAL("TestingProfilePath")); | 117 path_ = path_.Append(FILE_PATH_LITERAL("TestingProfilePath")); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) | 224 #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) |
| 196 theme_provider_.reset(new GtkThemeProvider); | 225 theme_provider_.reset(new GtkThemeProvider); |
| 197 #else | 226 #else |
| 198 theme_provider_.reset(new BrowserThemeProvider); | 227 theme_provider_.reset(new BrowserThemeProvider); |
| 199 #endif | 228 #endif |
| 200 theme_provider_->Init(this); | 229 theme_provider_->Init(this); |
| 201 created_theme_provider_ = true; | 230 created_theme_provider_ = true; |
| 202 } | 231 } |
| 203 } | 232 } |
| 204 | 233 |
| 234 URLRequestContextGetter* TestingProfile::GetRequestContext() { |
| 235 return request_context_.get(); |
| 236 } |
| 237 |
| 238 void TestingProfile::CreateRequestContext() { |
| 239 if (!request_context_) |
| 240 request_context_ = new TestURLRequestContextGetter(); |
| 241 } |
| 242 |
| 205 NTPResourceCache* TestingProfile::GetNTPResourceCache() { | 243 NTPResourceCache* TestingProfile::GetNTPResourceCache() { |
| 206 if (!ntp_resource_cache_.get()) | 244 if (!ntp_resource_cache_.get()) |
| 207 ntp_resource_cache_.reset(new NTPResourceCache(this)); | 245 ntp_resource_cache_.reset(new NTPResourceCache(this)); |
| 208 return ntp_resource_cache_.get(); | 246 return ntp_resource_cache_.get(); |
| 209 } | 247 } |
| 210 | 248 |
| 211 void TestingProfile::BlockUntilHistoryProcessesPendingRequests() { | 249 void TestingProfile::BlockUntilHistoryProcessesPendingRequests() { |
| 212 DCHECK(history_service_.get()); | 250 DCHECK(history_service_.get()); |
| 213 DCHECK(MessageLoop::current()); | 251 DCHECK(MessageLoop::current()); |
| 214 | 252 |
| 215 CancelableRequestConsumer consumer; | 253 CancelableRequestConsumer consumer; |
| 216 history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer); | 254 history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer); |
| 217 MessageLoop::current()->Run(); | 255 MessageLoop::current()->Run(); |
| 218 } | 256 } |
| 219 | 257 |
| 220 void TestingProfile::CreateProfileSyncService() { | 258 void TestingProfile::CreateProfileSyncService() { |
| 221 if (!profile_sync_service_.get()) { | 259 if (!profile_sync_service_.get()) { |
| 222 profile_sync_service_.reset(new ProfileSyncService(this)); | 260 profile_sync_service_.reset(new ProfileSyncService(this)); |
| 223 profile_sync_service_->Initialize(); | 261 profile_sync_service_->Initialize(); |
| 224 } | 262 } |
| 225 } | 263 } |
| 226 | 264 |
| 227 ProfileSyncService* TestingProfile::GetProfileSyncService() { | 265 ProfileSyncService* TestingProfile::GetProfileSyncService() { |
| 228 return profile_sync_service_.get(); | 266 return profile_sync_service_.get(); |
| 229 } | 267 } |
| OLD | NEW |