Index: components/autofill/core/browser/autofill_manager_unittest.cc |
diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc |
index 4421a1d4a9d84c34d13c7e662d5b5c8dbc4a9d67..ab4da523f352175454acf24bb1f7231767889c74 100644 |
--- a/components/autofill/core/browser/autofill_manager_unittest.cc |
+++ b/components/autofill/core/browser/autofill_manager_unittest.cc |
@@ -77,6 +77,7 @@ using testing::_; |
using testing::AtLeast; |
using testing::Return; |
using testing::SaveArg; |
+using testing::UnorderedElementsAre; |
namespace autofill { |
namespace { |
@@ -117,7 +118,9 @@ class TestPaymentsClient : public payments::PaymentsClient { |
~TestPaymentsClient() override {} |
void GetUploadDetails(const std::vector<AutofillProfile>& addresses, |
+ const std::vector<const char*>& active_experiments, |
const std::string& app_locale) override { |
+ active_experiments_ = active_experiments; |
delegate_->OnDidGetUploadDetails( |
app_locale == "en-US" ? AutofillClient::SUCCESS |
: AutofillClient::PERMANENT_FAILURE, |
@@ -127,10 +130,12 @@ class TestPaymentsClient : public payments::PaymentsClient { |
void UploadCard(const payments::PaymentsClient::UploadRequestDetails& |
request_details) override { |
+ active_experiments_ = request_details.active_experiments; |
delegate_->OnDidUploadCard(AutofillClient::SUCCESS, server_id_); |
} |
std::string server_id_; |
+ std::vector<const char*> active_experiments_; |
private: |
payments::PaymentsClientDelegate* const delegate_; |
@@ -559,12 +564,13 @@ class TestAutofillManager : public AutofillManager { |
: AutofillManager(driver, client, personal_data), |
personal_data_(personal_data), |
context_getter_(driver->GetURLRequestContext()), |
+ test_payments_client_(new TestPaymentsClient(context_getter_, this)), |
autofill_enabled_(true), |
credit_card_upload_enabled_(false), |
credit_card_was_uploaded_(false), |
expected_observed_submission_(true), |
call_parent_upload_form_data_(false) { |
- set_payments_client(new TestPaymentsClient(context_getter_, this)); |
+ set_payments_client(test_payments_client_); |
} |
~TestAutofillManager() override {} |
@@ -675,6 +681,10 @@ class TestAutofillManager : public AutofillManager { |
personal_data_->AddCreditCard(credit_card); |
} |
+ const std::vector<const char*>& GetActiveExperiments() const { |
+ return test_payments_client_->active_experiments_; |
+ } |
+ |
int GetPackedCreditCardID(int credit_card_id) { |
std::string credit_card_guid = |
base::StringPrintf("00000000-0000-0000-0000-%012d", credit_card_id); |
@@ -704,6 +714,7 @@ class TestAutofillManager : public AutofillManager { |
TestPersonalDataManager* personal_data_; // Weak reference. |
net::URLRequestContextGetter* context_getter_; // Weak reference. |
+ TestPaymentsClient* test_payments_client_; // Weak reference. |
bool autofill_enabled_; |
bool credit_card_upload_enabled_; |
bool credit_card_was_uploaded_; |
@@ -1071,8 +1082,8 @@ class AutofillManagerTest : public testing::Test { |
} |
void EnableAutofillUpstreamRequestCvcIfMissingExperiment() { |
- scoped_feature_list_.InitWithFeatures( |
- {kAutofillUpstreamRequestCvcIfMissing}, {}); |
+ scoped_feature_list_.InitAndEnableFeature( |
+ kAutofillUpstreamRequestCvcIfMissing); |
} |
void DisableAutofillUpstreamUseAutofillProfileComparatorForName() { |
@@ -4668,6 +4679,9 @@ TEST_F(AutofillManagerTest, UploadCreditCard) { |
EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
FormSubmitted(credit_card_form); |
EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
+ EXPECT_THAT(autofill_manager_->GetActiveExperiments(), |
+ UnorderedElementsAre( |
+ kAutofillUpstreamUseAutofillProfileComparatorForName.name)); |
// Server did not send a server_id, expect copy of card is not stored. |
EXPECT_TRUE(autofill_manager_->GetCreditCards().empty()); |
@@ -4685,6 +4699,43 @@ TEST_F(AutofillManagerTest, UploadCreditCard) { |
"Autofill.DaysSincePreviousUseAtSubmission.Profile", 0); |
} |
+TEST_F(AutofillManagerTest, UploadCreditCard_RequestCVCEnabled_DoesNotTrigger) { |
+ EnableAutofillUpstreamRequestCvcIfMissingExperiment(); |
+ |
+ personal_data_.ClearCreditCards(); |
+ personal_data_.ClearAutofillProfiles(); |
+ autofill_manager_->set_credit_card_upload_enabled(true); |
+ |
+ // Create, fill and submit an address form in order to establish a recent |
+ // profile which can be selected for the upload request. |
+ FormData address_form; |
+ test::CreateTestAddressFormData(&address_form); |
+ FormsSeen({address_form}); |
+ |
+ ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); |
+ FormSubmitted(address_form); |
+ |
+ // Set up our credit card form data. |
+ FormData credit_card_form; |
+ CreateTestCreditCardFormData(&credit_card_form, true, false); |
+ FormsSeen({credit_card_form}); |
+ |
+ // Edit the data, and submit. |
+ credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); |
+ credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
+ credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
+ credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
+ credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
+ |
+ EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
+ FormSubmitted(credit_card_form); |
+ EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
+ // Submitted form included CVC, so user did not need to enter CVC. |
+ EXPECT_THAT(autofill_manager_->GetActiveExperiments(), |
+ UnorderedElementsAre( |
+ kAutofillUpstreamUseAutofillProfileComparatorForName.name)); |
+} |
+ |
TEST_F(AutofillManagerTest, UploadCreditCardAndSaveCopy) { |
personal_data_.ClearCreditCards(); |
personal_data_.ClearAutofillProfiles(); |
@@ -5211,6 +5262,10 @@ TEST_F(AutofillManagerTest, |
EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
FormSubmitted(credit_card_form); |
EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
+ EXPECT_THAT(autofill_manager_->GetActiveExperiments(), |
+ UnorderedElementsAre( |
+ kAutofillUpstreamUseAutofillProfileComparatorForName.name, |
+ kAutofillUpstreamRequestCvcIfMissing.name)); |
// Verify that the correct histogram entries were logged. |
ExpectCardUploadDecision(histogram_tester, AutofillMetrics::UPLOAD_OFFERED); |
@@ -5428,6 +5483,10 @@ TEST_F(AutofillManagerTest, |
EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
FormSubmitted(credit_card_form); |
EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
+ EXPECT_THAT(autofill_manager_->GetActiveExperiments(), |
+ UnorderedElementsAre( |
+ kAutofillUpstreamUseAutofillProfileComparatorForName.name, |
+ kAutofillUpstreamUseNotRecentlyUsedAutofillProfile.name)); |
// Verify that the correct histogram entry (and only that) was logged. |
ExpectUniqueCardUploadDecision(histogram_tester, |
@@ -5757,6 +5816,7 @@ TEST_F(AutofillManagerTest, |
EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
FormSubmitted(credit_card_form); |
EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
+ EXPECT_TRUE(autofill_manager_->GetActiveExperiments().empty()); |
// Verify that the correct histogram entry (and only that) was logged. |
ExpectUniqueCardUploadDecision(histogram_tester, |
@@ -6114,6 +6174,10 @@ TEST_F(AutofillManagerTest, |
EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
FormSubmitted(credit_card_form); |
EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
+ // Recently used profile was available, so did not need to use old profile. |
+ EXPECT_THAT(autofill_manager_->GetActiveExperiments(), |
+ UnorderedElementsAre( |
+ kAutofillUpstreamUseAutofillProfileComparatorForName.name)); |
// Verify that the correct histogram entry (and only that) was logged. |
ExpectUniqueCardUploadDecision(histogram_tester, |