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

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

Issue 22040002: [Autofill] Add a separate enumeration for HTML field type hints. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix browser test 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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ServerFieldTypeSet& 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 (ServerFieldTypeSet::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(*it).ToString();
526 } 526 }
527 } 527 }
528 } 528 }
529 529
530 AutofillManager::UploadFormDataAsyncCallback(submitted_form, 530 AutofillManager::UploadFormDataAsyncCallback(submitted_form,
531 load_time, 531 load_time,
532 interaction_time, 532 interaction_time,
533 submission_time); 533 submission_time);
534 } 534 }
535 535
(...skipping 2109 matching lines...) Expand 10 before | Expand all | Expand 10 after
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<ServerFieldType> 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().server_type()); 2655 server_types.push_back(form_structure->field(i)->heuristic_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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
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<ServerFieldType> 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().server_type()); 3169 server_types.push_back(form_structure->field(i)->heuristic_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<ServerFieldType> 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().server_type()); 3198 heuristic_types.push_back(form_structure->field(i)->heuristic_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 24 matching lines...) Expand all
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<ServerFieldType> 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().server_type()); 3243 server_types.push_back(form_structure->field(i)->heuristic_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