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