Commit 6fb111eb authored by siyua's avatar siyua Committed by Commit Bot

[AF][Paradise] Enable migration flow for non-sync users

Also removed the EnableAutofillCreditCardLocalCardMigrationExperiment()
in unittests since as we add more experiment flags, this function does
not help.

Set a helper function in TestPersonalDataManager to change the sync
state, which can help us in case of such need in the future.

Bug: 897998
Change-Id: Id212077092d80738b8495f4b50bd7034e9f1ead6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1501754
Commit-Queue: Siyu An <siyua@chromium.org>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638336}
parent a909223e
...@@ -208,18 +208,24 @@ bool LocalCardMigrationManager::IsCreditCardMigrationEnabled() { ...@@ -208,18 +208,24 @@ bool LocalCardMigrationManager::IsCreditCardMigrationEnabled() {
observer_for_testing_ || observer_for_testing_ ||
::autofill::IsCreditCardUploadEnabled( ::autofill::IsCreditCardUploadEnabled(
client_->GetPrefs(), client_->GetSyncService(), client_->GetPrefs(), client_->GetSyncService(),
client_->GetIdentityManager()->GetPrimaryAccountInfo().email); personal_data_manager_->GetAccountInfoForPaymentsServer().email);
bool has_google_payments_account = bool has_google_payments_account =
(payments::GetBillingCustomerId(personal_data_manager_, (payments::GetBillingCustomerId(personal_data_manager_,
payments_client_->GetPrefService()) != 0); payments_client_->GetPrefService()) != 0);
bool sync_feature_enabled = AutofillSyncSigninState sync_state =
(personal_data_manager_->GetSyncSigninState() == personal_data_manager_->GetSyncSigninState();
AutofillSyncSigninState::kSignedInAndSyncFeature);
return migration_experiment_enabled && credit_card_upload_enabled && return migration_experiment_enabled && credit_card_upload_enabled &&
has_google_payments_account && sync_feature_enabled; has_google_payments_account &&
// User signed-in and turned sync on.
(sync_state == AutofillSyncSigninState::kSignedInAndSyncFeature ||
// User signed-in but not turned on sync.
(sync_state == AutofillSyncSigninState::
kSignedInAndWalletSyncTransportEnabled &&
base::FeatureList::IsEnabled(
features::kAutofillEnableLocalCardMigrationForNonSyncUser)));
} }
void LocalCardMigrationManager::OnDidGetUploadDetails( void LocalCardMigrationManager::OnDidGetUploadDetails(
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "components/autofill/core/browser/mock_autocomplete_history_manager.h" #include "components/autofill/core/browser/mock_autocomplete_history_manager.h"
#include "components/autofill/core/browser/payments/test_payments_client.h" #include "components/autofill/core/browser/payments/test_payments_client.h"
#include "components/autofill/core/browser/personal_data_manager.h" #include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/sync_utils.h"
#include "components/autofill/core/browser/test_autofill_client.h" #include "components/autofill/core/browser/test_autofill_client.h"
#include "components/autofill/core/browser/test_autofill_clock.h" #include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/autofill/core/browser/test_autofill_driver.h" #include "components/autofill/core/browser/test_autofill_driver.h"
...@@ -112,16 +113,6 @@ class LocalCardMigrationManagerTest : public testing::Test { ...@@ -112,16 +113,6 @@ class LocalCardMigrationManagerTest : public testing::Test {
request_context_ = nullptr; request_context_ = nullptr;
} }
void EnableAutofillCreditCardLocalCardMigrationExperiment() {
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
}
void DisableAutofillCreditCardLocalCardMigrationExperiment() {
scoped_feature_list_.InitAndDisableFeature(
features::kAutofillCreditCardLocalCardMigration);
}
void FormsSeen(const std::vector<FormData>& forms) { void FormsSeen(const std::vector<FormData>& forms) {
autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); autofill_manager_->OnFormsSeen(forms, base::TimeTicks());
} }
...@@ -194,7 +185,8 @@ class LocalCardMigrationManagerTest : public testing::Test { ...@@ -194,7 +185,8 @@ class LocalCardMigrationManagerTest : public testing::Test {
// Having one local card on file and using it will not trigger migration. // Having one local card on file and using it will not trigger migration.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_UseLocalCardWithOneLocal) { MigrateCreditCard_UseLocalCardWithOneLocal) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -227,7 +219,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -227,7 +219,8 @@ TEST_F(LocalCardMigrationManagerTest,
// trigger migration. // trigger migration.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_UseNewCardWithAnyLocal) { MigrateCreditCard_UseNewCardWithAnyLocal) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -257,7 +250,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -257,7 +250,8 @@ TEST_F(LocalCardMigrationManagerTest,
// migration. // migration.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_UseLocalCardWithMoreLocal) { MigrateCreditCard_UseLocalCardWithMoreLocal) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -303,7 +297,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -303,7 +297,8 @@ TEST_F(LocalCardMigrationManagerTest,
// cards as long as the other local cards are not eligible for migration. // cards as long as the other local cards are not eligible for migration.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_UseLocalCardWithInvalidLocal) { MigrateCreditCard_UseLocalCardWithInvalidLocal) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -336,7 +331,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -336,7 +331,8 @@ TEST_F(LocalCardMigrationManagerTest,
// will trigger migration. // will trigger migration.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_UseServerCardWithOneValidLocal) { MigrateCreditCard_UseServerCardWithOneValidLocal) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -385,7 +381,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -385,7 +381,8 @@ TEST_F(LocalCardMigrationManagerTest,
// cards as long as the other local cards are not eligible for migration. // cards as long as the other local cards are not eligible for migration.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_UseServerCardWithNoneValidLocal) { MigrateCreditCard_UseServerCardWithNoneValidLocal) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -427,7 +424,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -427,7 +424,8 @@ TEST_F(LocalCardMigrationManagerTest,
// is off, will not trigger migration. // is off, will not trigger migration.
TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_FeatureNotEnabled) { TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_FeatureNotEnabled) {
// Turn off the experiment flag. // Turn off the experiment flag.
DisableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndDisableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -454,20 +452,22 @@ TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_FeatureNotEnabled) { ...@@ -454,20 +452,22 @@ TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_FeatureNotEnabled) {
} }
// Do not trigger migration if user only signs in. // Do not trigger migration if user only signs in.
TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_SignInOnly) { TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_SignInOnlyWhenExpOff) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitWithFeatures(
// Enabled
{features::kAutofillCreditCardLocalCardMigration,
features::kAutofillEnableAccountWalletStorage},
// Disabled
{features::kAutofillEnableLocalCardMigrationForNonSyncUser});
// Make a non-primary account available with both a refresh token and cookie // Set the billing_customer_number Priority Preference to designate
// to be in Sync Transport for Wallet mode, in which case this account is // existence of a Payments account.
// signed in only without sync enabled. autofill_client_.GetPrefs()->SetDouble(prefs::kAutofillBillingCustomerNumber,
sync_service_.SetIsAuthenticatedAccountPrimary(false); 12345);
sync_service_.SetActiveDataTypes(
syncer::ModelTypeSet(syncer::AUTOFILL_WALLET_DATA));
base::test::ScopedFeatureList scoped_features; // Mock Chrome Sync is disabled.
scoped_features.InitWithFeatures( local_card_migration_manager_->ResetSyncState(
/*enabled_features=*/{features::kAutofillEnableAccountWalletStorage}, AutofillSyncSigninState::kSignedInAndWalletSyncTransportEnabled);
/*disabled_features=*/{});
// Add a local credit card whose |TypeAndLastFourDigits| matches what we will // Add a local credit card whose |TypeAndLastFourDigits| matches what we will
// enter below. // enter below.
...@@ -489,10 +489,50 @@ TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_SignInOnly) { ...@@ -489,10 +489,50 @@ TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_SignInOnly) {
EXPECT_FALSE(local_card_migration_manager_->LocalCardMigrationWasTriggered()); EXPECT_FALSE(local_card_migration_manager_->LocalCardMigrationWasTriggered());
} }
// Trigger migration if user only signs in and if experiment is enabled.
TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_SignInOnlyWhenExpOn) {
scoped_feature_list_.InitWithFeatures(
// Enabled
{features::kAutofillCreditCardLocalCardMigration,
features::kAutofillEnableLocalCardMigrationForNonSyncUser,
features::kAutofillEnableAccountWalletStorage},
// Disabled
{});
// Set the billing_customer_number Priority Preference to designate
// existence of a Payments account.
autofill_client_.GetPrefs()->SetDouble(prefs::kAutofillBillingCustomerNumber,
12345);
// Mock Chrome Sync is disabled.
local_card_migration_manager_->ResetSyncState(
AutofillSyncSigninState::kSignedInAndWalletSyncTransportEnabled);
// Add a local credit card whose |TypeAndLastFourDigits| matches what we will
// enter below.
AddLocalCreditCard(personal_data_, "Flo Master", "4111111111111111", "11",
test::NextYear().c_str(), "1", "guid1");
// Add another local credit card.
AddLocalCreditCard(personal_data_, "Flo Master", "5555555555554444", "11",
test::NextYear().c_str(), "1", "guid2");
// Set up our credit card form data.
FormData credit_card_form;
test::CreateTestCreditCardFormData(&credit_card_form, true, false);
FormsSeen(std::vector<FormData>(1, credit_card_form));
// Edit the data, and submit.
EditCreditCardFrom(credit_card_form, "Flo Master", "4111111111111111", "11",
test::NextYear().c_str(), "123");
FormSubmitted(credit_card_form);
EXPECT_TRUE(local_card_migration_manager_->LocalCardMigrationWasTriggered());
}
// Use one local card with more valid local cards available but billing customer // Use one local card with more valid local cards available but billing customer
// number is blank, will not trigger migration. // number is blank, will not trigger migration.
TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_NoPaymentsAccount) { TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_NoPaymentsAccount) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Add a local credit card whose |TypeAndLastFourDigits| matches what we will // Add a local credit card whose |TypeAndLastFourDigits| matches what we will
// enter below. // enter below.
...@@ -518,7 +558,8 @@ TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_NoPaymentsAccount) { ...@@ -518,7 +558,8 @@ TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_NoPaymentsAccount) {
// migratable. // migratable.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_LocalCardMatchMaskedServerCard) { MigrateCreditCard_LocalCardMatchMaskedServerCard) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -555,7 +596,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -555,7 +596,8 @@ TEST_F(LocalCardMigrationManagerTest,
// migratable. // migratable.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_LocalCardMatchFullServerCard) { MigrateCreditCard_LocalCardMatchFullServerCard) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -587,7 +629,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -587,7 +629,8 @@ TEST_F(LocalCardMigrationManagerTest,
// GetDetectedValues() should includes cardholder name if all cards have it. // GetDetectedValues() should includes cardholder name if all cards have it.
TEST_F(LocalCardMigrationManagerTest, GetDetectedValues_AllWithCardHolderName) { TEST_F(LocalCardMigrationManagerTest, GetDetectedValues_AllWithCardHolderName) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -619,7 +662,8 @@ TEST_F(LocalCardMigrationManagerTest, GetDetectedValues_AllWithCardHolderName) { ...@@ -619,7 +662,8 @@ TEST_F(LocalCardMigrationManagerTest, GetDetectedValues_AllWithCardHolderName) {
// a cardholder name. // a cardholder name.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
GetDetectedValues_OneCardWithoutCardHolderName) { GetDetectedValues_OneCardWithoutCardHolderName) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -650,7 +694,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -650,7 +694,8 @@ TEST_F(LocalCardMigrationManagerTest,
// account. // account.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
GetDetectedValues_IncludeGooglePaymentsAccount) { GetDetectedValues_IncludeGooglePaymentsAccount) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -681,7 +726,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -681,7 +726,8 @@ TEST_F(LocalCardMigrationManagerTest,
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_ShouldAddMigrateCardsBillableServiceNumberInRequest) { MigrateCreditCard_ShouldAddMigrateCardsBillableServiceNumberInRequest) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -714,7 +760,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -714,7 +760,8 @@ TEST_F(LocalCardMigrationManagerTest,
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_ShouldAddUploadCardSourceInRequest_CheckoutFlow) { MigrateCreditCard_ShouldAddUploadCardSourceInRequest_CheckoutFlow) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -747,7 +794,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -747,7 +794,8 @@ TEST_F(LocalCardMigrationManagerTest,
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_ShouldAddUploadCardSourceInRequest_SettingsPage) { MigrateCreditCard_ShouldAddUploadCardSourceInRequest_SettingsPage) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -776,7 +824,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -776,7 +824,8 @@ TEST_F(LocalCardMigrationManagerTest,
// be triggered. // be triggered.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_TriggerFromSettingsPage) { MigrateCreditCard_TriggerFromSettingsPage) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -815,7 +864,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -815,7 +864,8 @@ TEST_F(LocalCardMigrationManagerTest,
// prompt are both triggered. // prompt are both triggered.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_TriggerFromSubmittedForm) { MigrateCreditCard_TriggerFromSubmittedForm) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -846,7 +896,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -846,7 +896,8 @@ TEST_F(LocalCardMigrationManagerTest,
// prompt are not triggered as user previously rejected the prompt. // prompt are not triggered as user previously rejected the prompt.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_DontTriggerFromSubmittedForm) { MigrateCreditCard_DontTriggerFromSubmittedForm) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -883,7 +934,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -883,7 +934,8 @@ TEST_F(LocalCardMigrationManagerTest,
// Verify that given the parsed response from the payments client, the migration // Verify that given the parsed response from the payments client, the migration
// status is correctly set. // status is correctly set.
TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_MigrationSuccess) { TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_MigrationSuccess) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -924,7 +976,8 @@ TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_MigrationSuccess) { ...@@ -924,7 +976,8 @@ TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_MigrationSuccess) {
// status is correctly set. // status is correctly set.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_MigrationTemporaryFailure) { MigrateCreditCard_MigrationTemporaryFailure) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -967,7 +1020,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -967,7 +1020,8 @@ TEST_F(LocalCardMigrationManagerTest,
// status is correctly set. // status is correctly set.
TEST_F(LocalCardMigrationManagerTest, TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_MigrationPermanentFailure) { MigrateCreditCard_MigrationPermanentFailure) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
// Set the billing_customer_number Priority Preference to designate // Set the billing_customer_number Priority Preference to designate
// existence of a Payments account. // existence of a Payments account.
...@@ -1008,7 +1062,8 @@ TEST_F(LocalCardMigrationManagerTest, ...@@ -1008,7 +1062,8 @@ TEST_F(LocalCardMigrationManagerTest,
// Verify selected cards are correctly passed to manager. // Verify selected cards are correctly passed to manager.
TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_ToggleIsChosen) { TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_ToggleIsChosen) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
AddLocalCreditCard(personal_data_, "Flo Master", "4111111111111111", "11", AddLocalCreditCard(personal_data_, "Flo Master", "4111111111111111", "11",
test::NextYear().c_str(), "1", "guid1"); test::NextYear().c_str(), "1", "guid1");
AddLocalCreditCard(personal_data_, "Flo Master", "5454545454545454", "11", AddLocalCreditCard(personal_data_, "Flo Master", "5454545454545454", "11",
...@@ -1031,7 +1086,8 @@ TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_ToggleIsChosen) { ...@@ -1031,7 +1086,8 @@ TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_ToggleIsChosen) {
} }
TEST_F(LocalCardMigrationManagerTest, DeleteLocalCardViaMigrationDialog) { TEST_F(LocalCardMigrationManagerTest, DeleteLocalCardViaMigrationDialog) {
EnableAutofillCreditCardLocalCardMigrationExperiment(); scoped_feature_list_.InitAndEnableFeature(
features::kAutofillCreditCardLocalCardMigration);
AddLocalCreditCard(personal_data_, "Flo Master", "4111111111111111", "11", AddLocalCreditCard(personal_data_, "Flo Master", "4111111111111111", "11",
test::NextYear().c_str(), "1", "guid1"); test::NextYear().c_str(), "1", "guid1");
......
...@@ -126,7 +126,7 @@ class PersonalDataManager : public KeyedService, ...@@ -126,7 +126,7 @@ class PersonalDataManager : public KeyedService,
void OnAccountsCookieDeletedByUserAction() override; void OnAccountsCookieDeletedByUserAction() override;
// Returns the current sync status. // Returns the current sync status.
AutofillSyncSigninState GetSyncSigninState() const; virtual AutofillSyncSigninState GetSyncSigninState() const;
// Adds a listener to be notified of PersonalDataManager events. // Adds a listener to be notified of PersonalDataManager events.
virtual void AddObserver(PersonalDataManagerObserver* observer); virtual void AddObserver(PersonalDataManagerObserver* observer);
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "components/autofill/core/browser/payments/test_payments_client.h" #include "components/autofill/core/browser/payments/test_payments_client.h"
#include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_prefs.h" #include "components/autofill/core/common/autofill_prefs.h"
#include "services/identity/public/cpp/identity_manager.h"
namespace autofill { namespace autofill {
...@@ -16,11 +15,12 @@ TestLocalCardMigrationManager::TestLocalCardMigrationManager( ...@@ -16,11 +15,12 @@ TestLocalCardMigrationManager::TestLocalCardMigrationManager(
AutofillDriver* driver, AutofillDriver* driver,
AutofillClient* client, AutofillClient* client,
payments::TestPaymentsClient* payments_client, payments::TestPaymentsClient* payments_client,
PersonalDataManager* personal_data_manager) TestPersonalDataManager* personal_data_manager)
: LocalCardMigrationManager(client, : LocalCardMigrationManager(client,
payments_client, payments_client,
"en-US", "en-US",
personal_data_manager) {} personal_data_manager),
personal_data_manager_(personal_data_manager) {}
TestLocalCardMigrationManager::~TestLocalCardMigrationManager() {} TestLocalCardMigrationManager::~TestLocalCardMigrationManager() {}
...@@ -28,10 +28,19 @@ bool TestLocalCardMigrationManager::IsCreditCardMigrationEnabled() { ...@@ -28,10 +28,19 @@ bool TestLocalCardMigrationManager::IsCreditCardMigrationEnabled() {
bool migration_experiment_enabled = bool migration_experiment_enabled =
features::GetLocalCardMigrationExperimentalFlag() != features::GetLocalCardMigrationExperimentalFlag() !=
features::LocalCardMigrationExperimentalFlag::kMigrationDisabled; features::LocalCardMigrationExperimentalFlag::kMigrationDisabled;
bool has_google_payments_account = bool has_google_payments_account =
(static_cast<int64_t>(payments_client_->GetPrefService()->GetDouble( (static_cast<int64_t>(payments_client_->GetPrefService()->GetDouble(
prefs::kAutofillBillingCustomerNumber)) != 0); prefs::kAutofillBillingCustomerNumber)) != 0);
return migration_experiment_enabled && has_google_payments_account;
bool sync_feature_enabled =
(personal_data_manager_->GetSyncSigninState() ==
AutofillSyncSigninState::kSignedInAndSyncFeature);
return migration_experiment_enabled && has_google_payments_account &&
(sync_feature_enabled ||
base::FeatureList::IsEnabled(
features::kAutofillEnableLocalCardMigrationForNonSyncUser));
} }
bool TestLocalCardMigrationManager::LocalCardMigrationWasTriggered() { bool TestLocalCardMigrationManager::LocalCardMigrationWasTriggered() {
...@@ -58,6 +67,11 @@ void TestLocalCardMigrationManager::OnUserAcceptedMainMigrationDialog( ...@@ -58,6 +67,11 @@ void TestLocalCardMigrationManager::OnUserAcceptedMainMigrationDialog(
LocalCardMigrationManager::OnUserAcceptedMainMigrationDialog(selected_cards); LocalCardMigrationManager::OnUserAcceptedMainMigrationDialog(selected_cards);
} }
void TestLocalCardMigrationManager::ResetSyncState(
AutofillSyncSigninState sync_state) {
personal_data_manager_->SetSyncAndSignInState(sync_state);
}
void TestLocalCardMigrationManager::OnDidGetUploadDetails( void TestLocalCardMigrationManager::OnDidGetUploadDetails(
bool is_from_settings_page, bool is_from_settings_page,
AutofillClient::PaymentsRpcResult result, AutofillClient::PaymentsRpcResult result,
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <string> #include <string>
#include "components/autofill/core/browser/local_card_migration_manager.h" #include "components/autofill/core/browser/local_card_migration_manager.h"
#include "components/autofill/core/browser/sync_utils.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
namespace autofill { namespace autofill {
...@@ -17,14 +19,13 @@ class TestPaymentsClient; ...@@ -17,14 +19,13 @@ class TestPaymentsClient;
class AutofillClient; class AutofillClient;
class AutofillDriver; class AutofillDriver;
class PersonalDataManager;
class TestLocalCardMigrationManager : public LocalCardMigrationManager { class TestLocalCardMigrationManager : public LocalCardMigrationManager {
public: public:
TestLocalCardMigrationManager(AutofillDriver* driver, TestLocalCardMigrationManager(AutofillDriver* driver,
AutofillClient* client, AutofillClient* client,
payments::TestPaymentsClient* payments_client, payments::TestPaymentsClient* payments_client,
PersonalDataManager* personal_data_manager); TestPersonalDataManager* personal_data_manager);
~TestLocalCardMigrationManager() override; ~TestLocalCardMigrationManager() override;
// Override the base function. Checks the existnece of billing customer number // Override the base function. Checks the existnece of billing customer number
...@@ -50,6 +51,10 @@ class TestLocalCardMigrationManager : public LocalCardMigrationManager { ...@@ -50,6 +51,10 @@ class TestLocalCardMigrationManager : public LocalCardMigrationManager {
void OnUserAcceptedMainMigrationDialog( void OnUserAcceptedMainMigrationDialog(
const std::vector<std::string>& selected_cards) override; const std::vector<std::string>& selected_cards) override;
// Mock the Chrome Sync state in the LocalCardMigrationManager. If not set,
// default to AutofillSyncSigninState::kSignedInAndSyncFeature.
void ResetSyncState(AutofillSyncSigninState sync_state);
private: private:
void OnDidGetUploadDetails( void OnDidGetUploadDetails(
bool is_from_settings_page, bool is_from_settings_page,
...@@ -63,6 +68,8 @@ class TestLocalCardMigrationManager : public LocalCardMigrationManager { ...@@ -63,6 +68,8 @@ class TestLocalCardMigrationManager : public LocalCardMigrationManager {
bool main_prompt_was_shown_ = false; bool main_prompt_was_shown_ = false;
TestPersonalDataManager* personal_data_manager_;
DISALLOW_COPY_AND_ASSIGN(TestLocalCardMigrationManager); DISALLOW_COPY_AND_ASSIGN(TestLocalCardMigrationManager);
}; };
......
...@@ -19,6 +19,10 @@ void TestPersonalDataManager::OnSyncServiceInitialized( ...@@ -19,6 +19,10 @@ void TestPersonalDataManager::OnSyncServiceInitialized(
sync_service_initialized_ = true; sync_service_initialized_ = true;
} }
AutofillSyncSigninState TestPersonalDataManager::GetSyncSigninState() const {
return sync_and_signin_state_;
}
void TestPersonalDataManager::RecordUseOf(const AutofillDataModel& data_model) { void TestPersonalDataManager::RecordUseOf(const AutofillDataModel& data_model) {
CreditCard* credit_card = GetCreditCardWithGUID(data_model.guid().c_str()); CreditCard* credit_card = GetCreditCardWithGUID(data_model.guid().c_str());
if (credit_card) if (credit_card)
......
...@@ -28,6 +28,7 @@ class TestPersonalDataManager : public PersonalDataManager { ...@@ -28,6 +28,7 @@ class TestPersonalDataManager : public PersonalDataManager {
// for various tests, whether to skip calls to uncreated databases/services, // for various tests, whether to skip calls to uncreated databases/services,
// or to make things easier in general to toggle. // or to make things easier in general to toggle.
void OnSyncServiceInitialized(syncer::SyncService* sync_service) override; void OnSyncServiceInitialized(syncer::SyncService* sync_service) override;
AutofillSyncSigninState GetSyncSigninState() const override;
void RecordUseOf(const AutofillDataModel& data_model) override; void RecordUseOf(const AutofillDataModel& data_model) override;
std::string SaveImportedProfile( std::string SaveImportedProfile(
const AutofillProfile& imported_profile) override; const AutofillProfile& imported_profile) override;
...@@ -115,6 +116,10 @@ class TestPersonalDataManager : public PersonalDataManager { ...@@ -115,6 +116,10 @@ class TestPersonalDataManager : public PersonalDataManager {
void SetSyncFeatureEnabled(bool enabled) { sync_feature_enabled_ = enabled; } void SetSyncFeatureEnabled(bool enabled) { sync_feature_enabled_ = enabled; }
void SetSyncAndSignInState(AutofillSyncSigninState sync_and_signin_state) {
sync_and_signin_state_ = sync_and_signin_state;
}
void SetAccountInfoForPayments(const CoreAccountInfo& account_info) { void SetAccountInfoForPayments(const CoreAccountInfo& account_info) {
account_info_ = account_info; account_info_ = account_info;
} }
...@@ -129,6 +134,8 @@ class TestPersonalDataManager : public PersonalDataManager { ...@@ -129,6 +134,8 @@ class TestPersonalDataManager : public PersonalDataManager {
base::Optional<bool> autofill_credit_card_enabled_; base::Optional<bool> autofill_credit_card_enabled_;
base::Optional<bool> autofill_wallet_import_enabled_; base::Optional<bool> autofill_wallet_import_enabled_;
bool sync_feature_enabled_ = false; bool sync_feature_enabled_ = false;
AutofillSyncSigninState sync_and_signin_state_ =
AutofillSyncSigninState::kSignedInAndSyncFeature;
bool sync_service_initialized_ = false; bool sync_service_initialized_ = false;
CoreAccountInfo account_info_; CoreAccountInfo account_info_;
......
...@@ -96,6 +96,12 @@ const base::Feature kAutofillEnableCompanyName{ ...@@ -96,6 +96,12 @@ const base::Feature kAutofillEnableCompanyName{
const base::Feature kAutofillEnableIFrameSupportOniOS{ const base::Feature kAutofillEnableIFrameSupportOniOS{
"AutofillEnableIFrameSupportOniOS", base::FEATURE_ENABLED_BY_DEFAULT}; "AutofillEnableIFrameSupportOniOS", base::FEATURE_ENABLED_BY_DEFAULT};
// When enabled, enable local card migration flow for user who has signed in but
// has not turned on sync.
const base::Feature kAutofillEnableLocalCardMigrationForNonSyncUser{
"AutofillEnableLocalCardMigrationForNonSyncUser",
base::FEATURE_DISABLED_BY_DEFAULT};
// When enabled, no local copy of server card will be saved when upload // When enabled, no local copy of server card will be saved when upload
// succeeds. // succeeds.
const base::Feature kAutofillNoLocalSaveOnUploadSuccess{ const base::Feature kAutofillNoLocalSaveOnUploadSuccess{
......
...@@ -39,6 +39,7 @@ extern const base::Feature kAutofillEnableAccountWalletStorage; ...@@ -39,6 +39,7 @@ extern const base::Feature kAutofillEnableAccountWalletStorage;
extern const base::Feature kAutofillEnableAccountWalletStorageUpload; extern const base::Feature kAutofillEnableAccountWalletStorageUpload;
extern const base::Feature kAutofillEnableCompanyName; extern const base::Feature kAutofillEnableCompanyName;
extern const base::Feature kAutofillEnableIFrameSupportOniOS; extern const base::Feature kAutofillEnableIFrameSupportOniOS;
extern const base::Feature kAutofillEnableLocalCardMigrationForNonSyncUser;
extern const base::Feature kAutofillEnforceMinRequiredFieldsForHeuristics; extern const base::Feature kAutofillEnforceMinRequiredFieldsForHeuristics;
extern const base::Feature kAutofillEnforceMinRequiredFieldsForQuery; extern const base::Feature kAutofillEnforceMinRequiredFieldsForQuery;
extern const base::Feature kAutofillEnforceMinRequiredFieldsForUpload; extern const base::Feature kAutofillEnforceMinRequiredFieldsForUpload;
......
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