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

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

Issue 2740633002: [Autofill] Add upstreaming UKM (Closed)
Patch Set: Added tests Created 3 years, 9 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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/feature_list.h" 14 #include "base/feature_list.h"
15 #include "base/format_macros.h" 15 #include "base/format_macros.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_vector.h" 19 #include "base/memory/scoped_vector.h"
20 #include "base/metrics/field_trial.h" 20 #include "base/metrics/field_trial.h"
21 #include "base/metrics/metrics_hashes.h"
21 #include "base/run_loop.h" 22 #include "base/run_loop.h"
22 #include "base/strings/string16.h" 23 #include "base/strings/string16.h"
23 #include "base/strings/string_number_conversions.h" 24 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
25 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
26 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
27 #include "base/test/histogram_tester.h" 28 #include "base/test/histogram_tester.h"
28 #include "base/test/scoped_feature_list.h" 29 #include "base/test/scoped_feature_list.h"
29 #include "base/threading/thread_task_runner_handle.h" 30 #include "base/threading/thread_task_runner_handle.h"
30 #include "base/time/time.h" 31 #include "base/time/time.h"
31 #include "build/build_config.h" 32 #include "build/build_config.h"
32 #include "components/autofill/core/browser/autocomplete_history_manager.h" 33 #include "components/autofill/core/browser/autocomplete_history_manager.h"
33 #include "components/autofill/core/browser/autofill_download_manager.h" 34 #include "components/autofill/core/browser/autofill_download_manager.h"
34 #include "components/autofill/core/browser/autofill_experiments.h" 35 #include "components/autofill/core/browser/autofill_experiments.h"
35 #include "components/autofill/core/browser/autofill_profile.h" 36 #include "components/autofill/core/browser/autofill_profile.h"
36 #include "components/autofill/core/browser/autofill_test_utils.h" 37 #include "components/autofill/core/browser/autofill_test_utils.h"
37 #include "components/autofill/core/browser/credit_card.h" 38 #include "components/autofill/core/browser/credit_card.h"
38 #include "components/autofill/core/browser/personal_data_manager.h" 39 #include "components/autofill/core/browser/personal_data_manager.h"
39 #include "components/autofill/core/browser/popup_item_ids.h" 40 #include "components/autofill/core/browser/popup_item_ids.h"
40 #include "components/autofill/core/browser/test_autofill_client.h" 41 #include "components/autofill/core/browser/test_autofill_client.h"
41 #include "components/autofill/core/browser/test_autofill_driver.h" 42 #include "components/autofill/core/browser/test_autofill_driver.h"
42 #include "components/autofill/core/browser/test_autofill_external_delegate.h" 43 #include "components/autofill/core/browser/test_autofill_external_delegate.h"
43 #include "components/autofill/core/browser/validation.h" 44 #include "components/autofill/core/browser/validation.h"
44 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 45 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
45 #include "components/autofill/core/common/autofill_pref_names.h" 46 #include "components/autofill/core/common/autofill_pref_names.h"
46 #include "components/autofill/core/common/autofill_switches.h" 47 #include "components/autofill/core/common/autofill_switches.h"
47 #include "components/autofill/core/common/autofill_util.h" 48 #include "components/autofill/core/common/autofill_util.h"
48 #include "components/autofill/core/common/form_data.h" 49 #include "components/autofill/core/common/form_data.h"
49 #include "components/autofill/core/common/form_field_data.h" 50 #include "components/autofill/core/common/form_field_data.h"
51 #include "components/metrics/proto/ukm/entry.pb.h"
50 #include "components/prefs/pref_service.h" 52 #include "components/prefs/pref_service.h"
51 #include "components/rappor/test_rappor_service.h" 53 #include "components/rappor/test_rappor_service.h"
52 #include "components/security_state/core/security_state.h" 54 #include "components/security_state/core/security_state.h"
53 #include "components/strings/grit/components_strings.h" 55 #include "components/strings/grit/components_strings.h"
56 #include "components/ukm/test_ukm_service.h"
57 #include "components/ukm/ukm_entry.h"
58 #include "components/ukm/ukm_source.h"
54 #include "components/variations/variations_associated_data.h" 59 #include "components/variations/variations_associated_data.h"
55 #include "net/url_request/url_request_test_util.h" 60 #include "net/url_request/url_request_test_util.h"
56 #include "testing/gmock/include/gmock/gmock.h" 61 #include "testing/gmock/include/gmock/gmock.h"
57 #include "testing/gtest/include/gtest/gtest.h" 62 #include "testing/gtest/include/gtest/gtest.h"
58 #include "ui/base/l10n/l10n_util.h" 63 #include "ui/base/l10n/l10n_util.h"
59 #include "ui/gfx/geometry/rect.h" 64 #include "ui/gfx/geometry/rect.h"
60 #include "url/gurl.h" 65 #include "url/gurl.h"
61 66
62 using base::ASCIIToUTF16; 67 using base::ASCIIToUTF16;
63 using base::UTF8ToUTF16; 68 using base::UTF8ToUTF16;
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 772
768 // The query id of the most recent Autofill query. 773 // The query id of the most recent Autofill query.
769 int query_id_; 774 int query_id_;
770 775
771 // The results returned by the most recent Autofill query. 776 // The results returned by the most recent Autofill query.
772 std::vector<Suggestion> suggestions_; 777 std::vector<Suggestion> suggestions_;
773 778
774 DISALLOW_COPY_AND_ASSIGN(TestAutofillExternalDelegate); 779 DISALLOW_COPY_AND_ASSIGN(TestAutofillExternalDelegate);
775 }; 780 };
776 781
782 // Finds the specified UKM metric by |name| in the specified UKM |metrics|.
783 const ukm::Entry_Metric* FindMetric(
784 const char* name,
785 const google::protobuf::RepeatedPtrField<ukm::Entry_Metric>& metrics) {
786 for (const auto& metric : metrics) {
787 if (metric.metric_hash() == base::HashMetricName(name))
788 return &metric;
789 }
790 return nullptr;
791 }
792
777 } // namespace 793 } // namespace
778 794
779 class AutofillManagerTest : public testing::Test { 795 class AutofillManagerTest : public testing::Test {
780 public: 796 public:
781 AutofillManagerTest() : field_trial_list_(nullptr) {} 797 AutofillManagerTest() : field_trial_list_(nullptr) {}
782 798
783 void SetUp() override { 799 void SetUp() override {
784 autofill_client_.SetPrefs(test::PrefServiceForTesting()); 800 autofill_client_.SetPrefs(test::PrefServiceForTesting());
785 personal_data_.set_database(autofill_client_.GetDatabase()); 801 personal_data_.set_database(autofill_client_.GetDatabase());
786 personal_data_.SetPrefService(autofill_client_.GetPrefs()); 802 personal_data_.SetPrefService(autofill_client_.GetPrefs());
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 DCHECK(autofill_manager_->full_card_request_); 1007 DCHECK(autofill_manager_->full_card_request_);
992 return static_cast<CardUnmaskDelegate*>( 1008 return static_cast<CardUnmaskDelegate*>(
993 autofill_manager_->full_card_request_.get()); 1009 autofill_manager_->full_card_request_.get());
994 } 1010 }
995 1011
996 void SetHttpWarningEnabled() { 1012 void SetHttpWarningEnabled() {
997 scoped_feature_list_.InitAndEnableFeature( 1013 scoped_feature_list_.InitAndEnableFeature(
998 security_state::kHttpFormWarningFeature); 1014 security_state::kHttpFormWarningFeature);
999 } 1015 }
1000 1016
1017 void EnableUkmLogging() {
1018 scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging);
1019 }
1020
1021 void ExpectUniqueCardUploadDecisionUkm(
1022 AutofillMetrics::CardUploadDecisionMetric upload_decision) {
1023 ukm::TestUkmService* ukm_service = autofill_client_.GetTestUkmService();
1024
1025 // Check that one source is logged.
1026 ASSERT_EQ(1U, ukm_service->sources_count());
1027 const ukm::UkmSource* source = ukm_service->GetSource(0);
1028
1029 // Check that one entry is logged.
1030 EXPECT_EQ(1U, ukm_service->entries_count());
1031 const ukm::UkmEntry* entry = ukm_service->GetEntry(0);
1032 EXPECT_EQ(entry->source_id(), source->id());
1033
1034 ukm::Entry entry_proto;
1035 entry->PopulateProto(&entry_proto);
1036 EXPECT_EQ(entry_proto.source_id(), source->id());
1037
1038 // Check if there is an entry for card upload decisions.
1039 EXPECT_EQ(entry_proto.event_hash(),
1040 base::HashMetricName(internal::kUKMCardUploadDecisionEntryName));
1041 EXPECT_EQ(entry_proto.metrics_size(), 1);
1042
1043 // Check that the expected upload decision is logged.
1044 const ukm::Entry_Metric* metric = FindMetric(
1045 internal::kUKMCardUploadDecisionMetricName, entry_proto.metrics());
1046 ASSERT_NE(nullptr, metric);
1047 EXPECT_EQ(static_cast<int>(upload_decision), metric->value());
1048 }
1049
1001 protected: 1050 protected:
1002 base::MessageLoop message_loop_; 1051 base::MessageLoop message_loop_;
1003 MockAutofillClient autofill_client_; 1052 MockAutofillClient autofill_client_;
1004 std::unique_ptr<MockAutofillDriver> autofill_driver_; 1053 std::unique_ptr<MockAutofillDriver> autofill_driver_;
1005 std::unique_ptr<TestAutofillManager> autofill_manager_; 1054 std::unique_ptr<TestAutofillManager> autofill_manager_;
1006 std::unique_ptr<TestAutofillExternalDelegate> external_delegate_; 1055 std::unique_ptr<TestAutofillExternalDelegate> external_delegate_;
1007 scoped_refptr<net::TestURLRequestContextGetter> request_context_; 1056 scoped_refptr<net::TestURLRequestContextGetter> request_context_;
1008 TestPaymentsClient* payments_client_; 1057 TestPaymentsClient* payments_client_;
1009 TestAutofillDownloadManager* download_manager_; 1058 TestAutofillDownloadManager* download_manager_;
1010 TestPersonalDataManager personal_data_; 1059 TestPersonalDataManager personal_data_;
(...skipping 3450 matching lines...) Expand 10 before | Expand all | Expand 10 after
4461 "4012888888881881"); 4510 "4012888888881881");
4462 } 4511 }
4463 4512
4464 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 4513 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4465 #if defined(OS_ANDROID) 4514 #if defined(OS_ANDROID)
4466 #define MAYBE_UploadCreditCard DISABLED_UploadCreditCard 4515 #define MAYBE_UploadCreditCard DISABLED_UploadCreditCard
4467 #else 4516 #else
4468 #define MAYBE_UploadCreditCard UploadCreditCard 4517 #define MAYBE_UploadCreditCard UploadCreditCard
4469 #endif 4518 #endif
4470 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard) { 4519 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard) {
4520 EnableUkmLogging();
4471 personal_data_.ClearAutofillProfiles(); 4521 personal_data_.ClearAutofillProfiles();
4472 autofill_manager_->set_credit_card_upload_enabled(true); 4522 autofill_manager_->set_credit_card_upload_enabled(true);
4473 4523
4474 // Create, fill and submit an address form in order to establish a recent 4524 // Create, fill and submit an address form in order to establish a recent
4475 // profile which can be selected for the upload request. 4525 // profile which can be selected for the upload request.
4476 FormData address_form; 4526 FormData address_form;
4477 test::CreateTestAddressFormData(&address_form); 4527 test::CreateTestAddressFormData(&address_form);
4478 FormsSeen(std::vector<FormData>(1, address_form)); 4528 FormsSeen(std::vector<FormData>(1, address_form));
4479 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); 4529 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form);
4480 FormSubmitted(address_form); 4530 FormSubmitted(address_form);
(...skipping 11 matching lines...) Expand all
4492 credit_card_form.fields[4].value = ASCIIToUTF16("123"); 4542 credit_card_form.fields[4].value = ASCIIToUTF16("123");
4493 4543
4494 base::HistogramTester histogram_tester; 4544 base::HistogramTester histogram_tester;
4495 4545
4496 FormSubmitted(credit_card_form); 4546 FormSubmitted(credit_card_form);
4497 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); 4547 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded());
4498 4548
4499 // Verify that the correct histogram entry (and only that) was logged. 4549 // Verify that the correct histogram entry (and only that) was logged.
4500 histogram_tester.ExpectUniqueSample("Autofill.CardUploadDecisionExpanded", 4550 histogram_tester.ExpectUniqueSample("Autofill.CardUploadDecisionExpanded",
4501 AutofillMetrics::UPLOAD_OFFERED, 1); 4551 AutofillMetrics::UPLOAD_OFFERED, 1);
4552 // Verify that the correct UKM was logged.
4553 ExpectUniqueCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED);
4502 } 4554 }
4503 4555
4504 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 4556 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4505 #if defined(OS_ANDROID) 4557 #if defined(OS_ANDROID)
4506 #define MAYBE_UploadCreditCard_FeatureNotEnabled DISABLED_UploadCreditCard_Featu reNotEnabled 4558 #define MAYBE_UploadCreditCard_FeatureNotEnabled DISABLED_UploadCreditCard_Featu reNotEnabled
4507 #else 4559 #else
4508 #define MAYBE_UploadCreditCard_FeatureNotEnabled UploadCreditCard_FeatureNotEnab led 4560 #define MAYBE_UploadCreditCard_FeatureNotEnabled UploadCreditCard_FeatureNotEnab led
4509 #endif 4561 #endif
4510 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_FeatureNotEnabled) { 4562 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_FeatureNotEnabled) {
4511 personal_data_.ClearAutofillProfiles(); 4563 personal_data_.ClearAutofillProfiles();
(...skipping 30 matching lines...) Expand all
4542 histogram_tester.ExpectTotalCount("Autofill.CardUploadDecisionExpanded", 0); 4594 histogram_tester.ExpectTotalCount("Autofill.CardUploadDecisionExpanded", 0);
4543 } 4595 }
4544 4596
4545 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 4597 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4546 #if defined(OS_ANDROID) 4598 #if defined(OS_ANDROID)
4547 #define MAYBE_UploadCreditCard_CvcUnavailable DISABLED_UploadCreditCard_CvcUnava ilable 4599 #define MAYBE_UploadCreditCard_CvcUnavailable DISABLED_UploadCreditCard_CvcUnava ilable
4548 #else 4600 #else
4549 #define MAYBE_UploadCreditCard_CvcUnavailable UploadCreditCard_CvcUnavailable 4601 #define MAYBE_UploadCreditCard_CvcUnavailable UploadCreditCard_CvcUnavailable
4550 #endif 4602 #endif
4551 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_CvcUnavailable) { 4603 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_CvcUnavailable) {
4604 EnableUkmLogging();
4552 personal_data_.ClearAutofillProfiles(); 4605 personal_data_.ClearAutofillProfiles();
4553 autofill_manager_->set_credit_card_upload_enabled(true); 4606 autofill_manager_->set_credit_card_upload_enabled(true);
4554 4607
4555 // Create, fill and submit an address form in order to establish a recent 4608 // Create, fill and submit an address form in order to establish a recent
4556 // profile which can be selected for the upload request. 4609 // profile which can be selected for the upload request.
4557 FormData address_form; 4610 FormData address_form;
4558 test::CreateTestAddressFormData(&address_form); 4611 test::CreateTestAddressFormData(&address_form);
4559 FormsSeen(std::vector<FormData>(1, address_form)); 4612 FormsSeen(std::vector<FormData>(1, address_form));
4560 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); 4613 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form);
4561 FormSubmitted(address_form); 4614 FormSubmitted(address_form);
(...skipping 14 matching lines...) Expand all
4576 4629
4577 // Neither a local save nor an upload should happen in this case. 4630 // Neither a local save nor an upload should happen in this case.
4578 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); 4631 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4579 FormSubmitted(credit_card_form); 4632 FormSubmitted(credit_card_form);
4580 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); 4633 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded());
4581 4634
4582 // Verify that the correct histogram entry (and only that) was logged. 4635 // Verify that the correct histogram entry (and only that) was logged.
4583 histogram_tester.ExpectUniqueSample( 4636 histogram_tester.ExpectUniqueSample(
4584 "Autofill.CardUploadDecisionExpanded", 4637 "Autofill.CardUploadDecisionExpanded",
4585 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC, 1); 4638 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC, 1);
4639 // Verify that the correct UKM was logged.
4640 ExpectUniqueCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC);
4586 4641
4587 rappor::TestRapporServiceImpl* rappor_service = 4642 rappor::TestRapporServiceImpl* rappor_service =
4588 autofill_client_.test_rappor_service(); 4643 autofill_client_.test_rappor_service();
4589 EXPECT_EQ(1, rappor_service->GetReportsCount()); 4644 EXPECT_EQ(1, rappor_service->GetReportsCount());
4590 std::string sample; 4645 std::string sample;
4591 rappor::RapporType type; 4646 rappor::RapporType type;
4592 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( 4647 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric(
4593 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); 4648 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type));
4594 EXPECT_EQ("myform.com", sample); 4649 EXPECT_EQ("myform.com", sample);
4595 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); 4650 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
4596 } 4651 }
4597 4652
4598 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 4653 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4599 #if defined(OS_ANDROID) 4654 #if defined(OS_ANDROID)
4600 #define MAYBE_UploadCreditCard_CvcInvalidLength DISABLED_UploadCreditCard_CvcInv alidLength 4655 #define MAYBE_UploadCreditCard_CvcInvalidLength DISABLED_UploadCreditCard_CvcInv alidLength
4601 #else 4656 #else
4602 #define MAYBE_UploadCreditCard_CvcInvalidLength UploadCreditCard_CvcInvalidLengt h 4657 #define MAYBE_UploadCreditCard_CvcInvalidLength UploadCreditCard_CvcInvalidLengt h
4603 #endif 4658 #endif
4604 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_CvcInvalidLength) { 4659 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_CvcInvalidLength) {
4660 EnableUkmLogging();
4605 personal_data_.ClearAutofillProfiles(); 4661 personal_data_.ClearAutofillProfiles();
4606 autofill_manager_->set_credit_card_upload_enabled(true); 4662 autofill_manager_->set_credit_card_upload_enabled(true);
4607 4663
4608 // Create, fill and submit an address form in order to establish a recent 4664 // Create, fill and submit an address form in order to establish a recent
4609 // profile which can be selected for the upload request. 4665 // profile which can be selected for the upload request.
4610 FormData address_form; 4666 FormData address_form;
4611 test::CreateTestAddressFormData(&address_form); 4667 test::CreateTestAddressFormData(&address_form);
4612 FormsSeen(std::vector<FormData>(1, address_form)); 4668 FormsSeen(std::vector<FormData>(1, address_form));
4613 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form); 4669 ManuallyFillAddressForm("Flo", "Master", "77401", "US", &address_form);
4614 FormSubmitted(address_form); 4670 FormSubmitted(address_form);
(...skipping 14 matching lines...) Expand all
4629 4685
4630 // Neither a local save nor an upload should happen in this case. 4686 // Neither a local save nor an upload should happen in this case.
4631 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); 4687 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4632 FormSubmitted(credit_card_form); 4688 FormSubmitted(credit_card_form);
4633 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); 4689 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded());
4634 4690
4635 // Verify that the correct histogram entry (and only that) was logged. 4691 // Verify that the correct histogram entry (and only that) was logged.
4636 histogram_tester.ExpectUniqueSample( 4692 histogram_tester.ExpectUniqueSample(
4637 "Autofill.CardUploadDecisionExpanded", 4693 "Autofill.CardUploadDecisionExpanded",
4638 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC, 1); 4694 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC, 1);
4695 // Verify that the correct UKM was logged.
4696 ExpectUniqueCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC);
4639 4697
4640 rappor::TestRapporServiceImpl* rappor_service = 4698 rappor::TestRapporServiceImpl* rappor_service =
4641 autofill_client_.test_rappor_service(); 4699 autofill_client_.test_rappor_service();
4642 EXPECT_EQ(1, rappor_service->GetReportsCount()); 4700 EXPECT_EQ(1, rappor_service->GetReportsCount());
4643 std::string sample; 4701 std::string sample;
4644 rappor::RapporType type; 4702 rappor::RapporType type;
4645 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( 4703 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric(
4646 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); 4704 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type));
4647 EXPECT_EQ("myform.com", sample); 4705 EXPECT_EQ("myform.com", sample);
4648 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); 4706 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
4649 } 4707 }
4650 4708
4651 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 4709 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4652 #if defined(OS_ANDROID) 4710 #if defined(OS_ANDROID)
4653 #define MAYBE_UploadCreditCard_MultipleCvcFields DISABLED_UploadCreditCard_Multi pleCvcFields 4711 #define MAYBE_UploadCreditCard_MultipleCvcFields DISABLED_UploadCreditCard_Multi pleCvcFields
4654 #else 4712 #else
4655 #define MAYBE_UploadCreditCard_MultipleCvcFields UploadCreditCard_MultipleCvcFie lds 4713 #define MAYBE_UploadCreditCard_MultipleCvcFields UploadCreditCard_MultipleCvcFie lds
4656 #endif 4714 #endif
4657 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_MultipleCvcFields) { 4715 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_MultipleCvcFields) {
4716 EnableUkmLogging();
4658 autofill_manager_->set_credit_card_upload_enabled(true); 4717 autofill_manager_->set_credit_card_upload_enabled(true);
4659 4718
4660 // Remove the profiles that were created in the TestPersonalDataManager 4719 // Remove the profiles that were created in the TestPersonalDataManager
4661 // constructor because they would result in conflicting names that would 4720 // constructor because they would result in conflicting names that would
4662 // prevent the upload. 4721 // prevent the upload.
4663 personal_data_.ClearAutofillProfiles(); 4722 personal_data_.ClearAutofillProfiles();
4664 4723
4665 // Create, fill and submit an address form in order to establish a recent 4724 // Create, fill and submit an address form in order to establish a recent
4666 // profile which can be selected for the upload request. 4725 // profile which can be selected for the upload request.
4667 FormData address_form; 4726 FormData address_form;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4704 4763
4705 // A CVC value appeared in one of the two CVC fields, upload should happen. 4764 // A CVC value appeared in one of the two CVC fields, upload should happen.
4706 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); 4765 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4707 FormSubmitted(credit_card_form); 4766 FormSubmitted(credit_card_form);
4708 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); 4767 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded());
4709 4768
4710 // Verify that the correct histogram entry (and only that) was logged. 4769 // Verify that the correct histogram entry (and only that) was logged.
4711 histogram_tester.ExpectUniqueSample( 4770 histogram_tester.ExpectUniqueSample(
4712 "Autofill.CardUploadDecisionExpanded", 4771 "Autofill.CardUploadDecisionExpanded",
4713 AutofillMetrics::UPLOAD_OFFERED, 1); 4772 AutofillMetrics::UPLOAD_OFFERED, 1);
4773 // Verify that the correct UKM was logged.
4774 ExpectUniqueCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED);
4714 } 4775 }
4715 4776
4716 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 4777 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4717 #if defined(OS_ANDROID) 4778 #if defined(OS_ANDROID)
4718 #define MAYBE_UploadCreditCard_NoProfileAvailable DISABLED_UploadCreditCard_NoPr ofileAvailable 4779 #define MAYBE_UploadCreditCard_NoProfileAvailable DISABLED_UploadCreditCard_NoPr ofileAvailable
4719 #else 4780 #else
4720 #define MAYBE_UploadCreditCard_NoProfileAvailable UploadCreditCard_NoProfileAvai lable 4781 #define MAYBE_UploadCreditCard_NoProfileAvailable UploadCreditCard_NoProfileAvai lable
4721 #endif 4782 #endif
4722 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoProfileAvailable) { 4783 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoProfileAvailable) {
4784 EnableUkmLogging();
4723 personal_data_.ClearAutofillProfiles(); 4785 personal_data_.ClearAutofillProfiles();
4724 autofill_manager_->set_credit_card_upload_enabled(true); 4786 autofill_manager_->set_credit_card_upload_enabled(true);
4725 4787
4726 // Don't fill or submit an address form. 4788 // Don't fill or submit an address form.
4727 4789
4728 // Set up our credit card form data. 4790 // Set up our credit card form data.
4729 FormData credit_card_form; 4791 FormData credit_card_form;
4730 CreateTestCreditCardFormData(&credit_card_form, true, false); 4792 CreateTestCreditCardFormData(&credit_card_form, true, false);
4731 FormsSeen(std::vector<FormData>(1, credit_card_form)); 4793 FormsSeen(std::vector<FormData>(1, credit_card_form));
4732 4794
4733 // Edit the data, and submit. 4795 // Edit the data, and submit.
4734 credit_card_form.fields[0].value = ASCIIToUTF16("Bob Master"); 4796 credit_card_form.fields[0].value = ASCIIToUTF16("Bob Master");
4735 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111"); 4797 credit_card_form.fields[1].value = ASCIIToUTF16("4111111111111111");
4736 credit_card_form.fields[2].value = ASCIIToUTF16("11"); 4798 credit_card_form.fields[2].value = ASCIIToUTF16("11");
4737 credit_card_form.fields[3].value = ASCIIToUTF16("2017"); 4799 credit_card_form.fields[3].value = ASCIIToUTF16("2017");
4738 credit_card_form.fields[4].value = ASCIIToUTF16("123"); 4800 credit_card_form.fields[4].value = ASCIIToUTF16("123");
4739 4801
4740 base::HistogramTester histogram_tester; 4802 base::HistogramTester histogram_tester;
4741 4803
4742 // Neither a local save nor an upload should happen in this case. 4804 // Neither a local save nor an upload should happen in this case.
4743 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); 4805 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4744 FormSubmitted(credit_card_form); 4806 FormSubmitted(credit_card_form);
4745 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); 4807 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded());
4746 4808
4747 // Verify that the correct histogram entry (and only that) was logged. 4809 // Verify that the correct histogram entry (and only that) was logged.
4748 histogram_tester.ExpectUniqueSample( 4810 histogram_tester.ExpectUniqueSample(
4749 "Autofill.CardUploadDecisionExpanded", 4811 "Autofill.CardUploadDecisionExpanded",
4750 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS, 1); 4812 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS, 1);
4813 // Verify that the correct UKM was logged.
4814 ExpectUniqueCardUploadDecisionUkm(
4815 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS);
4751 4816
4752 rappor::TestRapporServiceImpl* rappor_service = 4817 rappor::TestRapporServiceImpl* rappor_service =
4753 autofill_client_.test_rappor_service(); 4818 autofill_client_.test_rappor_service();
4754 EXPECT_EQ(1, rappor_service->GetReportsCount()); 4819 EXPECT_EQ(1, rappor_service->GetReportsCount());
4755 std::string sample; 4820 std::string sample;
4756 rappor::RapporType type; 4821 rappor::RapporType type;
4757 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( 4822 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric(
4758 "Autofill.CardUploadNotOfferedNoAddress", &sample, &type)); 4823 "Autofill.CardUploadNotOfferedNoAddress", &sample, &type));
4759 EXPECT_EQ("myform.com", sample); 4824 EXPECT_EQ("myform.com", sample);
4760 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); 4825 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
4761 } 4826 }
4762 4827
4763 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 4828 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4764 #if defined(OS_ANDROID) 4829 #if defined(OS_ANDROID)
4765 #define MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable DISABLED_Uplo adCreditCard_CvcUnavailableAndNoProfileAvailable 4830 #define MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable DISABLED_Uplo adCreditCard_CvcUnavailableAndNoProfileAvailable
4766 #else 4831 #else
4767 #define MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable UploadCreditC ard_CvcUnavailableAndNoProfileAvailable 4832 #define MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable UploadCreditC ard_CvcUnavailableAndNoProfileAvailable
4768 #endif 4833 #endif
4769 TEST_F(AutofillManagerTest, 4834 TEST_F(AutofillManagerTest,
4770 MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable) { 4835 MAYBE_UploadCreditCard_CvcUnavailableAndNoProfileAvailable) {
4836 EnableUkmLogging();
4771 personal_data_.ClearAutofillProfiles(); 4837 personal_data_.ClearAutofillProfiles();
4772 autofill_manager_->set_credit_card_upload_enabled(true); 4838 autofill_manager_->set_credit_card_upload_enabled(true);
4773 4839
4774 // Don't fill or submit an address form. 4840 // Don't fill or submit an address form.
4775 4841
4776 // Set up our credit card form data. 4842 // Set up our credit card form data.
4777 FormData credit_card_form; 4843 FormData credit_card_form;
4778 CreateTestCreditCardFormData(&credit_card_form, true, false); 4844 CreateTestCreditCardFormData(&credit_card_form, true, false);
4779 FormsSeen(std::vector<FormData>(1, credit_card_form)); 4845 FormsSeen(std::vector<FormData>(1, credit_card_form));
4780 4846
(...skipping 10 matching lines...) Expand all
4791 // Note that AutofillManager should *check* for both no CVC and no address 4857 // Note that AutofillManager should *check* for both no CVC and no address
4792 // profile, but the no CVC case should have priority over being reported. 4858 // profile, but the no CVC case should have priority over being reported.
4793 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); 4859 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4794 FormSubmitted(credit_card_form); 4860 FormSubmitted(credit_card_form);
4795 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); 4861 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded());
4796 4862
4797 // Verify that the correct histogram entry (and only that) was logged. 4863 // Verify that the correct histogram entry (and only that) was logged.
4798 histogram_tester.ExpectUniqueSample( 4864 histogram_tester.ExpectUniqueSample(
4799 "Autofill.CardUploadDecisionExpanded", 4865 "Autofill.CardUploadDecisionExpanded",
4800 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC, 1); 4866 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC, 1);
4867 // Verify that the correct UKM was logged.
4868 ExpectUniqueCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC);
4801 4869
4802 rappor::TestRapporServiceImpl* rappor_service = 4870 rappor::TestRapporServiceImpl* rappor_service =
4803 autofill_client_.test_rappor_service(); 4871 autofill_client_.test_rappor_service();
4804 EXPECT_EQ(1, rappor_service->GetReportsCount()); 4872 EXPECT_EQ(1, rappor_service->GetReportsCount());
4805 std::string sample; 4873 std::string sample;
4806 rappor::RapporType type; 4874 rappor::RapporType type;
4807 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( 4875 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric(
4808 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type)); 4876 "Autofill.CardUploadNotOfferedNoCvc", &sample, &type));
4809 EXPECT_EQ("myform.com", sample); 4877 EXPECT_EQ("myform.com", sample);
4810 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); 4878 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
4811 } 4879 }
4812 4880
4813 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 4881 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4814 #if defined(OS_ANDROID) 4882 #if defined(OS_ANDROID)
4815 #define MAYBE_UploadCreditCard_NoNameAvailable DISABLED_UploadCreditCard_NoNameA vailable 4883 #define MAYBE_UploadCreditCard_NoNameAvailable DISABLED_UploadCreditCard_NoNameA vailable
4816 #else 4884 #else
4817 #define MAYBE_UploadCreditCard_NoNameAvailable UploadCreditCard_NoNameAvailable 4885 #define MAYBE_UploadCreditCard_NoNameAvailable UploadCreditCard_NoNameAvailable
4818 #endif 4886 #endif
4819 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoNameAvailable) { 4887 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoNameAvailable) {
4888 EnableUkmLogging();
4820 personal_data_.ClearAutofillProfiles(); 4889 personal_data_.ClearAutofillProfiles();
4821 autofill_manager_->set_credit_card_upload_enabled(true); 4890 autofill_manager_->set_credit_card_upload_enabled(true);
4822 4891
4823 // Create, fill and submit an address form in order to establish a recent 4892 // Create, fill and submit an address form in order to establish a recent
4824 // profile which can be selected for the upload request. 4893 // profile which can be selected for the upload request.
4825 FormData address_form; 4894 FormData address_form;
4826 test::CreateTestAddressFormData(&address_form); 4895 test::CreateTestAddressFormData(&address_form);
4827 FormsSeen(std::vector<FormData>(1, address_form)); 4896 FormsSeen(std::vector<FormData>(1, address_form));
4828 // But omit the name: 4897 // But omit the name:
4829 ManuallyFillAddressForm("", "", "77401", "US", &address_form); 4898 ManuallyFillAddressForm("", "", "77401", "US", &address_form);
(...skipping 14 matching lines...) Expand all
4844 4913
4845 // Neither a local save nor an upload should happen in this case. 4914 // Neither a local save nor an upload should happen in this case.
4846 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); 4915 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4847 FormSubmitted(credit_card_form); 4916 FormSubmitted(credit_card_form);
4848 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); 4917 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded());
4849 4918
4850 // Verify that the correct histogram entry (and only that) was logged. 4919 // Verify that the correct histogram entry (and only that) was logged.
4851 histogram_tester.ExpectUniqueSample( 4920 histogram_tester.ExpectUniqueSample(
4852 "Autofill.CardUploadDecisionExpanded", 4921 "Autofill.CardUploadDecisionExpanded",
4853 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME, 1); 4922 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME, 1);
4923 // Verify that the correct UKM was logged.
4924 ExpectUniqueCardUploadDecisionUkm(
4925 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME);
4854 4926
4855 rappor::TestRapporServiceImpl* rappor_service = 4927 rappor::TestRapporServiceImpl* rappor_service =
4856 autofill_client_.test_rappor_service(); 4928 autofill_client_.test_rappor_service();
4857 EXPECT_EQ(1, rappor_service->GetReportsCount()); 4929 EXPECT_EQ(1, rappor_service->GetReportsCount());
4858 std::string sample; 4930 std::string sample;
4859 rappor::RapporType type; 4931 rappor::RapporType type;
4860 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( 4932 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric(
4861 "Autofill.CardUploadNotOfferedNoName", &sample, &type)); 4933 "Autofill.CardUploadNotOfferedNoName", &sample, &type));
4862 EXPECT_EQ("myform.com", sample); 4934 EXPECT_EQ("myform.com", sample);
4863 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); 4935 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
4864 } 4936 }
4865 4937
4866 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 4938 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4867 #if defined(OS_ANDROID) 4939 #if defined(OS_ANDROID)
4868 #define MAYBE_UploadCreditCard_ZipCodesConflict DISABLED_UploadCreditCard_ZipCod esConflict 4940 #define MAYBE_UploadCreditCard_ZipCodesConflict DISABLED_UploadCreditCard_ZipCod esConflict
4869 #else 4941 #else
4870 #define MAYBE_UploadCreditCard_ZipCodesConflict UploadCreditCard_ZipCodesConflic t 4942 #define MAYBE_UploadCreditCard_ZipCodesConflict UploadCreditCard_ZipCodesConflic t
4871 #endif 4943 #endif
4872 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_ZipCodesConflict) { 4944 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_ZipCodesConflict) {
4945 EnableUkmLogging();
4873 personal_data_.ClearAutofillProfiles(); 4946 personal_data_.ClearAutofillProfiles();
4874 autofill_manager_->set_credit_card_upload_enabled(true); 4947 autofill_manager_->set_credit_card_upload_enabled(true);
4875 4948
4876 // Create, fill and submit two address forms with different zip codes. 4949 // Create, fill and submit two address forms with different zip codes.
4877 FormData address_form1, address_form2; 4950 FormData address_form1, address_form2;
4878 test::CreateTestAddressFormData(&address_form1); 4951 test::CreateTestAddressFormData(&address_form1);
4879 test::CreateTestAddressFormData(&address_form2); 4952 test::CreateTestAddressFormData(&address_form2);
4880 4953
4881 std::vector<FormData> address_forms; 4954 std::vector<FormData> address_forms;
4882 address_forms.push_back(address_form1); 4955 address_forms.push_back(address_form1);
(...skipping 22 matching lines...) Expand all
4905 4978
4906 // Neither a local save nor an upload should happen in this case. 4979 // Neither a local save nor an upload should happen in this case.
4907 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); 4980 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4908 FormSubmitted(credit_card_form); 4981 FormSubmitted(credit_card_form);
4909 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); 4982 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded());
4910 4983
4911 // Verify that the correct histogram entry (and only that) was logged. 4984 // Verify that the correct histogram entry (and only that) was logged.
4912 histogram_tester.ExpectUniqueSample( 4985 histogram_tester.ExpectUniqueSample(
4913 "Autofill.CardUploadDecisionExpanded", 4986 "Autofill.CardUploadDecisionExpanded",
4914 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_ZIPS, 1); 4987 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_ZIPS, 1);
4988 // Verify that the correct UKM was logged.
4989 ExpectUniqueCardUploadDecisionUkm(
4990 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_ZIPS);
4915 } 4991 }
4916 4992
4917 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 4993 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4918 #if defined(OS_ANDROID) 4994 #if defined(OS_ANDROID)
4919 #define MAYBE_UploadCreditCard_ZipCodesHavePrefixMatch DISABLED_UploadCreditCard _ZipCodesHavePrefixMatch 4995 #define MAYBE_UploadCreditCard_ZipCodesHavePrefixMatch DISABLED_UploadCreditCard _ZipCodesHavePrefixMatch
4920 #else 4996 #else
4921 #define MAYBE_UploadCreditCard_ZipCodesHavePrefixMatch UploadCreditCard_ZipCodes HavePrefixMatch 4997 #define MAYBE_UploadCreditCard_ZipCodesHavePrefixMatch UploadCreditCard_ZipCodes HavePrefixMatch
4922 #endif 4998 #endif
4923 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_ZipCodesHavePrefixMatch) { 4999 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_ZipCodesHavePrefixMatch) {
5000 EnableUkmLogging();
4924 personal_data_.ClearAutofillProfiles(); 5001 personal_data_.ClearAutofillProfiles();
4925 autofill_manager_->set_credit_card_upload_enabled(true); 5002 autofill_manager_->set_credit_card_upload_enabled(true);
4926 5003
4927 // Create, fill and submit two address forms with different zip codes. 5004 // Create, fill and submit two address forms with different zip codes.
4928 FormData address_form1, address_form2; 5005 FormData address_form1, address_form2;
4929 test::CreateTestAddressFormData(&address_form1); 5006 test::CreateTestAddressFormData(&address_form1);
4930 test::CreateTestAddressFormData(&address_form2); 5007 test::CreateTestAddressFormData(&address_form2);
4931 5008
4932 std::vector<FormData> address_forms; 5009 std::vector<FormData> address_forms;
4933 address_forms.push_back(address_form1); 5010 address_forms.push_back(address_form1);
(...skipping 22 matching lines...) Expand all
4956 5033
4957 // One zip is a prefix of the other, upload should happen. 5034 // One zip is a prefix of the other, upload should happen.
4958 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); 5035 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
4959 FormSubmitted(credit_card_form); 5036 FormSubmitted(credit_card_form);
4960 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); 5037 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded());
4961 5038
4962 // Verify that the correct histogram entry (and only that) was logged. 5039 // Verify that the correct histogram entry (and only that) was logged.
4963 histogram_tester.ExpectUniqueSample( 5040 histogram_tester.ExpectUniqueSample(
4964 "Autofill.CardUploadDecisionExpanded", 5041 "Autofill.CardUploadDecisionExpanded",
4965 AutofillMetrics::UPLOAD_OFFERED, 1); 5042 AutofillMetrics::UPLOAD_OFFERED, 1);
5043 // Verify that the correct UKM was logged.
5044 ExpectUniqueCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED);
4966 } 5045 }
4967 5046
4968 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 5047 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
4969 #if defined(OS_ANDROID) 5048 #if defined(OS_ANDROID)
4970 #define MAYBE_UploadCreditCard_NoZipCodeAvailable DISABLED_UploadCreditCard_NoZi pCodeAvailable 5049 #define MAYBE_UploadCreditCard_NoZipCodeAvailable DISABLED_UploadCreditCard_NoZi pCodeAvailable
4971 #else 5050 #else
4972 #define MAYBE_UploadCreditCard_NoZipCodeAvailable UploadCreditCard_NoZipCodeAvai lable 5051 #define MAYBE_UploadCreditCard_NoZipCodeAvailable UploadCreditCard_NoZipCodeAvai lable
4973 #endif 5052 #endif
4974 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoZipCodeAvailable) { 5053 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NoZipCodeAvailable) {
5054 EnableUkmLogging();
4975 personal_data_.ClearAutofillProfiles(); 5055 personal_data_.ClearAutofillProfiles();
4976 autofill_manager_->set_credit_card_upload_enabled(true); 5056 autofill_manager_->set_credit_card_upload_enabled(true);
4977 5057
4978 // Create, fill and submit an address form in order to establish a recent 5058 // Create, fill and submit an address form in order to establish a recent
4979 // profile which can be selected for the upload request. 5059 // profile which can be selected for the upload request.
4980 FormData address_form; 5060 FormData address_form;
4981 test::CreateTestAddressFormData(&address_form); 5061 test::CreateTestAddressFormData(&address_form);
4982 FormsSeen(std::vector<FormData>(1, address_form)); 5062 FormsSeen(std::vector<FormData>(1, address_form));
4983 // Autofill's validation requirements for Venezuala ("VE", see 5063 // Autofill's validation requirements for Venezuala ("VE", see
4984 // src/components/autofill/core/browser/country_data.cc) do not require zip 5064 // src/components/autofill/core/browser/country_data.cc) do not require zip
(...skipping 21 matching lines...) Expand all
5006 5086
5007 // Neither a local save nor an upload should happen in this case. 5087 // Neither a local save nor an upload should happen in this case.
5008 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); 5088 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
5009 FormSubmitted(credit_card_form); 5089 FormSubmitted(credit_card_form);
5010 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); 5090 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded());
5011 5091
5012 // Verify that the correct histogram entry (and only that) was logged. 5092 // Verify that the correct histogram entry (and only that) was logged.
5013 histogram_tester.ExpectUniqueSample( 5093 histogram_tester.ExpectUniqueSample(
5014 "Autofill.CardUploadDecisionExpanded", 5094 "Autofill.CardUploadDecisionExpanded",
5015 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE, 1); 5095 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE, 1);
5096 // Verify that the correct UKM was logged.
5097 ExpectUniqueCardUploadDecisionUkm(
5098 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ZIP_CODE);
5016 } 5099 }
5017 5100
5018 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 5101 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
5019 #if defined(OS_ANDROID) 5102 #if defined(OS_ANDROID)
5020 #define MAYBE_UploadCreditCard_NamesMatchLoosely DISABLED_UploadCreditCard_Names MatchLoosely 5103 #define MAYBE_UploadCreditCard_NamesMatchLoosely DISABLED_UploadCreditCard_Names MatchLoosely
5021 #else 5104 #else
5022 #define MAYBE_UploadCreditCard_NamesMatchLoosely UploadCreditCard_NamesMatchLoos ely 5105 #define MAYBE_UploadCreditCard_NamesMatchLoosely UploadCreditCard_NamesMatchLoos ely
5023 #endif 5106 #endif
5024 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesMatchLoosely) { 5107 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesMatchLoosely) {
5108 EnableUkmLogging();
5025 personal_data_.ClearAutofillProfiles(); 5109 personal_data_.ClearAutofillProfiles();
5026 autofill_manager_->set_credit_card_upload_enabled(true); 5110 autofill_manager_->set_credit_card_upload_enabled(true);
5027 5111
5028 // Create, fill and submit two address forms with different names. 5112 // Create, fill and submit two address forms with different names.
5029 FormData address_form1, address_form2; 5113 FormData address_form1, address_form2;
5030 test::CreateTestAddressFormData(&address_form1); 5114 test::CreateTestAddressFormData(&address_form1);
5031 test::CreateTestAddressFormData(&address_form2); 5115 test::CreateTestAddressFormData(&address_form2);
5032 5116
5033 std::vector<FormData> address_forms; 5117 std::vector<FormData> address_forms;
5034 address_forms.push_back(address_form1); 5118 address_forms.push_back(address_form1);
(...skipping 25 matching lines...) Expand all
5060 5144
5061 // Names match loosely, upload should happen. 5145 // Names match loosely, upload should happen.
5062 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); 5146 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
5063 FormSubmitted(credit_card_form); 5147 FormSubmitted(credit_card_form);
5064 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded()); 5148 EXPECT_TRUE(autofill_manager_->credit_card_was_uploaded());
5065 5149
5066 // Verify that the correct histogram entry (and only that) was logged. 5150 // Verify that the correct histogram entry (and only that) was logged.
5067 histogram_tester.ExpectUniqueSample( 5151 histogram_tester.ExpectUniqueSample(
5068 "Autofill.CardUploadDecisionExpanded", 5152 "Autofill.CardUploadDecisionExpanded",
5069 AutofillMetrics::UPLOAD_OFFERED, 1); 5153 AutofillMetrics::UPLOAD_OFFERED, 1);
5154 // Verify that the correct UKM was logged.
5155 ExpectUniqueCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED);
5070 } 5156 }
5071 5157
5072 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 5158 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
5073 #if defined(OS_ANDROID) 5159 #if defined(OS_ANDROID)
5074 #define MAYBE_UploadCreditCard_NamesHaveToMatch DISABLED_UploadCreditCard_NamesH aveToMatch 5160 #define MAYBE_UploadCreditCard_NamesHaveToMatch DISABLED_UploadCreditCard_NamesH aveToMatch
5075 #else 5161 #else
5076 #define MAYBE_UploadCreditCard_NamesHaveToMatch UploadCreditCard_NamesHaveToMatc h 5162 #define MAYBE_UploadCreditCard_NamesHaveToMatch UploadCreditCard_NamesHaveToMatc h
5077 #endif 5163 #endif
5078 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesHaveToMatch) { 5164 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_NamesHaveToMatch) {
5165 EnableUkmLogging();
5079 personal_data_.ClearAutofillProfiles(); 5166 personal_data_.ClearAutofillProfiles();
5080 autofill_manager_->set_credit_card_upload_enabled(true); 5167 autofill_manager_->set_credit_card_upload_enabled(true);
5081 5168
5082 // Create, fill and submit two address forms with different names. 5169 // Create, fill and submit two address forms with different names.
5083 FormData address_form1, address_form2; 5170 FormData address_form1, address_form2;
5084 test::CreateTestAddressFormData(&address_form1); 5171 test::CreateTestAddressFormData(&address_form1);
5085 test::CreateTestAddressFormData(&address_form2); 5172 test::CreateTestAddressFormData(&address_form2);
5086 5173
5087 std::vector<FormData> address_forms; 5174 std::vector<FormData> address_forms;
5088 address_forms.push_back(address_form1); 5175 address_forms.push_back(address_form1);
(...skipping 22 matching lines...) Expand all
5111 5198
5112 // Names are required to match, upload should not happen. 5199 // Names are required to match, upload should not happen.
5113 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0); 5200 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)).Times(0);
5114 FormSubmitted(credit_card_form); 5201 FormSubmitted(credit_card_form);
5115 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); 5202 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded());
5116 5203
5117 // Verify that the correct histogram entry (and only that) was logged. 5204 // Verify that the correct histogram entry (and only that) was logged.
5118 histogram_tester.ExpectUniqueSample( 5205 histogram_tester.ExpectUniqueSample(
5119 "Autofill.CardUploadDecisionExpanded", 5206 "Autofill.CardUploadDecisionExpanded",
5120 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES, 1); 5207 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES, 1);
5208 // Verify that the correct UKM was logged.
5209 ExpectUniqueCardUploadDecisionUkm(
5210 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES);
5121 5211
5122 rappor::TestRapporServiceImpl* rappor_service = 5212 rappor::TestRapporServiceImpl* rappor_service =
5123 autofill_client_.test_rappor_service(); 5213 autofill_client_.test_rappor_service();
5124 EXPECT_EQ(1, rappor_service->GetReportsCount()); 5214 EXPECT_EQ(1, rappor_service->GetReportsCount());
5125 std::string sample; 5215 std::string sample;
5126 rappor::RapporType type; 5216 rappor::RapporType type;
5127 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric( 5217 EXPECT_TRUE(rappor_service->GetRecordedSampleForMetric(
5128 "Autofill.CardUploadNotOfferedConflictingNames", &sample, &type)); 5218 "Autofill.CardUploadNotOfferedConflictingNames", &sample, &type));
5129 EXPECT_EQ("myform.com", sample); 5219 EXPECT_EQ("myform.com", sample);
5130 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); 5220 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
5131 } 5221 }
5132 5222
5133 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot. 5223 // TODO(crbug.com/666704): Flaky on android_n5x_swarming_rel bot.
5134 #if defined(OS_ANDROID) 5224 #if defined(OS_ANDROID)
5135 #define MAYBE_UploadCreditCard_UploadDetailsFails DISABLED_UploadCreditCard_Uplo adDetailsFails 5225 #define MAYBE_UploadCreditCard_UploadDetailsFails DISABLED_UploadCreditCard_Uplo adDetailsFails
5136 #else 5226 #else
5137 #define MAYBE_UploadCreditCard_UploadDetailsFails UploadCreditCard_UploadDetails Fails 5227 #define MAYBE_UploadCreditCard_UploadDetailsFails UploadCreditCard_UploadDetails Fails
5138 #endif 5228 #endif
5139 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_UploadDetailsFails) { 5229 TEST_F(AutofillManagerTest, MAYBE_UploadCreditCard_UploadDetailsFails) {
5230 EnableUkmLogging();
5140 personal_data_.ClearAutofillProfiles(); 5231 personal_data_.ClearAutofillProfiles();
5141 autofill_manager_->set_credit_card_upload_enabled(true); 5232 autofill_manager_->set_credit_card_upload_enabled(true);
5142 5233
5143 // Anything other than "en-US" will cause GetUploadDetails to return a failure 5234 // Anything other than "en-US" will cause GetUploadDetails to return a failure
5144 // response. 5235 // response.
5145 autofill_manager_->set_app_locale("pt-BR"); 5236 autofill_manager_->set_app_locale("pt-BR");
5146 5237
5147 // Create, fill and submit an address form in order to establish a recent 5238 // Create, fill and submit an address form in order to establish a recent
5148 // profile which can be selected for the upload request. 5239 // profile which can be selected for the upload request.
5149 FormData address_form; 5240 FormData address_form;
(...skipping 18 matching lines...) Expand all
5168 5259
5169 // The save prompt should be shown instead of doing an upload. 5260 // The save prompt should be shown instead of doing an upload.
5170 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _)); 5261 EXPECT_CALL(autofill_client_, ConfirmSaveCreditCardLocally(_, _));
5171 FormSubmitted(credit_card_form); 5262 FormSubmitted(credit_card_form);
5172 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded()); 5263 EXPECT_FALSE(autofill_manager_->credit_card_was_uploaded());
5173 5264
5174 // Verify that the correct histogram entry (and only that) was logged. 5265 // Verify that the correct histogram entry (and only that) was logged.
5175 histogram_tester.ExpectUniqueSample( 5266 histogram_tester.ExpectUniqueSample(
5176 "Autofill.CardUploadDecisionExpanded", 5267 "Autofill.CardUploadDecisionExpanded",
5177 AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED, 1); 5268 AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED, 1);
5269 // Verify that the correct UKM was logged.
5270 ExpectUniqueCardUploadDecisionUkm(
5271 AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED);
5178 } 5272 }
5179 5273
5180 // Verify that typing "gmail" will match "theking@gmail.com" and 5274 // Verify that typing "gmail" will match "theking@gmail.com" and
5181 // "buddy@gmail.com" when substring matching is enabled. 5275 // "buddy@gmail.com" when substring matching is enabled.
5182 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens) { 5276 TEST_F(AutofillManagerTest, DisplaySuggestionsWithMatchingTokens) {
5183 // Token matching is currently behind a flag. 5277 // Token matching is currently behind a flag.
5184 base::CommandLine::ForCurrentProcess()->AppendSwitch( 5278 base::CommandLine::ForCurrentProcess()->AppendSwitch(
5185 switches::kEnableSuggestionsWithSubstringMatch); 5279 switches::kEnableSuggestionsWithSubstringMatch);
5186 5280
5187 // Set up our form data. 5281 // Set up our form data.
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
5642 5736
5643 // The driver should always be notified. 5737 // The driver should always be notified.
5644 for (const FormFieldData& field : form.fields) { 5738 for (const FormFieldData& field : form.fields) {
5645 GetAutofillSuggestions(form, field); 5739 GetAutofillSuggestions(form, field);
5646 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); 5740 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form());
5647 autofill_driver_->ClearDidInteractWithCreditCardForm(); 5741 autofill_driver_->ClearDidInteractWithCreditCardForm();
5648 } 5742 }
5649 } 5743 }
5650 5744
5651 } // namespace autofill 5745 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698