| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/stringprintf.h" | 5 #include "base/stringprintf.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/autofill/autofill_profile.h" | 7 #include "chrome/browser/autofill/autofill_profile.h" |
| 8 #include "chrome/browser/autofill/autofill_type.h" | 8 #include "chrome/browser/autofill/autofill_type.h" |
| 9 #include "chrome/browser/autofill/credit_card.h" | 9 #include "chrome/browser/autofill/credit_card.h" |
| 10 #include "chrome/browser/autofill/select_control_handler.h" | 10 #include "chrome/browser/autofill/select_control_handler.h" |
| 11 #include "chrome/test/testing_browser_process_test.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "webkit/glue/form_field.h" | 13 #include "webkit/glue/form_field.h" |
| 13 | 14 |
| 14 TEST(SelectControlHandlerTest, CreditCardMonthExact) { | 15 typedef TestingBrowserProcessTest SelectControlHandlerTest; |
| 16 |
| 17 TEST_F(SelectControlHandlerTest, CreditCardMonthExact) { |
| 15 const char* const kMonthsNumeric[] = { | 18 const char* const kMonthsNumeric[] = { |
| 16 "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", | 19 "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", |
| 17 }; | 20 }; |
| 18 std::vector<string16> options(arraysize(kMonthsNumeric)); | 21 std::vector<string16> options(arraysize(kMonthsNumeric)); |
| 19 for (size_t i = 0; i < arraysize(kMonthsNumeric); ++i) | 22 for (size_t i = 0; i < arraysize(kMonthsNumeric); ++i) |
| 20 options[i] = ASCIIToUTF16(kMonthsNumeric[i]); | 23 options[i] = ASCIIToUTF16(kMonthsNumeric[i]); |
| 21 | 24 |
| 22 webkit_glue::FormField field; | 25 webkit_glue::FormField field; |
| 23 field.form_control_type = ASCIIToUTF16("select-one"); | 26 field.form_control_type = ASCIIToUTF16("select-one"); |
| 24 field.option_values = options; | 27 field.option_values = options; |
| 25 field.option_contents = options; | 28 field.option_contents = options; |
| 26 | 29 |
| 27 CreditCard credit_card; | 30 CreditCard credit_card; |
| 28 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); | 31 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
| 29 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); | 32 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); |
| 30 EXPECT_EQ(ASCIIToUTF16("01"), field.value); | 33 EXPECT_EQ(ASCIIToUTF16("01"), field.value); |
| 31 } | 34 } |
| 32 | 35 |
| 33 TEST(SelectControlHandlerTest, CreditCardMonthAbbreviated) { | 36 TEST_F(SelectControlHandlerTest, CreditCardMonthAbbreviated) { |
| 34 const char* const kMonthsAbbreviated[] = { | 37 const char* const kMonthsAbbreviated[] = { |
| 35 "Jan", "Feb", "Mar", "Apr", "May", "Jun", | 38 "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 36 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", | 39 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", |
| 37 }; | 40 }; |
| 38 std::vector<string16> options(arraysize(kMonthsAbbreviated)); | 41 std::vector<string16> options(arraysize(kMonthsAbbreviated)); |
| 39 for (size_t i = 0; i < arraysize(kMonthsAbbreviated); ++i) | 42 for (size_t i = 0; i < arraysize(kMonthsAbbreviated); ++i) |
| 40 options[i] = ASCIIToUTF16(kMonthsAbbreviated[i]); | 43 options[i] = ASCIIToUTF16(kMonthsAbbreviated[i]); |
| 41 | 44 |
| 42 webkit_glue::FormField field; | 45 webkit_glue::FormField field; |
| 43 field.form_control_type = ASCIIToUTF16("select-one"); | 46 field.form_control_type = ASCIIToUTF16("select-one"); |
| 44 field.option_values = options; | 47 field.option_values = options; |
| 45 field.option_contents = options; | 48 field.option_contents = options; |
| 46 | 49 |
| 47 CreditCard credit_card; | 50 CreditCard credit_card; |
| 48 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); | 51 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
| 49 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); | 52 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); |
| 50 EXPECT_EQ(ASCIIToUTF16("Jan"), field.value); | 53 EXPECT_EQ(ASCIIToUTF16("Jan"), field.value); |
| 51 } | 54 } |
| 52 | 55 |
| 53 TEST(SelectControlHandlerTest, CreditCardMonthFull) { | 56 TEST_F(SelectControlHandlerTest, CreditCardMonthFull) { |
| 54 const char* const kMonthsFull[] = { | 57 const char* const kMonthsFull[] = { |
| 55 "January", "February", "March", "April", "May", "June", | 58 "January", "February", "March", "April", "May", "June", |
| 56 "July", "August", "September", "October", "November", "December", | 59 "July", "August", "September", "October", "November", "December", |
| 57 }; | 60 }; |
| 58 std::vector<string16> options(arraysize(kMonthsFull)); | 61 std::vector<string16> options(arraysize(kMonthsFull)); |
| 59 for (size_t i = 0; i < arraysize(kMonthsFull); ++i) | 62 for (size_t i = 0; i < arraysize(kMonthsFull); ++i) |
| 60 options[i] = ASCIIToUTF16(kMonthsFull[i]); | 63 options[i] = ASCIIToUTF16(kMonthsFull[i]); |
| 61 | 64 |
| 62 webkit_glue::FormField field; | 65 webkit_glue::FormField field; |
| 63 field.form_control_type = ASCIIToUTF16("select-one"); | 66 field.form_control_type = ASCIIToUTF16("select-one"); |
| 64 field.option_values = options; | 67 field.option_values = options; |
| 65 field.option_contents = options; | 68 field.option_contents = options; |
| 66 | 69 |
| 67 CreditCard credit_card; | 70 CreditCard credit_card; |
| 68 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); | 71 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
| 69 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); | 72 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); |
| 70 EXPECT_EQ(ASCIIToUTF16("January"), field.value); | 73 EXPECT_EQ(ASCIIToUTF16("January"), field.value); |
| 71 } | 74 } |
| 72 | 75 |
| 73 TEST(SelectControlHandlerTest, CreditCardMonthNumeric) { | 76 TEST_F(SelectControlHandlerTest, CreditCardMonthNumeric) { |
| 74 const char* const kMonthsNumeric[] = { | 77 const char* const kMonthsNumeric[] = { |
| 75 "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", | 78 "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", |
| 76 }; | 79 }; |
| 77 std::vector<string16> options(arraysize(kMonthsNumeric)); | 80 std::vector<string16> options(arraysize(kMonthsNumeric)); |
| 78 for (size_t i = 0; i < arraysize(kMonthsNumeric); ++i) | 81 for (size_t i = 0; i < arraysize(kMonthsNumeric); ++i) |
| 79 options[i] = ASCIIToUTF16(kMonthsNumeric[i]); | 82 options[i] = ASCIIToUTF16(kMonthsNumeric[i]); |
| 80 | 83 |
| 81 webkit_glue::FormField field; | 84 webkit_glue::FormField field; |
| 82 field.form_control_type = ASCIIToUTF16("select-one"); | 85 field.form_control_type = ASCIIToUTF16("select-one"); |
| 83 field.option_values = options; | 86 field.option_values = options; |
| 84 field.option_contents = options; | 87 field.option_contents = options; |
| 85 | 88 |
| 86 CreditCard credit_card; | 89 CreditCard credit_card; |
| 87 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); | 90 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
| 88 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); | 91 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); |
| 89 EXPECT_EQ(ASCIIToUTF16("1"), field.value); | 92 EXPECT_EQ(ASCIIToUTF16("1"), field.value); |
| 90 } | 93 } |
| 91 | 94 |
| 92 TEST(SelectControlHandlerTest, AddressCountryFull) { | 95 TEST_F(SelectControlHandlerTest, AddressCountryFull) { |
| 93 const char* const kCountries[] = { | 96 const char* const kCountries[] = { |
| 94 "Albania", "Canada" | 97 "Albania", "Canada" |
| 95 }; | 98 }; |
| 96 std::vector<string16> options(arraysize(kCountries)); | 99 std::vector<string16> options(arraysize(kCountries)); |
| 97 for (size_t i = 0; i < arraysize(kCountries); ++i) | 100 for (size_t i = 0; i < arraysize(kCountries); ++i) |
| 98 options[i] = ASCIIToUTF16(kCountries[i]); | 101 options[i] = ASCIIToUTF16(kCountries[i]); |
| 99 | 102 |
| 100 webkit_glue::FormField field; | 103 webkit_glue::FormField field; |
| 101 field.form_control_type = ASCIIToUTF16("select-one"); | 104 field.form_control_type = ASCIIToUTF16("select-one"); |
| 102 field.option_values = options; | 105 field.option_values = options; |
| 103 field.option_contents = options; | 106 field.option_contents = options; |
| 104 | 107 |
| 105 AutofillProfile profile; | 108 AutofillProfile profile; |
| 106 profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); | 109 profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); |
| 107 autofill::FillSelectControl(profile, ADDRESS_HOME_COUNTRY, &field); | 110 autofill::FillSelectControl(profile, ADDRESS_HOME_COUNTRY, &field); |
| 108 EXPECT_EQ(ASCIIToUTF16("Canada"), field.value); | 111 EXPECT_EQ(ASCIIToUTF16("Canada"), field.value); |
| 109 } | 112 } |
| 110 | 113 |
| 111 TEST(SelectControlHandlerTest, AddressCountryAbbrev) { | 114 TEST_F(SelectControlHandlerTest, AddressCountryAbbrev) { |
| 112 const char* const kCountries[] = { | 115 const char* const kCountries[] = { |
| 113 "AL", "CA" | 116 "AL", "CA" |
| 114 }; | 117 }; |
| 115 std::vector<string16> options(arraysize(kCountries)); | 118 std::vector<string16> options(arraysize(kCountries)); |
| 116 for (size_t i = 0; i < arraysize(kCountries); ++i) | 119 for (size_t i = 0; i < arraysize(kCountries); ++i) |
| 117 options[i] = ASCIIToUTF16(kCountries[i]); | 120 options[i] = ASCIIToUTF16(kCountries[i]); |
| 118 | 121 |
| 119 webkit_glue::FormField field; | 122 webkit_glue::FormField field; |
| 120 field.form_control_type = ASCIIToUTF16("select-one"); | 123 field.form_control_type = ASCIIToUTF16("select-one"); |
| 121 field.option_values = options; | 124 field.option_values = options; |
| 122 field.option_contents = options; | 125 field.option_contents = options; |
| 123 | 126 |
| 124 AutofillProfile profile; | 127 AutofillProfile profile; |
| 125 profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Canada")); | 128 profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Canada")); |
| 126 autofill::FillSelectControl(profile, ADDRESS_HOME_COUNTRY, &field); | 129 autofill::FillSelectControl(profile, ADDRESS_HOME_COUNTRY, &field); |
| 127 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); | 130 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); |
| 128 } | 131 } |
| 129 | 132 |
| 130 TEST(SelectControlHandlerTest, AddressStateFull) { | 133 TEST_F(SelectControlHandlerTest, AddressStateFull) { |
| 131 const char* const kStates[] = { | 134 const char* const kStates[] = { |
| 132 "Alabama", "California" | 135 "Alabama", "California" |
| 133 }; | 136 }; |
| 134 std::vector<string16> options(arraysize(kStates)); | 137 std::vector<string16> options(arraysize(kStates)); |
| 135 for (size_t i = 0; i < arraysize(kStates); ++i) | 138 for (size_t i = 0; i < arraysize(kStates); ++i) |
| 136 options[i] = ASCIIToUTF16(kStates[i]); | 139 options[i] = ASCIIToUTF16(kStates[i]); |
| 137 | 140 |
| 138 webkit_glue::FormField field; | 141 webkit_glue::FormField field; |
| 139 field.form_control_type = ASCIIToUTF16("select-one"); | 142 field.form_control_type = ASCIIToUTF16("select-one"); |
| 140 field.option_values = options; | 143 field.option_values = options; |
| 141 field.option_contents = options; | 144 field.option_contents = options; |
| 142 | 145 |
| 143 AutofillProfile profile; | 146 AutofillProfile profile; |
| 144 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); | 147 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); |
| 145 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); | 148 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); |
| 146 EXPECT_EQ(ASCIIToUTF16("California"), field.value); | 149 EXPECT_EQ(ASCIIToUTF16("California"), field.value); |
| 147 } | 150 } |
| 148 | 151 |
| 149 TEST(SelectControlHandlerTest, AddressStateAbbrev) { | 152 TEST_F(SelectControlHandlerTest, AddressStateAbbrev) { |
| 150 const char* const kStates[] = { | 153 const char* const kStates[] = { |
| 151 "AL", "CA" | 154 "AL", "CA" |
| 152 }; | 155 }; |
| 153 std::vector<string16> options(arraysize(kStates)); | 156 std::vector<string16> options(arraysize(kStates)); |
| 154 for (size_t i = 0; i < arraysize(kStates); ++i) | 157 for (size_t i = 0; i < arraysize(kStates); ++i) |
| 155 options[i] = ASCIIToUTF16(kStates[i]); | 158 options[i] = ASCIIToUTF16(kStates[i]); |
| 156 | 159 |
| 157 webkit_glue::FormField field; | 160 webkit_glue::FormField field; |
| 158 field.form_control_type = ASCIIToUTF16("select-one"); | 161 field.form_control_type = ASCIIToUTF16("select-one"); |
| 159 field.option_values = options; | 162 field.option_values = options; |
| 160 field.option_contents = options; | 163 field.option_contents = options; |
| 161 | 164 |
| 162 AutofillProfile profile; | 165 AutofillProfile profile; |
| 163 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); | 166 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); |
| 164 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); | 167 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); |
| 165 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); | 168 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); |
| 166 } | 169 } |
| 167 | 170 |
| 168 TEST(SelectControlHandlerTest, FillByValue) { | 171 TEST_F(SelectControlHandlerTest, FillByValue) { |
| 169 const char* const kStates[] = { | 172 const char* const kStates[] = { |
| 170 "Alabama", "California" | 173 "Alabama", "California" |
| 171 }; | 174 }; |
| 172 std::vector<string16> values(arraysize(kStates)); | 175 std::vector<string16> values(arraysize(kStates)); |
| 173 std::vector<string16> contents(arraysize(kStates)); | 176 std::vector<string16> contents(arraysize(kStates)); |
| 174 for (size_t i = 0; i < arraysize(kStates); ++i) { | 177 for (size_t i = 0; i < arraysize(kStates); ++i) { |
| 175 values[i] = ASCIIToUTF16(kStates[i]); | 178 values[i] = ASCIIToUTF16(kStates[i]); |
| 176 contents[i] = ASCIIToUTF16(base::StringPrintf("%d", static_cast<int>(i))); | 179 contents[i] = ASCIIToUTF16(base::StringPrintf("%d", static_cast<int>(i))); |
| 177 } | 180 } |
| 178 | 181 |
| 179 webkit_glue::FormField field; | 182 webkit_glue::FormField field; |
| 180 field.form_control_type = ASCIIToUTF16("select-one"); | 183 field.form_control_type = ASCIIToUTF16("select-one"); |
| 181 field.option_values = values; | 184 field.option_values = values; |
| 182 field.option_contents = contents; | 185 field.option_contents = contents; |
| 183 | 186 |
| 184 AutofillProfile profile; | 187 AutofillProfile profile; |
| 185 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); | 188 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); |
| 186 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); | 189 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); |
| 187 EXPECT_EQ(ASCIIToUTF16("California"), field.value); | 190 EXPECT_EQ(ASCIIToUTF16("California"), field.value); |
| 188 } | 191 } |
| 189 | 192 |
| 190 TEST(SelectControlHandlerTest, FillByContents) { | 193 TEST_F(SelectControlHandlerTest, FillByContents) { |
| 191 const char* const kStates[] = { | 194 const char* const kStates[] = { |
| 192 "Alabama", "California" | 195 "Alabama", "California" |
| 193 }; | 196 }; |
| 194 std::vector<string16> values(arraysize(kStates)); | 197 std::vector<string16> values(arraysize(kStates)); |
| 195 std::vector<string16> contents(arraysize(kStates)); | 198 std::vector<string16> contents(arraysize(kStates)); |
| 196 for (size_t i = 0; i < arraysize(kStates); ++i) { | 199 for (size_t i = 0; i < arraysize(kStates); ++i) { |
| 197 values[i] = ASCIIToUTF16(base::StringPrintf("%d", static_cast<int>(i + 1))); | 200 values[i] = ASCIIToUTF16(base::StringPrintf("%d", static_cast<int>(i + 1))); |
| 198 contents[i] = ASCIIToUTF16(kStates[i]); | 201 contents[i] = ASCIIToUTF16(kStates[i]); |
| 199 } | 202 } |
| 200 | 203 |
| 201 webkit_glue::FormField field; | 204 webkit_glue::FormField field; |
| 202 field.form_control_type = ASCIIToUTF16("select-one"); | 205 field.form_control_type = ASCIIToUTF16("select-one"); |
| 203 field.option_values = values; | 206 field.option_values = values; |
| 204 field.option_contents = contents; | 207 field.option_contents = contents; |
| 205 | 208 |
| 206 AutofillProfile profile; | 209 AutofillProfile profile; |
| 207 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); | 210 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); |
| 208 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); | 211 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); |
| 209 EXPECT_EQ(ASCIIToUTF16("2"), field.value); | 212 EXPECT_EQ(ASCIIToUTF16("2"), field.value); |
| 210 } | 213 } |
| OLD | NEW |