OLD | NEW |
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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 AutofillMetrics::TYPE_MATCH), | 357 AutofillMetrics::TYPE_MATCH), |
358 1); | 358 1); |
359 // Mismatch: | 359 // Mismatch: |
360 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType", | 360 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType", |
361 AutofillMetrics::TYPE_MISMATCH, 1); | 361 AutofillMetrics::TYPE_MISMATCH, 1); |
362 histogram_tester.ExpectBucketCount( | 362 histogram_tester.ExpectBucketCount( |
363 "Autofill.Quality.PredictedType.ByFieldType", | 363 "Autofill.Quality.PredictedType.ByFieldType", |
364 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1); | 364 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1); |
365 } | 365 } |
366 | 366 |
| 367 // Verify that when a field is annotated with the autocomplete attribute, its |
| 368 // predicted type is remembered when quality metrics are logged. |
| 369 TEST_F(AutofillMetricsTest, PredictedMetricsWithAutocomplete) { |
| 370 // Set up our form data. |
| 371 FormData form; |
| 372 form.name = ASCIIToUTF16("TestForm"); |
| 373 form.origin = GURL("http://example.com/form.html"); |
| 374 form.action = GURL("http://example.com/submit.html"); |
| 375 form.user_submitted = true; |
| 376 |
| 377 FormFieldData field1; |
| 378 test::CreateTestFormField("Select", "select", "USA", "select-one", &field1); |
| 379 field1.autocomplete_attribute = "country"; |
| 380 form.fields.push_back(field1); |
| 381 |
| 382 // Two other fields to have the minimum of 3 to be parsed by autofill. Note |
| 383 // that they have default values not found in the user profiles. They will be |
| 384 // changed between the time the form is seen/parsed, and the time it is |
| 385 // submitted. |
| 386 FormFieldData field2; |
| 387 test::CreateTestFormField("Unknown", "Unknown", "", "text", &field2); |
| 388 form.fields.push_back(field2); |
| 389 FormFieldData field3; |
| 390 test::CreateTestFormField("Phone", "phone", "", "tel", &field3); |
| 391 form.fields.push_back(field3); |
| 392 |
| 393 std::vector<FormData> forms(1, form); |
| 394 |
| 395 { |
| 396 base::HistogramTester histogram_tester; |
| 397 autofill_manager_->OnFormsSeen(forms, TimeTicks()); |
| 398 // We change the value of the text fields to change the default/seen values |
| 399 // (hence the values are not cleared in UpdateFromCache). The new values |
| 400 // match what is in the test profile. |
| 401 form.fields[1].value = base::ASCIIToUTF16("79401"); |
| 402 form.fields[2].value = base::ASCIIToUTF16("2345678901"); |
| 403 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); |
| 404 |
| 405 // First verify that country was not predicted by client or server. |
| 406 histogram_tester.ExpectBucketCount( |
| 407 "Autofill.Quality.ServerType.ByFieldType", |
| 408 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, |
| 409 AutofillMetrics::TYPE_UNKNOWN), |
| 410 1); |
| 411 histogram_tester.ExpectBucketCount( |
| 412 "Autofill.Quality.HeuristicType.ByFieldType", |
| 413 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, |
| 414 AutofillMetrics::TYPE_UNKNOWN), |
| 415 1); |
| 416 // We expect a match for country because it had |autocomplete_attribute|. |
| 417 histogram_tester.ExpectBucketCount( |
| 418 "Autofill.Quality.PredictedType.ByFieldType", |
| 419 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY, |
| 420 AutofillMetrics::TYPE_MATCH), |
| 421 1); |
| 422 |
| 423 // We did not predict zip code or phone number, because they did not have |
| 424 // |autocomplete_attribute|, nor client or server predictions. |
| 425 histogram_tester.ExpectBucketCount( |
| 426 "Autofill.Quality.ServerType.ByFieldType", |
| 427 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, |
| 428 AutofillMetrics::TYPE_UNKNOWN), |
| 429 1); |
| 430 histogram_tester.ExpectBucketCount( |
| 431 "Autofill.Quality.HeuristicType.ByFieldType", |
| 432 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, |
| 433 AutofillMetrics::TYPE_UNKNOWN), |
| 434 1); |
| 435 histogram_tester.ExpectBucketCount( |
| 436 "Autofill.Quality.PredictedType.ByFieldType", |
| 437 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP, |
| 438 AutofillMetrics::TYPE_UNKNOWN), |
| 439 1); |
| 440 histogram_tester.ExpectBucketCount( |
| 441 "Autofill.Quality.ServerType.ByFieldType", |
| 442 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, |
| 443 AutofillMetrics::TYPE_UNKNOWN), |
| 444 1); |
| 445 histogram_tester.ExpectBucketCount( |
| 446 "Autofill.Quality.HeuristicType.ByFieldType", |
| 447 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, |
| 448 AutofillMetrics::TYPE_UNKNOWN), |
| 449 1); |
| 450 histogram_tester.ExpectBucketCount( |
| 451 "Autofill.Quality.PredictedType.ByFieldType", |
| 452 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER, |
| 453 AutofillMetrics::TYPE_UNKNOWN), |
| 454 1); |
| 455 |
| 456 // Sanity check. |
| 457 histogram_tester.ExpectTotalCount("Autofill.Quality.PredictedType", 3); |
| 458 } |
| 459 } |
| 460 |
367 // Test that we behave sanely when the cached form differs from the submitted | 461 // Test that we behave sanely when the cached form differs from the submitted |
368 // one. | 462 // one. |
369 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) { | 463 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) { |
370 // Set up our form data. | 464 // Set up our form data. |
371 FormData form; | 465 FormData form; |
372 form.name = ASCIIToUTF16("TestForm"); | 466 form.name = ASCIIToUTF16("TestForm"); |
373 form.origin = GURL("http://example.com/form.html"); | 467 form.origin = GURL("http://example.com/form.html"); |
374 form.action = GURL("http://example.com/submit.html"); | 468 form.action = GURL("http://example.com/submit.html"); |
375 form.user_submitted = true; | 469 form.user_submitted = true; |
376 | 470 |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 histogram_tester.ExpectTotalCount( | 1187 histogram_tester.ExpectTotalCount( |
1094 "Autofill.FillDuration.FromInteraction.WithAutofill", 0); | 1188 "Autofill.FillDuration.FromInteraction.WithAutofill", 0); |
1095 histogram_tester.ExpectTotalCount( | 1189 histogram_tester.ExpectTotalCount( |
1096 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); | 1190 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); |
1097 | 1191 |
1098 autofill_manager_->Reset(); | 1192 autofill_manager_->Reset(); |
1099 } | 1193 } |
1100 } | 1194 } |
1101 | 1195 |
1102 } // namespace autofill | 1196 } // namespace autofill |
OLD | NEW |