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

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

Issue 2864483005: Uses AutofillProfileComparator to compare profile names. (Closed)
Patch Set: Uses AutofillProfileComparator to compare profile names. Created 3 years, 7 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 5423 matching lines...) Expand 10 before | Expand all | Expand 10 after
5434 5434
5435 // Verify that the correct histogram entries were logged. 5435 // Verify that the correct histogram entries were logged.
5436 ExpectCardUploadDecision(histogram_tester, 5436 ExpectCardUploadDecision(histogram_tester,
5437 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); 5437 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE);
5438 // Verify that the correct UKM was logged. 5438 // Verify that the correct UKM was logged.
5439 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE); 5439 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE);
5440 } 5440 }
5441 5441
5442 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 5442 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
5443 #if defined(OS_ANDROID) 5443 #if defined(OS_ANDROID)
5444 #define MAYBE_UploadCreditCard_NamesMatchLoosely \ 5444 #define MAYBE_UploadCreditCard_CreditCardFormHasMiddleInitial \
5445 DISABLED_UploadCreditCard_NamesMatchLoosely 5445 DISABLED_UploadCreditCard_CreditCardFormHasMiddleInitial
5446 #else 5446 #else
5447 #define MAYBE_UploadCreditCard_NamesMatchLoosely \ 5447 #define MAYBE_UploadCreditCard_CreditCardFormHasMiddleInitial \
5448 UploadCreditCard_NamesMatchLoosely 5448 UploadCreditCard_CreditCardFormHasMiddleInitial
5449 #endif 5449 #endif
5450 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesMatchLoosely) { 5450 TEST_F(AutofillManagerTest,
5451 MAYBE_UploadCreditCard_CreditCardFormHasMiddleInitial) {
5451 EnableUkmLogging(); 5452 EnableUkmLogging();
5452 personal_data_.ClearAutofillProfiles(); 5453 personal_data_.ClearAutofillProfiles();
5453 autofill_manager_->set_credit_card_upload_enabled(true); 5454 autofill_manager_->set_credit_card_upload_enabled(true);
5454 5455
5455 // Create, fill and submit two address forms with different names. 5456 // Create, fill and submit two address forms with different names.
5456 FormData address_form1, address_form2; 5457 FormData address_form1, address_form2;
5457 test::CreateTestAddressFormData(&address_form1); 5458 test::CreateTestAddressFormData(&address_form1);
5458 test::CreateTestAddressFormData(&address_form2); 5459 test::CreateTestAddressFormData(&address_form2);
5459 5460 FormsSeen({address_form1, address_form2});
5460 std::vector<FormData> address_forms;
5461 address_forms.push_back(address_form1);
5462 address_forms.push_back(address_form2);
5463 FormsSeen(address_forms);
5464 5461
5465 // Names can be different case. 5462 // Names can be different case.
5466 ManuallyFillAddressForm("flo", "master", "77401", "US", &address_form1); 5463 ManuallyFillAddressForm("flo", "master", "77401", "US", &address_form1);
5467 FormSubmitted(address_form1); 5464 FormSubmitted(address_form1);
5468 5465
5469 // And they can have a middle initial even if the other names don't. 5466 // And they can have a middle initial even if the other names don't.
5470 ManuallyFillAddressForm("Flo W", "Master", "77401", "US", &address_form2); 5467 ManuallyFillAddressForm("Flo W", "Master", "77401", "US", &address_form2);
5471 FormSubmitted(address_form2); 5468 FormSubmitted(address_form2);
5472 5469
5473 // Set up our credit card form data. 5470 // Set up our credit card form data.
5474 FormData credit_card_form; 5471 FormData credit_card_form;
5475 CreateTestCreditCardFormData(&credit_card_form, true, false); 5472 CreateTestCreditCardFormData(&credit_card_form, true, false);
5476 FormsSeen(std::vector<FormData>(1, credit_card_form)); 5473 FormsSeen({credit_card_form});
5477 5474
5478 // Edit the data, but use the name with a middle initial *and* period, and 5475 // Edit the data, but use the name with a middle initial *and* period, and
5479 // submit. 5476 // submit.
5480 credit_card_form.fields[0].value = ASCIIToUTF16("Flo W. Master"); 5477 credit_card_form.fields[0].value = ASCIIToUTF16("Flo W. Master");
5481 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); 5478 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111");
5482 credit_card_form.fields[2].value = ASCIIToUTF16("11"); 5479 credit_card_form.fields[2].value = ASCIIToUTF16("11");
5483 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); 5480 credit_card_form.fields[3].value = ASCIIToUTF16("2017");
5484 credit_card_form.fields[4].value = ASCIIToUTF16("123"); 5481 credit_card_form.fields[4].value = ASCIIToUTF16("123");
5485 5482
5486 base::HistogramTester histogram_tester; 5483 base::HistogramTester histogram_tester;
5487 5484
5488 // Names match loosely, upload should happen. 5485 // Names match loosely, upload should happen.
5489 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); 5486 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
5490 FormSubmitted(credit_card_form); 5487 FormSubmitted(credit_card_form);
5491 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); 5488 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded());
5492 5489
5493 // Verify that the correct histogram entry (and only that) was logged. 5490 // Verify that the correct histogram entry (and only that) was logged.
5494 ExpectUniqueCardUploadDecision(histogram_tester, 5491 ExpectUniqueCardUploadDecision(histogram_tester,
5495 AutofillMetrics::UPLOAD_OFFERED); 5492 AutofillMetrics::UPLOAD_OFFERED);
5496 // Verify that the correct UKM was logged. 5493 // Verify that the correct UKM was logged.
5497 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); 5494 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED);
5498 } 5495 }
5499 5496
5500 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 5497 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
5501 #if defined(OS_ANDROID) 5498 #if defined(OS_ANDROID)
5499 #define MAYBE_UploadCreditCard_CreditCardFormDoesNotHaveMiddleInitial \
5500 DISABLED_UploadCreditCard_CreditCardFormDoesNotHaveMiddleInitial
5501 #else
5502 #define MAYBE_UploadCreditCard_CreditCardFormDoesNotHaveMiddleInitial \
5503 UploadCreditCard_CreditCardFormDoesNotHaveMiddleInitial
5504 #endif
5505 TEST_F(AutofillManagerTest,
5506 MAYBE_UploadCreditCard_CreditCardFormDoesNotHaveMiddleInitial) {
5507 EnableUkmLogging();
5508 personal_data_.ClearAutofillProfiles();
5509 autofill_manager_->set_credit_card_upload_enabled(true);
5510
5511 // Create, fill and submit two address forms with different names.
5512 FormData address_form1, address_form2;
5513 test::CreateTestAddressFormData(&address_form1);
5514 test::CreateTestAddressFormData(&address_form2);
5515 FormsSeen({address_form1, address_form2});
5516
5517 // Names can have different variations of middle initials.
5518 ManuallyFillAddressForm("flo w.", "master", "77401", "US", &address_form1);
5519 FormSubmitted(address_form1);
5520 ManuallyFillAddressForm("Flo W", "Master", "77401", "US", &address_form2);
5521 FormSubmitted(address_form2);
5522
5523 // Set up our credit card form data.
5524 FormData credit_card_form;
5525 CreateTestCreditCardFormData(&credit_card_form, true, false);
5526 FormsSeen({credit_card_form});
5527
5528 // Edit the data, but do not use middle initial.
5529 credit_card_form.fields[0].value = ASCIIToUTF16("Flo Master");
5530 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111");
5531 credit_card_form.fields[2].value = ASCIIToUTF16("11");
5532 credit_card_form.fields[3].value = ASCIIToUTF16("2017");
5533 credit_card_form.fields[4].value = ASCIIToUTF16("123");
5534
5535 base::HistogramTester histogram_tester;
5536
5537 // Names match loosely, upload should happen.
5538 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
5539 FormSubmitted(credit_card_form);
5540 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded());
5541
5542 // Verify that the correct histogram entry (and only that) was logged.
5543 ExpectUniqueCardUploadDecision(histogram_tester,
5544 AutofillMetrics::UPLOAD_OFFERED);
5545 // Verify that the correct UKM was logged.
5546 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED);
5547 }
5548
5549 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
5550 #if defined(OS_ANDROID)
5551 #define MAYBE_UploadCreditCard_CreditCardFormHasMiddleName \
5552 DISABLED_UploadCreditCard_CreditCardFormHasMiddleName
5553 #else
5554 #define MAYBE_UploadCreditCard_CreditCardFormHasMiddleName \
5555 UploadCreditCard_CreditCardFormHasMiddleName
5556 #endif
5557 TEST_F(AutofillManagerTest,
5558 MAYBE_UploadCreditCard_CreditCardFormHasMiddleName) {
5559 EnableUkmLogging();
5560 personal_data_.ClearAutofillProfiles();
5561 autofill_manager_->set_credit_card_upload_enabled(true);
5562
5563 // Create, fill and submit address form without middle name.
5564 FormData address_form;
5565 test::CreateTestAddressFormData(&address_form);
5566 FormsSeen({address_form});
5567 ManuallyFillAddressForm("John", "Adams", "77401", "US", &address_form);
5568 FormSubmitted(address_form);
5569
5570 // Set up our credit card form data.
5571 FormData credit_card_form;
5572 CreateTestCreditCardFormData(&credit_card_form, true, false);
5573 FormsSeen({credit_card_form});
5574
5575 // Edit the name by adding a middle name.
5576 credit_card_form.fields[0].value = ASCIIToUTF16("John Quincy Adams");
5577 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111");
5578 credit_card_form.fields[2].value = ASCIIToUTF16("11");
5579 credit_card_form.fields[3].value = ASCIIToUTF16("2017");
5580 credit_card_form.fields[4].value = ASCIIToUTF16("123");
5581
5582 base::HistogramTester histogram_tester;
5583
5584 // Names match loosely, upload should happen.
5585 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
5586 FormSubmitted(credit_card_form);
5587 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded());
5588
5589 // Verify that the correct histogram entry (and only that) was logged.
5590 ExpectUniqueCardUploadDecision(histogram_tester,
5591 AutofillMetrics::UPLOAD_OFFERED);
5592 // Verify that the correct UKM was logged.
5593 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED);
5594 }
5595
5596 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
5597 #if defined(OS_ANDROID)
5598 #define MAYBE_UploadCreditCard_CreditCardFormRemovesMiddleName \
5599 DISABLED_UploadCreditCard_CreditCardFormRemovesMiddleName
5600 #else
5601 #define MAYBE_UploadCreditCard_CreditCardFormRemovesMiddleName \
5602 UploadCreditCard_CreditCardFormRemovesMiddleName
5603 #endif
5604 TEST_F(AutofillManagerTest,
5605 MAYBE_UploadCreditCard_CreditCardFormRemovesMiddleName) {
5606 EnableUkmLogging();
5607 personal_data_.ClearAutofillProfiles();
5608 autofill_manager_->set_credit_card_upload_enabled(true);
5609
5610 // Create, fill and submit address form with middle name.
5611 FormData address_form;
5612 test::CreateTestAddressFormData(&address_form);
5613 FormsSeen({address_form});
5614 ManuallyFillAddressForm("John Quincy", "Adams", "77401", "US", &address_form);
5615 FormSubmitted(address_form);
5616
5617 // Set up our credit card form data.
5618 FormData credit_card_form;
5619 CreateTestCreditCardFormData(&credit_card_form, true, false);
5620 FormsSeen({credit_card_form});
5621
5622 // Edit the name by removing middle name.
5623 credit_card_form.fields[0].value = ASCIIToUTF16("John Adams");
5624 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111");
5625 credit_card_form.fields[2].value = ASCIIToUTF16("11");
5626 credit_card_form.fields[3].value = ASCIIToUTF16("2017");
5627 credit_card_form.fields[4].value = ASCIIToUTF16("123");
5628
5629 base::HistogramTester histogram_tester;
5630
5631 // Names match loosely, upload should happen.
5632 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
5633 FormSubmitted(credit_card_form);
5634 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded());
5635
5636 // Verify that the correct histogram entry (and only that) was logged.
5637 ExpectUniqueCardUploadDecision(histogram_tester,
5638 AutofillMetrics::UPLOAD_OFFERED);
5639 // Verify that the correct UKM was logged.
5640 ExpectCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED);
5641 }
5642
5643 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
5644 #if defined(OS_ANDROID)
5502 #define MAYBE_UploadCreditCard_NamesHaveToMatch \ 5645 #define MAYBE_UploadCreditCard_NamesHaveToMatch \
5503 DISABLED_UploadCreditCard_NamesHaveToMatch 5646 DISABLED_UploadCreditCard_NamesHaveToMatch
5504 #else 5647 #else
5505 #define MAYBE_UploadCreditCard_NamesHaveToMatch \ 5648 #define MAYBE_UploadCreditCard_NamesHaveToMatch \
5506 UploadCreditCard_NamesHaveToMatch 5649 UploadCreditCard_NamesHaveToMatch
5507 #endif 5650 #endif
5508 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesHaveToMatch) { 5651 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesHaveToMatch) {
5509 EnableUkmLogging(); 5652 EnableUkmLogging();
5510 personal_data_.ClearAutofillProfiles(); 5653 personal_data_.ClearAutofillProfiles();
5511 autofill_manager_->set_credit_card_upload_enabled(true); 5654 autofill_manager_->set_credit_card_upload_enabled(true);
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
6269 6412
6270 // Wait for upload to complete (will check expected types as well). 6413 // Wait for upload to complete (will check expected types as well).
6271 autofill_manager_->WaitForAsyncUploadProcess(); 6414 autofill_manager_->WaitForAsyncUploadProcess();
6272 6415
6273 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature()); 6416 EXPECT_EQ(signature, autofill_manager_->GetSubmittedFormSignature());
6274 EXPECT_NE(uploaded_available_types.end(), 6417 EXPECT_NE(uploaded_available_types.end(),
6275 uploaded_available_types.find(autofill::PASSWORD)); 6418 uploaded_available_types.find(autofill::PASSWORD));
6276 } 6419 }
6277 6420
6278 } // namespace autofill 6421 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698