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

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: Android should still not know about SaveCardBubbleController 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 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 1022
1023 void SetHttpWarningEnabled() { 1023 void SetHttpWarningEnabled() {
1024 scoped_feature_list_.InitAndEnableFeature( 1024 scoped_feature_list_.InitAndEnableFeature(
1025 security_state::kHttpFormWarningFeature); 1025 security_state::kHttpFormWarningFeature);
1026 } 1026 }
1027 1027
1028 void EnableUkmLogging() { 1028 void EnableUkmLogging() {
1029 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging); 1029 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging);
1030 } 1030 }
1031 1031
1032 void EnableAutofillUpstreamRequestCvcIfMissingExperimentAndUkmLogging() {
1033 scoped_feature_list_.InitWithFeatures(
1034 {kAutofillUpstreamRequestCvcIfMissing, kAutofillUkmLogging}, {});
1035 }
1036
1032 void ExpectUniqueFillableFormParsedUkm() { 1037 void ExpectUniqueFillableFormParsedUkm() {
1033 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService(); 1038 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
1034 1039
1035 // Check that one source is logged. 1040 // Check that one source is logged.
1036 ASSERT_EQ(1U, ukm_service->sources_count()); 1041 ASSERT_EQ(1U, ukm_service->sources_count());
1037 const ukm::UkmSource* source = GetUkmSources(ukm_service)[0]; 1042 const ukm::UkmSource* source = GetUkmSources(ukm_service)[0];
1038 1043
1039 // Check that one entry is logged. 1044 // Check that one entry is logged.
1040 EXPECT_EQ(1U, ukm_service->entries_count()); 1045 EXPECT_EQ(1U, ukm_service->entries_count());
1041 const ukm::UkmEntry* entry = ukm_service->GetEntry(0); 1046 const ukm::UkmEntry* entry = ukm_service->GetEntry(0);
(...skipping 3790 matching lines...) Expand 10 before | Expand all | Expand 10 after
4832 // Verify that the correct histogram entry (and only that) was logged. 4837 // Verify that the correct histogram entry (and only that) was logged.
4833 histogram_tester.ExpectUniqueSample( 4838 histogram_tester.ExpectUniqueSample(
4834 "Autofill.CardUploadDecisionExpanded", 4839 "Autofill.CardUploadDecisionExpanded",
4835 AutofillMetrics::UPLOAD_OFFERED, 1); 4840 AutofillMetrics::UPLOAD_OFFERED, 1);
4836 // Verify that the correct UKM was logged. 4841 // Verify that the correct UKM was logged.
4837 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); 4842 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED);
4838 } 4843 }
4839 4844
4840 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 4845 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4841 #if defined(OS_ANDROID) 4846 #if defined(OS_ANDROID)
4847 #define MAYBE_UploadCreditCard_NoCvcFieldOnForm \
4848 DISABLED_UploadCreditCard_NoCvcFieldOnForm
4849 #else
4850 #define MAYBE_UploadCreditCard_NoCvcFieldOnForm \
4851 UploadCreditCard_NoCvcFieldOnForm
4852 #endif
4853 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoCvcFieldOnForm) {
4854 EnableAutofillUpstreamRequestCvcIfMissingExperimentAndUkmLogging();
4855 autofill_manager_->set_credit_card_upload_enabled(true);
4856
4857 // Remove the profiles that were created in the TestPersonalDataManager
4858 // constructor because they would result in conflicting names that would
4859 // prevent the upload.
4860 personal_data_.ClearAutofillProfiles();
4861
4862 // Create, fill and submit an address form in order to establish a recent
4863 // profile which can be selected for the upload request.
4864 FormData address_form;
4865 test::CreateTestAddressFormData(&address_form);
4866 FormsSeen(std::vector<FormData>(1, address_form));
4867 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form);
4868 FormSubmitted(address_form);
4869
4870 // Set up our credit card form data. Note that CVC field is missing.
4871 FormData credit_card_form;
4872 credit_card_form.name = ASCIIToUTF16("MyForm");
4873 credit_card_form.origin = GURL("https://myform.com/form.html");
4874 credit_card_form.action = GURL("https://myform.com/submit.html");
4875
4876 FormFieldData field;
4877 test::CreateTestFormField("Card Name", "cardname", "", "text", &field);
4878 credit_card_form.fields.push_back(field);
4879 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field);
4880 credit_card_form.fields.push_back(field);
4881 test::CreateTestFormField("Expiration Month", "ccmonth", "", "text", &field);
4882 credit_card_form.fields.push_back(field);
4883 test::CreateTestFormField("Expiration Year", "ccyear", "", "text", &field);
4884 credit_card_form.fields.push_back(field);
4885
4886 FormsSeen(std::vector<FormData>(1, credit_card_form));
4887
4888 // Edit the data, and submit.
4889 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master");
4890 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111");
4891 credit_card_form.fields[2].value = ASCIIToUTF16("11");
4892 credit_card_form.fields[3].value = ASCIIToUTF16("2017");
4893
4894 base::HistogramTester histogram_tester;
4895
4896 // Upload should still happen as long as the user provides CVC in the bubble.
4897 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4898 FormSubmitted(credit_card_form);
4899 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded());
4900
4901 // Verify that the correct histogram entry (and only that) was logged.
4902 histogram_tester.ExpectUniqueSample("Autofill.CardUploadDecisionExpanded",
4903 AutofillMetrics::UPLOAD_OFFERED_NO_CVC,
4904 1);
4905 // Verify that the correct UKM was logged.
4906 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED_NO_CVC);
4907 }
4908
4909 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4910 #if defined(OS_ANDROID)
4911 #define MAYBE_UploadCreditCard_NoCvcFieldOnFormExperimentOff \
4912 DISABLED_UploadCreditCard_NoCvcFieldOnFormExperimentOff
4913 #else
4914 #define MAYBE_UploadCreditCard_NoCvcFieldOnFormExperimentOff \
4915 UploadCreditCard_NoCvcFieldOnFormExperimentOff
4916 #endif
4917 TEST_F(AutofillManagerTest,
4918 MAYBE_UploadCreditCard_NoCvcFieldOnFormExperimentOff) {
4919 EnableUkmLogging();
4920 autofill_manager_->set_credit_card_upload_enabled(true);
4921
4922 // Remove the profiles that were created in the TestPersonalDataManager
4923 // constructor because they would result in conflicting names that would
4924 // prevent the upload.
4925 personal_data_.ClearAutofillProfiles();
4926
4927 // Create, fill and submit an address form in order to establish a recent
4928 // profile which can be selected for the upload request.
4929 FormData address_form;
4930 test::CreateTestAddressFormData(&address_form);
4931 FormsSeen(std::vector<FormData>(1, address_form));
4932 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form);
4933 FormSubmitted(address_form);
4934
4935 // Set up our credit card form data. Note that CVC field is missing.
4936 FormData credit_card_form;
4937 credit_card_form.name = ASCIIToUTF16("MyForm");
4938 credit_card_form.origin = GURL("https://myform.com/form.html");
4939 credit_card_form.action = GURL("https://myform.com/submit.html");
4940
4941 FormFieldData field;
4942 test::CreateTestFormField("Card Name", "cardname", "", "text", &field);
4943 credit_card_form.fields.push_back(field);
4944 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field);
4945 credit_card_form.fields.push_back(field);
4946 test::CreateTestFormField("Expiration Month", "ccmonth", "", "text", &field);
4947 credit_card_form.fields.push_back(field);
4948 test::CreateTestFormField("Expiration Year", "ccyear", "", "text", &field);
4949 credit_card_form.fields.push_back(field);
4950
4951 FormsSeen(std::vector<FormData>(1, credit_card_form));
4952
4953 // Edit the data, and submit.
4954 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master");
4955 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111");
4956 credit_card_form.fields[2].value = ASCIIToUTF16("11");
4957 credit_card_form.fields[3].value = ASCIIToUTF16("2017");
4958
4959 base::HistogramTester histogram_tester;
4960
4961 // Neither a local save nor an upload should happen in this case.
4962 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4963 FormSubmitted(credit_card_form);
4964 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded());
4965
4966 // Verify that the correct histogram entry (and only that) was logged.
4967 histogram_tester.ExpectUniqueSample(
4968 "Autofill.CardUploadDecisionExpanded",
4969 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC, 1);
4970 // Verify that the correct UKM was logged.
4971 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC);
4972
4973 rappor::TestRapporServiceImpl* rappor_service =
4974 autofill_client_.test_rappor_service();
4975 EXPECT_EQ(1, rappor_service->GetReportsCount());
4976 std::string sample;
4977 rappor::RapporType type;
4978 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric(
4979 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type));
4980 EXPECT_EQ("myform.com", sample);
4981 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
4982 }
4983
4984 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4985 #if defined(OS_ANDROID)
4842 #define MAYBE_UploadCreditCard_NoProfileAvailable DISABLED_UploadCreditCard_NoPr ofileAvailable 4986 #define MAYBE_UploadCreditCard_NoProfileAvailable DISABLED_UploadCreditCard_NoPr ofileAvailable
4843 #else 4987 #else
4844 #define MAYBE_UploadCreditCard_NoProfileAvailable UploadCreditCard_NoProfileAvai lable 4988 #define MAYBE_UploadCreditCard_NoProfileAvailable UploadCreditCard_NoProfileAvai lable
4845 #endif 4989 #endif
4846 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoProfileAvailable) { 4990 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoProfileAvailable) {
4847 EnableUkmLogging(); 4991 EnableUkmLogging();
4848 personal_data_.ClearAutofillProfiles(); 4992 personal_data_.ClearAutofillProfiles();
4849 autofill_manager_->set_credit_card_upload_enabled(true); 4993 autofill_manager_->set_credit_card_upload_enabled(true);
4850 4994
4851 // Don't fill or submit an address form. 4995 // Don't fill or submit an address form.
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after
5890 FormsSeen({form}); 6034 FormsSeen({form});
5891 6035
5892 // Suggestions should be displayed. 6036 // Suggestions should be displayed.
5893 for (const FormFieldData& field : form.fields) { 6037 for (const FormFieldData& field : form.fields) {
5894 GetAutofillSuggestions(form, field); 6038 GetAutofillSuggestions(form, field);
5895 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); 6039 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
5896 } 6040 }
5897 } 6041 }
5898 6042
5899 } // namespace autofill 6043 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698