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

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

Issue 2776223002: Adds UKM for autofill attributes in form_structure. (Closed)
Patch Set: Adds UKM for autofill attributes in form_structure. 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/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 3438 matching lines...) Expand 10 before | Expand all | Expand 10 after
3449 // Test that OnLoadedServerPredictions can obtain the FormStructure with the 3449 // Test that OnLoadedServerPredictions can obtain the FormStructure with the
3450 // signature of the queried form and apply type predictions. 3450 // signature of the queried form and apply type predictions.
3451 TEST_F(AutofillManagerTest, OnLoadedServerPredictions) { 3451 TEST_F(AutofillManagerTest, OnLoadedServerPredictions) {
3452 // Set up our form data. 3452 // Set up our form data.
3453 FormData form; 3453 FormData form;
3454 test::CreateTestAddressFormData(&form); 3454 test::CreateTestAddressFormData(&form);
3455 3455
3456 // Simulate having seen this form on page load. 3456 // Simulate having seen this form on page load.
3457 // |form_structure| will be owned by |autofill_manager_|. 3457 // |form_structure| will be owned by |autofill_manager_|.
3458 TestFormStructure* form_structure = new TestFormStructure(form); 3458 TestFormStructure* form_structure = new TestFormStructure(form);
3459 form_structure->DetermineHeuristicTypes(); 3459 form_structure->DetermineHeuristicTypes(nullptr /* ukm_service */, GURL());
3460 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure)); 3460 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure));
3461 3461
3462 // Similarly, a second form. 3462 // Similarly, a second form.
3463 FormData form2; 3463 FormData form2;
3464 form2.name = ASCIIToUTF16("MyForm"); 3464 form2.name = ASCIIToUTF16("MyForm");
3465 form2.origin = GURL("http://myform.com/form.html"); 3465 form2.origin = GURL("http://myform.com/form.html");
3466 form2.action = GURL("http://myform.com/submit.html"); 3466 form2.action = GURL("http://myform.com/submit.html");
3467 3467
3468 FormFieldData field; 3468 FormFieldData field;
3469 test::CreateTestFormField("Last Name", "lastname", "", "text", &field); 3469 test::CreateTestFormField("Last Name", "lastname", "", "text", &field);
3470 form2.fields.push_back(field); 3470 form2.fields.push_back(field);
3471 3471
3472 test::CreateTestFormField("Middle Name", "middlename", "", "text", &field); 3472 test::CreateTestFormField("Middle Name", "middlename", "", "text", &field);
3473 form2.fields.push_back(field); 3473 form2.fields.push_back(field);
3474 3474
3475 test::CreateTestFormField("Postal Code", "zipcode", "", "text", &field); 3475 test::CreateTestFormField("Postal Code", "zipcode", "", "text", &field);
3476 form2.fields.push_back(field); 3476 form2.fields.push_back(field);
3477 3477
3478 TestFormStructure* form_structure2 = new TestFormStructure(form2); 3478 TestFormStructure* form_structure2 = new TestFormStructure(form2);
3479 form_structure2->DetermineHeuristicTypes(); 3479 form_structure2->DetermineHeuristicTypes(nullptr /* ukm_service */, GURL());
3480 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure2)); 3480 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure2));
3481 3481
3482 AutofillQueryResponseContents response; 3482 AutofillQueryResponseContents response;
3483 response.add_field()->set_autofill_type(3); 3483 response.add_field()->set_autofill_type(3);
3484 for (int i = 0; i < 7; ++i) { 3484 for (int i = 0; i < 7; ++i) {
3485 response.add_field()->set_autofill_type(0); 3485 response.add_field()->set_autofill_type(0);
3486 } 3486 }
3487 response.add_field()->set_autofill_type(3); 3487 response.add_field()->set_autofill_type(3);
3488 response.add_field()->set_autofill_type(2); 3488 response.add_field()->set_autofill_type(2);
3489 response.add_field()->set_autofill_type(61); 3489 response.add_field()->set_autofill_type(61);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3522 // AutofillManager has been reset between the time the query was sent and the 3522 // AutofillManager has been reset between the time the query was sent and the
3523 // response received. 3523 // response received.
3524 TEST_F(AutofillManagerTest, OnLoadedServerPredictions_ResetManager) { 3524 TEST_F(AutofillManagerTest, OnLoadedServerPredictions_ResetManager) {
3525 // Set up our form data. 3525 // Set up our form data.
3526 FormData form; 3526 FormData form;
3527 test::CreateTestAddressFormData(&form); 3527 test::CreateTestAddressFormData(&form);
3528 3528
3529 // Simulate having seen this form on page load. 3529 // Simulate having seen this form on page load.
3530 // |form_structure| will be owned by |autofill_manager_|. 3530 // |form_structure| will be owned by |autofill_manager_|.
3531 TestFormStructure* form_structure = new TestFormStructure(form); 3531 TestFormStructure* form_structure = new TestFormStructure(form);
3532 form_structure->DetermineHeuristicTypes(); 3532 form_structure->DetermineHeuristicTypes(nullptr /* ukm_service */, GURL());
3533 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure)); 3533 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure));
3534 3534
3535 AutofillQueryResponseContents response; 3535 AutofillQueryResponseContents response;
3536 response.add_field()->set_autofill_type(3); 3536 response.add_field()->set_autofill_type(3);
3537 for (int i = 0; i < 7; ++i) { 3537 for (int i = 0; i < 7; ++i) {
3538 response.add_field()->set_autofill_type(0); 3538 response.add_field()->set_autofill_type(0);
3539 } 3539 }
3540 response.add_field()->set_autofill_type(3); 3540 response.add_field()->set_autofill_type(3);
3541 response.add_field()->set_autofill_type(2); 3541 response.add_field()->set_autofill_type(2);
3542 response.add_field()->set_autofill_type(61); 3542 response.add_field()->set_autofill_type(61);
(...skipping 17 matching lines...) Expand all
3560 // Test that we are able to save form data when forms are submitted and we only 3560 // Test that we are able to save form data when forms are submitted and we only
3561 // have server data for the field types. 3561 // have server data for the field types.
3562 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) { 3562 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) {
3563 // Set up our form data. 3563 // Set up our form data.
3564 FormData form; 3564 FormData form;
3565 test::CreateTestAddressFormData(&form); 3565 test::CreateTestAddressFormData(&form);
3566 3566
3567 // Simulate having seen this form on page load. 3567 // Simulate having seen this form on page load.
3568 // |form_structure| will be owned by |autofill_manager_|. 3568 // |form_structure| will be owned by |autofill_manager_|.
3569 TestFormStructure* form_structure = new TestFormStructure(form); 3569 TestFormStructure* form_structure = new TestFormStructure(form);
3570 form_structure->DetermineHeuristicTypes(); 3570 form_structure->DetermineHeuristicTypes(nullptr /* ukm_service */, GURL());
3571 3571
3572 // Clear the heuristic types, and instead set the appropriate server types. 3572 // Clear the heuristic types, and instead set the appropriate server types.
3573 std::vector<ServerFieldType> heuristic_types, server_types; 3573 std::vector<ServerFieldType> heuristic_types, server_types;
3574 for (size_t i = 0; i < form.fields.size(); ++i) { 3574 for (size_t i = 0; i < form.fields.size(); ++i) {
3575 heuristic_types.push_back(UNKNOWN_TYPE); 3575 heuristic_types.push_back(UNKNOWN_TYPE);
3576 server_types.push_back(form_structure->field(i)->heuristic_type()); 3576 server_types.push_back(form_structure->field(i)->heuristic_type());
3577 } 3577 }
3578 form_structure->SetFieldTypes(heuristic_types, server_types); 3578 form_structure->SetFieldTypes(heuristic_types, server_types);
3579 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure)); 3579 autofill_manager_->AddSeenForm(base::WrapUnique(form_structure));
3580 3580
(...skipping 2183 matching lines...) Expand 10 before | Expand all | Expand 10 after
5764 5764
5765 FormFieldData field; 5765 FormFieldData field;
5766 test::CreateTestFormField("Field 1", "field1", "", "text", &field); 5766 test::CreateTestFormField("Field 1", "field1", "", "text", &field);
5767 form.fields.push_back(field); 5767 form.fields.push_back(field);
5768 test::CreateTestFormField("Field 2", "field2", "", "text", &field); 5768 test::CreateTestFormField("Field 2", "field2", "", "text", &field);
5769 form.fields.push_back(field); 5769 form.fields.push_back(field);
5770 test::CreateTestFormField("Field 3", "field3", "", "text", &field); 5770 test::CreateTestFormField("Field 3", "field3", "", "text", &field);
5771 form.fields.push_back(field); 5771 form.fields.push_back(field);
5772 5772
5773 auto form_structure = base::MakeUnique<TestFormStructure>(form); 5773 auto form_structure = base::MakeUnique<TestFormStructure>(form);
5774 form_structure->DetermineHeuristicTypes(); 5774 form_structure->DetermineHeuristicTypes(nullptr /* ukm_service */, GURL());
5775 // Make sure the form can not be autofilled now. 5775 // Make sure the form can not be autofilled now.
5776 ASSERT_EQ(0u, form_structure->autofill_count()); 5776 ASSERT_EQ(0u, form_structure->autofill_count());
5777 for (size_t idx = 0; idx < form_structure->field_count(); ++idx) { 5777 for (size_t idx = 0; idx < form_structure->field_count(); ++idx) {
5778 ASSERT_EQ(UNKNOWN_TYPE, form_structure->field(idx)->heuristic_type()); 5778 ASSERT_EQ(UNKNOWN_TYPE, form_structure->field(idx)->heuristic_type());
5779 } 5779 }
5780 5780
5781 // Prepare and set known server fields. 5781 // Prepare and set known server fields.
5782 const std::vector<ServerFieldType> heuristic_types(form.fields.size(), 5782 const std::vector<ServerFieldType> heuristic_types(form.fields.size(),
5783 UNKNOWN_TYPE); 5783 UNKNOWN_TYPE);
5784 const std::vector<ServerFieldType> server_types{NAME_FIRST, NAME_MIDDLE, 5784 const std::vector<ServerFieldType> server_types{NAME_FIRST, NAME_MIDDLE,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
5839 FormsSeen({form}); 5839 FormsSeen({form});
5840 5840
5841 // Suggestions should be displayed. 5841 // Suggestions should be displayed.
5842 for (const FormFieldData& field : form.fields) { 5842 for (const FormFieldData& field : form.fields) {
5843 GetAutofillSuggestions(form, field); 5843 GetAutofillSuggestions(form, field);
5844 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); 5844 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
5845 } 5845 }
5846 } 5846 }
5847 5847
5848 } // namespace autofill 5848 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698