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

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

Issue 2773433002: Log observations of explicit UPI-VPA autocomplete hints. (Closed)
Patch Set: Initial CL Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/form_structure.h" 5 #include "components/autofill/core/browser/form_structure.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/test/histogram_tester.h"
17 #include "components/autofill/core/browser/autofill_test_utils.h" 18 #include "components/autofill/core/browser/autofill_test_utils.h"
18 #include "components/autofill/core/common/autofill_switches.h" 19 #include "components/autofill/core/common/autofill_switches.h"
19 #include "components/autofill/core/common/form_data.h" 20 #include "components/autofill/core/common/form_data.h"
20 #include "components/autofill/core/common/form_field_data.h" 21 #include "components/autofill/core/common/form_field_data.h"
21 #include "components/autofill/core/common/signatures_util.h" 22 #include "components/autofill/core/common/signatures_util.h"
22 #include "components/variations/entropy_provider.h" 23 #include "components/variations/entropy_provider.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 using base::ASCIIToUTF16; 27 using base::ASCIIToUTF16;
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 // City. 429 // City.
429 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(6)->heuristic_type()); 430 EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(6)->heuristic_type());
430 // Zip. 431 // Zip.
431 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(7)->heuristic_type()); 432 EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(7)->heuristic_type());
432 // Submit. 433 // Submit.
433 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(8)->heuristic_type()); 434 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(8)->heuristic_type());
434 } 435 }
435 436
436 // Verify that we can correctly process the |autocomplete| attribute. 437 // Verify that we can correctly process the |autocomplete| attribute.
437 TEST_F(FormStructureTest, HeuristicsAutocompleteAttribute) { 438 TEST_F(FormStructureTest, HeuristicsAutocompleteAttribute) {
439 base::HistogramTester histograms;
Mathieu 2017/03/23 11:26:22 there is no histogram testing in this file (histog
Roger McFarlane (Chromium) 2017/03/28 19:08:24 Done.
438 std::unique_ptr<FormStructure> form_structure; 440 std::unique_ptr<FormStructure> form_structure;
439 FormData form; 441 FormData form;
440 442
441 FormFieldData field; 443 FormFieldData field;
442 field.form_control_type = "text"; 444 field.form_control_type = "text";
443 445
444 field.label = base::string16(); 446 field.label = base::string16();
445 field.name = ASCIIToUTF16("field1"); 447 field.name = ASCIIToUTF16("field1");
446 field.autocomplete_attribute = "given-name"; 448 field.autocomplete_attribute = "given-name";
447 form.fields.push_back(field); 449 form.fields.push_back(field);
448 450
449 field.label = base::string16(); 451 field.label = base::string16();
450 field.name = ASCIIToUTF16("field2"); 452 field.name = ASCIIToUTF16("field2");
451 field.autocomplete_attribute = "family-name"; 453 field.autocomplete_attribute = "family-name";
452 form.fields.push_back(field); 454 form.fields.push_back(field);
453 455
454 field.label = base::string16(); 456 field.label = base::string16();
455 field.name = ASCIIToUTF16("field3"); 457 field.name = ASCIIToUTF16("field3");
456 field.autocomplete_attribute = "email"; 458 field.autocomplete_attribute = "email";
457 form.fields.push_back(field); 459 form.fields.push_back(field);
458 460
461 field.label = base::string16();
462 field.name = ASCIIToUTF16("field4");
463 field.autocomplete_attribute = "upi-vpa";
464 form.fields.push_back(field);
465
459 form_structure.reset(new FormStructure(form)); 466 form_structure.reset(new FormStructure(form));
460 form_structure->DetermineHeuristicTypes(); 467 form_structure->DetermineHeuristicTypes();
461 EXPECT_TRUE(form_structure->IsAutofillable()); 468 EXPECT_TRUE(form_structure->IsAutofillable());
462 469
463 // Expect the correct number of fields. 470 // Expect the correct number of fields.
464 ASSERT_EQ(3U, form_structure->field_count()); 471 ASSERT_EQ(4U, form_structure->field_count());
465 ASSERT_EQ(3U, form_structure->autofill_count()); 472 ASSERT_EQ(3U, form_structure->autofill_count());
466 473
467 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type()); 474 EXPECT_EQ(HTML_TYPE_GIVEN_NAME, form_structure->field(0)->html_type());
468 EXPECT_EQ(HTML_TYPE_FAMILY_NAME, form_structure->field(1)->html_type()); 475 EXPECT_EQ(HTML_TYPE_FAMILY_NAME, form_structure->field(1)->html_type());
469 EXPECT_EQ(HTML_TYPE_EMAIL, form_structure->field(2)->html_type()); 476 EXPECT_EQ(HTML_TYPE_EMAIL, form_structure->field(2)->html_type());
477 EXPECT_EQ(HTML_TYPE_UNRECOGNIZED, form_structure->field(3)->html_type());
470 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type()); 478 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(0)->heuristic_type());
471 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type()); 479 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type());
472 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type()); 480 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
481 EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type());
482
483 histograms.ExpectBucketCount("Autofill.ExplicitUpiVpaHint",
484 static_cast<int>(true), 1);
473 } 485 }
474 486
475 // Verify that the heuristics are not run for non checkout formless forms. 487 // Verify that the heuristics are not run for non checkout formless forms.
476 TEST_F(FormStructureTest, Heuristics_FormlessNonCheckoutForm) { 488 TEST_F(FormStructureTest, Heuristics_FormlessNonCheckoutForm) {
477 std::unique_ptr<FormStructure> form_structure; 489 std::unique_ptr<FormStructure> form_structure;
478 FormData form; 490 FormData form;
479 491
480 FormFieldData field; 492 FormFieldData field;
481 field.form_control_type = "text"; 493 field.form_control_type = "text";
482 494
(...skipping 3343 matching lines...) Expand 10 before | Expand all | Expand 10 after
3826 prefix = FormStructure::FindLongestCommonPrefix(strings); 3838 prefix = FormStructure::FindLongestCommonPrefix(strings);
3827 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix); 3839 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix);
3828 3840
3829 // Empty vector. 3841 // Empty vector.
3830 strings.clear(); 3842 strings.clear();
3831 prefix = FormStructure::FindLongestCommonPrefix(strings); 3843 prefix = FormStructure::FindLongestCommonPrefix(strings);
3832 EXPECT_EQ(ASCIIToUTF16(""), prefix); 3844 EXPECT_EQ(ASCIIToUTF16(""), prefix);
3833 } 3845 }
3834 3846
3835 } // namespace autofill 3847 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698