Commit ee7c6129 authored by Lakshmi Kumar Dabbiru's avatar Lakshmi Kumar Dabbiru Committed by Commit Bot

Dont offer migration again if rejected in the past

Bug: 852904
Change-Id: I5236586d58bea0888964c9f9babc5b1f183768d9
Reviewed-on: https://chromium-review.googlesource.com/1242395
Commit-Queue: Lakshmi Kumar Dabbiru <dlkumar@google.com>
Reviewed-by: default avatarFabio Tirelo <ftirelo@chromium.org>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Cr-Commit-Position: refs/heads/master@{#595955}
parent 74e0dceb
......@@ -15,17 +15,25 @@
#include "build/build_config.h"
#include "chrome/browser/ui/autofill/local_card_migration_dialog.h"
#include "chrome/browser/ui/autofill/local_card_migration_dialog_state.h"
#include "chrome/browser/ui/browser.h"
#include "components/autofill/core/browser/autofill_metrics.h"
#include "components/autofill/core/browser/local_card_migration_manager.h"
#include "components/autofill/core/browser/payments/payments_service_url.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
namespace autofill {
LocalCardMigrationDialogControllerImpl::LocalCardMigrationDialogControllerImpl(
content::WebContents* web_contents)
: web_contents_(web_contents), local_card_migration_dialog_(nullptr) {}
: web_contents_(web_contents),
local_card_migration_dialog_(nullptr),
pref_service_(
user_prefs::UserPrefs::Get(web_contents->GetBrowserContext())) {}
LocalCardMigrationDialogControllerImpl::
~LocalCardMigrationDialogControllerImpl() {
......@@ -92,6 +100,8 @@ void LocalCardMigrationDialogControllerImpl::OnCancelButtonClicked() {
AutofillMetrics::
LOCAL_CARD_MIGRATION_DIALOG_CLOSED_CANCEL_BUTTON_CLICKED);
prefs::SetLocalCardMigrationPromptPreviouslyCancelled(pref_service_, true);
start_migrating_cards_callback_.Reset();
}
......
......@@ -57,6 +57,8 @@ class LocalCardMigrationDialogControllerImpl
LocalCardMigrationDialog* local_card_migration_dialog_;
PrefService* pref_service_;
LocalCardMigrationDialogState view_state_;
LegalMessageLines legal_message_lines_;
......
......@@ -61,6 +61,10 @@ bool LocalCardMigrationManager::ShouldOfferLocalCardMigration(
if (!IsCreditCardMigrationEnabled())
return false;
// Don't show the the prompt if user cancelled/rejected previously.
if (prefs::IsLocalCardMigrationPromptPreviouslyCancelled(client_->GetPrefs()))
return false;
// Fetch all migratable credit cards and store in |migratable_credit_cards_|.
GetMigratableCreditCards();
......
......@@ -695,6 +695,44 @@ TEST_F(LocalCardMigrationManagerTest,
EXPECT_TRUE(local_card_migration_manager_->MainPromptWasShown());
}
// Verify that when triggering from submitted form, intermediate prompt and main
// prompt are not triggered as user previously rejected the prompt.
TEST_F(LocalCardMigrationManagerTest,
MigrateCreditCard_DontTriggerFromSubmittedForm) {
EnableAutofillCreditCardLocalCardMigrationExperiment();
// Set the billing_customer_number Priority Preference to designate
// existence of a Payments account.
autofill_client_.GetPrefs()->SetDouble(prefs::kAutofillBillingCustomerNumber,
12345);
// Set that previously user rejected this prompt.
prefs::SetLocalCardMigrationPromptPreviouslyCancelled(
autofill_client_.GetPrefs(), true);
// Add a local credit card whose |TypeAndLastFourDigits| matches what we will
// enter below.
AddLocalCrediCard(personal_data_, "Flo Master", "4111111111111111", "11",
test::NextYear().c_str(), "1", "guid1");
// Add another local credit card, so it will trigger migration.
AddLocalCrediCard(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");
// Migration should not be offered because user previously rejected
// migration prompt.
FormSubmitted(credit_card_form);
EXPECT_FALSE(local_card_migration_manager_->IntermediatePromptWasShown());
EXPECT_FALSE(local_card_migration_manager_->MainPromptWasShown());
}
// Verify that given the parsed response from the payments client, the migration
// status is correctly set.
TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_MigrationSuccess) {
......
......@@ -54,6 +54,11 @@ const char kAutofillLastVersionDisusedAddressesDeleted[] =
const char kAutofillLastVersionDisusedCreditCardsDeleted[] =
"autofill.last_version_disused_credit_cards_deleted";
// Boolean that is set to denote whether user cancelled/rejected local card
// migration prompt.
const char kAutofillMigrateLocalCardsCancelledPrompt[] =
"autofill.migrate_local_card_cancelled_state";
// Boolean that is true if the orphan rows in the autofill table were removed.
const char kAutofillOrphanRowsRemoved[] = "autofill.orphan_rows_removed";
......@@ -116,6 +121,8 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE);
registry->RegisterIntegerPref(
prefs::kAutofillLastVersionDisusedCreditCardsDeleted, 0);
registry->RegisterBooleanPref(
prefs::kAutofillMigrateLocalCardsCancelledPrompt, false);
registry->RegisterBooleanPref(prefs::kAutofillOrphanRowsRemoved, false);
registry->RegisterDictionaryPref(prefs::kAutofillUploadEvents);
registry->RegisterTimePref(prefs::kAutofillUploadEventsLastResetTimestamp,
......@@ -165,6 +172,14 @@ void SetAutofillEnabled(PrefService* prefs, bool enabled) {
SetCreditCardAutofillEnabled(prefs, enabled);
}
bool IsCreditCardAutofillEnabled(const PrefService* prefs) {
return prefs->GetBoolean(kAutofillCreditCardEnabled);
}
void SetCreditCardAutofillEnabled(PrefService* prefs, bool enabled) {
prefs->SetBoolean(kAutofillCreditCardEnabled, enabled);
}
bool IsAutofillManaged(const PrefService* prefs) {
return prefs->IsManagedPreference(kAutofillEnabledDeprecated);
}
......@@ -185,12 +200,13 @@ void SetProfileAutofillEnabled(PrefService* prefs, bool enabled) {
prefs->SetBoolean(kAutofillProfileEnabled, enabled);
}
bool IsCreditCardAutofillEnabled(const PrefService* prefs) {
return prefs->GetBoolean(kAutofillCreditCardEnabled);
bool IsLocalCardMigrationPromptPreviouslyCancelled(const PrefService* prefs) {
return prefs->GetBoolean(kAutofillMigrateLocalCardsCancelledPrompt);
}
void SetCreditCardAutofillEnabled(PrefService* prefs, bool enabled) {
prefs->SetBoolean(kAutofillCreditCardEnabled, enabled);
void SetLocalCardMigrationPromptPreviouslyCancelled(PrefService* prefs,
bool enabled) {
prefs->SetBoolean(kAutofillMigrateLocalCardsCancelledPrompt, enabled);
}
bool IsPaymentsIntegrationEnabled(const PrefService* prefs) {
......
......@@ -29,14 +29,15 @@ extern const char kAutofillJapanCityFieldMigrated[];
extern const char kAutofillLastVersionDeduped[];
extern const char kAutofillLastVersionDisusedAddressesDeleted[];
extern const char kAutofillLastVersionDisusedCreditCardsDeleted[];
extern const char kAutofillMigrateLocalCardsCancelledPrompt[];
extern const char kAutofillOrphanRowsRemoved[];
// Do not get/set the value of this pref directly. Use provided getter/setter.
extern const char kAutofillProfileEnabled[];
extern const char kAutofillProfileValidity[];
extern const char kAutofillUploadEvents[];
extern const char kAutofillUploadEventsLastResetTimestamp[];
extern const char kAutofillWalletImportEnabled[];
extern const char kAutofillWalletImportStorageCheckboxState[];
extern const char kAutofillProfileValidity[];
// Possible values for previous user decision when we displayed a save credit
// card prompt.
......@@ -59,6 +60,10 @@ bool IsAutofillEnabled(const PrefService* prefs);
void SetAutofillEnabled(PrefService* prefs, bool enabled);
bool IsCreditCardAutofillEnabled(const PrefService* prefs);
void SetCreditCardAutofillEnabled(PrefService* prefs, bool enabled);
bool IsAutofillManaged(const PrefService* prefs);
bool IsProfileAutofillManaged(const PrefService* prefs);
......@@ -69,9 +74,10 @@ bool IsProfileAutofillEnabled(const PrefService* prefs);
void SetProfileAutofillEnabled(PrefService* prefs, bool enabled);
bool IsCreditCardAutofillEnabled(const PrefService* prefs);
bool IsLocalCardMigrationPromptPreviouslyCancelled(const PrefService* prefs);
void SetCreditCardAutofillEnabled(PrefService* prefs, bool enabled);
void SetLocalCardMigrationPromptPreviouslyCancelled(PrefService* prefs,
bool enabled);
bool IsPaymentsIntegrationEnabled(const PrefService* prefs);
......
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