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

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

Issue 22009003: [Autofill] Distinguish between native field types and potentially HTML field types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 4 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 | Annotate | Revision Log
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/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 return autocheckout_url_prefix_; 487 return autocheckout_url_prefix_;
488 } 488 }
489 489
490 const std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >& 490 const std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >&
491 request_autocomplete_results() const { 491 request_autocomplete_results() const {
492 return request_autocomplete_results_; 492 return request_autocomplete_results_;
493 } 493 }
494 494
495 495
496 void set_expected_submitted_field_types( 496 void set_expected_submitted_field_types(
497 const std::vector<FieldTypeSet>& expected_types) { 497 const std::vector<ServerFieldTypeSet>& expected_types) {
498 expected_submitted_field_types_ = expected_types; 498 expected_submitted_field_types_ = expected_types;
499 } 499 }
500 500
501 virtual void UploadFormDataAsyncCallback( 501 virtual void UploadFormDataAsyncCallback(
502 const FormStructure* submitted_form, 502 const FormStructure* submitted_form,
503 const base::TimeTicks& load_time, 503 const base::TimeTicks& load_time,
504 const base::TimeTicks& interaction_time, 504 const base::TimeTicks& interaction_time,
505 const base::TimeTicks& submission_time) OVERRIDE { 505 const base::TimeTicks& submission_time) OVERRIDE {
506 message_loop_runner_->Quit(); 506 message_loop_runner_->Quit();
507 507
508 // If we have expected field types set, make sure they match. 508 // If we have expected field types set, make sure they match.
509 if (!expected_submitted_field_types_.empty()) { 509 if (!expected_submitted_field_types_.empty()) {
510 ASSERT_EQ(expected_submitted_field_types_.size(), 510 ASSERT_EQ(expected_submitted_field_types_.size(),
511 submitted_form->field_count()); 511 submitted_form->field_count());
512 for (size_t i = 0; i < expected_submitted_field_types_.size(); ++i) { 512 for (size_t i = 0; i < expected_submitted_field_types_.size(); ++i) {
513 SCOPED_TRACE( 513 SCOPED_TRACE(
514 base::StringPrintf( 514 base::StringPrintf(
515 "Field %d with value %s", static_cast<int>(i), 515 "Field %d with value %s", static_cast<int>(i),
516 UTF16ToUTF8(submitted_form->field(i)->value).c_str())); 516 UTF16ToUTF8(submitted_form->field(i)->value).c_str()));
517 const FieldTypeSet& possible_types = 517 const ServerFieldTypeSet& possible_types =
518 submitted_form->field(i)->possible_types(); 518 submitted_form->field(i)->possible_types();
519 EXPECT_EQ(expected_submitted_field_types_[i].size(), 519 EXPECT_EQ(expected_submitted_field_types_[i].size(),
520 possible_types.size()); 520 possible_types.size());
521 for (FieldTypeSet::const_iterator it = 521 for (ServerFieldTypeSet::const_iterator it =
522 expected_submitted_field_types_[i].begin(); 522 expected_submitted_field_types_[i].begin();
523 it != expected_submitted_field_types_[i].end(); ++it) { 523 it != expected_submitted_field_types_[i].end(); ++it) {
524 EXPECT_TRUE(possible_types.count(*it)) 524 EXPECT_TRUE(possible_types.count(*it))
525 << "Expected type: " << AutofillType::FieldTypeToString(*it); 525 << "Expected type: " << AutofillType::FieldTypeToString(*it);
526 } 526 }
527 } 527 }
528 } 528 }
529 529
530 AutofillManager::UploadFormDataAsyncCallback(submitted_form, 530 AutofillManager::UploadFormDataAsyncCallback(submitted_form,
531 load_time, 531 load_time,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 TestPersonalDataManager* personal_data_; 631 TestPersonalDataManager* personal_data_;
632 632
633 bool autofill_enabled_; 633 bool autofill_enabled_;
634 std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> > 634 std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >
635 request_autocomplete_results_; 635 request_autocomplete_results_;
636 636
637 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 637 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
638 638
639 std::string autocheckout_url_prefix_; 639 std::string autocheckout_url_prefix_;
640 std::string submitted_form_signature_; 640 std::string submitted_form_signature_;
641 std::vector<FieldTypeSet> expected_submitted_field_types_; 641 std::vector<ServerFieldTypeSet> expected_submitted_field_types_;
642 642
643 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); 643 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
644 }; 644 };
645 645
646 class TestAutofillExternalDelegate : public AutofillExternalDelegate { 646 class TestAutofillExternalDelegate : public AutofillExternalDelegate {
647 public: 647 public:
648 explicit TestAutofillExternalDelegate(content::WebContents* web_contents, 648 explicit TestAutofillExternalDelegate(content::WebContents* web_contents,
649 AutofillManager* autofill_manager, 649 AutofillManager* autofill_manager,
650 AutofillDriver* autofill_driver) 650 AutofillDriver* autofill_driver)
651 : AutofillExternalDelegate(web_contents, autofill_manager, 651 : AutofillExternalDelegate(web_contents, autofill_manager,
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 // profile from which the off the record profile is derived. 857 // profile from which the off the record profile is derived.
858 scoped_ptr<Profile> other_browser_context_; 858 scoped_ptr<Profile> other_browser_context_;
859 }; 859 };
860 860
861 class TestFormStructure : public FormStructure { 861 class TestFormStructure : public FormStructure {
862 public: 862 public:
863 explicit TestFormStructure(const FormData& form) 863 explicit TestFormStructure(const FormData& form)
864 : FormStructure(form, std::string()) {} 864 : FormStructure(form, std::string()) {}
865 virtual ~TestFormStructure() {} 865 virtual ~TestFormStructure() {}
866 866
867 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types, 867 void SetFieldTypes(const std::vector<ServerFieldType>& heuristic_types,
868 const std::vector<AutofillFieldType>& server_types) { 868 const std::vector<ServerFieldType>& server_types) {
869 ASSERT_EQ(field_count(), heuristic_types.size()); 869 ASSERT_EQ(field_count(), heuristic_types.size());
870 ASSERT_EQ(field_count(), server_types.size()); 870 ASSERT_EQ(field_count(), server_types.size());
871 871
872 for (size_t i = 0; i < field_count(); ++i) { 872 for (size_t i = 0; i < field_count(); ++i) {
873 AutofillField* form_field = field(i); 873 AutofillField* form_field = field(i);
874 ASSERT_TRUE(form_field); 874 ASSERT_TRUE(form_field);
875 form_field->set_heuristic_type(heuristic_types[i]); 875 form_field->set_heuristic_type(heuristic_types[i]);
876 form_field->set_server_type(server_types[i]); 876 form_field->set_server_type(server_types[i]);
877 } 877 }
878 878
(...skipping 1763 matching lines...) Expand 10 before | Expand all | Expand 10 after
2642 FormData form; 2642 FormData form;
2643 test::CreateTestAddressFormData(&form); 2643 test::CreateTestAddressFormData(&form);
2644 2644
2645 // Simulate having seen this form on page load. 2645 // Simulate having seen this form on page load.
2646 // |form_structure| will be owned by |autofill_manager_|. 2646 // |form_structure| will be owned by |autofill_manager_|.
2647 TestFormStructure* form_structure = new TestFormStructure(form); 2647 TestFormStructure* form_structure = new TestFormStructure(form);
2648 AutofillMetrics metrics_logger; // ignored 2648 AutofillMetrics metrics_logger; // ignored
2649 form_structure->DetermineHeuristicTypes(metrics_logger); 2649 form_structure->DetermineHeuristicTypes(metrics_logger);
2650 2650
2651 // Clear the heuristic types, and instead set the appropriate server types. 2651 // Clear the heuristic types, and instead set the appropriate server types.
2652 std::vector<AutofillFieldType> heuristic_types, server_types; 2652 std::vector<ServerFieldType> heuristic_types, server_types;
2653 for (size_t i = 0; i < form.fields.size(); ++i) { 2653 for (size_t i = 0; i < form.fields.size(); ++i) {
2654 heuristic_types.push_back(UNKNOWN_TYPE); 2654 heuristic_types.push_back(UNKNOWN_TYPE);
2655 server_types.push_back(form_structure->field(i)->type()); 2655 server_types.push_back(form_structure->field(i)->Type().server_type());
2656 } 2656 }
2657 form_structure->SetFieldTypes(heuristic_types, server_types); 2657 form_structure->SetFieldTypes(heuristic_types, server_types);
2658 autofill_manager_->AddSeenForm(form_structure); 2658 autofill_manager_->AddSeenForm(form_structure);
2659 2659
2660 // Fill the form. 2660 // Fill the form.
2661 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); 2661 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0);
2662 GUIDPair empty(std::string(), 0); 2662 GUIDPair empty(std::string(), 0);
2663 int response_page_id = 0; 2663 int response_page_id = 0;
2664 FormData response_data; 2664 FormData response_data;
2665 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], 2665 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0],
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
2763 } 2763 }
2764 2764
2765 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) { 2765 TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) {
2766 FormData form; 2766 FormData form;
2767 form.name = ASCIIToUTF16("MyForm"); 2767 form.name = ASCIIToUTF16("MyForm");
2768 form.method = ASCIIToUTF16("POST"); 2768 form.method = ASCIIToUTF16("POST");
2769 form.origin = GURL("http://myform.com/form.html"); 2769 form.origin = GURL("http://myform.com/form.html");
2770 form.action = GURL("http://myform.com/submit.html"); 2770 form.action = GURL("http://myform.com/submit.html");
2771 form.user_submitted = true; 2771 form.user_submitted = true;
2772 2772
2773 std::vector<FieldTypeSet> expected_types; 2773 std::vector<ServerFieldTypeSet> expected_types;
2774 2774
2775 // These fields should all match. 2775 // These fields should all match.
2776 FormFieldData field; 2776 FormFieldData field;
2777 FieldTypeSet types; 2777 ServerFieldTypeSet types;
2778 test::CreateTestFormField("", "1", "Elvis", "text", &field); 2778 test::CreateTestFormField("", "1", "Elvis", "text", &field);
2779 types.clear(); 2779 types.clear();
2780 types.insert(NAME_FIRST); 2780 types.insert(NAME_FIRST);
2781 form.fields.push_back(field); 2781 form.fields.push_back(field);
2782 expected_types.push_back(types); 2782 expected_types.push_back(types);
2783 2783
2784 test::CreateTestFormField("", "2", "Aaron", "text", &field); 2784 test::CreateTestFormField("", "2", "Aaron", "text", &field);
2785 types.clear(); 2785 types.clear();
2786 types.insert(NAME_MIDDLE); 2786 types.insert(NAME_MIDDLE);
2787 form.fields.push_back(field); 2787 form.fields.push_back(field);
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
3156 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); 3156 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow();
3157 3157
3158 FormData form; 3158 FormData form;
3159 test::CreateTestAddressFormData(&form); 3159 test::CreateTestAddressFormData(&form);
3160 3160
3161 TestFormStructure* form_structure = new TestFormStructure(form); 3161 TestFormStructure* form_structure = new TestFormStructure(form);
3162 AutofillMetrics metrics_logger; // ignored 3162 AutofillMetrics metrics_logger; // ignored
3163 form_structure->DetermineHeuristicTypes(metrics_logger); 3163 form_structure->DetermineHeuristicTypes(metrics_logger);
3164 3164
3165 // Build and add form structure with server data. 3165 // Build and add form structure with server data.
3166 std::vector<AutofillFieldType> heuristic_types, server_types; 3166 std::vector<ServerFieldType> heuristic_types, server_types;
3167 for (size_t i = 0; i < form.fields.size(); ++i) { 3167 for (size_t i = 0; i < form.fields.size(); ++i) {
3168 heuristic_types.push_back(UNKNOWN_TYPE); 3168 heuristic_types.push_back(UNKNOWN_TYPE);
3169 server_types.push_back(form_structure->field(i)->type()); 3169 server_types.push_back(form_structure->field(i)->Type().server_type());
3170 } 3170 }
3171 form_structure->SetFieldTypes(heuristic_types, server_types); 3171 form_structure->SetFieldTypes(heuristic_types, server_types);
3172 autofill_manager_->AddSeenForm(form_structure); 3172 autofill_manager_->AddSeenForm(form_structure);
3173 3173
3174 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); 3174 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF());
3175 3175
3176 EXPECT_TRUE(delegate.autocheckout_bubble_shown()); 3176 EXPECT_TRUE(delegate.autocheckout_bubble_shown());
3177 } 3177 }
3178 3178
3179 // Test that Autocheckout bubble is not offered when server doesn't have data 3179 // Test that Autocheckout bubble is not offered when server doesn't have data
3180 // for the form. 3180 // for the form.
3181 TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) { 3181 TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) {
3182 MockAutofillManagerDelegate delegate; 3182 MockAutofillManagerDelegate delegate;
3183 autofill_manager_.reset(new TestAutofillManager( 3183 autofill_manager_.reset(new TestAutofillManager(
3184 autofill_driver_.get(), &delegate, &personal_data_)); 3184 autofill_driver_.get(), &delegate, &personal_data_));
3185 autofill_manager_->set_autofill_enabled(true); 3185 autofill_manager_->set_autofill_enabled(true);
3186 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); 3186 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow();
3187 3187
3188 FormData form; 3188 FormData form;
3189 test::CreateTestAddressFormData(&form); 3189 test::CreateTestAddressFormData(&form);
3190 3190
3191 TestFormStructure* form_structure = new TestFormStructure(form); 3191 TestFormStructure* form_structure = new TestFormStructure(form);
3192 AutofillMetrics metrics_logger; // ignored 3192 AutofillMetrics metrics_logger; // ignored
3193 form_structure->DetermineHeuristicTypes(metrics_logger); 3193 form_structure->DetermineHeuristicTypes(metrics_logger);
3194 3194
3195 // Build form structure without server data. 3195 // Build form structure without server data.
3196 std::vector<AutofillFieldType> heuristic_types, server_types; 3196 std::vector<ServerFieldType> heuristic_types, server_types;
3197 for (size_t i = 0; i < form.fields.size(); ++i) { 3197 for (size_t i = 0; i < form.fields.size(); ++i) {
3198 heuristic_types.push_back(form_structure->field(i)->type()); 3198 heuristic_types.push_back(form_structure->field(i)->Type().server_type());
3199 server_types.push_back(NO_SERVER_DATA); 3199 server_types.push_back(NO_SERVER_DATA);
3200 } 3200 }
3201 form_structure->SetFieldTypes(heuristic_types, server_types); 3201 form_structure->SetFieldTypes(heuristic_types, server_types);
3202 autofill_manager_->AddSeenForm(form_structure); 3202 autofill_manager_->AddSeenForm(form_structure);
3203 3203
3204 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); 3204 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF());
3205 3205
3206 EXPECT_FALSE(delegate.autocheckout_bubble_shown()); 3206 EXPECT_FALSE(delegate.autocheckout_bubble_shown());
3207 } 3207 }
3208 3208
(...skipping 21 matching lines...) Expand all
3230 FormData address; 3230 FormData address;
3231 test::CreateTestAddressFormData(&address); 3231 test::CreateTestAddressFormData(&address);
3232 3232
3233 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); 3233 autofill_manager_->set_autocheckout_url_prefix("test-prefix");
3234 // Push address only 3234 // Push address only
3235 std::vector<FormData> forms; 3235 std::vector<FormData> forms;
3236 forms.push_back(address); 3236 forms.push_back(address);
3237 3237
3238 // Build and add form structure with server data. 3238 // Build and add form structure with server data.
3239 scoped_ptr<TestFormStructure> form_structure(new TestFormStructure(address)); 3239 scoped_ptr<TestFormStructure> form_structure(new TestFormStructure(address));
3240 std::vector<AutofillFieldType> heuristic_types, server_types; 3240 std::vector<ServerFieldType> heuristic_types, server_types;
3241 for (size_t i = 0; i < address.fields.size(); ++i) { 3241 for (size_t i = 0; i < address.fields.size(); ++i) {
3242 heuristic_types.push_back(UNKNOWN_TYPE); 3242 heuristic_types.push_back(UNKNOWN_TYPE);
3243 server_types.push_back(form_structure->field(i)->type()); 3243 server_types.push_back(form_structure->field(i)->Type().server_type());
3244 } 3244 }
3245 form_structure->SetFieldTypes(heuristic_types, server_types); 3245 form_structure->SetFieldTypes(heuristic_types, server_types);
3246 autofill_manager_->AddSeenForm(form_structure.release()); 3246 autofill_manager_->AddSeenForm(form_structure.release());
3247 3247
3248 // Make sure normal form is handled correctly. 3248 // Make sure normal form is handled correctly.
3249 autofill_manager_->MarkAsFirstPageInAutocheckoutFlowIgnoringAjax(); 3249 autofill_manager_->MarkAsFirstPageInAutocheckoutFlowIgnoringAjax();
3250 std::vector<FormStructure*> form_structures; 3250 std::vector<FormStructure*> form_structures;
3251 form_structures = autofill_manager_->GetFormStructures(); 3251 form_structures = autofill_manager_->GetFormStructures();
3252 ASSERT_EQ(1U, form_structures.size()); 3252 ASSERT_EQ(1U, form_structures.size());
3253 EXPECT_EQ("/form.html", form_structures[0]->source_url().path()); 3253 EXPECT_EQ("/form.html", form_structures[0]->source_url().path());
3254 3254
3255 scoped_ptr<FormStructure> filled_form(new TestFormStructure(address)); 3255 scoped_ptr<FormStructure> filled_form(new TestFormStructure(address));
3256 delegate.SetUserSuppliedData(filled_form.Pass()); 3256 delegate.SetUserSuppliedData(filled_form.Pass());
3257 autofill_manager_->OnMaybeShowAutocheckoutBubble(address, gfx::RectF()); 3257 autofill_manager_->OnMaybeShowAutocheckoutBubble(address, gfx::RectF());
3258 3258
3259 // Push other forms 3259 // Push other forms
3260 forms.push_back(shipping_options); 3260 forms.push_back(shipping_options);
3261 forms.push_back(user_supplied); 3261 forms.push_back(user_supplied);
3262 3262
3263 // FormStructure should contain the same forms as before. 3263 // FormStructure should contain the same forms as before.
3264 DynamicFormsSeen(forms); 3264 DynamicFormsSeen(forms);
3265 form_structures = autofill_manager_->GetFormStructures(); 3265 form_structures = autofill_manager_->GetFormStructures();
3266 ASSERT_EQ(1U, form_structures.size()); 3266 ASSERT_EQ(1U, form_structures.size());
3267 EXPECT_EQ("/form.html", form_structures[0]->source_url().path()); 3267 EXPECT_EQ("/form.html", form_structures[0]->source_url().path());
3268 } 3268 }
3269 3269
3270 } // namespace autofill 3270 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | components/autofill/core/browser/autofill_merge_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698