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