Commit da6b56b3 authored by Parastoo Geranmayeh's avatar Parastoo Geranmayeh Committed by Commit Bot

[AF] Tests vs Browsers PDM Factory

The tests sometimes use the personal data manager factory,
as in ChromeBrowsingDataRemoverDelegateUnittest.
The factory should distinguish between the two.

For the tests we should use the fake test source of autofill
profile validation, and not the real one.

Change-Id: I694bf487fc42176cfa874567908774f0f971094a
Reviewed-on: https://chromium-review.googlesource.com/c/1351771Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Parastoo Geranmayeh <parastoog@google.com>
Cr-Commit-Position: refs/heads/master@{#612783}
parent 03e5e255
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/browser/autofill/personal_data_manager_factory.h" #include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "chrome/browser/autofill/autofill_profile_validator_factory.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/incognito_helpers.h"
...@@ -45,8 +44,9 @@ PersonalDataManagerFactory::PersonalDataManagerFactory() ...@@ -45,8 +44,9 @@ PersonalDataManagerFactory::PersonalDataManagerFactory()
PersonalDataManagerFactory::~PersonalDataManagerFactory() { PersonalDataManagerFactory::~PersonalDataManagerFactory() {
} }
KeyedService* PersonalDataManagerFactory::BuildServiceInstanceFor( KeyedService* PersonalDataManagerFactory::BuildPersonalDataManager(
content::BrowserContext* context) const { autofill::AutofillProfileValidator* autofill_validator,
content::BrowserContext* context) {
Profile* profile = Profile::FromBrowserContext(context); Profile* profile = Profile::FromBrowserContext(context);
PersonalDataManager* service = PersonalDataManager* service =
new PersonalDataManager(g_browser_process->GetApplicationLocale()); new PersonalDataManager(g_browser_process->GetApplicationLocale());
...@@ -58,12 +58,18 @@ KeyedService* PersonalDataManagerFactory::BuildServiceInstanceFor( ...@@ -58,12 +58,18 @@ KeyedService* PersonalDataManagerFactory::BuildServiceInstanceFor(
profile, ServiceAccessType::EXPLICIT_ACCESS); profile, ServiceAccessType::EXPLICIT_ACCESS);
service->Init(local_storage, account_storage, profile->GetPrefs(), service->Init(local_storage, account_storage, profile->GetPrefs(),
IdentityManagerFactory::GetForProfile(profile), IdentityManagerFactory::GetForProfile(profile),
AutofillProfileValidatorFactory::GetInstance(), history_service, autofill_validator, history_service,
GaiaCookieManagerServiceFactory::GetForProfile(profile), GaiaCookieManagerServiceFactory::GetForProfile(profile),
profile->IsOffTheRecord()); profile->IsOffTheRecord());
return service; return service;
} }
KeyedService* PersonalDataManagerFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return BuildPersonalDataManager(
AutofillProfileValidatorFactory::GetInstance(), context);
}
content::BrowserContext* PersonalDataManagerFactory::GetBrowserContextToUse( content::BrowserContext* PersonalDataManagerFactory::GetBrowserContextToUse(
content::BrowserContext* context) const { content::BrowserContext* context) const {
return chrome::GetBrowserContextOwnInstanceInIncognito(context); return chrome::GetBrowserContextOwnInstanceInIncognito(context);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_FACTORY_H_ #define CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_FACTORY_H_
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "chrome/browser/autofill/autofill_profile_validator_factory.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
...@@ -31,6 +32,10 @@ class PersonalDataManagerFactory : public BrowserContextKeyedServiceFactory { ...@@ -31,6 +32,10 @@ class PersonalDataManagerFactory : public BrowserContextKeyedServiceFactory {
static PersonalDataManagerFactory* GetInstance(); static PersonalDataManagerFactory* GetInstance();
static KeyedService* BuildPersonalDataManager(
autofill::AutofillProfileValidator* autofill_validator,
content::BrowserContext* context);
private: private:
friend struct base::DefaultSingletonTraits<PersonalDataManagerFactory>; friend struct base::DefaultSingletonTraits<PersonalDataManagerFactory>;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/autocomplete/in_memory_url_index_factory.h" #include "chrome/browser/autocomplete/in_memory_url_index_factory.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/chrome_bookmark_client.h" #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
#include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
...@@ -46,6 +47,8 @@ ...@@ -46,6 +47,8 @@
#include "chrome/browser/profiles/storage_partition_descriptor.h" #include "chrome/browser/profiles/storage_partition_descriptor.h"
#include "chrome/browser/search_engines/template_url_fetcher_factory.h" #include "chrome/browser/search_engines/template_url_fetcher_factory.h"
#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_util.h" #include "chrome/browser/signin/signin_util.h"
#include "chrome/browser/sync/bookmark_sync_service_factory.h" #include "chrome/browser/sync/bookmark_sync_service_factory.h"
#include "chrome/browser/sync/glue/sync_start_util.h" #include "chrome/browser/sync/glue/sync_start_util.h"
...@@ -56,6 +59,8 @@ ...@@ -56,6 +59,8 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/test_autofill_profile_validator.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h" #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/common/bookmark_constants.h" #include "components/bookmarks/common/bookmark_constants.h"
...@@ -214,6 +219,13 @@ std::unique_ptr<KeyedService> BuildOfflinePageModel( ...@@ -214,6 +219,13 @@ std::unique_ptr<KeyedService> BuildOfflinePageModel(
} }
#endif #endif
std::unique_ptr<KeyedService> BuildPersonalDataManagerInstanceFor(
content::BrowserContext* context) {
return std::unique_ptr<KeyedService>(
autofill::PersonalDataManagerFactory::BuildPersonalDataManager(
autofill::TestAutofillProfileValidator::GetInstance(), context));
}
} // namespace } // namespace
// static // static
...@@ -435,6 +447,9 @@ void TestingProfile::Init() { ...@@ -435,6 +447,9 @@ void TestingProfile::Init() {
launcher->MaybeSetProfile(this); launcher->MaybeSetProfile(this);
#endif #endif
autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory(
this, base::BindRepeating(&BuildPersonalDataManagerInstanceFor));
// TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl
// anymore, after converting the PrefService to a PKS. Until then it must // anymore, after converting the PrefService to a PKS. Until then it must
// be associated with a TestingProfile too. // be associated with a TestingProfile too.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment