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

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

Issue 447903003: Autofill: improve GetCreditCardSuggestions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ah so there were tests after all Created 6 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
« no previous file with comments | « no previous file | components/autofill/core/browser/personal_data_manager.cc » ('j') | 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 847 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 858
859 // No suggestions provided, so send an empty vector as the results. 859 // No suggestions provided, so send an empty vector as the results.
860 // This triggers the combined message send. 860 // This triggers the combined message send.
861 AutocompleteSuggestionsReturned(std::vector<base::string16>()); 861 AutocompleteSuggestionsReturned(std::vector<base::string16>());
862 862
863 // Test that we sent the right values to the external delegate. 863 // Test that we sent the right values to the external delegate.
864 base::string16 expected_values[] = { 864 base::string16 expected_values[] = {
865 ASCIIToUTF16("************3456"), 865 ASCIIToUTF16("************3456"),
866 ASCIIToUTF16("************8765") 866 ASCIIToUTF16("************8765")
867 }; 867 };
868 base::string16 expected_labels[] = { ASCIIToUTF16("*3456"), 868 base::string16 expected_labels[] = { ASCIIToUTF16("04/12"),
869 ASCIIToUTF16("*8765")}; 869 ASCIIToUTF16("10/14")};
870 base::string16 expected_icons[] = { 870 base::string16 expected_icons[] = {
871 ASCIIToUTF16(kVisaCard), 871 ASCIIToUTF16(kVisaCard),
872 ASCIIToUTF16(kMasterCard) 872 ASCIIToUTF16(kMasterCard)
873 }; 873 };
874 int expected_unique_ids[] = { 874 int expected_unique_ids[] = {
875 autofill_manager_->GetPackedCreditCardID(4), 875 autofill_manager_->GetPackedCreditCardID(4),
876 autofill_manager_->GetPackedCreditCardID(5) 876 autofill_manager_->GetPackedCreditCardID(5)
877 }; 877 };
878 external_delegate_->CheckSuggestions( 878 external_delegate_->CheckSuggestions(
879 kDefaultPageID, arraysize(expected_values), expected_values, 879 kDefaultPageID, arraysize(expected_values), expected_values,
(...skipping 12 matching lines...) Expand all
892 FormFieldData field; 892 FormFieldData field;
893 test::CreateTestFormField("Card Number", "cardnumber", "4", "text", &field); 893 test::CreateTestFormField("Card Number", "cardnumber", "4", "text", &field);
894 GetAutofillSuggestions(form, field); 894 GetAutofillSuggestions(form, field);
895 895
896 // No suggestions provided, so send an empty vector as the results. 896 // No suggestions provided, so send an empty vector as the results.
897 // This triggers the combined message send. 897 // This triggers the combined message send.
898 AutocompleteSuggestionsReturned(std::vector<base::string16>()); 898 AutocompleteSuggestionsReturned(std::vector<base::string16>());
899 899
900 // Test that we sent the right values to the external delegate. 900 // Test that we sent the right values to the external delegate.
901 base::string16 expected_values[] = {ASCIIToUTF16("************3456")}; 901 base::string16 expected_values[] = {ASCIIToUTF16("************3456")};
902 base::string16 expected_labels[] = {ASCIIToUTF16("*3456")}; 902 base::string16 expected_labels[] = {ASCIIToUTF16("04/12")};
903 base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)}; 903 base::string16 expected_icons[] = {ASCIIToUTF16(kVisaCard)};
904 int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)}; 904 int expected_unique_ids[] = {autofill_manager_->GetPackedCreditCardID(4)};
905 external_delegate_->CheckSuggestions( 905 external_delegate_->CheckSuggestions(
906 kDefaultPageID, arraysize(expected_values), expected_values, 906 kDefaultPageID, arraysize(expected_values), expected_values,
907 expected_labels, expected_icons, expected_unique_ids); 907 expected_labels, expected_icons, expected_unique_ids);
908 } 908 }
909 909
910 // Test that we return credit card profile suggestions when the selected form 910 // Test that we return credit card profile suggestions when the selected form
911 // field is not the credit card number field. 911 // field is not the credit card number field.
912 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonCCNumber) { 912 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsNonCCNumber) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 } 1001 }
1002 1002
1003 // Test that we return all credit card suggestions in the case that two cards 1003 // Test that we return all credit card suggestions in the case that two cards
1004 // have the same obfuscated number. 1004 // have the same obfuscated number.
1005 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) { 1005 TEST_F(AutofillManagerTest, GetCreditCardSuggestionsRepeatedObfuscatedNumber) {
1006 // Add a credit card with the same obfuscated number as Elvis's. 1006 // Add a credit card with the same obfuscated number as Elvis's.
1007 // |credit_card| will be owned by the mock PersonalDataManager. 1007 // |credit_card| will be owned by the mock PersonalDataManager.
1008 CreditCard* credit_card = new CreditCard; 1008 CreditCard* credit_card = new CreditCard;
1009 test::SetCreditCardInfo(credit_card, "Elvis Presley", 1009 test::SetCreditCardInfo(credit_card, "Elvis Presley",
1010 "5231567890123456", // Mastercard 1010 "5231567890123456", // Mastercard
1011 "04", "2012"); 1011 "05", "2012");
1012 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); 1012 credit_card->set_guid("00000000-0000-0000-0000-000000000007");
1013 autofill_manager_->AddCreditCard(credit_card); 1013 autofill_manager_->AddCreditCard(credit_card);
1014 1014
1015 // Set up our form data. 1015 // Set up our form data.
1016 FormData form; 1016 FormData form;
1017 CreateTestCreditCardFormData(&form, true, false); 1017 CreateTestCreditCardFormData(&form, true, false);
1018 std::vector<FormData> forms(1, form); 1018 std::vector<FormData> forms(1, form);
1019 FormsSeen(forms); 1019 FormsSeen(forms);
1020 1020
1021 FormFieldData field = form.fields[1]; 1021 FormFieldData field = form.fields[1];
1022 GetAutofillSuggestions(form, field); 1022 GetAutofillSuggestions(form, field);
1023 1023
1024 // No suggestions provided, so send an empty vector as the results. 1024 // No suggestions provided, so send an empty vector as the results.
1025 // This triggers the combined message send. 1025 // This triggers the combined message send.
1026 AutocompleteSuggestionsReturned(std::vector<base::string16>()); 1026 AutocompleteSuggestionsReturned(std::vector<base::string16>());
1027 1027
1028 // Test that we sent the right values to the external delegate. 1028 // Test that we sent the right values to the external delegate.
1029 base::string16 expected_values[] = { 1029 base::string16 expected_values[] = {
1030 ASCIIToUTF16("************3456"), 1030 ASCIIToUTF16("************3456"),
1031 ASCIIToUTF16("************8765"), 1031 ASCIIToUTF16("************8765"),
1032 ASCIIToUTF16("************3456") 1032 ASCIIToUTF16("************3456")
1033 }; 1033 };
1034 base::string16 expected_labels[] = { 1034 base::string16 expected_labels[] = {
1035 ASCIIToUTF16("*3456"), 1035 ASCIIToUTF16("04/12"),
1036 ASCIIToUTF16("*8765"), 1036 ASCIIToUTF16("10/14"),
1037 ASCIIToUTF16("*3456"), 1037 ASCIIToUTF16("05/12"),
1038 }; 1038 };
1039 base::string16 expected_icons[] = { 1039 base::string16 expected_icons[] = {
1040 ASCIIToUTF16(kVisaCard), 1040 ASCIIToUTF16(kVisaCard),
1041 ASCIIToUTF16(kMasterCard), 1041 ASCIIToUTF16(kMasterCard),
1042 ASCIIToUTF16(kMasterCard) 1042 ASCIIToUTF16(kMasterCard)
1043 }; 1043 };
1044 int expected_unique_ids[] = { 1044 int expected_unique_ids[] = {
1045 autofill_manager_->GetPackedCreditCardID(4), 1045 autofill_manager_->GetPackedCreditCardID(4),
1046 autofill_manager_->GetPackedCreditCardID(5), 1046 autofill_manager_->GetPackedCreditCardID(5),
1047 autofill_manager_->GetPackedCreditCardID(7) 1047 autofill_manager_->GetPackedCreditCardID(7)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 1088
1089 // No suggestions provided, so send an empty vector as the results. 1089 // No suggestions provided, so send an empty vector as the results.
1090 // This triggers the combined message send. 1090 // This triggers the combined message send.
1091 AutocompleteSuggestionsReturned(std::vector<base::string16>()); 1091 AutocompleteSuggestionsReturned(std::vector<base::string16>());
1092 1092
1093 // Test that we sent the credit card suggestions to the external delegate. 1093 // Test that we sent the credit card suggestions to the external delegate.
1094 base::string16 expected_values2[] = { 1094 base::string16 expected_values2[] = {
1095 ASCIIToUTF16("************3456"), 1095 ASCIIToUTF16("************3456"),
1096 ASCIIToUTF16("************8765") 1096 ASCIIToUTF16("************8765")
1097 }; 1097 };
1098 base::string16 expected_labels2[] = { ASCIIToUTF16("*3456"), 1098 base::string16 expected_labels2[] = { ASCIIToUTF16("04/12"),
1099 ASCIIToUTF16("*8765")}; 1099 ASCIIToUTF16("10/14")};
1100 base::string16 expected_icons2[] = { 1100 base::string16 expected_icons2[] = {
1101 ASCIIToUTF16(kVisaCard), 1101 ASCIIToUTF16(kVisaCard),
1102 ASCIIToUTF16(kMasterCard) 1102 ASCIIToUTF16(kMasterCard)
1103 }; 1103 };
1104 int expected_unique_ids2[] = { 1104 int expected_unique_ids2[] = {
1105 autofill_manager_->GetPackedCreditCardID(4), 1105 autofill_manager_->GetPackedCreditCardID(4),
1106 autofill_manager_->GetPackedCreditCardID(5) 1106 autofill_manager_->GetPackedCreditCardID(5)
1107 }; 1107 };
1108 external_delegate_->CheckSuggestions( 1108 external_delegate_->CheckSuggestions(
1109 kPageID2, arraysize(expected_values2), expected_values2, 1109 kPageID2, arraysize(expected_values2), expected_values2,
(...skipping 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after
2817 test::CreateTestAddressFormData(&form); 2817 test::CreateTestAddressFormData(&form);
2818 std::vector<FormData> forms(1, form); 2818 std::vector<FormData> forms(1, form);
2819 FormsSeen(forms); 2819 FormsSeen(forms);
2820 const FormFieldData& field = form.fields[0]; 2820 const FormFieldData& field = form.fields[0];
2821 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() 2821 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
2822 2822
2823 EXPECT_TRUE(external_delegate_->on_query_seen()); 2823 EXPECT_TRUE(external_delegate_->on_query_seen());
2824 } 2824 }
2825 2825
2826 } // namespace autofill 2826 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/personal_data_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698