Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 17 #include "chrome/browser/browser_thread.h" | 17 #include "chrome/browser/browser_thread.h" |
| 18 #include "chrome/browser/dom_ui/ntp_resource_cache.h" | 18 #include "chrome/browser/dom_ui/ntp_resource_cache.h" |
| 19 #include "chrome/browser/extensions/extensions_service.h" | 19 #include "chrome/browser/extensions/extensions_service.h" |
| 20 #include "chrome/browser/favicon_service.h" | 20 #include "chrome/browser/favicon_service.h" |
| 21 #include "chrome/browser/find_bar_state.h" | 21 #include "chrome/browser/find_bar_state.h" |
| 22 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 22 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| 23 #include "chrome/browser/geolocation/geolocation_permission_context.h" | 23 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
| 24 #include "chrome/browser/history/history.h" | 24 #include "chrome/browser/history/history.h" |
| 25 #include "chrome/browser/history/history_backend.h" | 25 #include "chrome/browser/history/history_backend.h" |
| 26 #include "chrome/browser/history/top_sites.h" | 26 #include "chrome/browser/history/top_sites.h" |
| 27 #include "chrome/browser/host_content_settings_map.h" | 27 #include "chrome/browser/host_content_settings_map.h" |
| 28 #include "chrome/browser/in_process_webkit/webkit_context.h" | 28 #include "chrome/browser/in_process_webkit/webkit_context.h" |
| 29 #include "chrome/browser/net/gaia/token_service.h" | 29 #include "chrome/browser/net/gaia/token_service.h" |
| 30 #include "chrome/browser/net/pref_proxy_config_service.h" | |
| 30 #include "chrome/browser/notifications/desktop_notification_service.h" | 31 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 31 #include "chrome/browser/prefs/browser_prefs.h" | 32 #include "chrome/browser/prefs/browser_prefs.h" |
| 32 #include "chrome/browser/search_engines/template_url_fetcher.h" | 33 #include "chrome/browser/search_engines/template_url_fetcher.h" |
| 33 #include "chrome/browser/search_engines/template_url_model.h" | 34 #include "chrome/browser/search_engines/template_url_model.h" |
| 34 #include "chrome/browser/sessions/session_service.h" | 35 #include "chrome/browser/sessions/session_service.h" |
| 35 #include "chrome/browser/sync/profile_sync_service_mock.h" | 36 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 36 #include "chrome/browser/themes/browser_theme_provider.h" | 37 #include "chrome/browser/themes/browser_theme_provider.h" |
| 37 #include "chrome/common/chrome_constants.h" | 38 #include "chrome/common/chrome_constants.h" |
| 38 #include "chrome/common/net/url_request_context_getter.h" | 39 #include "chrome/common/net/url_request_context_getter.h" |
| 39 #include "chrome/common/notification_service.h" | 40 #include "chrome/common/notification_service.h" |
| 40 #include "chrome/common/url_constants.h" | 41 #include "chrome/common/url_constants.h" |
| 41 #include "chrome/test/testing_pref_service.h" | 42 #include "chrome/test/testing_pref_service.h" |
| 42 #include "chrome/test/test_url_request_context_getter.h" | |
| 43 #include "chrome/test/ui_test_utils.h" | 43 #include "chrome/test/ui_test_utils.h" |
| 44 #include "net/base/cookie_monster.h" | 44 #include "net/base/cookie_monster.h" |
| 45 #include "net/url_request/url_request_context.h" | 45 #include "net/url_request/url_request_context.h" |
| 46 #include "net/url_request/url_request_unittest.h" | 46 #include "net/url_request/url_request_unittest.h" |
| 47 #include "testing/gmock/include/gmock/gmock.h" | 47 #include "testing/gmock/include/gmock/gmock.h" |
| 48 #include "webkit/database/database_tracker.h" | 48 #include "webkit/database/database_tracker.h" |
| 49 | 49 |
| 50 #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) | 50 #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) |
| 51 #include "chrome/browser/gtk/gtk_theme_provider.h" | 51 #include "chrome/browser/gtk/gtk_theme_provider.h" |
| 52 #endif | 52 #endif |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 const BookmarkNode* node) {} | 105 const BookmarkNode* node) {} |
| 106 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, | 106 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, |
| 107 const BookmarkNode* node) {} | 107 const BookmarkNode* node) {} |
| 108 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, | 108 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, |
| 109 const BookmarkNode* node) {} | 109 const BookmarkNode* node) {} |
| 110 | 110 |
| 111 private: | 111 private: |
| 112 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadObserver); | 112 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadObserver); |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 // Used to return a dummy context (normally the context is on the IO thread). | |
| 116 // The one here can be run on the main test thread. Note that this can lead to | |
| 117 // a leak if your test does not have a BrowserThread::IO in it because | |
| 118 // URLRequestContextGetter is defined as a ReferenceCounted object with a | |
| 119 // special trait that deletes it on the IO thread. | |
| 120 class TestURLRequestContextGetter : public URLRequestContextGetter { | |
|
eroman
2010/11/30 02:58:54
What is this used for? (I don't see it referenced
battre (please use the other)
2010/12/02 18:06:12
Line 427, see below.
| |
| 121 public: | |
| 122 virtual URLRequestContext* GetURLRequestContext() { | |
| 123 if (!context_) | |
| 124 context_ = new TestURLRequestContext(); | |
| 125 return context_.get(); | |
| 126 } | |
| 127 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { | |
| 128 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | |
| 129 } | |
| 130 | |
| 131 private: | |
| 132 scoped_refptr<URLRequestContext> context_; | |
| 133 }; | |
| 134 | |
| 115 class TestExtensionURLRequestContext : public URLRequestContext { | 135 class TestExtensionURLRequestContext : public URLRequestContext { |
| 116 public: | 136 public: |
| 117 TestExtensionURLRequestContext() { | 137 TestExtensionURLRequestContext() { |
| 118 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); | 138 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); |
| 119 const char* schemes[] = {chrome::kExtensionScheme}; | 139 const char* schemes[] = {chrome::kExtensionScheme}; |
| 120 cookie_monster->SetCookieableSchemes(schemes, 1); | 140 cookie_monster->SetCookieableSchemes(schemes, 1); |
| 121 cookie_store_ = cookie_monster; | 141 cookie_store_ = cookie_monster; |
| 122 } | 142 } |
| 123 }; | 143 }; |
| 124 | 144 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 NotificationService::NoDetails()); | 198 NotificationService::NoDetails()); |
| 179 DestroyTopSites(); | 199 DestroyTopSites(); |
| 180 DestroyHistoryService(); | 200 DestroyHistoryService(); |
| 181 // FaviconService depends on HistoryServce so destroying it later. | 201 // FaviconService depends on HistoryServce so destroying it later. |
| 182 DestroyFaviconService(); | 202 DestroyFaviconService(); |
| 183 DestroyWebDataService(); | 203 DestroyWebDataService(); |
| 184 if (extensions_service_.get()) { | 204 if (extensions_service_.get()) { |
| 185 extensions_service_->DestroyingProfile(); | 205 extensions_service_->DestroyingProfile(); |
| 186 extensions_service_ = NULL; | 206 extensions_service_ = NULL; |
| 187 } | 207 } |
| 208 if (pref_proxy_config_tracker_.get()) | |
| 209 pref_proxy_config_tracker_->DetachFromPrefService(); | |
| 188 } | 210 } |
| 189 | 211 |
| 190 void TestingProfile::CreateFaviconService() { | 212 void TestingProfile::CreateFaviconService() { |
| 191 favicon_service_ = NULL; | 213 favicon_service_ = NULL; |
| 192 favicon_service_ = new FaviconService(this); | 214 favicon_service_ = new FaviconService(this); |
| 193 } | 215 } |
| 194 | 216 |
| 195 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { | 217 void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { |
| 196 DestroyHistoryService(); | 218 DestroyHistoryService(); |
| 197 if (delete_file) { | 219 if (delete_file) { |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 | 485 |
| 464 DesktopNotificationService* TestingProfile::GetDesktopNotificationService() { | 486 DesktopNotificationService* TestingProfile::GetDesktopNotificationService() { |
| 465 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 466 if (!desktop_notification_service_.get()) { | 488 if (!desktop_notification_service_.get()) { |
| 467 desktop_notification_service_.reset(new DesktopNotificationService( | 489 desktop_notification_service_.reset(new DesktopNotificationService( |
| 468 this, NULL)); | 490 this, NULL)); |
| 469 } | 491 } |
| 470 return desktop_notification_service_.get(); | 492 return desktop_notification_service_.get(); |
| 471 } | 493 } |
| 472 | 494 |
| 495 PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() { | |
| 496 if (!pref_proxy_config_tracker_) | |
| 497 pref_proxy_config_tracker_ = new PrefProxyConfigTracker(GetPrefs()); | |
| 498 | |
| 499 return pref_proxy_config_tracker_; | |
| 500 } | |
| 501 | |
| 473 void TestingProfile::BlockUntilHistoryProcessesPendingRequests() { | 502 void TestingProfile::BlockUntilHistoryProcessesPendingRequests() { |
| 474 DCHECK(history_service_.get()); | 503 DCHECK(history_service_.get()); |
| 475 DCHECK(MessageLoop::current()); | 504 DCHECK(MessageLoop::current()); |
| 476 | 505 |
| 477 CancelableRequestConsumer consumer; | 506 CancelableRequestConsumer consumer; |
| 478 history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer); | 507 history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer); |
| 479 MessageLoop::current()->Run(); | 508 MessageLoop::current()->Run(); |
| 480 } | 509 } |
| 481 | 510 |
| 482 TokenService* TestingProfile::GetTokenService() { | 511 TokenService* TestingProfile::GetTokenService() { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 501 } | 530 } |
| 502 return profile_sync_service_.get(); | 531 return profile_sync_service_.get(); |
| 503 } | 532 } |
| 504 | 533 |
| 505 void TestingProfile::DestroyWebDataService() { | 534 void TestingProfile::DestroyWebDataService() { |
| 506 if (!web_data_service_.get()) | 535 if (!web_data_service_.get()) |
| 507 return; | 536 return; |
| 508 | 537 |
| 509 web_data_service_->Shutdown(); | 538 web_data_service_->Shutdown(); |
| 510 } | 539 } |
| OLD | NEW |