| OLD | NEW | 
|---|
| 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" | 
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" | 
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" | 
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" | 
| 14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" | 
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" | 
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" | 
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" | 
|  | 18 #include "base/strings/string_util.h" | 
| 18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" | 
| 19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" | 
| 20 #include "base/time/time.h" | 21 #include "base/time/time.h" | 
| 21 #include "base/tuple.h" | 22 #include "base/tuple.h" | 
| 22 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 23 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 
| 23 #include "components/autofill/core/browser/autofill_manager.h" | 24 #include "components/autofill/core/browser/autofill_manager.h" | 
| 24 #include "components/autofill/core/browser/autofill_metrics.h" | 25 #include "components/autofill/core/browser/autofill_metrics.h" | 
| 25 #include "components/autofill/core/browser/autofill_profile.h" | 26 #include "components/autofill/core/browser/autofill_profile.h" | 
| 26 #include "components/autofill/core/browser/autofill_test_utils.h" | 27 #include "components/autofill/core/browser/autofill_test_utils.h" | 
| 27 #include "components/autofill/core/browser/credit_card.h" | 28 #include "components/autofill/core/browser/credit_card.h" | 
| (...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 891 // Test that we return only matching credit card profile suggestions when the | 892 // Test that we return only matching credit card profile suggestions when the | 
| 892 // selected form field has been partially filled out. | 893 // selected form field has been partially filled out. | 
| 893 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { | 894 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsMatchCharacter) { | 
| 894   // Set up our form data. | 895   // Set up our form data. | 
| 895   FormData form; | 896   FormData form; | 
| 896   CreateTestCreditCardFormData(&form, true, false); | 897   CreateTestCreditCardFormData(&form, true, false); | 
| 897   std::vector<FormData> forms(1, form); | 898   std::vector<FormData> forms(1, form); | 
| 898   FormsSeen(forms); | 899   FormsSeen(forms); | 
| 899 | 900 | 
| 900   FormFieldData field; | 901   FormFieldData field; | 
| 901   test::CreateTestFormField("Card Number", "cardnumber", "4", "text", &field); | 902   test::CreateTestFormField("Card Number", "cardnumber", "78", "text", &field); | 
| 902   GetAutofillSuggestions(form, field); | 903   GetAutofillSuggestions(form, field); | 
| 903 | 904 | 
| 904   // No suggestions provided, so send an empty vector as the results. | 905   // No suggestions provided, so send an empty vector as the results. | 
| 905   // This triggers the combined message send. | 906   // This triggers the combined message send. | 
| 906   AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 907   AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 
| 907 | 908 | 
| 908   // Test that we sent the right values to the external delegate. | 909   // Test that we sent the right values to the external delegate. | 
| 909   base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; | 910   base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; | 
| 910   base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; | 911   base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; | 
| 911   base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; | 912   base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; | 
| (...skipping 2069 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2981   FormData form; | 2982   FormData form; | 
| 2982   test::CreateTestAddressFormData(&form); | 2983   test::CreateTestAddressFormData(&form); | 
| 2983   std::vector<FormData> forms(1, form); | 2984   std::vector<FormData> forms(1, form); | 
| 2984   FormsSeen(forms); | 2985   FormsSeen(forms); | 
| 2985   const FormFieldData& field = form.fields[0]; | 2986   const FormFieldData& field = form.fields[0]; | 
| 2986   GetAutofillSuggestions(form, field);  // should call the delegate's OnQuery() | 2987   GetAutofillSuggestions(form, field);  // should call the delegate's OnQuery() | 
| 2987 | 2988 | 
| 2988   EXPECT_TRUE(external_delegate_->on_query_seen()); | 2989   EXPECT_TRUE(external_delegate_->on_query_seen()); | 
| 2989 } | 2990 } | 
| 2990 | 2991 | 
|  | 2992 // Test to verify suggestions appears for forms having credit card number split | 
|  | 2993 // across fields. | 
|  | 2994 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsForNumberSpitAcrossFields) { | 
|  | 2995   // Set up our form data with credit card number split across fields. | 
|  | 2996   FormData form; | 
|  | 2997   form.name = ASCIIToUTF16("MyForm"); | 
|  | 2998   form.origin = GURL("https://myform.com/form.html"); | 
|  | 2999   form.action = GURL("https://myform.com/submit.html"); | 
|  | 3000   form.user_submitted = true; | 
|  | 3001 | 
|  | 3002   FormFieldData name_field; | 
|  | 3003   test::CreateTestFormField("Name on Card", "nameoncard", "", "text", | 
|  | 3004                             &name_field); | 
|  | 3005   form.fields.push_back(name_field); | 
|  | 3006 | 
|  | 3007   // Add new 4 |card_number_field|s to the |form|. | 
|  | 3008   FormFieldData card_number_field; | 
|  | 3009   card_number_field.max_length = 4; | 
|  | 3010   test::CreateTestFormField("Card Number", "cardnumber_1", "", "text", | 
|  | 3011                             &card_number_field); | 
|  | 3012   form.fields.push_back(card_number_field); | 
|  | 3013 | 
|  | 3014   test::CreateTestFormField("", "cardnumber_2", "", "text", &card_number_field); | 
|  | 3015   form.fields.push_back(card_number_field); | 
|  | 3016 | 
|  | 3017   test::CreateTestFormField("", "cardnumber_3", "", "text", &card_number_field); | 
|  | 3018   form.fields.push_back(card_number_field); | 
|  | 3019 | 
|  | 3020   test::CreateTestFormField("", "cardnumber_4", "", "text", &card_number_field); | 
|  | 3021   form.fields.push_back(card_number_field); | 
|  | 3022 | 
|  | 3023   FormFieldData exp_field; | 
|  | 3024   test::CreateTestFormField("Expiration Date", "ccmonth", "", "text", | 
|  | 3025                             &exp_field); | 
|  | 3026   form.fields.push_back(exp_field); | 
|  | 3027 | 
|  | 3028   test::CreateTestFormField("", "ccyear", "", "text", &exp_field); | 
|  | 3029   form.fields.push_back(exp_field); | 
|  | 3030 | 
|  | 3031   std::vector<FormData> forms(1, form); | 
|  | 3032   FormsSeen(forms); | 
|  | 3033 | 
|  | 3034   // Verify whether suggestions are populated correctly for one of the middle | 
|  | 3035   // credit card number fields when filled partially. | 
|  | 3036   FormFieldData number_field = form.fields[3]; | 
|  | 3037   number_field.value = ASCIIToUTF16("901"); | 
|  | 3038 | 
|  | 3039   // Get the suggestions for already filled credit card |number_field|. | 
|  | 3040   GetAutofillSuggestions(form, number_field); | 
|  | 3041 | 
|  | 3042   // No autocomplete suggestions provided, so send an empty vector as the | 
|  | 3043   // results. This triggers the combined message send. | 
|  | 3044   AutocompleteSuggestionsReturned(std::vector<base::string16>()); | 
|  | 3045 | 
|  | 3046   base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; | 
|  | 3047   base::string16 expected_labels[] = {ASCIIToUTF16("04/12")}; | 
|  | 3048   base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; | 
|  | 3049   int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)}; | 
|  | 3050   external_delegate_->CheckSuggestions( | 
|  | 3051       kDefaultPageID, arraysize(expected_values), expected_values, | 
|  | 3052       expected_labels, expected_icons, expected_unique_ids); | 
|  | 3053 } | 
|  | 3054 | 
| 2991 }  // namespace autofill | 3055 }  // namespace autofill | 
| OLD | NEW | 
|---|