| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/autofill_manager.h" | 5 #include "components/autofill/core/browser/autofill_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 void EnableAutofillOfferLocalSaveIfServerCardManuallyEnteredExperiment() { | 1074 void EnableAutofillOfferLocalSaveIfServerCardManuallyEnteredExperiment() { |
| 1075 scoped_feature_list_.InitAndEnableFeature( | 1075 scoped_feature_list_.InitAndEnableFeature( |
| 1076 kAutofillOfferLocalSaveIfServerCardManuallyEntered); | 1076 kAutofillOfferLocalSaveIfServerCardManuallyEntered); |
| 1077 } | 1077 } |
| 1078 | 1078 |
| 1079 void EnableAutofillUpstreamRequestCvcIfMissingExperiment() { | 1079 void EnableAutofillUpstreamRequestCvcIfMissingExperiment() { |
| 1080 scoped_feature_list_.InitAndEnableFeature( | 1080 scoped_feature_list_.InitAndEnableFeature( |
| 1081 kAutofillUpstreamRequestCvcIfMissing); | 1081 kAutofillUpstreamRequestCvcIfMissing); |
| 1082 } | 1082 } |
| 1083 | 1083 |
| 1084 void EnableAutofillUpstreamShowNewUiExperiment() { |
| 1085 scoped_feature_list_.InitAndEnableFeature(kAutofillUpstreamShowNewUi); |
| 1086 } |
| 1087 |
| 1084 void DisableAutofillUpstreamUseAutofillProfileComparator() { | 1088 void DisableAutofillUpstreamUseAutofillProfileComparator() { |
| 1085 scoped_feature_list_.InitAndDisableFeature( | 1089 scoped_feature_list_.InitAndDisableFeature( |
| 1086 kAutofillUpstreamUseAutofillProfileComparator); | 1090 kAutofillUpstreamUseAutofillProfileComparator); |
| 1087 } | 1091 } |
| 1088 | 1092 |
| 1089 void ExpectUniqueFillableFormParsedUkm() { | 1093 void ExpectUniqueFillableFormParsedUkm() { |
| 1090 // Check that one source is logged. | 1094 // Check that one source is logged. |
| 1091 ASSERT_EQ(1U, test_ukm_recorder_.sources_count()); | 1095 ASSERT_EQ(1U, test_ukm_recorder_.sources_count()); |
| 1092 const ukm::UkmSource* source = GetUkmSources(&test_ukm_recorder_)[0]; | 1096 const ukm::UkmSource* source = GetUkmSources(&test_ukm_recorder_)[0]; |
| 1093 | 1097 |
| (...skipping 4201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5295 FormSubmitted(credit_card_form); | 5299 FormSubmitted(credit_card_form); |
| 5296 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); | 5300 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); |
| 5297 | 5301 |
| 5298 // Verify that the correct histogram entry (and only that) was logged. | 5302 // Verify that the correct histogram entry (and only that) was logged. |
| 5299 ExpectUniqueCardUploadDecision(histogram_tester, | 5303 ExpectUniqueCardUploadDecision(histogram_tester, |
| 5300 AutofillMetrics::CVC_FIELD_NOT_FOUND); | 5304 AutofillMetrics::CVC_FIELD_NOT_FOUND); |
| 5301 // Verify that the correct UKM was logged. | 5305 // Verify that the correct UKM was logged. |
| 5302 ExpectCardUploadDecisionUkm(AutofillMetrics::CVC_FIELD_NOT_FOUND); | 5306 ExpectCardUploadDecisionUkm(AutofillMetrics::CVC_FIELD_NOT_FOUND); |
| 5303 } | 5307 } |
| 5304 | 5308 |
| 5309 // kAutofillUpstreamShowNewUi flag is currently not available on Android. |
| 5310 #if !defined(OS_ANDROID) |
| 5311 TEST_F(AutofillManagerTest, |
| 5312 UploadCreditCard_AddNewUiFlagStateToRequestIfExperimentOn) { |
| 5313 EnableAutofillUpstreamShowNewUiExperiment(); |
| 5314 personal_data_.ClearAutofillProfiles(); |
| 5315 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5316 |
| 5317 // Create, fill and submit an address form in order to establish a recent |
| 5318 // profile which can be selected for the upload request. |
| 5319 FormData address_form; |
| 5320 test::CreateTestAddressFormData(&address_form); |
| 5321 FormsSeen(std::vector<FormData>(1, address_form)); |
| 5322 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); |
| 5323 FormSubmitted(address_form); |
| 5324 |
| 5325 // Set up our credit card form data. |
| 5326 FormData credit_card_form; |
| 5327 CreateTestCreditCardFormData(&credit_card_form, true, false); |
| 5328 FormsSeen(std::vector<FormData>(1, credit_card_form)); |
| 5329 |
| 5330 // Edit the data, and submit. |
| 5331 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); |
| 5332 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
| 5333 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
| 5334 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
| 5335 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 5336 |
| 5337 base::HistogramTester histogram_tester; |
| 5338 |
| 5339 // Confirm upload happened and the new UI flag was sent in the request. |
| 5340 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 5341 FormSubmitted(credit_card_form); |
| 5342 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 5343 EXPECT_THAT( |
| 5344 autofill_manager_->GetActiveExperiments(), |
| 5345 UnorderedElementsAre(kAutofillUpstreamUseAutofillProfileComparator.name, |
| 5346 kAutofillUpstreamShowNewUi.name)); |
| 5347 } |
| 5348 |
| 5349 TEST_F(AutofillManagerTest, |
| 5350 UploadCreditCard_DoNotAddNewUiFlagStateToRequestIfExperimentOff) { |
| 5351 personal_data_.ClearAutofillProfiles(); |
| 5352 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5353 |
| 5354 // Create, fill and submit an address form in order to establish a recent |
| 5355 // profile which can be selected for the upload request. |
| 5356 FormData address_form; |
| 5357 test::CreateTestAddressFormData(&address_form); |
| 5358 FormsSeen(std::vector<FormData>(1, address_form)); |
| 5359 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); |
| 5360 FormSubmitted(address_form); |
| 5361 |
| 5362 // Set up our credit card form data. |
| 5363 FormData credit_card_form; |
| 5364 CreateTestCreditCardFormData(&credit_card_form, true, false); |
| 5365 FormsSeen(std::vector<FormData>(1, credit_card_form)); |
| 5366 |
| 5367 // Edit the data, and submit. |
| 5368 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master"); |
| 5369 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); |
| 5370 credit_card_form.fields[2].value = ASCIIToUTF16("11"); |
| 5371 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); |
| 5372 credit_card_form.fields[4].value = ASCIIToUTF16("123"); |
| 5373 |
| 5374 base::HistogramTester histogram_tester; |
| 5375 |
| 5376 // Confirm upload happened and the new UI flag was sent in the request. |
| 5377 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); |
| 5378 FormSubmitted(credit_card_form); |
| 5379 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); |
| 5380 EXPECT_THAT( |
| 5381 autofill_manager_->GetActiveExperiments(), |
| 5382 UnorderedElementsAre(kAutofillUpstreamUseAutofillProfileComparator.name)); |
| 5383 } |
| 5384 #endif |
| 5385 |
| 5305 TEST_F(AutofillManagerTest, UploadCreditCard_NoProfileAvailable) { | 5386 TEST_F(AutofillManagerTest, UploadCreditCard_NoProfileAvailable) { |
| 5306 personal_data_.ClearAutofillProfiles(); | 5387 personal_data_.ClearAutofillProfiles(); |
| 5307 autofill_manager_->set_credit_card_upload_enabled(true); | 5388 autofill_manager_->set_credit_card_upload_enabled(true); |
| 5308 | 5389 |
| 5309 // Don't fill or submit an address form. | 5390 // Don't fill or submit an address form. |
| 5310 | 5391 |
| 5311 // Set up our credit card form data. | 5392 // Set up our credit card form data. |
| 5312 FormData credit_card_form; | 5393 FormData credit_card_form; |
| 5313 CreateTestCreditCardFormData(&credit_card_form, true, false); | 5394 CreateTestCreditCardFormData(&credit_card_form, true, false); |
| 5314 FormsSeen(std::vector<FormData>(1, credit_card_form)); | 5395 FormsSeen(std::vector<FormData>(1, credit_card_form)); |
| (...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7020 | 7101 |
| 7021 // Wait for upload to complete (will check expected types as well). | 7102 // Wait for upload to complete (will check expected types as well). |
| 7022 autofill_manager_->WaitForAsyncUploadProcess(); | 7103 autofill_manager_->WaitForAsyncUploadProcess(); |
| 7023 | 7104 |
| 7024 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); | 7105 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); |
| 7025 EXPECT_NE(uploaded_available_types.end(), | 7106 EXPECT_NE(uploaded_available_types.end(), |
| 7026 uploaded_available_types.find(autofill::PASSWORD)); | 7107 uploaded_available_types.find(autofill::PASSWORD)); |
| 7027 } | 7108 } |
| 7028 | 7109 |
| 7029 } // namespace autofill | 7110 } // namespace autofill |
| OLD | NEW |