Chromium Code Reviews| Index: components/autofill/core/browser/autofill_metrics_unittest.cc |
| diff --git a/components/autofill/core/browser/autofill_metrics_unittest.cc b/components/autofill/core/browser/autofill_metrics_unittest.cc |
| index d101f879395c0cfd9de4ca60d87252e3ed1a4b3f..8ea54efc7b9639715c3bfef3b176616a4c2e0209 100644 |
| --- a/components/autofill/core/browser/autofill_metrics_unittest.cc |
| +++ b/components/autofill/core/browser/autofill_metrics_unittest.cc |
| @@ -364,6 +364,103 @@ TEST_F(AutofillMetricsTest, QualityMetrics) { |
| GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1); |
| } |
| +// Verify that when a field is annotated with the autocomplete attribute, its |
| +// predicted type is remembered when quality metrics are logged. |
| +TEST_F(AutofillMetricsTest, PredictedMetricsWithAutocomplete) { |
| + // Set up our form data. |
| + FormData form; |
| + form.name = ASCIIToUTF16("TestForm"); |
| + form.origin = GURL("http://example.com/form.html"); |
| + form.action = GURL("http://example.com/submit.html"); |
| + form.user_submitted = true; |
| + |
| + FormFieldData field1; |
| + test::CreateTestFormField("Select", "select", "USA", "select-one", &field1); |
| + field1.autocomplete_attribute = "country"; |
| + field1.is_autofilled = false; |
|
Ilya Sherman
2015/02/02 22:28:12
Isn't false the default value for is_autofilled?
Mathieu
2015/02/03 03:19:48
Done.
|
| + form.fields.push_back(field1); |
| + |
| + // Two other fields to have the minimum of 3 to be parsed by autofill. Note |
| + // that they have default values not found in the user profiles. They will be |
| + // changed between the time the form is seen/parsed, and the time it is |
| + // submitted. |
| + FormFieldData field2; |
| + test::CreateTestFormField("Unknown", "Unknown", "90210", "text", &field2); |
| + field2.is_autofilled = false; |
| + form.fields.push_back(field2); |
| + FormFieldData field3; |
| + test::CreateTestFormField("Phone", "phone", "2125551212", "tel", &field3); |
|
Ilya Sherman
2015/02/02 22:28:12
nit: I'd recommend setting the starting values for
Mathieu
2015/02/03 03:19:48
Done.
|
| + field3.is_autofilled = false; |
| + form.fields.push_back(field3); |
| + |
| + std::vector<FormData> forms(1, form); |
| + |
| + { |
| + base::HistogramTester histogram_tester; |
| + autofill_manager_->OnFormsSeen(forms, TimeTicks()); |
| + // We change the value of the text fields to change the default/seen values |
| + // (hence the values are not cleared in UpdateFromCache). The new values |
| + // match what is in the test profile. |
| + form.fields[1].value = base::ASCIIToUTF16("79401"); |
| + form.fields[2].value = base::ASCIIToUTF16("2345678901"); |
| + autofill_manager_->FormSubmitted(form, TimeTicks::Now()); |
| + |
| + // First verify that country was not predicted by client or server. |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.Quality.ServerType.ByFieldType", |
| + GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, |
| + AutofillMetrics::TYPE_UNKNOWN), |
| + 1); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.Quality.HeuristicType.ByFieldType", |
| + GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, |
| + AutofillMetrics::TYPE_UNKNOWN), |
| + 1); |
| + // We expect a match for country because it had |autocomplete_attribute|. |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.Quality.PredictedType.ByFieldType", |
| + GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, |
| + AutofillMetrics::TYPE_MATCH), |
| + 1); |
| + |
| + // We did not predict zip code or phone number, because they did not have |
| + // |autocomplete_attribute|, nor client or server predictions. |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.Quality.ServerType.ByFieldType", |
| + GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, |
| + AutofillMetrics::TYPE_UNKNOWN), |
| + 1); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.Quality.HeuristicType.ByFieldType", |
| + GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, |
| + AutofillMetrics::TYPE_UNKNOWN), |
| + 1); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.Quality.PredictedType.ByFieldType", |
| + GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, |
| + AutofillMetrics::TYPE_UNKNOWN), |
| + 1); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.Quality.ServerType.ByFieldType", |
| + GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, |
| + AutofillMetrics::TYPE_UNKNOWN), |
| + 1); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.Quality.HeuristicType.ByFieldType", |
| + GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, |
| + AutofillMetrics::TYPE_UNKNOWN), |
| + 1); |
| + histogram_tester.ExpectBucketCount( |
| + "Autofill.Quality.PredictedType.ByFieldType", |
| + GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, |
| + AutofillMetrics::TYPE_UNKNOWN), |
| + 1); |
| + |
| + // Sanity check. |
| + histogram_tester.ExpectTotalCount("Autofill.Quality.PredictedType", 3); |
| + } |
| +} |
| + |
| // Test that we behave sanely when the cached form differs from the submitted |
| // one. |
| TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) { |