Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: chrome/test/base/testing_profile.cc

Issue 777863002: Introduce new component webdata_services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compile as static_library instead of component Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | components/OWNERS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/base/testing_profile.h" 5 #include "chrome/test/base/testing_profile.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "chrome/browser/profiles/profile_manager.h" 42 #include "chrome/browser/profiles/profile_manager.h"
43 #include "chrome/browser/profiles/storage_partition_descriptor.h" 43 #include "chrome/browser/profiles/storage_partition_descriptor.h"
44 #include "chrome/browser/search_engines/template_url_fetcher_factory.h" 44 #include "chrome/browser/search_engines/template_url_fetcher_factory.h"
45 #include "chrome/browser/webdata/web_data_service_factory.h" 45 #include "chrome/browser/webdata/web_data_service_factory.h"
46 #include "chrome/common/chrome_constants.h" 46 #include "chrome/common/chrome_constants.h"
47 #include "chrome/common/chrome_switches.h" 47 #include "chrome/common/chrome_switches.h"
48 #include "chrome/common/pref_names.h" 48 #include "chrome/common/pref_names.h"
49 #include "chrome/common/url_constants.h" 49 #include "chrome/common/url_constants.h"
50 #include "chrome/test/base/history_index_restore_observer.h" 50 #include "chrome/test/base/history_index_restore_observer.h"
51 #include "chrome/test/base/testing_pref_service_syncable.h" 51 #include "chrome/test/base/testing_pref_service_syncable.h"
52 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
52 #include "components/bookmarks/browser/bookmark_model.h" 53 #include "components/bookmarks/browser/bookmark_model.h"
53 #include "components/bookmarks/common/bookmark_constants.h" 54 #include "components/bookmarks/common/bookmark_constants.h"
54 #include "components/content_settings/core/browser/host_content_settings_map.h" 55 #include "components/content_settings/core/browser/host_content_settings_map.h"
55 #include "components/history/core/browser/history_constants.h" 56 #include "components/history/core/browser/history_constants.h"
56 #include "components/history/core/browser/top_sites_observer.h" 57 #include "components/history/core/browser/top_sites_observer.h"
57 #include "components/keyed_service/content/browser_context_dependency_manager.h" 58 #include "components/keyed_service/content/browser_context_dependency_manager.h"
58 #include "components/policy/core/common/policy_service.h" 59 #include "components/policy/core/common/policy_service.h"
59 #include "components/user_prefs/user_prefs.h" 60 #include "components/user_prefs/user_prefs.h"
61 #include "components/webdata_services/web_data_service_wrapper.h"
60 #include "content/public/browser/browser_thread.h" 62 #include "content/public/browser/browser_thread.h"
61 #include "content/public/browser/cookie_store_factory.h" 63 #include "content/public/browser/cookie_store_factory.h"
62 #include "content/public/browser/notification_service.h" 64 #include "content/public/browser/notification_service.h"
63 #include "content/public/browser/render_process_host.h" 65 #include "content/public/browser/render_process_host.h"
64 #include "content/public/browser/storage_partition.h" 66 #include "content/public/browser/storage_partition.h"
65 #include "content/public/test/mock_resource_context.h" 67 #include "content/public/test/mock_resource_context.h"
66 #include "content/public/test/test_utils.h" 68 #include "content/public/test/test_utils.h"
67 #include "extensions/common/constants.h" 69 #include "extensions/common/constants.h"
68 #include "net/cookies/cookie_monster.h" 70 #include "net/cookies/cookie_monster.h"
69 #include "net/url_request/url_request_context.h" 71 #include "net/url_request/url_request_context.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 scoped_ptr<net::URLRequestContext> context_; 179 scoped_ptr<net::URLRequestContext> context_;
178 }; 180 };
179 181
180 #if defined(ENABLE_NOTIFICATIONS) 182 #if defined(ENABLE_NOTIFICATIONS)
181 KeyedService* CreateTestDesktopNotificationService( 183 KeyedService* CreateTestDesktopNotificationService(
182 content::BrowserContext* profile) { 184 content::BrowserContext* profile) {
183 return new DesktopNotificationService(static_cast<Profile*>(profile)); 185 return new DesktopNotificationService(static_cast<Profile*>(profile));
184 } 186 }
185 #endif 187 #endif
186 188
189 KeyedService* BuildFaviconService(content::BrowserContext* profile) {
190 FaviconClient* favicon_client =
191 ChromeFaviconClientFactory::GetForProfile(static_cast<Profile*>(profile));
192 return new FaviconService(static_cast<Profile*>(profile), favicon_client);
193 }
194
195 KeyedService* BuildHistoryService(content::BrowserContext* context) {
196 Profile* profile = static_cast<Profile*>(context);
197 HistoryService* history_service = new HistoryService(
198 ChromeHistoryClientFactory::GetForProfile(profile), profile);
199 return history_service;
200 }
201
202 KeyedService* BuildBookmarkModel(content::BrowserContext* context) {
203 Profile* profile = static_cast<Profile*>(context);
204 ChromeBookmarkClient* bookmark_client =
205 ChromeBookmarkClientFactory::GetForProfile(profile);
206 BookmarkModel* bookmark_model = new BookmarkModel(bookmark_client);
207 bookmark_client->Init(bookmark_model);
208 bookmark_model->Load(profile->GetPrefs(),
209 profile->GetPrefs()->GetString(prefs::kAcceptLanguages),
210 profile->GetPath(),
211 profile->GetIOTaskRunner(),
212 content::BrowserThread::GetMessageLoopProxyForThread(
213 content::BrowserThread::UI));
214 return bookmark_model;
215 }
216
217 KeyedService* BuildChromeBookmarkClient(
218 content::BrowserContext* context) {
219 return new ChromeBookmarkClient(static_cast<Profile*>(context));
220 }
221
222 KeyedService* BuildChromeHistoryClient(
223 content::BrowserContext* context) {
224 Profile* profile = static_cast<Profile*>(context);
225 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile),
226 profile,
227 profile->GetTopSites());
228 }
229
230 void TestProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type,
231 sql::InitStatus status) {
232 NOTREACHED();
233 }
234
235 KeyedService* BuildWebDataService(content::BrowserContext* profile) {
236 WebDataServiceWrapper* web_data_service_wrapper = new WebDataServiceWrapper(
237 static_cast<Profile*>(profile)->GetPath(),
238 g_browser_process->GetApplicationLocale(),
239 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
240 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
241 &TestProfileErrorCallback);
242 web_data_service_wrapper->GetAutofillWebData()->GetAutofillBackend(
243 base::Bind(&InitSyncableServicesOnDBThread,
244 web_data_service_wrapper->GetAutofillWebData(),
245 static_cast<Profile*>(profile)->GetPath(),
246 g_browser_process->GetApplicationLocale()));
247 return web_data_service_wrapper;
248 }
249
187 } // namespace 250 } // namespace
188 251
189 // static 252 // static
190 #if defined(OS_CHROMEOS) 253 #if defined(OS_CHROMEOS)
191 // Must be kept in sync with 254 // Must be kept in sync with
192 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization. 255 // ChromeBrowserMainPartsChromeos::PreEarlyInitialization.
193 const char TestingProfile::kTestUserProfileDir[] = "test-user"; 256 const char TestingProfile::kTestUserProfileDir[] = "test-user";
194 #else 257 #else
195 const char TestingProfile::kTestUserProfileDir[] = "Default"; 258 const char TestingProfile::kTestUserProfileDir[] = "Default";
196 #endif 259 #endif
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // Failing a post == leaks == heapcheck failure. Make that an immediate test 509 // Failing a post == leaks == heapcheck failure. Make that an immediate test
447 // failure. 510 // failure.
448 if (resource_context_) { 511 if (resource_context_) {
449 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, 512 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
450 resource_context_)); 513 resource_context_));
451 resource_context_ = NULL; 514 resource_context_ = NULL;
452 content::RunAllPendingInMessageLoop(BrowserThread::IO); 515 content::RunAllPendingInMessageLoop(BrowserThread::IO);
453 } 516 }
454 } 517 }
455 518
456 static KeyedService* BuildFaviconService(content::BrowserContext* profile) {
457 FaviconClient* favicon_client =
458 ChromeFaviconClientFactory::GetForProfile(static_cast<Profile*>(profile));
459 return new FaviconService(static_cast<Profile*>(profile), favicon_client);
460 }
461
462 void TestingProfile::CreateFaviconService() { 519 void TestingProfile::CreateFaviconService() {
463 // It is up to the caller to create the history service if one is needed. 520 // It is up to the caller to create the history service if one is needed.
464 FaviconServiceFactory::GetInstance()->SetTestingFactory( 521 FaviconServiceFactory::GetInstance()->SetTestingFactory(
465 this, BuildFaviconService); 522 this, BuildFaviconService);
466 } 523 }
467 524
468 static KeyedService* BuildHistoryService(content::BrowserContext* context) {
469 Profile* profile = static_cast<Profile*>(context);
470 HistoryService* history_service = new HistoryService(
471 ChromeHistoryClientFactory::GetForProfile(profile), profile);
472 return history_service;
473 }
474
475 bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) { 525 bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
476 DestroyHistoryService(); 526 DestroyHistoryService();
477 if (delete_file) { 527 if (delete_file) {
478 base::FilePath path = GetPath(); 528 base::FilePath path = GetPath();
479 path = path.Append(history::kHistoryFilename); 529 path = path.Append(history::kHistoryFilename);
480 if (!base::DeleteFile(path, false) || base::PathExists(path)) 530 if (!base::DeleteFile(path, false) || base::PathExists(path))
481 return false; 531 return false;
482 } 532 }
483 // This will create and init the history service. 533 // This will create and init the history service.
484 HistoryService* history_service = static_cast<HistoryService*>( 534 HistoryService* history_service = static_cast<HistoryService*>(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 top_sites_->Shutdown(); 589 top_sites_->Shutdown();
540 top_sites_ = NULL; 590 top_sites_ = NULL;
541 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that 591 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that
542 // need to be run to properly shutdown. Run all pending tasks now. This is 592 // need to be run to properly shutdown. Run all pending tasks now. This is
543 // normally handled by browser_process shutdown. 593 // normally handled by browser_process shutdown.
544 if (base::MessageLoop::current()) 594 if (base::MessageLoop::current())
545 base::MessageLoop::current()->RunUntilIdle(); 595 base::MessageLoop::current()->RunUntilIdle();
546 } 596 }
547 } 597 }
548 598
549 static KeyedService* BuildBookmarkModel(content::BrowserContext* context) {
550 Profile* profile = static_cast<Profile*>(context);
551 ChromeBookmarkClient* bookmark_client =
552 ChromeBookmarkClientFactory::GetForProfile(profile);
553 BookmarkModel* bookmark_model = new BookmarkModel(bookmark_client);
554 bookmark_client->Init(bookmark_model);
555 bookmark_model->Load(profile->GetPrefs(),
556 profile->GetPrefs()->GetString(prefs::kAcceptLanguages),
557 profile->GetPath(),
558 profile->GetIOTaskRunner(),
559 content::BrowserThread::GetMessageLoopProxyForThread(
560 content::BrowserThread::UI));
561 return bookmark_model;
562 }
563
564 static KeyedService* BuildChromeBookmarkClient(
565 content::BrowserContext* context) {
566 return new ChromeBookmarkClient(static_cast<Profile*>(context));
567 }
568
569 static KeyedService* BuildChromeHistoryClient(
570 content::BrowserContext* context) {
571 Profile* profile = static_cast<Profile*>(context);
572 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile),
573 profile,
574 profile->GetTopSites());
575 }
576
577 void TestingProfile::CreateBookmarkModel(bool delete_file) { 599 void TestingProfile::CreateBookmarkModel(bool delete_file) {
578 if (delete_file) { 600 if (delete_file) {
579 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName); 601 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName);
580 base::DeleteFile(path, false); 602 base::DeleteFile(path, false);
581 } 603 }
582 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory( 604 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory(
583 this, BuildChromeHistoryClient); 605 this, BuildChromeHistoryClient);
584 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory( 606 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory(
585 this, BuildChromeBookmarkClient); 607 this, BuildChromeBookmarkClient);
586 // This creates the BookmarkModel. 608 // This creates the BookmarkModel.
587 ignore_result(BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse( 609 ignore_result(BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
588 this, BuildBookmarkModel)); 610 this, BuildBookmarkModel));
589 } 611 }
590 612
591 static KeyedService* BuildWebDataService(content::BrowserContext* profile) {
592 return new WebDataServiceWrapper(static_cast<Profile*>(profile));
593 }
594
595 void TestingProfile::CreateWebDataService() { 613 void TestingProfile::CreateWebDataService() {
596 WebDataServiceFactory::GetInstance()->SetTestingFactory( 614 WebDataServiceFactory::GetInstance()->SetTestingFactory(
597 this, BuildWebDataService); 615 this, BuildWebDataService);
598 } 616 }
599 617
600 void TestingProfile::BlockUntilHistoryIndexIsRefreshed() { 618 void TestingProfile::BlockUntilHistoryIndexIsRefreshed() {
601 // Only get the history service if it actually exists since the caller of the 619 // Only get the history service if it actually exists since the caller of the
602 // test should explicitly call CreateHistoryService to build it. 620 // test should explicitly call CreateHistoryService to build it.
603 HistoryService* history_service = 621 HistoryService* history_service =
604 HistoryServiceFactory::GetForProfileWithoutCreating(this); 622 HistoryServiceFactory::GetForProfileWithoutCreating(this);
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 #if defined(ENABLE_EXTENSIONS) 1068 #if defined(ENABLE_EXTENSIONS)
1051 extension_policy_, 1069 extension_policy_,
1052 #endif 1070 #endif
1053 pref_service_.Pass(), 1071 pref_service_.Pass(),
1054 original_profile, 1072 original_profile,
1055 guest_session_, 1073 guest_session_,
1056 supervised_user_id_, 1074 supervised_user_id_,
1057 policy_service_.Pass(), 1075 policy_service_.Pass(),
1058 testing_factories_); 1076 testing_factories_);
1059 } 1077 }
OLDNEW
« no previous file with comments | « chrome/chrome_tests_unit.gypi ('k') | components/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698