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

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

Issue 1010263002: [Autofill] Add FormEvent logging for "will submit form". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: split Created 5 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_metrics.h" 5 #include "components/autofill/core/browser/autofill_metrics.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 for (size_t i = 0; i < empty_form.fields.size(); ++i) { 222 for (size_t i = 0; i < empty_form.fields.size(); ++i) {
223 empty_form.fields[i].value = base::string16(); 223 empty_form.fields[i].value = base::string16();
224 } 224 }
225 225
226 // |form_structure| will be owned by |form_structures()|. 226 // |form_structure| will be owned by |form_structures()|.
227 TestFormStructure* form_structure = new TestFormStructure(empty_form); 227 TestFormStructure* form_structure = new TestFormStructure(empty_form);
228 form_structure->SetFieldTypes(heuristic_types, server_types); 228 form_structure->SetFieldTypes(heuristic_types, server_types);
229 form_structures()->push_back(form_structure); 229 form_structures()->push_back(form_structure);
230 } 230 }
231 231
232 // Calls AutofillManager::OnWillSubmitForm and waits for it to complete.
232 void WillSubmitForm(const FormData& form, const TimeTicks& timestamp) { 233 void WillSubmitForm(const FormData& form, const TimeTicks& timestamp) {
233 run_loop_.reset(new base::RunLoop()); 234 run_loop_.reset(new base::RunLoop());
234 if (!OnWillSubmitForm(form, timestamp)) 235 if (!OnWillSubmitForm(form, timestamp))
235 return; 236 return;
236 237
237 // Wait for the asynchronous OnWillSubmitForm() call to complete. 238 // Wait for the asynchronous OnWillSubmitForm() call to complete.
238 run_loop_->Run(); 239 run_loop_->Run();
239 } 240 }
240 241
242 // Calls both AutofillManager::OnWillSubmitForm and
243 // AutofillManager::OnFormSubmitted.
244 void SubmitForm(const FormData& form, const TimeTicks& timestamp) {
245 WillSubmitForm(form, timestamp);
246 OnFormSubmitted(form);
247 }
248
241 void UploadFormDataAsyncCallback( 249 void UploadFormDataAsyncCallback(
242 const FormStructure* submitted_form, 250 const FormStructure* submitted_form,
243 const base::TimeTicks& load_time, 251 const base::TimeTicks& load_time,
244 const base::TimeTicks& interaction_time, 252 const base::TimeTicks& interaction_time,
245 const base::TimeTicks& submission_time) override { 253 const base::TimeTicks& submission_time) override {
246 run_loop_->Quit(); 254 run_loop_->Quit();
247 255
248 AutofillManager::UploadFormDataAsyncCallback(submitted_form, 256 AutofillManager::UploadFormDataAsyncCallback(submitted_form,
249 load_time, 257 load_time,
250 interaction_time, 258 interaction_time,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 field.is_autofilled = true; 378 field.is_autofilled = true;
371 form.fields.push_back(field); 379 form.fields.push_back(field);
372 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER); 380 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
373 server_types.push_back(PHONE_HOME_WHOLE_NUMBER); 381 server_types.push_back(PHONE_HOME_WHOLE_NUMBER);
374 382
375 // Simulate having seen this form on page load. 383 // Simulate having seen this form on page load.
376 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); 384 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
377 385
378 // Simulate form submission. 386 // Simulate form submission.
379 base::HistogramTester histogram_tester; 387 base::HistogramTester histogram_tester;
380 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 388 autofill_manager_->SubmitForm(form, TimeTicks::Now());
381 389
382 // Heuristic predictions. 390 // Heuristic predictions.
383 // Unknown: 391 // Unknown:
384 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType", 392 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
385 AutofillMetrics::TYPE_UNKNOWN, 1); 393 AutofillMetrics::TYPE_UNKNOWN, 1);
386 histogram_tester.ExpectBucketCount( 394 histogram_tester.ExpectBucketCount(
387 "Autofill.Quality.HeuristicType.ByFieldType", 395 "Autofill.Quality.HeuristicType.ByFieldType",
388 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, 396 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY,
389 AutofillMetrics::TYPE_UNKNOWN), 397 AutofillMetrics::TYPE_UNKNOWN),
390 1); 398 1);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field); 500 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field);
493 field.is_autofilled = true; 501 field.is_autofilled = true;
494 form.fields.push_back(field); 502 form.fields.push_back(field);
495 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER); 503 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
496 server_types.push_back(EMAIL_ADDRESS); 504 server_types.push_back(EMAIL_ADDRESS);
497 505
498 // Simulate having seen this form on page load. 506 // Simulate having seen this form on page load.
499 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); 507 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
500 508
501 // Simulate form submission. 509 // Simulate form submission.
502 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 510 autofill_manager_->SubmitForm(form, TimeTicks::Now());
503 511
504 // The number of mismatches did not trigger the RAPPOR metric logging. 512 // The number of mismatches did not trigger the RAPPOR metric logging.
505 EXPECT_EQ(0, autofill_client_.test_rappor_service()->GetReportsCount()); 513 EXPECT_EQ(0, autofill_client_.test_rappor_service()->GetReportsCount());
506 } 514 }
507 515
508 // Test that we don't log RAPPOR metrics in the case heuristics and/or server 516 // Test that we don't log RAPPOR metrics in the case heuristics and/or server
509 // have no data. 517 // have no data.
510 TEST_F(AutofillMetricsTest, Rappor_NoDataServerAndHeuristic_NoMetricsReported) { 518 TEST_F(AutofillMetricsTest, Rappor_NoDataServerAndHeuristic_NoMetricsReported) {
511 // Set up our form data. 519 // Set up our form data.
512 FormData form; 520 FormData form;
(...skipping 22 matching lines...) Expand all
535 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field); 543 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field);
536 field.is_autofilled = true; 544 field.is_autofilled = true;
537 form.fields.push_back(field); 545 form.fields.push_back(field);
538 heuristic_types.push_back(UNKNOWN_TYPE); 546 heuristic_types.push_back(UNKNOWN_TYPE);
539 server_types.push_back(NO_SERVER_DATA); 547 server_types.push_back(NO_SERVER_DATA);
540 548
541 // Simulate having seen this form on page load. 549 // Simulate having seen this form on page load.
542 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); 550 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
543 551
544 // Simulate form submission. 552 // Simulate form submission.
545 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 553 autofill_manager_->SubmitForm(form, TimeTicks::Now());
546 554
547 // No RAPPOR metrics are logged in the case of multiple UNKNOWN_TYPE and 555 // No RAPPOR metrics are logged in the case of multiple UNKNOWN_TYPE and
548 // NO_SERVER_DATA for heuristics and server predictions, respectively. 556 // NO_SERVER_DATA for heuristics and server predictions, respectively.
549 EXPECT_EQ(0, autofill_client_.test_rappor_service()->GetReportsCount()); 557 EXPECT_EQ(0, autofill_client_.test_rappor_service()->GetReportsCount());
550 } 558 }
551 559
552 // Test that we log high number of mismatches for the server prediction. 560 // Test that we log high number of mismatches for the server prediction.
553 TEST_F(AutofillMetricsTest, Rappor_HighServerMismatchRate_MetricsReported) { 561 TEST_F(AutofillMetricsTest, Rappor_HighServerMismatchRate_MetricsReported) {
554 // Set up our form data. 562 // Set up our form data.
555 FormData form; 563 FormData form;
(...skipping 22 matching lines...) Expand all
578 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field); 586 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field);
579 field.is_autofilled = true; 587 field.is_autofilled = true;
580 form.fields.push_back(field); 588 form.fields.push_back(field);
581 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER); 589 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
582 server_types.push_back(EMAIL_ADDRESS); 590 server_types.push_back(EMAIL_ADDRESS);
583 591
584 // Simulate having seen this form on page load. 592 // Simulate having seen this form on page load.
585 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); 593 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
586 594
587 // Simulate form submission. 595 // Simulate form submission.
588 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 596 autofill_manager_->SubmitForm(form, TimeTicks::Now());
589 597
590 // The number of mismatches did trigger the RAPPOR metric logging for server 598 // The number of mismatches did trigger the RAPPOR metric logging for server
591 // predictions. 599 // predictions.
592 EXPECT_EQ(1, autofill_client_.test_rappor_service()->GetReportsCount()); 600 EXPECT_EQ(1, autofill_client_.test_rappor_service()->GetReportsCount());
593 std::string sample; 601 std::string sample;
594 rappor::RapporType type; 602 rappor::RapporType type;
595 EXPECT_FALSE( 603 EXPECT_FALSE(
596 autofill_client_.test_rappor_service()->GetRecordedSampleForMetric( 604 autofill_client_.test_rappor_service()->GetRecordedSampleForMetric(
597 "Autofill.HighNumberOfHeuristicMismatches", &sample, &type)); 605 "Autofill.HighNumberOfHeuristicMismatches", &sample, &type));
598 EXPECT_TRUE( 606 EXPECT_TRUE(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field); 639 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field);
632 field.is_autofilled = true; 640 field.is_autofilled = true;
633 form.fields.push_back(field); 641 form.fields.push_back(field);
634 heuristic_types.push_back(EMAIL_ADDRESS); 642 heuristic_types.push_back(EMAIL_ADDRESS);
635 server_types.push_back(PHONE_HOME_WHOLE_NUMBER); 643 server_types.push_back(PHONE_HOME_WHOLE_NUMBER);
636 644
637 // Simulate having seen this form on page load. 645 // Simulate having seen this form on page load.
638 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); 646 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
639 647
640 // Simulate form submission. 648 // Simulate form submission.
641 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 649 autofill_manager_->SubmitForm(form, TimeTicks::Now());
642 650
643 // The number of mismatches did trigger the RAPPOR metric logging for 651 // The number of mismatches did trigger the RAPPOR metric logging for
644 // heuristic predictions. 652 // heuristic predictions.
645 EXPECT_EQ(1, autofill_client_.test_rappor_service()->GetReportsCount()); 653 EXPECT_EQ(1, autofill_client_.test_rappor_service()->GetReportsCount());
646 std::string sample; 654 std::string sample;
647 rappor::RapporType type; 655 rappor::RapporType type;
648 EXPECT_FALSE( 656 EXPECT_FALSE(
649 autofill_client_.test_rappor_service()->GetRecordedSampleForMetric( 657 autofill_client_.test_rappor_service()->GetRecordedSampleForMetric(
650 "Autofill.HighNumberOfServerMismatches", &sample, &type)); 658 "Autofill.HighNumberOfServerMismatches", &sample, &type));
651 EXPECT_TRUE( 659 EXPECT_TRUE(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 std::vector<FormData> forms(1, form); 692 std::vector<FormData> forms(1, form);
685 693
686 { 694 {
687 base::HistogramTester histogram_tester; 695 base::HistogramTester histogram_tester;
688 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 696 autofill_manager_->OnFormsSeen(forms, TimeTicks());
689 // We change the value of the text fields to change the default/seen values 697 // We change the value of the text fields to change the default/seen values
690 // (hence the values are not cleared in UpdateFromCache). The new values 698 // (hence the values are not cleared in UpdateFromCache). The new values
691 // match what is in the test profile. 699 // match what is in the test profile.
692 form.fields[1].value = base::ASCIIToUTF16("79401"); 700 form.fields[1].value = base::ASCIIToUTF16("79401");
693 form.fields[2].value = base::ASCIIToUTF16("2345678901"); 701 form.fields[2].value = base::ASCIIToUTF16("2345678901");
694 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 702 autofill_manager_->SubmitForm(form, TimeTicks::Now());
695 703
696 // First verify that country was not predicted by client or server. 704 // First verify that country was not predicted by client or server.
697 histogram_tester.ExpectBucketCount( 705 histogram_tester.ExpectBucketCount(
698 "Autofill.Quality.ServerType.ByFieldType", 706 "Autofill.Quality.ServerType.ByFieldType",
699 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, 707 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY,
700 AutofillMetrics::TYPE_UNKNOWN), 708 AutofillMetrics::TYPE_UNKNOWN),
701 1); 709 1);
702 histogram_tester.ExpectBucketCount( 710 histogram_tester.ExpectBucketCount(
703 "Autofill.Quality.HeuristicType.ByFieldType", 711 "Autofill.Quality.HeuristicType.ByFieldType",
704 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, 712 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 test::CreateTestFormField( 805 test::CreateTestFormField(
798 "New field", "new field", "Tennessee", "text", &field); 806 "New field", "new field", "Tennessee", "text", &field);
799 form.fields.push_back(field); 807 form.fields.push_back(field);
800 form.fields.push_back(cached_fields[2]); 808 form.fields.push_back(cached_fields[2]);
801 form.fields.push_back(cached_fields[1]); 809 form.fields.push_back(cached_fields[1]);
802 form.fields.push_back(cached_fields[3]); 810 form.fields.push_back(cached_fields[3]);
803 form.fields.push_back(cached_fields[0]); 811 form.fields.push_back(cached_fields[0]);
804 812
805 // Simulate form submission. 813 // Simulate form submission.
806 base::HistogramTester histogram_tester; 814 base::HistogramTester histogram_tester;
807 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 815 autofill_manager_->SubmitForm(form, TimeTicks::Now());
808 816
809 // Heuristic predictions. 817 // Heuristic predictions.
810 // Unknown: 818 // Unknown:
811 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType", 819 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
812 AutofillMetrics::TYPE_UNKNOWN, 1); 820 AutofillMetrics::TYPE_UNKNOWN, 1);
813 histogram_tester.ExpectBucketCount( 821 histogram_tester.ExpectBucketCount(
814 "Autofill.Quality.HeuristicType.ByFieldType", 822 "Autofill.Quality.HeuristicType.ByFieldType",
815 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE, 823 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE,
816 AutofillMetrics::TYPE_UNKNOWN), 824 AutofillMetrics::TYPE_UNKNOWN),
817 1); 825 1);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 test::CreateTestFormField("Email", "email", "", "text", &field); 915 test::CreateTestFormField("Email", "email", "", "text", &field);
908 form.fields.push_back(field); 916 form.fields.push_back(field);
909 test::CreateTestFormField("Phone", "phone", "", "text", &field); 917 test::CreateTestFormField("Phone", "phone", "", "text", &field);
910 form.fields.push_back(field); 918 form.fields.push_back(field);
911 919
912 std::vector<FormData> forms(1, form); 920 std::vector<FormData> forms(1, form);
913 921
914 // Simulate form submission. 922 // Simulate form submission.
915 base::HistogramTester histogram_tester; 923 base::HistogramTester histogram_tester;
916 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 924 autofill_manager_->OnFormsSeen(forms, TimeTicks());
917 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 925 autofill_manager_->SubmitForm(form, TimeTicks::Now());
918 926
919 // An autofillable form was submitted, and the number of stored profiles is 927 // An autofillable form was submitted, and the number of stored profiles is
920 // logged. 928 // logged.
921 histogram_tester.ExpectUniqueSample( 929 histogram_tester.ExpectUniqueSample(
922 "Autofill.StoredProfileCountAtAutofillableFormSubmission", 2, 1); 930 "Autofill.StoredProfileCountAtAutofillableFormSubmission", 2, 1);
923 } 931 }
924 932
925 // Verify that when submitting a non-autofillable form, the stored profile 933 // Verify that when submitting a non-autofillable form, the stored profile
926 // metric is not logged. 934 // metric is not logged.
927 TEST_F(AutofillMetricsTest, StoredProfileCountNonAutofillableFormSubmission) { 935 TEST_F(AutofillMetricsTest, StoredProfileCountNonAutofillableFormSubmission) {
928 // Construct a non-fillable form. 936 // Construct a non-fillable form.
929 FormData form; 937 FormData form;
930 form.name = ASCIIToUTF16("TestForm"); 938 form.name = ASCIIToUTF16("TestForm");
931 form.origin = GURL("http://example.com/form.html"); 939 form.origin = GURL("http://example.com/form.html");
932 form.action = GURL("http://example.com/submit.html"); 940 form.action = GURL("http://example.com/submit.html");
933 form.user_submitted = true; 941 form.user_submitted = true;
934 942
935 // Two fields is not enough to make it an autofillable form. 943 // Two fields is not enough to make it an autofillable form.
936 FormFieldData field; 944 FormFieldData field;
937 test::CreateTestFormField("Name", "name", "", "text", &field); 945 test::CreateTestFormField("Name", "name", "", "text", &field);
938 form.fields.push_back(field); 946 form.fields.push_back(field);
939 test::CreateTestFormField("Email", "email", "", "text", &field); 947 test::CreateTestFormField("Email", "email", "", "text", &field);
940 form.fields.push_back(field); 948 form.fields.push_back(field);
941 949
942 std::vector<FormData> forms(1, form); 950 std::vector<FormData> forms(1, form);
943 951
944 // Simulate form submission. 952 // Simulate form submission.
945 base::HistogramTester histogram_tester; 953 base::HistogramTester histogram_tester;
946 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 954 autofill_manager_->OnFormsSeen(forms, TimeTicks());
947 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 955 autofill_manager_->SubmitForm(form, TimeTicks::Now());
948 956
949 // A non-autofillable form was submitted, and number of stored profiles is NOT 957 // A non-autofillable form was submitted, and number of stored profiles is NOT
950 // logged. 958 // logged.
951 histogram_tester.ExpectTotalCount( 959 histogram_tester.ExpectTotalCount(
952 "Autofill.StoredProfileCountAtAutofillableFormSubmission", 0); 960 "Autofill.StoredProfileCountAtAutofillableFormSubmission", 0);
953 } 961 }
954 962
955 // Verify that we correctly log metrics regarding developer engagement. 963 // Verify that we correctly log metrics regarding developer engagement.
956 TEST_F(AutofillMetricsTest, DeveloperEngagement) { 964 TEST_F(AutofillMetricsTest, DeveloperEngagement) {
957 // Start with a non-fillable form. 965 // Start with a non-fillable form.
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 1491
1484 // Simulate having seen this form on page load. 1492 // Simulate having seen this form on page load.
1485 // |form_structure| will be owned by |autofill_manager_|. 1493 // |form_structure| will be owned by |autofill_manager_|.
1486 autofill_manager_->AddSeenForm(form, field_types, field_types); 1494 autofill_manager_->AddSeenForm(form, field_types, field_types);
1487 1495
1488 { 1496 {
1489 // Simulating submission with no filled data. 1497 // Simulating submission with no filled data.
1490 base::HistogramTester histogram_tester; 1498 base::HistogramTester histogram_tester;
1491 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(), 1499 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1492 false); 1500 false);
1493 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 1501 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1502 histogram_tester.ExpectBucketCount(
1503 "Autofill.FormEvents.CreditCard",
1504 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1494 histogram_tester.ExpectBucketCount( 1505 histogram_tester.ExpectBucketCount(
1495 "Autofill.FormEvents.CreditCard", 1506 "Autofill.FormEvents.CreditCard",
1496 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); 1507 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
1497 } 1508 }
1498 1509
1499 // Reset the autofill manager state. 1510 // Reset the autofill manager state.
1500 autofill_manager_->Reset(); 1511 autofill_manager_->Reset();
1501 autofill_manager_->AddSeenForm(form, field_types, field_types); 1512 autofill_manager_->AddSeenForm(form, field_types, field_types);
1502 1513
1503 { 1514 {
1504 // Simulating submission with filled local data. 1515 // Simulating submission with filled local data.
1505 base::HistogramTester histogram_tester; 1516 base::HistogramTester histogram_tester;
1506 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(), 1517 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1507 false); 1518 false);
1508 SuggestionBackendID guid( 1519 SuggestionBackendID guid(
1509 "10000000-0000-0000-0000-000000000001", 0); // local card 1520 "10000000-0000-0000-0000-000000000001", 0); // local card
1510 autofill_manager_->FillOrPreviewForm( 1521 autofill_manager_->FillOrPreviewForm(
1511 AutofillDriver::FORM_DATA_ACTION_FILL, 1522 AutofillDriver::FORM_DATA_ACTION_FILL,
1512 0, form, form.fields.front(), 1523 0, form, form.fields.front(),
1513 autofill_manager_->MakeFrontendID(guid, SuggestionBackendID())); 1524 autofill_manager_->MakeFrontendID(guid, SuggestionBackendID()));
1514 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 1525 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1526 histogram_tester.ExpectBucketCount(
1527 "Autofill.FormEvents.CreditCard",
1528 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1515 histogram_tester.ExpectBucketCount( 1529 histogram_tester.ExpectBucketCount(
1516 "Autofill.FormEvents.CreditCard", 1530 "Autofill.FormEvents.CreditCard",
1517 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1); 1531 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1);
1518 } 1532 }
1519 1533
1520 // Reset the autofill manager state. 1534 // Reset the autofill manager state.
1521 autofill_manager_->Reset(); 1535 autofill_manager_->Reset();
1522 autofill_manager_->AddSeenForm(form, field_types, field_types); 1536 autofill_manager_->AddSeenForm(form, field_types, field_types);
1523 1537
1524 { 1538 {
1525 // Simulating submission with filled server data. 1539 // Simulating submission with filled server data.
1526 base::HistogramTester histogram_tester; 1540 base::HistogramTester histogram_tester;
1527 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(), 1541 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1528 false); 1542 false);
1529 SuggestionBackendID guid( 1543 SuggestionBackendID guid(
1530 "10000000-0000-0000-0000-000000000003", 0); // full server card 1544 "10000000-0000-0000-0000-000000000003", 0); // full server card
1531 autofill_manager_->FillOrPreviewForm( 1545 autofill_manager_->FillOrPreviewForm(
1532 AutofillDriver::FORM_DATA_ACTION_FILL, 1546 AutofillDriver::FORM_DATA_ACTION_FILL,
1533 0, form, form.fields.front(), 1547 0, form, form.fields.front(),
1534 autofill_manager_->MakeFrontendID(guid, SuggestionBackendID())); 1548 autofill_manager_->MakeFrontendID(guid, SuggestionBackendID()));
1535 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 1549 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1550 histogram_tester.ExpectBucketCount(
1551 "Autofill.FormEvents.CreditCard",
1552 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1536 histogram_tester.ExpectBucketCount( 1553 histogram_tester.ExpectBucketCount(
1537 "Autofill.FormEvents.CreditCard", 1554 "Autofill.FormEvents.CreditCard",
1538 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1); 1555 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1);
1539 } 1556 }
1540 1557
1541 // Reset the autofill manager state. 1558 // Reset the autofill manager state.
1542 autofill_manager_->Reset(); 1559 autofill_manager_->Reset();
1543 autofill_manager_->AddSeenForm(form, field_types, field_types); 1560 autofill_manager_->AddSeenForm(form, field_types, field_types);
1544 1561
1545 { 1562 {
(...skipping 25 matching lines...) Expand all
1571 1588
1572 // Reset the autofill manager state. 1589 // Reset the autofill manager state.
1573 autofill_manager_->Reset(); 1590 autofill_manager_->Reset();
1574 autofill_manager_->AddSeenForm(form, field_types, field_types); 1591 autofill_manager_->AddSeenForm(form, field_types, field_types);
1575 1592
1576 { 1593 {
1577 // Simulating multiple submissions. 1594 // Simulating multiple submissions.
1578 base::HistogramTester histogram_tester; 1595 base::HistogramTester histogram_tester;
1579 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(), 1596 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1580 false); 1597 false);
1581 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 1598 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1582 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 1599 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1600 histogram_tester.ExpectBucketCount(
1601 "Autofill.FormEvents.CreditCard",
1602 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1603 histogram_tester.ExpectBucketCount(
1604 "Autofill.FormEvents.CreditCard",
1605 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1606 histogram_tester.ExpectBucketCount(
1607 "Autofill.FormEvents.CreditCard",
1608 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1609 histogram_tester.ExpectBucketCount(
1610 "Autofill.FormEvents.CreditCard",
1611 AutofillMetrics::
1612 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE,
1613 0);
1583 histogram_tester.ExpectBucketCount( 1614 histogram_tester.ExpectBucketCount(
1584 "Autofill.FormEvents.CreditCard", 1615 "Autofill.FormEvents.CreditCard",
1585 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); 1616 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
1586 histogram_tester.ExpectBucketCount( 1617 histogram_tester.ExpectBucketCount(
1587 "Autofill.FormEvents.CreditCard", 1618 "Autofill.FormEvents.CreditCard",
1588 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0); 1619 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
1620 histogram_tester.ExpectBucketCount(
1621 "Autofill.FormEvents.CreditCard",
1622 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1623 histogram_tester.ExpectBucketCount(
1624 "Autofill.FormEvents.CreditCard",
1625 AutofillMetrics::
1626 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE,
1627 0);
1628 }
1629
1630 // Reset the autofill manager state.
1631 autofill_manager_->Reset();
1632 autofill_manager_->AddSeenForm(form, field_types, field_types);
1633
1634 {
1635 // Simulating submission without previous interaction.
1636 base::HistogramTester histogram_tester;
1637 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1638 histogram_tester.ExpectBucketCount(
1639 "Autofill.FormEvents.CreditCard",
1640 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1641 histogram_tester.ExpectBucketCount(
1642 "Autofill.FormEvents.CreditCard",
1643 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1644 histogram_tester.ExpectBucketCount(
1645 "Autofill.FormEvents.CreditCard",
1646 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1647 histogram_tester.ExpectBucketCount(
1648 "Autofill.FormEvents.CreditCard",
1649 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
1650 histogram_tester.ExpectBucketCount(
1651 "Autofill.FormEvents.CreditCard",
1652 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1653 histogram_tester.ExpectBucketCount(
1654 "Autofill.FormEvents.CreditCard",
1655 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1656 }
1657 }
1658
1659 // Test that we log "will submit" (but not submitted) form events for credit
1660 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any
1661 // "submitted" metrics.
1662 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) {
1663 EnableWalletSync();
1664 // Creating all kinds of cards.
1665 personal_data_->RecreateCreditCards(
1666 true /* include_local_credit_card */,
1667 true /* include_masked_server_credit_card */,
1668 true /* include_full_server_credit_card */);
1669 // Set up our form data.
1670 FormData form;
1671 form.name = ASCIIToUTF16("TestForm");
1672 form.origin = GURL("http://example.com/form.html");
1673 form.action = GURL("http://example.com/submit.html");
1674 form.user_submitted = true;
1675
1676 FormFieldData field;
1677 std::vector<ServerFieldType> field_types;
1678 test::CreateTestFormField("Month", "card_month", "", "text", &field);
1679 form.fields.push_back(field);
1680 field_types.push_back(CREDIT_CARD_EXP_MONTH);
1681 test::CreateTestFormField("Year", "card_year", "", "text", &field);
1682 form.fields.push_back(field);
1683 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
1684 test::CreateTestFormField("Credit card", "card", "", "text", &field);
1685 form.fields.push_back(field);
1686 field_types.push_back(CREDIT_CARD_NUMBER);
1687
1688 // Simulate having seen this form on page load.
1689 // |form_structure| will be owned by |autofill_manager_|.
1690 autofill_manager_->AddSeenForm(form, field_types, field_types);
1691
1692 {
1693 // Simulating submission with no filled data.
1694 base::HistogramTester histogram_tester;
1695 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1696 false);
1697 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
1698 histogram_tester.ExpectBucketCount(
1699 "Autofill.FormEvents.CreditCard",
1700 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1701 histogram_tester.ExpectBucketCount(
1702 "Autofill.FormEvents.CreditCard",
1703 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
1704 }
1705
1706 // Reset the autofill manager state.
1707 autofill_manager_->Reset();
1708 autofill_manager_->AddSeenForm(form, field_types, field_types);
1709
1710 {
1711 // Simulating submission with filled local data.
1712 base::HistogramTester histogram_tester;
1713 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1714 false);
1715 SuggestionBackendID guid("10000000-0000-0000-0000-000000000001",
1716 0); // local card
1717 autofill_manager_->FillOrPreviewForm(
1718 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1719 autofill_manager_->MakeFrontendID(guid, SuggestionBackendID()));
1720 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
1721 histogram_tester.ExpectBucketCount(
1722 "Autofill.FormEvents.CreditCard",
1723 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1724 histogram_tester.ExpectBucketCount(
1725 "Autofill.FormEvents.CreditCard",
1726 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
1727 }
1728
1729 // Reset the autofill manager state.
1730 autofill_manager_->Reset();
1731 autofill_manager_->AddSeenForm(form, field_types, field_types);
1732
1733 {
1734 // Simulating submission with filled server data.
1735 base::HistogramTester histogram_tester;
1736 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1737 false);
1738 SuggestionBackendID guid("10000000-0000-0000-0000-000000000003",
1739 0); // full server card
1740 autofill_manager_->FillOrPreviewForm(
1741 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1742 autofill_manager_->MakeFrontendID(guid, SuggestionBackendID()));
1743 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
1744 histogram_tester.ExpectBucketCount(
1745 "Autofill.FormEvents.CreditCard",
1746 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1747 histogram_tester.ExpectBucketCount(
1748 "Autofill.FormEvents.CreditCard",
1749 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1750 }
1751
1752 // Reset the autofill manager state.
1753 autofill_manager_->Reset();
1754 autofill_manager_->AddSeenForm(form, field_types, field_types);
1755
1756 {
1757 // Simulating submission with a masked card server suggestion.
1758 base::HistogramTester histogram_tester;
1759 SuggestionBackendID guid("10000000-0000-0000-0000-000000000002",
1760 0); // masked server card
1761 autofill_manager_->FillOrPreviewForm(
1762 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1763 autofill_manager_->MakeFrontendID(guid, SuggestionBackendID()));
1764 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS,
1765 "6011000990139424");
1766 histogram_tester.ExpectBucketCount(
1767 "Autofill.FormEvents.CreditCard",
1768 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1);
1769 histogram_tester.ExpectBucketCount(
1770 "Autofill.FormEvents.CreditCard",
1771 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE,
1772 1);
1773 }
1774
1775 // Recreating cards as the previous test should have upgraded the masked
1776 // card to a full card.
1777 personal_data_->RecreateCreditCards(
1778 true /* include_local_credit_card */,
1779 true /* include_masked_server_credit_card */,
1780 true /* include_full_server_credit_card */);
1781
1782 // Reset the autofill manager state.
1783 autofill_manager_->Reset();
1784 autofill_manager_->AddSeenForm(form, field_types, field_types);
1785
1786 {
1787 // Simulating multiple submissions.
1788 base::HistogramTester histogram_tester;
1789 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1790 false);
1791 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
1792 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
1793 histogram_tester.ExpectBucketCount(
1794 "Autofill.FormEvents.CreditCard",
1795 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1796 histogram_tester.ExpectBucketCount(
1797 "Autofill.FormEvents.CreditCard",
1798 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1799 histogram_tester.ExpectBucketCount(
1800 "Autofill.FormEvents.CreditCard",
1801 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1802 histogram_tester.ExpectBucketCount(
1803 "Autofill.FormEvents.CreditCard",
1804 AutofillMetrics::
1805 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE,
1806 0);
1807 histogram_tester.ExpectBucketCount(
1808 "Autofill.FormEvents.CreditCard",
1809 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
1810 histogram_tester.ExpectBucketCount(
1811 "Autofill.FormEvents.CreditCard",
1812 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
1589 histogram_tester.ExpectBucketCount( 1813 histogram_tester.ExpectBucketCount(
1590 "Autofill.FormEvents.CreditCard", 1814 "Autofill.FormEvents.CreditCard",
1591 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0); 1815 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1592 histogram_tester.ExpectBucketCount( 1816 histogram_tester.ExpectBucketCount(
1593 "Autofill.FormEvents.CreditCard", 1817 "Autofill.FormEvents.CreditCard",
1594 AutofillMetrics 1818 AutofillMetrics
1595 ::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE, 1819 ::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE,
1596 0); 1820 0);
1597 } 1821 }
1598 1822
1599 // Reset the autofill manager state. 1823 // Reset the autofill manager state.
1600 autofill_manager_->Reset(); 1824 autofill_manager_->Reset();
1601 autofill_manager_->AddSeenForm(form, field_types, field_types); 1825 autofill_manager_->AddSeenForm(form, field_types, field_types);
1602 1826
1603 { 1827 {
1604 // Simulating submission without previous interaction. 1828 // Simulating submission without previous interaction.
1605 base::HistogramTester histogram_tester; 1829 base::HistogramTester histogram_tester;
1606 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 1830 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
1607 histogram_tester.ExpectBucketCount( 1831 histogram_tester.ExpectBucketCount(
1608 "Autofill.FormEvents.CreditCard", 1832 "Autofill.FormEvents.CreditCard",
1833 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1834 histogram_tester.ExpectBucketCount(
1835 "Autofill.FormEvents.CreditCard",
1836 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1837 histogram_tester.ExpectBucketCount(
1838 "Autofill.FormEvents.CreditCard",
1839 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1840 histogram_tester.ExpectBucketCount(
1841 "Autofill.FormEvents.CreditCard",
1609 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0); 1842 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
1610 histogram_tester.ExpectBucketCount( 1843 histogram_tester.ExpectBucketCount(
1611 "Autofill.FormEvents.CreditCard", 1844 "Autofill.FormEvents.CreditCard",
1612 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0); 1845 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1613 histogram_tester.ExpectBucketCount( 1846 histogram_tester.ExpectBucketCount(
1614 "Autofill.FormEvents.CreditCard", 1847 "Autofill.FormEvents.CreditCard",
1615 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0); 1848 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1616 } 1849 }
1617 } 1850 }
1618 1851
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 2097
1865 // Simulate having seen this form on page load. 2098 // Simulate having seen this form on page load.
1866 // |form_structure| will be owned by |autofill_manager_|. 2099 // |form_structure| will be owned by |autofill_manager_|.
1867 autofill_manager_->AddSeenForm(form, field_types, field_types); 2100 autofill_manager_->AddSeenForm(form, field_types, field_types);
1868 2101
1869 { 2102 {
1870 // Simulating submission with no filled data. 2103 // Simulating submission with no filled data.
1871 base::HistogramTester histogram_tester; 2104 base::HistogramTester histogram_tester;
1872 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(), 2105 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1873 false); 2106 false);
1874 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 2107 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2108 histogram_tester.ExpectBucketCount(
2109 "Autofill.FormEvents.Address",
2110 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1875 histogram_tester.ExpectBucketCount( 2111 histogram_tester.ExpectBucketCount(
1876 "Autofill.FormEvents.Address", 2112 "Autofill.FormEvents.Address",
1877 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); 2113 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
1878 } 2114 }
1879 2115
1880 // Reset the autofill manager state. 2116 // Reset the autofill manager state.
1881 autofill_manager_->Reset(); 2117 autofill_manager_->Reset();
1882 autofill_manager_->AddSeenForm(form, field_types, field_types); 2118 autofill_manager_->AddSeenForm(form, field_types, field_types);
1883 2119
1884 { 2120 {
1885 // Simulating submission with filled local data. 2121 // Simulating submission with filled local data.
1886 base::HistogramTester histogram_tester; 2122 base::HistogramTester histogram_tester;
1887 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(), 2123 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1888 false); 2124 false);
1889 SuggestionBackendID guid( 2125 SuggestionBackendID guid(
1890 "00000000-0000-0000-0000-000000000001", 0); // local profile 2126 "00000000-0000-0000-0000-000000000001", 0); // local profile
1891 autofill_manager_->FillOrPreviewForm( 2127 autofill_manager_->FillOrPreviewForm(
1892 AutofillDriver::FORM_DATA_ACTION_FILL, 2128 AutofillDriver::FORM_DATA_ACTION_FILL,
1893 0, form, form.fields.front(), 2129 0, form, form.fields.front(),
1894 autofill_manager_->MakeFrontendID(SuggestionBackendID(), guid)); 2130 autofill_manager_->MakeFrontendID(SuggestionBackendID(), guid));
1895 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 2131 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2132 histogram_tester.ExpectBucketCount(
2133 "Autofill.FormEvents.Address",
2134 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1896 histogram_tester.ExpectBucketCount( 2135 histogram_tester.ExpectBucketCount(
1897 "Autofill.FormEvents.Address", 2136 "Autofill.FormEvents.Address",
1898 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1); 2137 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1);
1899 } 2138 }
1900 2139
1901 // Reset the autofill manager state. 2140 // Reset the autofill manager state.
1902 autofill_manager_->Reset(); 2141 autofill_manager_->Reset();
1903 autofill_manager_->AddSeenForm(form, field_types, field_types); 2142 autofill_manager_->AddSeenForm(form, field_types, field_types);
1904 2143
1905 { 2144 {
1906 // Simulating submission with filled server data. 2145 // Simulating submission with filled server data.
1907 base::HistogramTester histogram_tester; 2146 base::HistogramTester histogram_tester;
1908 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(), 2147 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1909 false); 2148 false);
1910 SuggestionBackendID guid( 2149 SuggestionBackendID guid(
1911 "00000000-0000-0000-0000-000000000002", 0); // server profile 2150 "00000000-0000-0000-0000-000000000002", 0); // server profile
1912 autofill_manager_->FillOrPreviewForm( 2151 autofill_manager_->FillOrPreviewForm(
1913 AutofillDriver::FORM_DATA_ACTION_FILL, 2152 AutofillDriver::FORM_DATA_ACTION_FILL,
1914 0, form, form.fields.front(), 2153 0, form, form.fields.front(),
1915 autofill_manager_->MakeFrontendID(SuggestionBackendID(), guid)); 2154 autofill_manager_->MakeFrontendID(SuggestionBackendID(), guid));
1916 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 2155 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2156 histogram_tester.ExpectBucketCount(
2157 "Autofill.FormEvents.Address",
2158 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1917 histogram_tester.ExpectBucketCount( 2159 histogram_tester.ExpectBucketCount(
1918 "Autofill.FormEvents.Address", 2160 "Autofill.FormEvents.Address",
1919 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1); 2161 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1);
1920 } 2162 }
1921 2163
1922 // Reset the autofill manager state. 2164 // Reset the autofill manager state.
1923 autofill_manager_->Reset(); 2165 autofill_manager_->Reset();
1924 autofill_manager_->AddSeenForm(form, field_types, field_types); 2166 autofill_manager_->AddSeenForm(form, field_types, field_types);
1925 2167
1926 { 2168 {
1927 // Simulating multiple submissions. 2169 // Simulating multiple submissions.
1928 base::HistogramTester histogram_tester; 2170 base::HistogramTester histogram_tester;
1929 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(), 2171 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
1930 false); 2172 false);
1931 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 2173 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2174 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2175 histogram_tester.ExpectBucketCount(
2176 "Autofill.FormEvents.Address",
2177 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2178 histogram_tester.ExpectBucketCount(
2179 "Autofill.FormEvents.Address",
2180 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2181 histogram_tester.ExpectBucketCount(
2182 "Autofill.FormEvents.Address",
2183 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1932 histogram_tester.ExpectBucketCount( 2184 histogram_tester.ExpectBucketCount(
1933 "Autofill.FormEvents.Address", 2185 "Autofill.FormEvents.Address",
1934 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1); 2186 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
1935 histogram_tester.ExpectBucketCount( 2187 histogram_tester.ExpectBucketCount(
1936 "Autofill.FormEvents.Address", 2188 "Autofill.FormEvents.Address",
1937 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0); 2189 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
1938 histogram_tester.ExpectBucketCount( 2190 histogram_tester.ExpectBucketCount(
1939 "Autofill.FormEvents.Address", 2191 "Autofill.FormEvents.Address",
1940 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0); 2192 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1941 } 2193 }
1942 2194
1943 // Reset the autofill manager state. 2195 // Reset the autofill manager state.
1944 autofill_manager_->Reset(); 2196 autofill_manager_->Reset();
1945 autofill_manager_->AddSeenForm(form, field_types, field_types); 2197 autofill_manager_->AddSeenForm(form, field_types, field_types);
1946 2198
1947 { 2199 {
1948 // Simulating submission without previous interaction. 2200 // Simulating submission without previous interaction.
1949 base::HistogramTester histogram_tester; 2201 base::HistogramTester histogram_tester;
2202 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2203 histogram_tester.ExpectBucketCount(
2204 "Autofill.FormEvents.Address",
2205 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2206 histogram_tester.ExpectBucketCount(
2207 "Autofill.FormEvents.Address",
2208 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2209 histogram_tester.ExpectBucketCount(
2210 "Autofill.FormEvents.Address",
2211 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2212 histogram_tester.ExpectBucketCount(
2213 "Autofill.FormEvents.Address",
2214 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
2215 histogram_tester.ExpectBucketCount(
2216 "Autofill.FormEvents.Address",
2217 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
2218 histogram_tester.ExpectBucketCount(
2219 "Autofill.FormEvents.Address",
2220 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
2221 }
2222 }
2223
2224 // Test that we log "will submit" (but not submitted) form events for address.
2225 // Mirrors AddressSubmittedFormEvents test but does not expect any "submitted"
2226 // metrics.
2227 TEST_F(AutofillMetricsTest, AddressWillSubmitFormEvents) {
2228 EnableWalletSync();
2229 // Creating all kinds of profiles.
2230 personal_data_->RecreateProfiles(true /* include_local_profile */,
2231 true /* include_server_profile */);
2232 // Set up our form data.
2233 FormData form;
2234 form.name = ASCIIToUTF16("TestForm");
2235 form.origin = GURL("http://example.com/form.html");
2236 form.action = GURL("http://example.com/submit.html");
2237 form.user_submitted = true;
2238
2239 FormFieldData field;
2240 std::vector<ServerFieldType> field_types;
2241 test::CreateTestFormField("State", "state", "", "text", &field);
2242 form.fields.push_back(field);
2243 field_types.push_back(ADDRESS_HOME_STATE);
2244 test::CreateTestFormField("City", "city", "", "text", &field);
2245 form.fields.push_back(field);
2246 field_types.push_back(ADDRESS_HOME_CITY);
2247 test::CreateTestFormField("Street", "street", "", "text", &field);
2248 form.fields.push_back(field);
2249 field_types.push_back(ADDRESS_HOME_STREET_ADDRESS);
2250
2251 // Simulate having seen this form on page load.
2252 // |form_structure| will be owned by |autofill_manager_|.
2253 autofill_manager_->AddSeenForm(form, field_types, field_types);
2254
2255 {
2256 // Simulating submission with no filled data.
2257 base::HistogramTester histogram_tester;
2258 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
2259 false);
2260 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
2261 histogram_tester.ExpectBucketCount(
2262 "Autofill.FormEvents.Address",
2263 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2264 histogram_tester.ExpectBucketCount(
2265 "Autofill.FormEvents.Address",
2266 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
2267 }
2268
2269 // Reset the autofill manager state.
2270 autofill_manager_->Reset();
2271 autofill_manager_->AddSeenForm(form, field_types, field_types);
2272
2273 {
2274 // Simulating submission with filled local data.
2275 base::HistogramTester histogram_tester;
2276 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
2277 false);
2278 SuggestionBackendID guid("00000000-0000-0000-0000-000000000001",
2279 0); // local profile
2280 autofill_manager_->FillOrPreviewForm(
2281 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2282 autofill_manager_->MakeFrontendID(SuggestionBackendID(), guid));
2283 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
2284 histogram_tester.ExpectBucketCount(
2285 "Autofill.FormEvents.Address",
2286 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2287 histogram_tester.ExpectBucketCount(
2288 "Autofill.FormEvents.Address",
2289 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
2290 }
2291
2292 // Reset the autofill manager state.
2293 autofill_manager_->Reset();
2294 autofill_manager_->AddSeenForm(form, field_types, field_types);
2295
2296 {
2297 // Simulating submission with filled server data.
2298 base::HistogramTester histogram_tester;
2299 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
2300 false);
2301 SuggestionBackendID guid("00000000-0000-0000-0000-000000000002",
2302 0); // server profile
2303 autofill_manager_->FillOrPreviewForm(
2304 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2305 autofill_manager_->MakeFrontendID(SuggestionBackendID(), guid));
2306 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
2307 histogram_tester.ExpectBucketCount(
2308 "Autofill.FormEvents.Address",
2309 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2310 histogram_tester.ExpectBucketCount(
2311 "Autofill.FormEvents.Address",
2312 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
2313 }
2314
2315 // Reset the autofill manager state.
2316 autofill_manager_->Reset();
2317 autofill_manager_->AddSeenForm(form, field_types, field_types);
2318
2319 {
2320 // Simulating multiple submissions.
2321 base::HistogramTester histogram_tester;
2322 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
2323 false);
2324 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
2325 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
2326 histogram_tester.ExpectBucketCount(
2327 "Autofill.FormEvents.Address",
2328 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2329 histogram_tester.ExpectBucketCount(
2330 "Autofill.FormEvents.Address",
2331 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
2332 histogram_tester.ExpectBucketCount(
2333 "Autofill.FormEvents.Address",
2334 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
2335 histogram_tester.ExpectBucketCount(
2336 "Autofill.FormEvents.Address",
2337 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
2338 }
2339
2340 // Reset the autofill manager state.
2341 autofill_manager_->Reset();
2342 autofill_manager_->AddSeenForm(form, field_types, field_types);
2343
2344 {
2345 // Simulating submission without previous interaction.
2346 base::HistogramTester histogram_tester;
1950 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 2347 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
1951 histogram_tester.ExpectBucketCount( 2348 histogram_tester.ExpectBucketCount(
1952 "Autofill.FormEvents.Address", 2349 "Autofill.FormEvents.Address",
2350 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2351 histogram_tester.ExpectBucketCount(
2352 "Autofill.FormEvents.Address",
2353 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2354 histogram_tester.ExpectBucketCount(
2355 "Autofill.FormEvents.Address",
2356 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2357 histogram_tester.ExpectBucketCount(
2358 "Autofill.FormEvents.Address",
1953 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0); 2359 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
1954 histogram_tester.ExpectBucketCount( 2360 histogram_tester.ExpectBucketCount(
1955 "Autofill.FormEvents.Address", 2361 "Autofill.FormEvents.Address",
1956 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0); 2362 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
1957 histogram_tester.ExpectBucketCount( 2363 histogram_tester.ExpectBucketCount(
1958 "Autofill.FormEvents.Address", 2364 "Autofill.FormEvents.Address",
1959 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0); 2365 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1960 } 2366 }
1961 } 2367 }
1962 2368
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
2201 { 2607 {
2202 base::HistogramTester histogram_tester; 2608 base::HistogramTester histogram_tester;
2203 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 2609 autofill_manager_->OnFormsSeen(forms, TimeTicks());
2204 histogram_tester.ExpectTotalCount("Autofill.UserHappiness", 0); 2610 histogram_tester.ExpectTotalCount("Autofill.UserHappiness", 0);
2205 } 2611 }
2206 2612
2207 2613
2208 // Expect no notifications when the form is submitted. 2614 // Expect no notifications when the form is submitted.
2209 { 2615 {
2210 base::HistogramTester histogram_tester; 2616 base::HistogramTester histogram_tester;
2211 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 2617 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2212 histogram_tester.ExpectTotalCount("Autofill.UserHappiness", 0); 2618 histogram_tester.ExpectTotalCount("Autofill.UserHappiness", 0);
2213 } 2619 }
2214 2620
2215 // Add more fields to the form. 2621 // Add more fields to the form.
2216 test::CreateTestFormField("Phone", "phone", "", "text", &field); 2622 test::CreateTestFormField("Phone", "phone", "", "text", &field);
2217 form.fields.push_back(field); 2623 form.fields.push_back(field);
2218 test::CreateTestFormField("Unknown", "unknown", "", "text", &field); 2624 test::CreateTestFormField("Unknown", "unknown", "", "text", &field);
2219 form.fields.push_back(field); 2625 form.fields.push_back(field);
2220 forms.front() = form; 2626 forms.front() = form;
2221 2627
2222 // Expect a notification when the form is first seen. 2628 // Expect a notification when the form is first seen.
2223 { 2629 {
2224 base::HistogramTester histogram_tester; 2630 base::HistogramTester histogram_tester;
2225 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 2631 autofill_manager_->OnFormsSeen(forms, TimeTicks());
2226 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness", 2632 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness",
2227 AutofillMetrics::FORMS_LOADED, 1); 2633 AutofillMetrics::FORMS_LOADED, 1);
2228 } 2634 }
2229 2635
2230 // Expect a notification when the form is submitted. 2636 // Expect a notification when the form is submitted.
2231 { 2637 {
2232 base::HistogramTester histogram_tester; 2638 base::HistogramTester histogram_tester;
2233 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 2639 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2234 histogram_tester.ExpectUniqueSample( 2640 histogram_tester.ExpectUniqueSample(
2235 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM, 2641 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM,
2236 1); 2642 1);
2237 } 2643 }
2238 2644
2239 // Fill in two of the fields. 2645 // Fill in two of the fields.
2240 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); 2646 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
2241 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); 2647 form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
2242 forms.front() = form; 2648 forms.front() = form;
2243 2649
2244 // Expect a notification when the form is submitted. 2650 // Expect a notification when the form is submitted.
2245 { 2651 {
2246 base::HistogramTester histogram_tester; 2652 base::HistogramTester histogram_tester;
2247 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 2653 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2248 histogram_tester.ExpectUniqueSample( 2654 histogram_tester.ExpectUniqueSample(
2249 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM, 2655 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM,
2250 1); 2656 1);
2251 } 2657 }
2252 2658
2253 // Fill in the third field. 2659 // Fill in the third field.
2254 form.fields[2].value = ASCIIToUTF16("12345678901"); 2660 form.fields[2].value = ASCIIToUTF16("12345678901");
2255 forms.front() = form; 2661 forms.front() = form;
2256 2662
2257 // Expect notifications when the form is submitted. 2663 // Expect notifications when the form is submitted.
2258 { 2664 {
2259 base::HistogramTester histogram_tester; 2665 base::HistogramTester histogram_tester;
2260 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 2666 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2261 histogram_tester.ExpectUniqueSample( 2667 histogram_tester.ExpectUniqueSample(
2262 "Autofill.UserHappiness", 2668 "Autofill.UserHappiness",
2263 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE, 1); 2669 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE, 1);
2264 } 2670 }
2265 2671
2266 2672
2267 // Mark one of the fields as autofilled. 2673 // Mark one of the fields as autofilled.
2268 form.fields[1].is_autofilled = true; 2674 form.fields[1].is_autofilled = true;
2269 forms.front() = form; 2675 forms.front() = form;
2270 2676
2271 // Expect notifications when the form is submitted. 2677 // Expect notifications when the form is submitted.
2272 { 2678 {
2273 base::HistogramTester histogram_tester; 2679 base::HistogramTester histogram_tester;
2274 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 2680 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2275 histogram_tester.ExpectUniqueSample( 2681 histogram_tester.ExpectUniqueSample(
2276 "Autofill.UserHappiness", 2682 "Autofill.UserHappiness",
2277 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME, 1); 2683 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME, 1);
2278 } 2684 }
2279 2685
2280 // Mark all of the fillable fields as autofilled. 2686 // Mark all of the fillable fields as autofilled.
2281 form.fields[0].is_autofilled = true; 2687 form.fields[0].is_autofilled = true;
2282 form.fields[2].is_autofilled = true; 2688 form.fields[2].is_autofilled = true;
2283 forms.front() = form; 2689 forms.front() = form;
2284 2690
2285 // Expect notifications when the form is submitted. 2691 // Expect notifications when the form is submitted.
2286 { 2692 {
2287 base::HistogramTester histogram_tester; 2693 base::HistogramTester histogram_tester;
2288 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 2694 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2289 histogram_tester.ExpectUniqueSample( 2695 histogram_tester.ExpectUniqueSample(
2290 "Autofill.UserHappiness", 2696 "Autofill.UserHappiness",
2291 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL, 1); 2697 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL, 1);
2292 } 2698 }
2293 2699
2294 // Clear out the third field's value. 2700 // Clear out the third field's value.
2295 form.fields[2].value = base::string16(); 2701 form.fields[2].value = base::string16();
2296 forms.front() = form; 2702 forms.front() = form;
2297 2703
2298 // Expect notifications when the form is submitted. 2704 // Expect notifications when the form is submitted.
2299 { 2705 {
2300 base::HistogramTester histogram_tester; 2706 base::HistogramTester histogram_tester;
2301 autofill_manager_->WillSubmitForm(form, TimeTicks::Now()); 2707 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2302 histogram_tester.ExpectUniqueSample( 2708 histogram_tester.ExpectUniqueSample(
2303 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM, 2709 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM,
2304 1); 2710 1);
2305 } 2711 }
2306 } 2712 }
2307 2713
2308 // Verify that we correctly log user happiness metrics dealing with form 2714 // Verify that we correctly log user happiness metrics dealing with form
2309 // interaction. 2715 // interaction.
2310 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { 2716 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
2311 // Load a fillable form. 2717 // Load a fillable form.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2447 second_form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); 2853 second_form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
2448 second_form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); 2854 second_form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
2449 second_form.fields[2].value = ASCIIToUTF16("12345678901"); 2855 second_form.fields[2].value = ASCIIToUTF16("12345678901");
2450 second_form.fields[3].value = ASCIIToUTF16("51512345678"); 2856 second_form.fields[3].value = ASCIIToUTF16("51512345678");
2451 2857
2452 // Expect only form load metrics to be logged if the form is submitted without 2858 // Expect only form load metrics to be logged if the form is submitted without
2453 // user interaction. 2859 // user interaction.
2454 { 2860 {
2455 base::HistogramTester histogram_tester; 2861 base::HistogramTester histogram_tester;
2456 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 2862 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
2457 autofill_manager_->WillSubmitForm(form, TimeTicks::FromInternalValue(17)); 2863 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17));
2458 2864
2459 histogram_tester.ExpectTotalCount( 2865 histogram_tester.ExpectTotalCount(
2460 "Autofill.FillDuration.FromLoad.WithAutofill", 0); 2866 "Autofill.FillDuration.FromLoad.WithAutofill", 0);
2461 histogram_tester.ExpectUniqueSample( 2867 histogram_tester.ExpectUniqueSample(
2462 "Autofill.FillDuration.FromLoad.WithoutAutofill", 16, 1); 2868 "Autofill.FillDuration.FromLoad.WithoutAutofill", 16, 1);
2463 histogram_tester.ExpectTotalCount( 2869 histogram_tester.ExpectTotalCount(
2464 "Autofill.FillDuration.FromInteraction.WithAutofill", 0); 2870 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
2465 histogram_tester.ExpectTotalCount( 2871 histogram_tester.ExpectTotalCount(
2466 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); 2872 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
2467 2873
2468 autofill_manager_->Reset(); 2874 autofill_manager_->Reset();
2469 } 2875 }
2470 2876
2471 // Expect metric to be logged if the user manually edited a form field. 2877 // Expect metric to be logged if the user manually edited a form field.
2472 { 2878 {
2473 base::HistogramTester histogram_tester; 2879 base::HistogramTester histogram_tester;
2474 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 2880 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
2475 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 2881 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
2476 TimeTicks::FromInternalValue(3)); 2882 TimeTicks::FromInternalValue(3));
2477 autofill_manager_->WillSubmitForm(form, TimeTicks::FromInternalValue(17)); 2883 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17));
2478 2884
2479 histogram_tester.ExpectTotalCount( 2885 histogram_tester.ExpectTotalCount(
2480 "Autofill.FillDuration.FromLoad.WithAutofill", 0); 2886 "Autofill.FillDuration.FromLoad.WithAutofill", 0);
2481 histogram_tester.ExpectUniqueSample( 2887 histogram_tester.ExpectUniqueSample(
2482 "Autofill.FillDuration.FromLoad.WithoutAutofill", 16, 1); 2888 "Autofill.FillDuration.FromLoad.WithoutAutofill", 16, 1);
2483 histogram_tester.ExpectTotalCount( 2889 histogram_tester.ExpectTotalCount(
2484 "Autofill.FillDuration.FromInteraction.WithAutofill", 0); 2890 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
2485 histogram_tester.ExpectUniqueSample( 2891 histogram_tester.ExpectUniqueSample(
2486 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 14, 1); 2892 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 14, 1);
2487 2893
2488 autofill_manager_->Reset(); 2894 autofill_manager_->Reset();
2489 } 2895 }
2490 2896
2491 // Expect metric to be logged if the user autofilled the form. 2897 // Expect metric to be logged if the user autofilled the form.
2492 form.fields[0].is_autofilled = true; 2898 form.fields[0].is_autofilled = true;
2493 { 2899 {
2494 base::HistogramTester histogram_tester; 2900 base::HistogramTester histogram_tester;
2495 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 2901 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
2496 autofill_manager_->OnDidFillAutofillFormData( 2902 autofill_manager_->OnDidFillAutofillFormData(
2497 TimeTicks::FromInternalValue(5)); 2903 TimeTicks::FromInternalValue(5));
2498 autofill_manager_->WillSubmitForm(form, TimeTicks::FromInternalValue(17)); 2904 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17));
2499 2905
2500 histogram_tester.ExpectUniqueSample( 2906 histogram_tester.ExpectUniqueSample(
2501 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1); 2907 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1);
2502 histogram_tester.ExpectTotalCount( 2908 histogram_tester.ExpectTotalCount(
2503 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0); 2909 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0);
2504 histogram_tester.ExpectUniqueSample( 2910 histogram_tester.ExpectUniqueSample(
2505 "Autofill.FillDuration.FromInteraction.WithAutofill", 12, 1); 2911 "Autofill.FillDuration.FromInteraction.WithAutofill", 12, 1);
2506 histogram_tester.ExpectTotalCount( 2912 histogram_tester.ExpectTotalCount(
2507 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); 2913 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
2508 2914
2509 autofill_manager_->Reset(); 2915 autofill_manager_->Reset();
2510 } 2916 }
2511 2917
2512 // Expect metric to be logged if the user both manually filled some fields 2918 // Expect metric to be logged if the user both manually filled some fields
2513 // and autofilled others. Messages can arrive out of order, so make sure they 2919 // and autofilled others. Messages can arrive out of order, so make sure they
2514 // take precedence appropriately. 2920 // take precedence appropriately.
2515 { 2921 {
2516 base::HistogramTester histogram_tester; 2922 base::HistogramTester histogram_tester;
2517 2923
2518 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 2924 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
2519 autofill_manager_->OnDidFillAutofillFormData( 2925 autofill_manager_->OnDidFillAutofillFormData(
2520 TimeTicks::FromInternalValue(5)); 2926 TimeTicks::FromInternalValue(5));
2521 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 2927 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
2522 TimeTicks::FromInternalValue(3)); 2928 TimeTicks::FromInternalValue(3));
2523 autofill_manager_->WillSubmitForm(form, TimeTicks::FromInternalValue(17)); 2929 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17));
2524 2930
2525 histogram_tester.ExpectUniqueSample( 2931 histogram_tester.ExpectUniqueSample(
2526 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1); 2932 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1);
2527 histogram_tester.ExpectTotalCount( 2933 histogram_tester.ExpectTotalCount(
2528 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0); 2934 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0);
2529 histogram_tester.ExpectUniqueSample( 2935 histogram_tester.ExpectUniqueSample(
2530 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1); 2936 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1);
2531 histogram_tester.ExpectTotalCount( 2937 histogram_tester.ExpectTotalCount(
2532 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); 2938 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
2533 2939
2534 autofill_manager_->Reset(); 2940 autofill_manager_->Reset();
2535 } 2941 }
2536 2942
2537 // Make sure that loading another form doesn't affect metrics from the first 2943 // Make sure that loading another form doesn't affect metrics from the first
2538 // form. 2944 // form.
2539 { 2945 {
2540 base::HistogramTester histogram_tester; 2946 base::HistogramTester histogram_tester;
2541 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 2947 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
2542 autofill_manager_->OnFormsSeen(second_forms, 2948 autofill_manager_->OnFormsSeen(second_forms,
2543 TimeTicks::FromInternalValue(3)); 2949 TimeTicks::FromInternalValue(3));
2544 autofill_manager_->OnDidFillAutofillFormData( 2950 autofill_manager_->OnDidFillAutofillFormData(
2545 TimeTicks::FromInternalValue(5)); 2951 TimeTicks::FromInternalValue(5));
2546 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 2952 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
2547 TimeTicks::FromInternalValue(3)); 2953 TimeTicks::FromInternalValue(3));
2548 autofill_manager_->WillSubmitForm(form, TimeTicks::FromInternalValue(17)); 2954 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17));
2549 2955
2550 histogram_tester.ExpectUniqueSample( 2956 histogram_tester.ExpectUniqueSample(
2551 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1); 2957 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1);
2552 histogram_tester.ExpectTotalCount( 2958 histogram_tester.ExpectTotalCount(
2553 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0); 2959 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0);
2554 histogram_tester.ExpectUniqueSample( 2960 histogram_tester.ExpectUniqueSample(
2555 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1); 2961 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1);
2556 histogram_tester.ExpectTotalCount( 2962 histogram_tester.ExpectTotalCount(
2557 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); 2963 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
2558 2964
2559 autofill_manager_->Reset(); 2965 autofill_manager_->Reset();
2560 } 2966 }
2561 2967
2562 // Make sure that submitting a form that was loaded later will report the 2968 // Make sure that submitting a form that was loaded later will report the
2563 // later loading time. 2969 // later loading time.
2564 { 2970 {
2565 base::HistogramTester histogram_tester; 2971 base::HistogramTester histogram_tester;
2566 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 2972 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
2567 autofill_manager_->OnFormsSeen(second_forms, 2973 autofill_manager_->OnFormsSeen(second_forms,
2568 TimeTicks::FromInternalValue(5)); 2974 TimeTicks::FromInternalValue(5));
2569 autofill_manager_->WillSubmitForm(second_form, 2975 autofill_manager_->SubmitForm(second_form,
2570 TimeTicks::FromInternalValue(17)); 2976 TimeTicks::FromInternalValue(17));
2571 2977
2572 histogram_tester.ExpectTotalCount( 2978 histogram_tester.ExpectTotalCount(
2573 "Autofill.FillDuration.FromLoad.WithAutofill", 0); 2979 "Autofill.FillDuration.FromLoad.WithAutofill", 0);
2574 histogram_tester.ExpectUniqueSample( 2980 histogram_tester.ExpectUniqueSample(
2575 "Autofill.FillDuration.FromLoad.WithoutAutofill", 12, 1); 2981 "Autofill.FillDuration.FromLoad.WithoutAutofill", 12, 1);
2576 histogram_tester.ExpectTotalCount( 2982 histogram_tester.ExpectTotalCount(
2577 "Autofill.FillDuration.FromInteraction.WithAutofill", 0); 2983 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
2578 histogram_tester.ExpectTotalCount( 2984 histogram_tester.ExpectTotalCount(
2579 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); 2985 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
2580 2986
2581 autofill_manager_->Reset(); 2987 autofill_manager_->Reset();
2582 } 2988 }
2583 } 2989 }
2584 2990
2585 } // namespace autofill 2991 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698