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

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

Issue 2003563003: [Autofill] Quality metric based on autocomplete attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: histograms.xml Created 4 years, 7 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
(...skipping 3495 matching lines...) Expand 10 before | Expand all | Expand 10 after
3506 FormStructure::ParseQueryResponse(response_string, forms.get(), nullptr); 3506 FormStructure::ParseQueryResponse(response_string, forms.get(), nullptr);
3507 3507
3508 ASSERT_GE(forms[0]->field_count(), 2U); 3508 ASSERT_GE(forms[0]->field_count(), 2U);
3509 ASSERT_GE(forms[1]->field_count(), 2U); 3509 ASSERT_GE(forms[1]->field_count(), 2U);
3510 EXPECT_EQ(7, forms[0]->field(0)->server_type()); 3510 EXPECT_EQ(7, forms[0]->field(0)->server_type());
3511 EXPECT_EQ(30, forms[0]->field(1)->server_type()); 3511 EXPECT_EQ(30, forms[0]->field(1)->server_type());
3512 EXPECT_EQ(9, forms[1]->field(0)->server_type()); 3512 EXPECT_EQ(9, forms[1]->field(0)->server_type());
3513 EXPECT_EQ(0, forms[1]->field(1)->server_type()); 3513 EXPECT_EQ(0, forms[1]->field(1)->server_type());
3514 } 3514 }
3515 3515
3516 // If user defined types are present, only parse password fields.
3517 TEST_F(FormStructureTest, ParseQueryResponseAuthorDefinedTypes) { 3516 TEST_F(FormStructureTest, ParseQueryResponseAuthorDefinedTypes) {
3518 FormData form; 3517 FormData form;
3519 form.origin = GURL("http://foo.com"); 3518 form.origin = GURL("http://foo.com");
3520 FormFieldData field; 3519 FormFieldData field;
3521 3520
3522 field.label = ASCIIToUTF16("email"); 3521 field.label = ASCIIToUTF16("email");
3523 field.name = ASCIIToUTF16("email"); 3522 field.name = ASCIIToUTF16("email");
3524 field.form_control_type = "text"; 3523 field.form_control_type = "text";
3525 field.autocomplete_attribute = "email"; 3524 field.autocomplete_attribute = "email";
3526 form.fields.push_back(field); 3525 form.fields.push_back(field);
3527 3526
3528 field.label = ASCIIToUTF16("password"); 3527 field.label = ASCIIToUTF16("password");
3529 field.name = ASCIIToUTF16("password"); 3528 field.name = ASCIIToUTF16("password");
3530 field.form_control_type = "password"; 3529 field.form_control_type = "password";
3531 field.autocomplete_attribute = "new-password"; 3530 field.autocomplete_attribute = "new-password";
3532 form.fields.push_back(field); 3531 form.fields.push_back(field);
3533 3532
3534 ScopedVector<FormStructure> forms; 3533 ScopedVector<FormStructure> forms;
3535 forms.push_back(new FormStructure(form)); 3534 forms.push_back(new FormStructure(form));
3536 forms.front()->DetermineHeuristicTypes(); 3535 forms.front()->DetermineHeuristicTypes();
3537 3536
3538 AutofillQueryResponseContents response; 3537 AutofillQueryResponseContents response;
3539 response.add_field()->set_autofill_type(9); 3538 response.add_field()->set_autofill_type(EMAIL_ADDRESS);
3540 response.add_field()->set_autofill_type(76); 3539 response.add_field()->set_autofill_type(ACCOUNT_CREATION_PASSWORD);
3541 3540
3542 std::string response_string; 3541 std::string response_string;
3543 ASSERT_TRUE(response.SerializeToString(&response_string)); 3542 ASSERT_TRUE(response.SerializeToString(&response_string));
3544 FormStructure::ParseQueryResponse(response_string, forms.get(), nullptr); 3543 FormStructure::ParseQueryResponse(response_string, forms.get(), nullptr);
3545 3544
3546 ASSERT_GE(forms[0]->field_count(), 2U); 3545 ASSERT_GE(forms[0]->field_count(), 2U);
3547 EXPECT_EQ(NO_SERVER_DATA, forms[0]->field(0)->server_type()); 3546 // Server type is parsed from the response and is the end result type.
3548 EXPECT_EQ(76, forms[0]->field(1)->server_type()); 3547 EXPECT_EQ(EMAIL_ADDRESS, forms[0]->field(0)->server_type());
3548 EXPECT_EQ(EMAIL_ADDRESS, forms[0]->field(0)->Type().GetStorableType());
3549 EXPECT_EQ(ACCOUNT_CREATION_PASSWORD, forms[0]->field(1)->server_type());
3550 // TODO(crbug.com/613666): Should be a properly defined type, and not
3551 // UNKNOWN_TYPE.
3552 EXPECT_EQ(UNKNOWN_TYPE, forms[0]->field(1)->Type().GetStorableType());
3549 } 3553 }
3550 3554
3551 TEST_F(FormStructureTest, FindLongestCommonPrefix) { 3555 TEST_F(FormStructureTest, FindLongestCommonPrefix) {
3552 // Normal case: All strings are longer than threshold; some are common. 3556 // Normal case: All strings are longer than threshold; some are common.
3553 std::vector<base::string16> strings; 3557 std::vector<base::string16> strings;
3554 strings.push_back(ASCIIToUTF16("1234567890123456789")); 3558 strings.push_back(ASCIIToUTF16("1234567890123456789"));
3555 strings.push_back(ASCIIToUTF16("123456789012345678_foo")); 3559 strings.push_back(ASCIIToUTF16("123456789012345678_foo"));
3556 strings.push_back(ASCIIToUTF16("1234567890123456")); 3560 strings.push_back(ASCIIToUTF16("1234567890123456"));
3557 strings.push_back(ASCIIToUTF16("12345678901234567890")); 3561 strings.push_back(ASCIIToUTF16("12345678901234567890"));
3558 base::string16 prefix = FormStructure::FindLongestCommonPrefix(strings); 3562 base::string16 prefix = FormStructure::FindLongestCommonPrefix(strings);
(...skipping 23 matching lines...) Expand all
3582 prefix = FormStructure::FindLongestCommonPrefix(strings); 3586 prefix = FormStructure::FindLongestCommonPrefix(strings);
3583 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix); 3587 EXPECT_EQ(ASCIIToUTF16("1234567890123456"), prefix);
3584 3588
3585 // Empty vector. 3589 // Empty vector.
3586 strings.clear(); 3590 strings.clear();
3587 prefix = FormStructure::FindLongestCommonPrefix(strings); 3591 prefix = FormStructure::FindLongestCommonPrefix(strings);
3588 EXPECT_EQ(ASCIIToUTF16(""), prefix); 3592 EXPECT_EQ(ASCIIToUTF16(""), prefix);
3589 } 3593 }
3590 3594
3591 } // namespace autofill 3595 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/form_structure.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698