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

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

Issue 1457793002: [Autofill] No longer pass FormStructure pointers in ParseQueryResponse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added AutofillManager tests Created 5 years, 1 month 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 <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 2574 matching lines...) Expand 10 before | Expand all | Expand 10 after
2585 // Set up our form data. 2585 // Set up our form data.
2586 FormData form; 2586 FormData form;
2587 test::CreateTestAddressFormData(&form); 2587 test::CreateTestAddressFormData(&form);
2588 std::vector<FormData> forms(1, form); 2588 std::vector<FormData> forms(1, form);
2589 FormsSeen(forms); 2589 FormsSeen(forms);
2590 FormFieldData* field = &form.fields[0]; 2590 FormFieldData* field = &form.fields[0];
2591 field->should_autocomplete = false; 2591 field->should_autocomplete = false;
2592 GetAutofillSuggestions(form, *field); 2592 GetAutofillSuggestions(form, *field);
2593 } 2593 }
2594 2594
2595 // Test that OnLoadedServerPredictions can obtain the FormStructure with the
2596 // signature of the queried form and apply type predictions.
2597 TEST_F(AutofillManagerTest, OnLoadedServerPredictions) {
2598 // Set up our form data.
2599 FormData form;
2600 test::CreateTestAddressFormData(&form);
2601
2602 // Simulate having seen this form on page load.
2603 // |form_structure| will be owned by |autofill_manager_|.
2604 TestFormStructure* form_structure = new TestFormStructure(form);
2605 form_structure->DetermineHeuristicTypes();
2606 autofill_manager_->AddSeenForm(form_structure);
2607
2608 std::string xml = "<autofillqueryresponse>"
2609 "<field autofilltype=\"3\" />" // This is tested below.
2610 "<field autofilltype=\"0\" />"
2611 "<field autofilltype=\"0\" />"
2612 "<field autofilltype=\"0\" />"
2613 "<field autofilltype=\"0\" />"
2614 "<field autofilltype=\"0\" />"
2615 "<field autofilltype=\"0\" />"
2616 "<field autofilltype=\"0\" />"
2617 "<field autofilltype=\"3\" />"
2618 "<field autofilltype=\"2\" />"
2619 "<field autofilltype=\"61\"/>"
2620 "</autofillqueryresponse>";
2621 std::vector<std::string> signatures;
2622 signatures.push_back(form_structure->FormSignature());
2623
2624 base::HistogramTester histogram_tester;
2625 autofill_manager_->OnLoadedServerPredictions(xml, signatures);
2626 // Verify that FormStructure::ParseQueryResponse was called (here and below).
2627 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse",
2628 AutofillMetrics::QUERY_RESPONSE_RECEIVED,
2629 1);
2630 histogram_tester.ExpectBucketCount("Autofill.ServerQueryResponse",
2631 AutofillMetrics::QUERY_RESPONSE_PARSED,
2632 1);
2633 // We expect the server type to have been applied to the first field.
2634 EXPECT_EQ(NAME_FIRST, form_structure->field(0)->Type().GetStorableType());
2635 }
2636
2637 // Test that OnLoadedServerPredictions does not call ParseQueryResponse if the
2638 // AutofillManager has been reset between the time the query was sent and the
2639 // response received.
2640 TEST_F(AutofillManagerTest, OnLoadedServerPredictions_ResetManager) {
2641 // Set up our form data.
2642 FormData form;
2643 test::CreateTestAddressFormData(&form);
2644
2645 // Simulate having seen this form on page load.
2646 // |form_structure| will be owned by |autofill_manager_|.
2647 TestFormStructure* form_structure = new TestFormStructure(form);
2648 form_structure->DetermineHeuristicTypes();
2649 autofill_manager_->AddSeenForm(form_structure);
2650
2651 std::string xml = "<autofillqueryresponse>"
2652 "<field autofilltype=\"3\" />" // This is tested below.
2653 "<field autofilltype=\"0\" />"
2654 "<field autofilltype=\"0\" />"
2655 "<field autofilltype=\"0\" />"
2656 "<field autofilltype=\"0\" />"
2657 "<field autofilltype=\"0\" />"
2658 "<field autofilltype=\"0\" />"
2659 "<field autofilltype=\"0\" />"
2660 "<field autofilltype=\"3\" />"
2661 "<field autofilltype=\"2\" />"
2662 "<field autofilltype=\"61\"/>"
2663 "</autofillqueryresponse>";
2664 std::vector<std::string> signatures;
2665 signatures.push_back(form_structure->FormSignature());
2666
2667 // Reset the manager (such as during a navigation).
2668 autofill_manager_->Reset();
2669
2670 base::HistogramTester histogram_tester;
2671 autofill_manager_->OnLoadedServerPredictions(xml, signatures);
2672
2673 // Verify that FormStructure::ParseQueryResponse was NOT called.
2674 histogram_tester.ExpectTotalCount("Autofill.ServerQueryResponse", 0);
2675 }
2676
2595 // Test that we are able to save form data when forms are submitted and we only 2677 // Test that we are able to save form data when forms are submitted and we only
2596 // have server data for the field types. 2678 // have server data for the field types.
2597 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) { 2679 TEST_F(AutofillManagerTest, FormSubmittedServerTypes) {
2598 // Set up our form data. 2680 // Set up our form data.
2599 FormData form; 2681 FormData form;
2600 test::CreateTestAddressFormData(&form); 2682 test::CreateTestAddressFormData(&form);
2601 2683
2602 // Simulate having seen this form on page load. 2684 // Simulate having seen this form on page load.
2603 // |form_structure| will be owned by |autofill_manager_|. 2685 // |form_structure| will be owned by |autofill_manager_|.
2604 TestFormStructure* form_structure = new TestFormStructure(form); 2686 TestFormStructure* form_structure = new TestFormStructure(form);
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
3612 3694
3613 external_delegate_->CheckSuggestions( 3695 external_delegate_->CheckSuggestions(
3614 kDefaultPageID, 3696 kDefaultPageID,
3615 Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "", 3697 Suggestion("Shawn Smith", "1234 Smith Blvd., Robin Adam Smith Grimes", "",
3616 1), 3698 1),
3617 Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "", 3699 Suggestion("Adam Smith", "1234 Smith Blvd., Carl Shawn Smith Grimes", "",
3618 2)); 3700 2));
3619 } 3701 }
3620 3702
3621 } // namespace autofill 3703 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | components/autofill/core/browser/form_structure.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698