Commit 606b1b55 authored by Ian Struiksma's avatar Ian Struiksma Committed by Commit Bot

Change PersonalDataManager autofill test helpers to use Profile*

There are various test helper methods to add:
AutofillProfile(s)
CreditCard
To the PersonalDataManager.

All of these only use the Browser* reference to reach the Profile*
object. Changing these methods to use Profile* directly.

This allows us to remove the Browser* references so we can run tests
on Android.

Bug: 1148435
Change-Id: I7ba1bb0491e487e5965fa837edc8abecdb15a471
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2545775Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Ian Struiksma <ianstruiksma@google.com>
Cr-Commit-Position: refs/heads/master@{#828796}
parent 571a108d
...@@ -167,7 +167,7 @@ class AutofillCapturedSitesInteractiveTest ...@@ -167,7 +167,7 @@ class AutofillCapturedSitesInteractiveTest
} }
bool SetupAutofillProfile() override { bool SetupAutofillProfile() override {
AddTestAutofillData(browser(), profile(), credit_card()); AddTestAutofillData(browser()->profile(), profile(), credit_card());
return true; return true;
} }
......
...@@ -356,7 +356,7 @@ class AutofillInteractiveTestBase : public AutofillUiTest { ...@@ -356,7 +356,7 @@ class AutofillInteractiveTestBase : public AutofillUiTest {
"4120 Freidrich Lane", "Basement", "Austin", "Texas", "4120 Freidrich Lane", "Basement", "Austin", "Texas",
"78744", "US", "15125551234"); "78744", "US", "15125551234");
profile.set_use_count(9999999); // We want this to be the first profile. profile.set_use_count(9999999); // We want this to be the first profile.
AddTestProfile(browser(), profile); AddTestProfile(browser()->profile(), profile);
} }
void CreateSecondTestProfile() { void CreateSecondTestProfile() {
...@@ -365,14 +365,14 @@ class AutofillInteractiveTestBase : public AutofillUiTest { ...@@ -365,14 +365,14 @@ class AutofillInteractiveTestBase : public AutofillUiTest {
"alice@wonderland.com", "Magic", "333 Cat Queen St.", "alice@wonderland.com", "Magic", "333 Cat Queen St.",
"Rooftop", "Liliput", "CA", "10003", "US", "Rooftop", "Liliput", "CA", "10003", "US",
"15166900292"); "15166900292");
AddTestProfile(browser(), profile); AddTestProfile(browser()->profile(), profile);
} }
void CreateTestCreditCart() { void CreateTestCreditCart() {
CreditCard card; CreditCard card;
test::SetCreditCardInfo(&card, "Milton Waddams", "4111111111111111", "09", test::SetCreditCardInfo(&card, "Milton Waddams", "4111111111111111", "09",
"2999", ""); "2999", "");
AddTestCreditCard(browser(), card); AddTestCreditCard(browser()->profile(), card);
} }
// Populates a webpage form using autofill data and keypress events. // Populates a webpage form using autofill data and keypress events.
...@@ -2027,7 +2027,7 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, ComparePhoneNumbers) { ...@@ -2027,7 +2027,7 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, ComparePhoneNumbers) {
profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("95110")); profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("95110"));
profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1-408-555-4567")); profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("1-408-555-4567"));
SetTestProfile(browser(), profile); SetTestProfile(browser()->profile(), profile);
GURL url = embedded_test_server()->GetURL("/autofill/form_phones.html"); GURL url = embedded_test_server()->GetURL("/autofill/form_phones.html");
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
...@@ -2081,7 +2081,7 @@ IN_PROC_BROWSER_TEST_F(AutofillCompanyInteractiveTest, ...@@ -2081,7 +2081,7 @@ IN_PROC_BROWSER_TEST_F(AutofillCompanyInteractiveTest,
profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("95110")); profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("95110"));
profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16(company_name)); profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16(company_name));
profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("408-871-4567")); profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("408-871-4567"));
SetTestProfile(browser(), profile); SetTestProfile(browser()->profile(), profile);
GURL url = GURL url =
embedded_test_server()->GetURL("/autofill/read_only_field_test.html"); embedded_test_server()->GetURL("/autofill/read_only_field_test.html");
...@@ -2140,7 +2140,7 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, NoAutofillForReadOnlyFields) { ...@@ -2140,7 +2140,7 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, NoAutofillForReadOnlyFields) {
profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("95110")); profile.SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("95110"));
profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Company X")); profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Company X"));
profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("408-871-4567")); profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("408-871-4567"));
SetTestProfile(browser(), profile); SetTestProfile(browser()->profile(), profile);
GURL url = GURL url =
embedded_test_server()->GetURL("/autofill/read_only_field_test.html"); embedded_test_server()->GetURL("/autofill/read_only_field_test.html");
...@@ -2214,7 +2214,7 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, ...@@ -2214,7 +2214,7 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith")); profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Smith"));
profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(email)); profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16(email));
profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("4088714567")); profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("4088714567"));
SetTestProfile(browser(), profile); SetTestProfile(browser()->profile(), profile);
GURL url = embedded_test_server()->GetURL( GURL url = embedded_test_server()->GetURL(
"/autofill/autofill_confirmemail_form.html"); "/autofill/autofill_confirmemail_form.html");
...@@ -2265,7 +2265,7 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, ...@@ -2265,7 +2265,7 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest,
profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
profiles.push_back(profile); profiles.push_back(profile);
} }
SetTestProfiles(browser(), &profiles); SetTestProfiles(browser()->profile(), &profiles);
GURL url = embedded_test_server()->GetURL( GURL url = embedded_test_server()->GetURL(
"/autofill/latency_after_submit_test.html"); "/autofill/latency_after_submit_test.html");
......
...@@ -6,8 +6,7 @@ ...@@ -6,8 +6,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h" #include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h" #include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/data_model/credit_card.h" #include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/personal_data_manager.h" #include "components/autofill/core/browser/personal_data_manager.h"
...@@ -20,10 +19,11 @@ namespace autofill { ...@@ -20,10 +19,11 @@ namespace autofill {
// to complete. // to complete.
class PdmChangeWaiter : public PersonalDataManagerObserver { class PdmChangeWaiter : public PersonalDataManagerObserver {
public: public:
explicit PdmChangeWaiter(Browser* browser) explicit PdmChangeWaiter(Profile* base_profile)
: alerted_(false), has_run_message_loop_(false), browser_(browser) { : alerted_(false),
PersonalDataManagerFactory::GetForProfile(browser_->profile())-> has_run_message_loop_(false),
AddObserver(this); base_profile_(base_profile) {
PersonalDataManagerFactory::GetForProfile(base_profile_)->AddObserver(this);
} }
~PdmChangeWaiter() override {} ~PdmChangeWaiter() override {}
...@@ -44,14 +44,14 @@ class PdmChangeWaiter : public PersonalDataManagerObserver { ...@@ -44,14 +44,14 @@ class PdmChangeWaiter : public PersonalDataManagerObserver {
has_run_message_loop_ = true; has_run_message_loop_ = true;
content::RunMessageLoop(); content::RunMessageLoop();
} }
PersonalDataManagerFactory::GetForProfile(browser_->profile())-> PersonalDataManagerFactory::GetForProfile(base_profile_)
RemoveObserver(this); ->RemoveObserver(this);
} }
private: private:
bool alerted_; bool alerted_;
bool has_run_message_loop_; bool has_run_message_loop_;
Browser* browser_; Profile* base_profile_;
DISALLOW_COPY_AND_ASSIGN(PdmChangeWaiter); DISALLOW_COPY_AND_ASSIGN(PdmChangeWaiter);
}; };
...@@ -60,56 +60,57 @@ static PersonalDataManager* GetPersonalDataManager(Profile* profile) { ...@@ -60,56 +60,57 @@ static PersonalDataManager* GetPersonalDataManager(Profile* profile) {
return PersonalDataManagerFactory::GetForProfile(profile); return PersonalDataManagerFactory::GetForProfile(profile);
} }
void AddTestProfile(Browser* browser, const AutofillProfile& profile) { void AddTestProfile(Profile* base_profile, const AutofillProfile& profile) {
PdmChangeWaiter observer(browser); PdmChangeWaiter observer(base_profile);
GetPersonalDataManager(browser->profile())->AddProfile(profile); GetPersonalDataManager(base_profile)->AddProfile(profile);
// AddProfile is asynchronous. Wait for it to finish before continuing the // AddProfile is asynchronous. Wait for it to finish before continuing the
// tests. // tests.
observer.Wait(); observer.Wait();
} }
void SetTestProfile(Browser* browser, const AutofillProfile& profile) { void SetTestProfile(Profile* base_profile, const AutofillProfile& profile) {
std::vector<AutofillProfile> profiles; std::vector<AutofillProfile> profiles;
profiles.push_back(profile); profiles.push_back(profile);
SetTestProfiles(browser, &profiles); SetTestProfiles(base_profile, &profiles);
} }
void SetTestProfiles(Browser* browser, std::vector<AutofillProfile>* profiles) { void SetTestProfiles(Profile* base_profile,
PdmChangeWaiter observer(browser); std::vector<AutofillProfile>* profiles) {
GetPersonalDataManager(browser->profile())->SetProfiles(profiles); PdmChangeWaiter observer(base_profile);
GetPersonalDataManager(base_profile)->SetProfiles(profiles);
observer.Wait(); observer.Wait();
} }
void AddTestCreditCard(Browser* browser, const CreditCard& card) { void AddTestCreditCard(Profile* base_profile, const CreditCard& card) {
PdmChangeWaiter observer(browser); PdmChangeWaiter observer(base_profile);
GetPersonalDataManager(browser->profile())->AddCreditCard(card); GetPersonalDataManager(base_profile)->AddCreditCard(card);
// AddCreditCard is asynchronous. Wait for it to finish before continuing the // AddCreditCard is asynchronous. Wait for it to finish before continuing the
// tests. // tests.
observer.Wait(); observer.Wait();
} }
void AddTestServerCreditCard(Browser* browser, const CreditCard& card) { void AddTestServerCreditCard(Profile* base_profile, const CreditCard& card) {
PdmChangeWaiter observer(browser); PdmChangeWaiter observer(base_profile);
GetPersonalDataManager(browser->profile())->AddFullServerCreditCard(card); GetPersonalDataManager(base_profile)->AddFullServerCreditCard(card);
// AddCreditCard is asynchronous. Wait for it to finish before continuing the // AddCreditCard is asynchronous. Wait for it to finish before continuing the
// tests. // tests.
observer.Wait(); observer.Wait();
} }
void AddTestAutofillData(Browser* browser, void AddTestAutofillData(Profile* base_profile,
const AutofillProfile& profile, const AutofillProfile& profile,
const CreditCard& card) { const CreditCard& card) {
AddTestProfile(browser, profile); AddTestProfile(base_profile, profile);
PdmChangeWaiter observer(browser); PdmChangeWaiter observer(base_profile);
GetPersonalDataManager(browser->profile())->AddCreditCard(card); GetPersonalDataManager(base_profile)->AddCreditCard(card);
observer.Wait(); observer.Wait();
} }
void WaitForPersonalDataChange(Browser* browser) { void WaitForPersonalDataChange(Profile* base_profile) {
PdmChangeWaiter observer(browser); PdmChangeWaiter observer(base_profile);
observer.Wait(); observer.Wait();
} }
......
...@@ -7,22 +7,23 @@ ...@@ -7,22 +7,23 @@
#include <vector> #include <vector>
class Browser; class Profile;
namespace autofill { namespace autofill {
class AutofillProfile; class AutofillProfile;
class CreditCard; class CreditCard;
void AddTestProfile(Browser* browser, const AutofillProfile& profile); void AddTestProfile(Profile* base_profile, const AutofillProfile& profile);
void SetTestProfile(Browser* browser, const AutofillProfile& profile); void SetTestProfile(Profile* base_profile, const AutofillProfile& profile);
void SetTestProfiles(Browser* browser, std::vector<AutofillProfile>* profiles); void SetTestProfiles(Profile* base_profile,
void AddTestCreditCard(Browser* browser, const CreditCard& card); std::vector<AutofillProfile>* profiles);
void AddTestServerCreditCard(Browser* browser, const CreditCard& card); void AddTestCreditCard(Profile* base_profile, const CreditCard& card);
void AddTestAutofillData(Browser* browser, void AddTestServerCreditCard(Profile* base_profile, const CreditCard& card);
void AddTestAutofillData(Profile* base_profile,
const AutofillProfile& profile, const AutofillProfile& profile,
const CreditCard& card); const CreditCard& card);
void WaitForPersonalDataChange(Browser* browser); void WaitForPersonalDataChange(Profile* base_profile);
} // namespace autofill } // namespace autofill
......
...@@ -231,7 +231,7 @@ IN_PROC_BROWSER_TEST_P(ChromeBrowsingDataLifetimeManagerTest, ...@@ -231,7 +231,7 @@ IN_PROC_BROWSER_TEST_P(ChromeBrowsingDataLifetimeManagerTest,
autofill::test::SetProfileInfo( autofill::test::SetProfileInfo(
&profile, "Marion", "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox", &profile, "Marion", "Mitchell", "Morrison", "johnwayne@me.xyz", "Fox",
"123 Zoo St.", "unit 5", "Hollywood", "CA", "91601", "US", "12345678910"); "123 Zoo St.", "unit 5", "Hollywood", "CA", "91601", "US", "12345678910");
autofill::AddTestProfile(GetBrowser(), profile); autofill::AddTestProfile(GetBrowser()->profile(), profile);
auto* personal_data_manager = auto* personal_data_manager =
autofill::PersonalDataManagerFactory::GetForProfile( autofill::PersonalDataManagerFactory::GetForProfile(
GetBrowser()->profile()); GetBrowser()->profile());
......
...@@ -54,7 +54,7 @@ class CreditCardAccessManagerBrowserTest : public InProcessBrowserTest { ...@@ -54,7 +54,7 @@ class CreditCardAccessManagerBrowserTest : public InProcessBrowserTest {
card_number.substr(0, 12)); card_number.substr(0, 12));
server_card.set_record_type(CreditCard::FULL_SERVER_CARD); server_card.set_record_type(CreditCard::FULL_SERVER_CARD);
server_card.set_server_id("full_id_" + card_number); server_card.set_server_id("full_id_" + card_number);
AddTestServerCreditCard(browser(), server_card); AddTestServerCreditCard(browser()->profile(), server_card);
return server_card; return server_card;
} }
......
...@@ -306,7 +306,7 @@ class LocalCardMigrationBrowserTest ...@@ -306,7 +306,7 @@ class LocalCardMigrationBrowserTest
if (set_nickname) if (set_nickname)
local_card.SetNickname(base::ASCIIToUTF16("card nickname")); local_card.SetNickname(base::ASCIIToUTF16("card nickname"));
AddTestCreditCard(browser(), local_card); AddTestCreditCard(browser()->profile(), local_card);
return local_card; return local_card;
} }
...@@ -318,7 +318,7 @@ class LocalCardMigrationBrowserTest ...@@ -318,7 +318,7 @@ class LocalCardMigrationBrowserTest
card_number.substr(0, 12)); card_number.substr(0, 12));
server_card.set_record_type(CreditCard::FULL_SERVER_CARD); server_card.set_record_type(CreditCard::FULL_SERVER_CARD);
server_card.set_server_id("full_id_" + card_number); server_card.set_server_id("full_id_" + card_number);
AddTestServerCreditCard(browser(), server_card); AddTestServerCreditCard(browser()->profile(), server_card);
return server_card; return server_card;
} }
...@@ -505,7 +505,9 @@ class LocalCardMigrationBrowserTest ...@@ -505,7 +505,9 @@ class LocalCardMigrationBrowserTest
return &test_url_loader_factory_; return &test_url_loader_factory_;
} }
void WaitForCardDeletion() { WaitForPersonalDataChange(browser()); } void WaitForCardDeletion() {
WaitForPersonalDataChange(browser()->profile());
}
void WaitForAnimationToComplete() { void WaitForAnimationToComplete() {
if (base::FeatureList::IsEnabled( if (base::FeatureList::IsEnabled(
......
...@@ -2170,7 +2170,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -2170,7 +2170,7 @@ IN_PROC_BROWSER_TEST_F(
// Set card number to match the number to be filled in the form. // Set card number to match the number to be filled in the form.
card.SetNumber(base::ASCIIToUTF16("5454545454545454")); card.SetNumber(base::ASCIIToUTF16("5454545454545454"));
card.SetNickname(base::ASCIIToUTF16("nickname")); card.SetNickname(base::ASCIIToUTF16("nickname"));
AddTestCreditCard(browser(), card); AddTestCreditCard(browser()->profile(), card);
// Start sync. // Start sync.
harness_->SetupSync(); harness_->SetupSync();
...@@ -2189,7 +2189,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -2189,7 +2189,7 @@ IN_PROC_BROWSER_TEST_F(
CreditCard card = test::GetCreditCard(); CreditCard card = test::GetCreditCard();
// Set card number to match the number to be filled in the form. // Set card number to match the number to be filled in the form.
card.SetNumber(base::ASCIIToUTF16("5454545454545454")); card.SetNumber(base::ASCIIToUTF16("5454545454545454"));
AddTestCreditCard(browser(), card); AddTestCreditCard(browser()->profile(), card);
// Start sync. // Start sync.
harness_->SetupSync(); harness_->SetupSync();
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
#include "components/sync/driver/sync_service_observer.h" #include "components/sync/driver/sync_service_observer.h"
#include "components/webdata/common/web_data_service_consumer.h" #include "components/webdata/common/web_data_service_consumer.h"
class Browser; class Profile;
class PrefService; class PrefService;
class RemoveAutofillTester; class RemoveAutofillTester;
...@@ -517,7 +517,7 @@ class PersonalDataManager : public KeyedService, ...@@ -517,7 +517,7 @@ class PersonalDataManager : public KeyedService,
friend void autofill_helper::SetCreditCards( friend void autofill_helper::SetCreditCards(
int, int,
std::vector<autofill::CreditCard>*); std::vector<autofill::CreditCard>*);
friend void SetTestProfiles(Browser* browser, friend void SetTestProfiles(Profile* base_profile,
std::vector<AutofillProfile>* profiles); std::vector<AutofillProfile>* profiles);
// Sets |web_profiles_| to the contents of |profiles| and updates the web // Sets |web_profiles_| to the contents of |profiles| and updates the web
......
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