Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 2789843004: [Payments] Upload card UI now has a CVC prompt (Closed)
Patch Set: Address code review comment Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 1025
1026 void SetHttpWarningEnabled() { 1026 void SetHttpWarningEnabled() {
1027 scoped_feature_list_.InitAndEnableFeature( 1027 scoped_feature_list_.InitAndEnableFeature(
1028 security_state::kHttpFormWarningFeature); 1028 security_state::kHttpFormWarningFeature);
1029 } 1029 }
1030 1030
1031 void EnableUkmLogging() { 1031 void EnableUkmLogging() {
1032 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging); 1032 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging);
1033 } 1033 }
1034 1034
1035 void EnableAutofillUpstreamRequestCvcIfMissingExperimentAndUkmLogging() {
1036 scoped_feature_list_.InitWithFeatures(
1037 {kAutofillUpstreamRequestCvcIfMissing, kAutofillUkmLogging}, {});
1038 }
1039
1035 void ExpectUniqueFillableFormParsedUkm() { 1040 void ExpectUniqueFillableFormParsedUkm() {
1036 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 1041 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
1037 1042
1038 // Check that one source is logged. 1043 // Check that one source is logged.
1039 ASSERT_EQ(1U, ukm_service->sources_count()); 1044 ASSERT_EQ(1U, ukm_service->sources_count());
1040 const ukm::UkmSource* source = GetUkmSources(ukm_service)[0]; 1045 const ukm::UkmSource* source = GetUkmSources(ukm_service)[0];
1041 1046
1042 // Check that one entry is logged. 1047 // Check that one entry is logged.
1043 EXPECT_EQ(1U, ukm_service->entries_count()); 1048 EXPECT_EQ(1U, ukm_service->entries_count());
1044 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); 1049 const ukm::UkmEntry* entry = ukm_service->GetEntry(0);
(...skipping 3790 matching lines...) Expand 10 before | Expand all | Expand 10 after
4835 // Verify that the correct histogram entry (and only that) was logged. 4840 // Verify that the correct histogram entry (and only that) was logged.
4836 histogram_tester.ExpectUniqueSample( 4841 histogram_tester.ExpectUniqueSample(
4837 "Autofill.CardUploadDecisionExpanded", 4842 "Autofill.CardUploadDecisionExpanded",
4838 AutofillMetrics::UPLOAD_OFFERED, 1); 4843 AutofillMetrics::UPLOAD_OFFERED, 1);
4839 // Verify that the correct UKM was logged. 4844 // Verify that the correct UKM was logged.
4840 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); 4845 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED);
4841 } 4846 }
4842 4847
4843 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 4848 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4844 #if defined(OS_ANDROID) 4849 #if defined(OS_ANDROID)
4850 #define MAYBE_UploadCreditCard_NoCvcFieldOnForm \
4851 DISABLED_UploadCreditCard_NoCvcFieldOnForm
4852 #else
4853 #define MAYBE_UploadCreditCard_NoCvcFieldOnForm \
4854 UploadCreditCard_NoCvcFieldOnForm
4855 #endif
4856 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoCvcFieldOnForm) {
4857 EnableAutofillUpstreamRequestCvcIfMissingExperimentAndUkmLogging();
4858 autofill_manager_->set_credit_card_upload_enabled(true);
4859
4860 // Remove the profiles that were created in the TestPersonalDataManager
4861 // constructor because they would result in conflicting names that would
4862 // prevent the upload.
4863 personal_data_.ClearAutofillProfiles();
4864
4865 // Create, fill and submit an address form in order to establish a recent
4866 // profile which can be selected for the upload request.
4867 FormData address_form;
4868 test::CreateTestAddressFormData(&address_form);
4869 FormsSeen(std::vector<FormData>(1, address_form));
4870 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form);
4871 FormSubmitted(address_form);
4872
4873 // Set up our credit card form data. Note that CVC field is missing.
4874 FormData credit_card_form;
4875 credit_card_form.name = ASCIIToUTF16("MyForm");
4876 credit_card_form.origin = GURL("https://myform.com/form.html");
4877 credit_card_form.action = GURL("https://myform.com/submit.html");
4878
4879 FormFieldData field;
4880 test::CreateTestFormField("Card Name", "cardname", "", "text", &field);
4881 credit_card_form.fields.push_back(field);
4882 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field);
4883 credit_card_form.fields.push_back(field);
4884 test::CreateTestFormField("Expiration Month", "ccmonth", "", "text", &field);
4885 credit_card_form.fields.push_back(field);
4886 test::CreateTestFormField("Expiration Year", "ccyear", "", "text", &field);
4887 credit_card_form.fields.push_back(field);
4888
4889 FormsSeen(std::vector<FormData>(1, credit_card_form));
4890
4891 // Edit the data, and submit.
4892 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master");
4893 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111");
4894 credit_card_form.fields[2].value = ASCIIToUTF16("11");
4895 credit_card_form.fields[3].value = ASCIIToUTF16("2017");
4896
4897 base::HistogramTester histogram_tester;
4898
4899 // Upload should still happen as long as the user provides CVC in the bubble.
4900 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4901 FormSubmitted(credit_card_form);
4902 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded());
4903
4904 // Verify that the correct histogram entry (and only that) was logged.
4905 histogram_tester.ExpectUniqueSample("Autofill.CardUploadDecisionExpanded",
4906 AutofillMetrics::UPLOAD_OFFERED_NO_CVC,
4907 1);
4908 // Verify that the correct UKM was logged.
4909 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED_NO_CVC);
4910 }
4911
4912 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4913 #if defined(OS_ANDROID)
4914 #define MAYBE_UploadCreditCard_NoCvcFieldOnFormExperimentOff \
4915 DISABLED_UploadCreditCard_NoCvcFieldOnFormExperimentOff
4916 #else
4917 #define MAYBE_UploadCreditCard_NoCvcFieldOnFormExperimentOff \
4918 UploadCreditCard_NoCvcFieldOnFormExperimentOff
4919 #endif
4920 TEST_F(AutofillManagerTest,
4921 MAYBE_UploadCreditCard_NoCvcFieldOnFormExperimentOff) {
4922 EnableUkmLogging();
4923 autofill_manager_->set_credit_card_upload_enabled(true);
4924
4925 // Remove the profiles that were created in the TestPersonalDataManager
4926 // constructor because they would result in conflicting names that would
4927 // prevent the upload.
4928 personal_data_.ClearAutofillProfiles();
4929
4930 // Create, fill and submit an address form in order to establish a recent
4931 // profile which can be selected for the upload request.
4932 FormData address_form;
4933 test::CreateTestAddressFormData(&address_form);
4934 FormsSeen(std::vector<FormData>(1, address_form));
4935 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form);
4936 FormSubmitted(address_form);
4937
4938 // Set up our credit card form data. Note that CVC field is missing.
4939 FormData credit_card_form;
4940 credit_card_form.name = ASCIIToUTF16("MyForm");
4941 credit_card_form.origin = GURL("https://myform.com/form.html");
4942 credit_card_form.action = GURL("https://myform.com/submit.html");
4943
4944 FormFieldData field;
4945 test::CreateTestFormField("Card Name", "cardname", "", "text", &field);
4946 credit_card_form.fields.push_back(field);
4947 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field);
4948 credit_card_form.fields.push_back(field);
4949 test::CreateTestFormField("Expiration Month", "ccmonth", "", "text", &field);
4950 credit_card_form.fields.push_back(field);
4951 test::CreateTestFormField("Expiration Year", "ccyear", "", "text", &field);
4952 credit_card_form.fields.push_back(field);
4953
4954 FormsSeen(std::vector<FormData>(1, credit_card_form));
4955
4956 // Edit the data, and submit.
4957 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master");
4958 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111");
4959 credit_card_form.fields[2].value = ASCIIToUTF16("11");
4960 credit_card_form.fields[3].value = ASCIIToUTF16("2017");
4961
4962 base::HistogramTester histogram_tester;
4963
4964 // Neither a local save nor an upload should happen in this case.
4965 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4966 FormSubmitted(credit_card_form);
4967 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded());
4968
4969 // Verify that the correct histogram entry (and only that) was logged.
4970 histogram_tester.ExpectUniqueSample(
4971 "Autofill.CardUploadDecisionExpanded",
4972 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC, 1);
4973 // Verify that the correct UKM was logged.
4974 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC);
4975
4976 rappor::TestRapporServiceImpl* rappor_service =
4977 autofill_client_.test_rappor_service();
4978 EXPECT_EQ(1, rappor_service->GetReportsCount());
4979 std::string sample;
4980 rappor::RapporType type;
4981 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric(
4982 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type));
4983 EXPECT_EQ("myform.com", sample);
4984 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
4985 }
4986
4987 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4988 #if defined(OS_ANDROID)
4845 #define MAYBE_UploadCreditCard_NoProfileAvailable DISABLED_UploadCreditCard_NoPr ofileAvailable 4989 #define MAYBE_UploadCreditCard_NoProfileAvailable DISABLED_UploadCreditCard_NoPr ofileAvailable
4846 #else 4990 #else
4847 #define MAYBE_UploadCreditCard_NoProfileAvailable UploadCreditCard_NoProfileAvai lable 4991 #define MAYBE_UploadCreditCard_NoProfileAvailable UploadCreditCard_NoProfileAvai lable
4848 #endif 4992 #endif
4849 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoProfileAvailable) { 4993 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoProfileAvailable) {
4850 EnableUkmLogging(); 4994 EnableUkmLogging();
4851 personal_data_.ClearAutofillProfiles(); 4995 personal_data_.ClearAutofillProfiles();
4852 autofill_manager_->set_credit_card_upload_enabled(true); 4996 autofill_manager_->set_credit_card_upload_enabled(true);
4853 4997
4854 // Don't fill or submit an address form. 4998 // Don't fill or submit an address form.
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after
5937 autofill_manager_->StartUploadProcess(std::move(form_structure), 6081 autofill_manager_->StartUploadProcess(std::move(form_structure),
5938 base::TimeTicks::Now(), true); 6082 base::TimeTicks::Now(), true);
5939 6083
5940 // Wait for upload to complete (will check expected types as well). 6084 // Wait for upload to complete (will check expected types as well).
5941 autofill_manager_->WaitForAsyncUploadProcess(); 6085 autofill_manager_->WaitForAsyncUploadProcess();
5942 6086
5943 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); 6087 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature());
5944 } 6088 }
5945 6089
5946 } // namespace autofill 6090 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | components/autofill/core/browser/autofill_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698