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

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

Issue 1472723003: [Autofill] OnLoadedServerPredictions correctly supplies FormStructure to ParseQueryResponse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 5 years 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
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 2587 matching lines...) Expand 10 before | Expand all | Expand 10 after
2598 // Set up our form data. 2598 // Set up our form data.
2599 FormData form; 2599 FormData form;
2600 test::CreateTestAddressFormData(&form); 2600 test::CreateTestAddressFormData(&form);
2601 2601
2602 // Simulate having seen this form on page load. 2602 // Simulate having seen this form on page load.
2603 // |form_structure| will be owned by |autofill_manager_|. 2603 // |form_structure| will be owned by |autofill_manager_|.
2604 TestFormStructure* form_structure = new TestFormStructure(form); 2604 TestFormStructure* form_structure = new TestFormStructure(form);
2605 form_structure->DetermineHeuristicTypes(); 2605 form_structure->DetermineHeuristicTypes();
2606 autofill_manager_->AddSeenForm(form_structure); 2606 autofill_manager_->AddSeenForm(form_structure);
2607 2607
2608 // Similarly, a second form.
2609 FormData form2;
2610 form2.name = ASCIIToUTF16("MyForm");
2611 form2.origin = GURL("http://myform.com/form.html");
2612 form2.action = GURL("http://myform.com/submit.html");
2613
2614 FormFieldData field;
2615 test::CreateTestFormField("Last Name", "lastname", "", "text", &field);
2616 form2.fields.push_back(field);
2617
2618 test::CreateTestFormField("Middle Name", "middlename", "", "text", &field);
2619 form2.fields.push_back(field);
2620
2621 test::CreateTestFormField("Postal Code", "zipcode", "", "text", &field);
2622 form2.fields.push_back(field);
2623
2624 TestFormStructure* form_structure2 = new TestFormStructure(form2);
2625 form_structure2->DetermineHeuristicTypes();
2626 autofill_manager_->AddSeenForm(form_structure2);
2627
2608 std::string xml = "<autofillqueryresponse>" 2628 std::string xml = "<autofillqueryresponse>"
2609 "<field autofilltype=\"3\" />" // This is tested below. 2629 "<field autofilltype=\"3\" />" // First test form.
2610 "<field autofilltype=\"0\" />" 2630 "<field autofilltype=\"0\" />"
2611 "<field autofilltype=\"0\" />" 2631 "<field autofilltype=\"0\" />"
2612 "<field autofilltype=\"0\" />" 2632 "<field autofilltype=\"0\" />"
2613 "<field autofilltype=\"0\" />" 2633 "<field autofilltype=\"0\" />"
2614 "<field autofilltype=\"0\" />" 2634 "<field autofilltype=\"0\" />"
2615 "<field autofilltype=\"0\" />" 2635 "<field autofilltype=\"0\" />"
2616 "<field autofilltype=\"0\" />" 2636 "<field autofilltype=\"0\" />"
2617 "<field autofilltype=\"3\" />" 2637 "<field autofilltype=\"3\" />"
2618 "<field autofilltype=\"2\" />" 2638 "<field autofilltype=\"2\" />"
2619 "<field autofilltype=\"61\"/>" 2639 "<field autofilltype=\"61\"/>"
2640 "<field autofilltype=\"5\" />" // Second form.
2641 "<field autofilltype=\"4\" />"
2642 "<field autofilltype=\"35\"/>"
2620 "</autofillqueryresponse>"; 2643 "</autofillqueryresponse>";
2621 std::vector<std::string> signatures; 2644 std::vector<std::string> signatures;
2622 signatures.push_back(form_structure->FormSignature()); 2645 signatures.push_back(form_structure->FormSignature());
2646 signatures.push_back(form_structure2->FormSignature());
2623 2647
2624 base::HistogramTester histogram_tester; 2648 base::HistogramTester histogram_tester;
2625 autofill_manager_->OnLoadedServerPredictions(xml, signatures); 2649 autofill_manager_->OnLoadedServerPredictions(xml, signatures);
2626 // Verify that FormStructure::ParseQueryResponse was called (here and below). 2650 // Verify that FormStructure::ParseQueryResponse was called (here and below).
2627 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", 2651 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse",
2628 AutofillMetrics::QUERY_RESPONSE_RECEIVED, 2652 AutofillMetrics::QUERY_RESPONSE_RECEIVED,
2629 1); 2653 1);
2630 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse", 2654 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse",
2631 AutofillMetrics::QUERY_RESPONSE_PARSED, 2655 AutofillMetrics::QUERY_RESPONSE_PARSED,
2632 1); 2656 1);
2633 // We expect the server type to have been applied to the first field. 2657 // We expect the server type to have been applied to the first field of the
2658 // first form.
2634 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->Type().GetStorableType()); 2659 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->Type().GetStorableType());
2660
2661 // We expect the server types to have been applied to the second form.
2662 EXPECT_EQ(NAME_LAST, form_structure2->field(0)->Type().GetStorableType());
2663 EXPECT_EQ(NAME_MIDDLE, form_structure2->field(1)->Type().GetStorableType());
2664 EXPECT_EQ(ADDRESS_HOME_ZIP,
2665 form_structure2->field(2)->Type().GetStorableType());
2635 } 2666 }
2636 2667
2637 // Test that OnLoadedServerPredictions does not call ParseQueryResponse if the 2668 // Test that OnLoadedServerPredictions does not call ParseQueryResponse if the
2638 // AutofillManager has been reset between the time the query was sent and the 2669 // AutofillManager has been reset between the time the query was sent and the
2639 // response received. 2670 // response received.
2640 TEST_F(AutofillManagerTest, OnLoadedServerPredictions_ResetManager) { 2671 TEST_F(AutofillManagerTest, OnLoadedServerPredictions_ResetManager) {
2641 // Set up our form data. 2672 // Set up our form data.
2642 FormData form; 2673 FormData form;
2643 test::CreateTestAddressFormData(&form); 2674 test::CreateTestAddressFormData(&form);
2644 2675
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
3694 3725
3695 external_delegate_->CheckSuggestions( 3726 external_delegate_->CheckSuggestions(
3696 kDefaultPageID, 3727 kDefaultPageID,
3697 Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "", 3728 Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "",
3698 1), 3729 1),
3699 Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "", 3730 Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "",
3700 2)); 3731 2));
3701 } 3732 }
3702 3733
3703 } // namespace autofill 3734 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698