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

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

Issue 1903183003: Look in all available CVC fields for a value for credit card upload. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use StringToInt instead of !empty Created 4 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
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4264 matching lines...) Expand 10 before | Expand all | Expand 10 after
4275 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); 4275 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4276 FormSubmitted(credit_card_form); 4276 FormSubmitted(credit_card_form);
4277 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); 4277 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded());
4278 4278
4279 // Verify that the correct histogram entry (and only that) was logged. 4279 // Verify that the correct histogram entry (and only that) was logged.
4280 histogram_tester.ExpectUniqueSample( 4280 histogram_tester.ExpectUniqueSample(
4281 "Autofill.CardUploadDecisionExpanded", 4281 "Autofill.CardUploadDecisionExpanded",
4282 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC, 1); 4282 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC, 1);
4283 } 4283 }
4284 4284
4285 TEST_F(AutofillManagerTest, UploadCreditCard_MultipleCvcFields) {
4286 autofill_manager_->set_credit_card_upload_enabled(true);
4287
4288 // Create, fill and submit an address form in order to establish a recent
4289 // profile which can be selected for the upload request.
4290 FormData address_form;
4291 test::CreateTestAddressFormData(&address_form);
4292 FormsSeen(std::vector<FormData>(1, address_form));
4293 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form);
4294 FormSubmitted(address_form);
4295
4296 // Set up our credit card form data.
4297 FormData credit_card_form;
4298 credit_card_form.name = ASCIIToUTF16("MyForm");
4299 credit_card_form.origin = GURL("https://myform.com/form.html");
4300 credit_card_form.action = GURL("https://myform.com/submit.html");
4301
4302 FormFieldData field;
4303 test::CreateTestFormField("Card Name", "cardname", "", "text", &field);
4304 credit_card_form.fields.push_back(field);
4305 test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field);
4306 credit_card_form.fields.push_back(field);
4307 test::CreateTestFormField("Expiration Month", "ccmonth", "", "text", &field);
4308 credit_card_form.fields.push_back(field);
4309 test::CreateTestFormField("Expiration Year", "ccyear", "", "text", &field);
4310 credit_card_form.fields.push_back(field);
4311 test::CreateTestFormField("CVC (hidden)", "cvc1", "", "text", &field);
4312 credit_card_form.fields.push_back(field);
4313 test::CreateTestFormField("CVC", "cvc2", "", "text", &field);
4314 credit_card_form.fields.push_back(field);
4315
4316 FormsSeen(std::vector<FormData>(1, credit_card_form));
4317
4318 // Edit the data, and submit.
4319 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master");
4320 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111");
4321 credit_card_form.fields[2].value = ASCIIToUTF16("11");
4322 credit_card_form.fields[3].value = ASCIIToUTF16("2017");
4323 credit_card_form.fields[4].value = ASCIIToUTF16(""); // CVC MISSING
4324 credit_card_form.fields[5].value = ASCIIToUTF16("123");
4325
4326 base::HistogramTester histogram_tester;
4327
4328 // A CVC value appeared in one of the two CVC fields, upload should happen.
4329 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4330 FormSubmitted(credit_card_form);
4331 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded());
4332
4333 // Verify that the correct histogram entry (and only that) was logged.
4334 histogram_tester.ExpectUniqueSample(
4335 "Autofill.CardUploadDecisionExpanded",
4336 AutofillMetrics::UPLOAD_OFFERED, 1);
4337 }
4338
4285 TEST_F(AutofillManagerTest, UploadCreditCard_NoProfileAvailable) { 4339 TEST_F(AutofillManagerTest, UploadCreditCard_NoProfileAvailable) {
4286 autofill_manager_->set_credit_card_upload_enabled(true); 4340 autofill_manager_->set_credit_card_upload_enabled(true);
4287 4341
4288 // Don't fill or submit an address form. 4342 // Don't fill or submit an address form.
4289 4343
4290 // Set up our credit card form data. 4344 // Set up our credit card form data.
4291 FormData credit_card_form; 4345 FormData credit_card_form;
4292 CreateTestCreditCardFormData(&credit_card_form, true, false); 4346 CreateTestCreditCardFormData(&credit_card_form, true, false);
4293 FormsSeen(std::vector<FormData>(1, credit_card_form)); 4347 FormsSeen(std::vector<FormData>(1, credit_card_form));
4294 4348
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
4893 FormsSeen(mixed_forms); 4947 FormsSeen(mixed_forms);
4894 4948
4895 // Suggestions should always be displayed. 4949 // Suggestions should always be displayed.
4896 for (const FormFieldData& field : mixed_form.fields) { 4950 for (const FormFieldData& field : mixed_form.fields) {
4897 GetAutofillSuggestions(mixed_form, field); 4951 GetAutofillSuggestions(mixed_form, field);
4898 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); 4952 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
4899 } 4953 }
4900 } 4954 }
4901 4955
4902 } // namespace autofill 4956 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698