| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <vector> | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/scoped_ptr.h" | |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "chrome/browser/autofill/address.h" | |
| 11 #include "chrome/browser/autofill/billing_address.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 class BillingAddressTest : public testing::Test { | |
| 17 public: | |
| 18 BillingAddressTest() { | |
| 19 address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE1), | |
| 20 ASCIIToUTF16("123 Appian Way")); | |
| 21 address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE2), | |
| 22 ASCIIToUTF16("Unit 6")); | |
| 23 address_.SetInfo(AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("#6")); | |
| 24 address_.SetInfo(AutoFillType(ADDRESS_BILLING_CITY), ASCIIToUTF16("Paris")); | |
| 25 address_.SetInfo(AutoFillType(ADDRESS_BILLING_STATE), | |
| 26 ASCIIToUTF16("Texas")); | |
| 27 address_.SetInfo(AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("12345")); | |
| 28 address_.SetInfo(AutoFillType(ADDRESS_BILLING_COUNTRY), | |
| 29 ASCIIToUTF16("USA")); | |
| 30 } | |
| 31 | |
| 32 protected: | |
| 33 BillingAddress address_; | |
| 34 | |
| 35 DISALLOW_COPY_AND_ASSIGN(BillingAddressTest); | |
| 36 }; | |
| 37 | |
| 38 TEST_F(BillingAddressTest, GetPossibleFieldTypes) { | |
| 39 // Empty string. | |
| 40 FieldTypeSet possible_types; | |
| 41 address_.GetPossibleFieldTypes(string16(), &possible_types); | |
| 42 ASSERT_EQ(0U, possible_types.size()); | |
| 43 | |
| 44 // Only use split-chars for the address_. | |
| 45 possible_types.clear(); | |
| 46 address_.GetPossibleFieldTypes(ASCIIToUTF16("-,#. "), &possible_types); | |
| 47 ASSERT_EQ(0U, possible_types.size()); | |
| 48 | |
| 49 // ADDRESS_BILLING_LINE1 ===================================================== | |
| 50 | |
| 51 // Exact match. | |
| 52 possible_types.clear(); | |
| 53 address_.GetPossibleFieldTypes(ASCIIToUTF16("123 Appian Way"), | |
| 54 &possible_types); | |
| 55 ASSERT_EQ(1U, possible_types.size()); | |
| 56 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != | |
| 57 possible_types.end()); | |
| 58 | |
| 59 // Fields are mixed up. | |
| 60 possible_types.clear(); | |
| 61 address_.GetPossibleFieldTypes(ASCIIToUTF16("Way 123 Appian"), | |
| 62 &possible_types); | |
| 63 ASSERT_EQ(1U, possible_types.size()); | |
| 64 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != | |
| 65 possible_types.end()); | |
| 66 | |
| 67 // The match is case-insensitive. | |
| 68 possible_types.clear(); | |
| 69 address_.GetPossibleFieldTypes(ASCIIToUTF16("123 aPPiaN wAy"), | |
| 70 &possible_types); | |
| 71 ASSERT_EQ(1U, possible_types.size()); | |
| 72 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != | |
| 73 possible_types.end()); | |
| 74 | |
| 75 // Case-insensitive match with fields mixed up. The previous test doesn't | |
| 76 // do a good job of testing for case-insensitivity because the underlying | |
| 77 // algorithm stops search when it matches '123'. | |
| 78 possible_types.clear(); | |
| 79 address_.GetPossibleFieldTypes(ASCIIToUTF16("wAy aPpIAn"), &possible_types); | |
| 80 ASSERT_EQ(1U, possible_types.size()); | |
| 81 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != | |
| 82 possible_types.end()); | |
| 83 | |
| 84 // The text is not complete. | |
| 85 possible_types.clear(); | |
| 86 address_.GetPossibleFieldTypes(ASCIIToUTF16("123 Appian"), &possible_types); | |
| 87 ASSERT_EQ(1U, possible_types.size()); | |
| 88 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != | |
| 89 possible_types.end()); | |
| 90 | |
| 91 // Extra text on the line. | |
| 92 possible_types.clear(); | |
| 93 address_.GetPossibleFieldTypes(ASCIIToUTF16("123 Appian Way #6"), | |
| 94 &possible_types); | |
| 95 ASSERT_EQ(0U, possible_types.size()); | |
| 96 | |
| 97 // Extra text in the middle | |
| 98 possible_types.clear(); | |
| 99 address_.GetPossibleFieldTypes(ASCIIToUTF16("123 Middle Appian Way"), | |
| 100 &possible_types); | |
| 101 ASSERT_EQ(0U, possible_types.size()); | |
| 102 | |
| 103 // Whitespace doesn't matter. | |
| 104 possible_types.clear(); | |
| 105 address_.GetPossibleFieldTypes(ASCIIToUTF16(" 123 Appian Way "), | |
| 106 &possible_types); | |
| 107 ASSERT_EQ(1U, possible_types.size()); | |
| 108 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != | |
| 109 possible_types.end()); | |
| 110 | |
| 111 // Address split characters don't matter. | |
| 112 possible_types.clear(); | |
| 113 address_.GetPossibleFieldTypes(ASCIIToUTF16("-123, #Appian.Way"), | |
| 114 &possible_types); | |
| 115 ASSERT_EQ(1U, possible_types.size()); | |
| 116 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != | |
| 117 possible_types.end()); | |
| 118 | |
| 119 // ADDRESS_BILLING_LINE2 ===================================================== | |
| 120 | |
| 121 // Exact match. | |
| 122 possible_types.clear(); | |
| 123 address_.GetPossibleFieldTypes(ASCIIToUTF16("Unit 6"), &possible_types); | |
| 124 ASSERT_EQ(1U, possible_types.size()); | |
| 125 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != | |
| 126 possible_types.end()); | |
| 127 | |
| 128 // Fields are mixed up. | |
| 129 possible_types.clear(); | |
| 130 address_.GetPossibleFieldTypes(ASCIIToUTF16("6 Unit"), &possible_types); | |
| 131 ASSERT_EQ(1U, possible_types.size()); | |
| 132 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != | |
| 133 possible_types.end()); | |
| 134 | |
| 135 // The match is case-insensitive. | |
| 136 possible_types.clear(); | |
| 137 address_.GetPossibleFieldTypes(ASCIIToUTF16("uNiT 6"), &possible_types); | |
| 138 ASSERT_EQ(1U, possible_types.size()); | |
| 139 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != | |
| 140 possible_types.end()); | |
| 141 | |
| 142 // The text is not complete. | |
| 143 possible_types.clear(); | |
| 144 address_.GetPossibleFieldTypes(ASCIIToUTF16("Unit"), &possible_types); | |
| 145 ASSERT_EQ(1U, possible_types.size()); | |
| 146 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != | |
| 147 possible_types.end()); | |
| 148 | |
| 149 // Extra text on the line. | |
| 150 possible_types.clear(); | |
| 151 address_.GetPossibleFieldTypes(ASCIIToUTF16("Unit 6 Extra"), &possible_types); | |
| 152 ASSERT_EQ(0U, possible_types.size()); | |
| 153 | |
| 154 // Extra text in the middle | |
| 155 possible_types.clear(); | |
| 156 address_.GetPossibleFieldTypes(ASCIIToUTF16("Unit Middle 6"), | |
| 157 &possible_types); | |
| 158 ASSERT_EQ(0U, possible_types.size()); | |
| 159 | |
| 160 // Whitespace doesn't matter. | |
| 161 possible_types.clear(); | |
| 162 address_.GetPossibleFieldTypes(ASCIIToUTF16(" Unit 6 "), &possible_types); | |
| 163 ASSERT_EQ(1U, possible_types.size()); | |
| 164 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != | |
| 165 possible_types.end()); | |
| 166 | |
| 167 // Address split characters don't matter. | |
| 168 possible_types.clear(); | |
| 169 address_.GetPossibleFieldTypes(ASCIIToUTF16("-#Unit, .6"), | |
| 170 &possible_types); | |
| 171 ASSERT_EQ(1U, possible_types.size()); | |
| 172 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != | |
| 173 possible_types.end()); | |
| 174 | |
| 175 // ADDRESS_BILLING_APT_NUM =================================================== | |
| 176 | |
| 177 // Exact match. This matches the apartment number exactly, and also matches | |
| 178 // 'Unit 6' because of the 6 and the fact that '#' is an address separator, | |
| 179 // which is ignored in the search for an address line. | |
| 180 possible_types.clear(); | |
| 181 address_.GetPossibleFieldTypes(ASCIIToUTF16("#6"), &possible_types); | |
| 182 ASSERT_EQ(2U, possible_types.size()); | |
| 183 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_APT_NUM) != | |
| 184 possible_types.end()); | |
| 185 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != | |
| 186 possible_types.end()); | |
| 187 | |
| 188 // The match is case-insensitive. | |
| 189 possible_types.clear(); | |
| 190 address_.SetInfo(AutoFillType(ADDRESS_BILLING_APT_NUM), | |
| 191 ASCIIToUTF16("Num 10")); | |
| 192 address_.GetPossibleFieldTypes(ASCIIToUTF16("nuM 10"), &possible_types); | |
| 193 ASSERT_EQ(1U, possible_types.size()); | |
| 194 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_APT_NUM) != | |
| 195 possible_types.end()); | |
| 196 | |
| 197 // The text is not complete. | |
| 198 possible_types.clear(); | |
| 199 address_.GetPossibleFieldTypes(ASCIIToUTF16("Num"), &possible_types); | |
| 200 ASSERT_EQ(0U, possible_types.size()); | |
| 201 | |
| 202 // Extra text on the line. | |
| 203 possible_types.clear(); | |
| 204 address_.GetPossibleFieldTypes(ASCIIToUTF16("Num 10 More"), &possible_types); | |
| 205 ASSERT_EQ(0U, possible_types.size()); | |
| 206 | |
| 207 // Extra text in the middle | |
| 208 possible_types.clear(); | |
| 209 address_.GetPossibleFieldTypes(ASCIIToUTF16("Num Middle 10"), | |
| 210 &possible_types); | |
| 211 ASSERT_EQ(0U, possible_types.size()); | |
| 212 | |
| 213 // Whitespace does matter for apartment number. | |
| 214 possible_types.clear(); | |
| 215 address_.GetPossibleFieldTypes(ASCIIToUTF16(" Num 10 "), &possible_types); | |
| 216 ASSERT_EQ(0U, possible_types.size()); | |
| 217 | |
| 218 // ADDRESS_BILLING_CITY ====================================================== | |
| 219 | |
| 220 // Exact match. | |
| 221 possible_types.clear(); | |
| 222 address_.GetPossibleFieldTypes(ASCIIToUTF16("Paris"), &possible_types); | |
| 223 ASSERT_EQ(1U, possible_types.size()); | |
| 224 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_CITY) != | |
| 225 possible_types.end()); | |
| 226 | |
| 227 // The match is case-insensitive. | |
| 228 possible_types.clear(); | |
| 229 address_.GetPossibleFieldTypes(ASCIIToUTF16("pARiS"), &possible_types); | |
| 230 ASSERT_EQ(1U, possible_types.size()); | |
| 231 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_CITY) != | |
| 232 possible_types.end()); | |
| 233 | |
| 234 // The text is not complete. | |
| 235 possible_types.clear(); | |
| 236 address_.GetPossibleFieldTypes(ASCIIToUTF16("Par"), &possible_types); | |
| 237 ASSERT_EQ(0U, possible_types.size()); | |
| 238 | |
| 239 // Extra text on the line. | |
| 240 possible_types.clear(); | |
| 241 address_.GetPossibleFieldTypes(ASCIIToUTF16("Paris City"), &possible_types); | |
| 242 ASSERT_EQ(0U, possible_types.size()); | |
| 243 | |
| 244 // Whitespace does matter for apartment number. | |
| 245 possible_types.clear(); | |
| 246 address_.GetPossibleFieldTypes(ASCIIToUTF16(" Paris "), &possible_types); | |
| 247 ASSERT_EQ(0U, possible_types.size()); | |
| 248 | |
| 249 // ADDRESS_BILLING_STATE ===================================================== | |
| 250 | |
| 251 // Exact match. | |
| 252 possible_types.clear(); | |
| 253 address_.GetPossibleFieldTypes(ASCIIToUTF16("Texas"), &possible_types); | |
| 254 ASSERT_EQ(1U, possible_types.size()); | |
| 255 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_STATE) != | |
| 256 possible_types.end()); | |
| 257 | |
| 258 // The match is case-insensitive. | |
| 259 possible_types.clear(); | |
| 260 address_.GetPossibleFieldTypes(ASCIIToUTF16("tExAs"), &possible_types); | |
| 261 ASSERT_EQ(1U, possible_types.size()); | |
| 262 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_STATE) != | |
| 263 possible_types.end()); | |
| 264 | |
| 265 // The text is not complete. | |
| 266 possible_types.clear(); | |
| 267 address_.GetPossibleFieldTypes(ASCIIToUTF16("Tex"), &possible_types); | |
| 268 ASSERT_EQ(0U, possible_types.size()); | |
| 269 | |
| 270 // Extra text on the line. | |
| 271 possible_types.clear(); | |
| 272 address_.GetPossibleFieldTypes(ASCIIToUTF16("Texas State"), &possible_types); | |
| 273 ASSERT_EQ(0U, possible_types.size()); | |
| 274 | |
| 275 // Whitespace does matter for apartment number. | |
| 276 possible_types.clear(); | |
| 277 address_.GetPossibleFieldTypes(ASCIIToUTF16(" Texas "), &possible_types); | |
| 278 ASSERT_EQ(0U, possible_types.size()); | |
| 279 | |
| 280 // ADDRESS_BILLING_COUNTRY =================================================== | |
| 281 | |
| 282 // Exact match. | |
| 283 possible_types.clear(); | |
| 284 address_.GetPossibleFieldTypes(ASCIIToUTF16("USA"), &possible_types); | |
| 285 ASSERT_EQ(1U, possible_types.size()); | |
| 286 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_COUNTRY) != | |
| 287 possible_types.end()); | |
| 288 | |
| 289 // The match is case-insensitive. | |
| 290 possible_types.clear(); | |
| 291 address_.GetPossibleFieldTypes(ASCIIToUTF16("uSa"), &possible_types); | |
| 292 ASSERT_EQ(1U, possible_types.size()); | |
| 293 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_COUNTRY) != | |
| 294 possible_types.end()); | |
| 295 | |
| 296 // The text is not complete. | |
| 297 possible_types.clear(); | |
| 298 address_.GetPossibleFieldTypes(ASCIIToUTF16("US"), &possible_types); | |
| 299 ASSERT_EQ(0U, possible_types.size()); | |
| 300 | |
| 301 // Extra text on the line. | |
| 302 possible_types.clear(); | |
| 303 address_.GetPossibleFieldTypes(ASCIIToUTF16("US Country"), &possible_types); | |
| 304 ASSERT_EQ(0U, possible_types.size()); | |
| 305 | |
| 306 // Whitespace does matter for apartment number. | |
| 307 possible_types.clear(); | |
| 308 address_.GetPossibleFieldTypes(ASCIIToUTF16(" US "), &possible_types); | |
| 309 ASSERT_EQ(0U, possible_types.size()); | |
| 310 | |
| 311 // ADDRESS_BILLING_ZIP ======================================================= | |
| 312 | |
| 313 // Exact match. | |
| 314 possible_types.clear(); | |
| 315 address_.GetPossibleFieldTypes(ASCIIToUTF16("12345"), &possible_types); | |
| 316 ASSERT_EQ(1U, possible_types.size()); | |
| 317 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_ZIP) != | |
| 318 possible_types.end()); | |
| 319 | |
| 320 // The text is not complete. | |
| 321 possible_types.clear(); | |
| 322 address_.GetPossibleFieldTypes(ASCIIToUTF16("1234"), &possible_types); | |
| 323 ASSERT_EQ(0U, possible_types.size()); | |
| 324 | |
| 325 // Extra text on the line. | |
| 326 possible_types.clear(); | |
| 327 address_.GetPossibleFieldTypes(ASCIIToUTF16("12345 678"), &possible_types); | |
| 328 ASSERT_EQ(0U, possible_types.size()); | |
| 329 | |
| 330 // Whitespace does matter for apartment number. | |
| 331 possible_types.clear(); | |
| 332 address_.GetPossibleFieldTypes(ASCIIToUTF16(" 12345 "), &possible_types); | |
| 333 ASSERT_EQ(0U, possible_types.size()); | |
| 334 | |
| 335 // Misc ====================================================================== | |
| 336 | |
| 337 // More than one type can match. | |
| 338 address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE1), ASCIIToUTF16("Same")); | |
| 339 address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE2), ASCIIToUTF16("Same")); | |
| 340 address_.SetInfo(AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("Same")); | |
| 341 possible_types.clear(); | |
| 342 address_.GetPossibleFieldTypes(ASCIIToUTF16("Same"), &possible_types); | |
| 343 ASSERT_EQ(3U, possible_types.size()); | |
| 344 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != | |
| 345 possible_types.end()); | |
| 346 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != | |
| 347 possible_types.end()); | |
| 348 EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_APT_NUM) != | |
| 349 possible_types.end()); | |
| 350 | |
| 351 // LINE1 is empty. | |
| 352 address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE1), string16()); | |
| 353 possible_types.clear(); | |
| 354 address_.GetPossibleFieldTypes(string16(), &possible_types); | |
| 355 ASSERT_EQ(0U, possible_types.size()); | |
| 356 } | |
| 357 | |
| 358 TEST_F(BillingAddressTest, FindInfoMatches) { | |
| 359 // ADDRESS_BILLING_LINE1 ===================================================== | |
| 360 | |
| 361 // Match the beginning of the string. | |
| 362 std::vector<string16> matches; | |
| 363 address_.FindInfoMatches( | |
| 364 AutoFillType(ADDRESS_BILLING_LINE1), ASCIIToUTF16("123"), &matches); | |
| 365 ASSERT_EQ(1U, matches.size()); | |
| 366 EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), matches[0]); | |
| 367 | |
| 368 // Search has too many characters. | |
| 369 matches.clear(); | |
| 370 address_.FindInfoMatches( | |
| 371 AutoFillType(ADDRESS_BILLING_LINE1), ASCIIToUTF16("123 B"), &matches); | |
| 372 ASSERT_EQ(0U, matches.size()); | |
| 373 | |
| 374 // Whitespace at the beginning of the search. | |
| 375 matches.clear(); | |
| 376 address_.FindInfoMatches( | |
| 377 AutoFillType(ADDRESS_BILLING_LINE1), ASCIIToUTF16(" 123"), &matches); | |
| 378 ASSERT_EQ(0U, matches.size()); | |
| 379 | |
| 380 // Search includes the entire match, but adds extra characters. | |
| 381 matches.clear(); | |
| 382 address_.FindInfoMatches(AutoFillType(ADDRESS_BILLING_LINE1), | |
| 383 ASCIIToUTF16("123 Appian Way B"), | |
| 384 &matches); | |
| 385 ASSERT_EQ(0U, matches.size()); | |
| 386 | |
| 387 // Matching is case-insensitive. | |
| 388 matches.clear(); | |
| 389 address_.FindInfoMatches(AutoFillType(ADDRESS_BILLING_LINE1), | |
| 390 ASCIIToUTF16("123 aPpiAN wAy"), | |
| 391 &matches); | |
| 392 ASSERT_EQ(1U, matches.size()); | |
| 393 EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), matches[0]); | |
| 394 | |
| 395 // Search is empty. | |
| 396 matches.clear(); | |
| 397 address_.FindInfoMatches( | |
| 398 AutoFillType(ADDRESS_BILLING_LINE1), string16(), &matches); | |
| 399 ASSERT_EQ(1U, matches.size()); | |
| 400 EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), matches[0]); | |
| 401 | |
| 402 // ADDRESS_BILLING_LINE2 ===================================================== | |
| 403 | |
| 404 // Match the beginning of the string. | |
| 405 matches.clear(); | |
| 406 address_.FindInfoMatches( | |
| 407 AutoFillType(ADDRESS_BILLING_LINE2), ASCIIToUTF16("Unit"), &matches); | |
| 408 ASSERT_EQ(1U, matches.size()); | |
| 409 EXPECT_EQ(ASCIIToUTF16("Unit 6"), matches[0]); | |
| 410 | |
| 411 // Search has too many characters. | |
| 412 matches.clear(); | |
| 413 address_.FindInfoMatches( | |
| 414 AutoFillType(ADDRESS_BILLING_LINE2), ASCIIToUTF16("Unita"), &matches); | |
| 415 ASSERT_EQ(0U, matches.size()); | |
| 416 | |
| 417 // Whitespace at the beginning of the search. | |
| 418 matches.clear(); | |
| 419 address_.FindInfoMatches( | |
| 420 AutoFillType(ADDRESS_BILLING_LINE2), ASCIIToUTF16(" Unit"), &matches); | |
| 421 ASSERT_EQ(0U, matches.size()); | |
| 422 | |
| 423 // Search includes the entire match, but adds extra characters. | |
| 424 matches.clear(); | |
| 425 address_.FindInfoMatches( | |
| 426 AutoFillType(ADDRESS_BILLING_LINE2), ASCIIToUTF16("Unit 6B"), &matches); | |
| 427 ASSERT_EQ(0U, matches.size()); | |
| 428 | |
| 429 // Matching is case-insensitive. | |
| 430 matches.clear(); | |
| 431 address_.FindInfoMatches( | |
| 432 AutoFillType(ADDRESS_BILLING_LINE2), ASCIIToUTF16("uNiT 6"), &matches); | |
| 433 ASSERT_EQ(1U, matches.size()); | |
| 434 EXPECT_EQ(ASCIIToUTF16("Unit 6"), matches[0]); | |
| 435 | |
| 436 // Search is empty. | |
| 437 matches.clear(); | |
| 438 address_.FindInfoMatches( | |
| 439 AutoFillType(ADDRESS_BILLING_LINE2), string16(), &matches); | |
| 440 ASSERT_EQ(1U, matches.size()); | |
| 441 EXPECT_EQ(ASCIIToUTF16("Unit 6"), matches[0]); | |
| 442 | |
| 443 // ADDRESS_BILLING_APT_NUM =================================================== | |
| 444 | |
| 445 // Match the beginning of the string. | |
| 446 matches.clear(); | |
| 447 address_.FindInfoMatches( | |
| 448 AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("#"), &matches); | |
| 449 ASSERT_EQ(1U, matches.size()); | |
| 450 EXPECT_EQ(ASCIIToUTF16("#6"), matches[0]); | |
| 451 | |
| 452 // Search has too many characters. | |
| 453 matches.clear(); | |
| 454 address_.FindInfoMatches( | |
| 455 AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("#a"), &matches); | |
| 456 ASSERT_EQ(0U, matches.size()); | |
| 457 | |
| 458 // Whitespace at the beginning of the search. | |
| 459 matches.clear(); | |
| 460 address_.FindInfoMatches( | |
| 461 AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16(" #"), &matches); | |
| 462 ASSERT_EQ(0U, matches.size()); | |
| 463 | |
| 464 // Search includes the entire match, but adds extra characters. | |
| 465 matches.clear(); | |
| 466 address_.FindInfoMatches( | |
| 467 AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("#6B"), &matches); | |
| 468 ASSERT_EQ(0U, matches.size()); | |
| 469 | |
| 470 // Matching is case-insensitive. | |
| 471 matches.clear(); | |
| 472 address_.SetInfo(AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("6B")); | |
| 473 address_.FindInfoMatches( | |
| 474 AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("6b"), &matches); | |
| 475 ASSERT_EQ(1U, matches.size()); | |
| 476 EXPECT_EQ(ASCIIToUTF16("6B"), matches[0]); | |
| 477 | |
| 478 // Search is empty. | |
| 479 matches.clear(); | |
| 480 address_.FindInfoMatches( | |
| 481 AutoFillType(ADDRESS_BILLING_APT_NUM), string16(), &matches); | |
| 482 ASSERT_EQ(1U, matches.size()); | |
| 483 EXPECT_EQ(ASCIIToUTF16("6B"), matches[0]); | |
| 484 | |
| 485 // ADDRESS_BILLING_CITY ====================================================== | |
| 486 | |
| 487 // Match the beginning of the string. | |
| 488 matches.clear(); | |
| 489 address_.FindInfoMatches( | |
| 490 AutoFillType(ADDRESS_BILLING_CITY), ASCIIToUTF16("Par"), &matches); | |
| 491 ASSERT_EQ(1U, matches.size()); | |
| 492 EXPECT_EQ(ASCIIToUTF16("Paris"), matches[0]); | |
| 493 | |
| 494 // Search has too many characters. | |
| 495 matches.clear(); | |
| 496 address_.FindInfoMatches( | |
| 497 AutoFillType(ADDRESS_BILLING_CITY), ASCIIToUTF16("ParA"), &matches); | |
| 498 ASSERT_EQ(0U, matches.size()); | |
| 499 | |
| 500 // Whitespace at the beginning of the search. | |
| 501 matches.clear(); | |
| 502 address_.FindInfoMatches( | |
| 503 AutoFillType(ADDRESS_BILLING_CITY), ASCIIToUTF16(" Paris"), &matches); | |
| 504 ASSERT_EQ(0U, matches.size()); | |
| 505 | |
| 506 // Search includes the entire match, but adds extra characters. | |
| 507 matches.clear(); | |
| 508 address_.FindInfoMatches( | |
| 509 AutoFillType(ADDRESS_BILLING_CITY), ASCIIToUTF16("ParisB"), &matches); | |
| 510 ASSERT_EQ(0U, matches.size()); | |
| 511 | |
| 512 // Matching is case-insensitive. | |
| 513 matches.clear(); | |
| 514 address_.FindInfoMatches( | |
| 515 AutoFillType(ADDRESS_BILLING_CITY), ASCIIToUTF16("PArIs"), &matches); | |
| 516 ASSERT_EQ(1U, matches.size()); | |
| 517 EXPECT_EQ(ASCIIToUTF16("Paris"), matches[0]); | |
| 518 | |
| 519 // Search is empty. | |
| 520 matches.clear(); | |
| 521 address_.FindInfoMatches( | |
| 522 AutoFillType(ADDRESS_BILLING_CITY), string16(), &matches); | |
| 523 ASSERT_EQ(1U, matches.size()); | |
| 524 EXPECT_EQ(ASCIIToUTF16("Paris"), matches[0]); | |
| 525 | |
| 526 // ADDRESS_BILLING_STATE ===================================================== | |
| 527 | |
| 528 // Match the beginning of the string. | |
| 529 matches.clear(); | |
| 530 address_.FindInfoMatches( | |
| 531 AutoFillType(ADDRESS_BILLING_STATE), ASCIIToUTF16("Tex"), &matches); | |
| 532 ASSERT_EQ(1U, matches.size()); | |
| 533 EXPECT_EQ(ASCIIToUTF16("Texas"), matches[0]); | |
| 534 | |
| 535 // Search has too many characters. | |
| 536 matches.clear(); | |
| 537 address_.FindInfoMatches( | |
| 538 AutoFillType(ADDRESS_BILLING_STATE), ASCIIToUTF16("TexC"), &matches); | |
| 539 ASSERT_EQ(0U, matches.size()); | |
| 540 | |
| 541 // Whitespace at the beginning of the search. | |
| 542 matches.clear(); | |
| 543 address_.FindInfoMatches( | |
| 544 AutoFillType(ADDRESS_BILLING_STATE), ASCIIToUTF16(" Texas"), &matches); | |
| 545 ASSERT_EQ(0U, matches.size()); | |
| 546 | |
| 547 // Search includes the entire match, but adds extra characters. | |
| 548 matches.clear(); | |
| 549 address_.FindInfoMatches( | |
| 550 AutoFillType(ADDRESS_BILLING_STATE), ASCIIToUTF16("TexasB"), &matches); | |
| 551 ASSERT_EQ(0U, matches.size()); | |
| 552 | |
| 553 // Matching is case-insensitive. | |
| 554 matches.clear(); | |
| 555 address_.FindInfoMatches( | |
| 556 AutoFillType(ADDRESS_BILLING_STATE), ASCIIToUTF16("TeXaS"), &matches); | |
| 557 ASSERT_EQ(1U, matches.size()); | |
| 558 EXPECT_EQ(ASCIIToUTF16("Texas"), matches[0]); | |
| 559 | |
| 560 // Search is empty. | |
| 561 matches.clear(); | |
| 562 address_.FindInfoMatches( | |
| 563 AutoFillType(ADDRESS_BILLING_STATE), string16(), &matches); | |
| 564 ASSERT_EQ(1U, matches.size()); | |
| 565 EXPECT_EQ(ASCIIToUTF16("Texas"), matches[0]); | |
| 566 | |
| 567 // ADDRESS_BILLING_ZIP ======================================================= | |
| 568 | |
| 569 // Match the beginning of the string. | |
| 570 matches.clear(); | |
| 571 address_.FindInfoMatches( | |
| 572 AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("123"), &matches); | |
| 573 ASSERT_EQ(1U, matches.size()); | |
| 574 EXPECT_EQ(ASCIIToUTF16("12345"), matches[0]); | |
| 575 | |
| 576 // Search has too many characters. | |
| 577 matches.clear(); | |
| 578 address_.FindInfoMatches( | |
| 579 AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("123a"), &matches); | |
| 580 ASSERT_EQ(0U, matches.size()); | |
| 581 | |
| 582 // Whitespace at the beginning of the search. | |
| 583 matches.clear(); | |
| 584 address_.FindInfoMatches( | |
| 585 AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16(" 123"), &matches); | |
| 586 ASSERT_EQ(0U, matches.size()); | |
| 587 | |
| 588 // Search includes the entire match, but adds extra characters. | |
| 589 matches.clear(); | |
| 590 address_.FindInfoMatches( | |
| 591 AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("123456"), &matches); | |
| 592 ASSERT_EQ(0U, matches.size()); | |
| 593 | |
| 594 // Matching is case-sensitive because we should only have numbers in the zip. | |
| 595 matches.clear(); | |
| 596 address_.SetInfo(AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("12345A")); | |
| 597 address_.FindInfoMatches( | |
| 598 AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("12345a"), &matches); | |
| 599 ASSERT_EQ(0U, matches.size()); | |
| 600 | |
| 601 // Reset the zip code. | |
| 602 address_.SetInfo(AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("12345")); | |
| 603 | |
| 604 // Search is empty. | |
| 605 matches.clear(); | |
| 606 address_.FindInfoMatches( | |
| 607 AutoFillType(ADDRESS_BILLING_ZIP), string16(), &matches); | |
| 608 ASSERT_EQ(1U, matches.size()); | |
| 609 EXPECT_EQ(ASCIIToUTF16("12345"), matches[0]); | |
| 610 | |
| 611 // ADDRESS_BILLING_COUNTRY =================================================== | |
| 612 | |
| 613 // Match the beginning of the string. | |
| 614 matches.clear(); | |
| 615 address_.FindInfoMatches( | |
| 616 AutoFillType(ADDRESS_BILLING_COUNTRY), ASCIIToUTF16("US"), &matches); | |
| 617 ASSERT_EQ(1U, matches.size()); | |
| 618 EXPECT_EQ(ASCIIToUTF16("USA"), matches[0]); | |
| 619 | |
| 620 // Search has too many characters. | |
| 621 matches.clear(); | |
| 622 address_.FindInfoMatches( | |
| 623 AutoFillType(ADDRESS_BILLING_COUNTRY), ASCIIToUTF16("USb"), &matches); | |
| 624 ASSERT_EQ(0U, matches.size()); | |
| 625 | |
| 626 // Whitespace at the beginning of the search. | |
| 627 matches.clear(); | |
| 628 address_.FindInfoMatches( | |
| 629 AutoFillType(ADDRESS_BILLING_COUNTRY), ASCIIToUTF16(" US"), &matches); | |
| 630 ASSERT_EQ(0U, matches.size()); | |
| 631 | |
| 632 // Search includes the entire match, but adds extra characters. | |
| 633 matches.clear(); | |
| 634 address_.FindInfoMatches( | |
| 635 AutoFillType(ADDRESS_BILLING_COUNTRY), ASCIIToUTF16("USAB"), &matches); | |
| 636 ASSERT_EQ(0U, matches.size()); | |
| 637 | |
| 638 // Matching is case-insensitive. | |
| 639 matches.clear(); | |
| 640 address_.FindInfoMatches( | |
| 641 AutoFillType(ADDRESS_BILLING_COUNTRY), ASCIIToUTF16("uSa"), &matches); | |
| 642 ASSERT_EQ(1U, matches.size()); | |
| 643 EXPECT_EQ(ASCIIToUTF16("USA"), matches[0]); | |
| 644 | |
| 645 // Search is empty. | |
| 646 matches.clear(); | |
| 647 address_.FindInfoMatches( | |
| 648 AutoFillType(ADDRESS_BILLING_COUNTRY), string16(), &matches); | |
| 649 ASSERT_EQ(1U, matches.size()); | |
| 650 EXPECT_EQ(ASCIIToUTF16("USA"), matches[0]); | |
| 651 | |
| 652 // Misc ====================================================================== | |
| 653 | |
| 654 // |type| is not handled by address_. | |
| 655 matches.clear(); | |
| 656 address_.FindInfoMatches( | |
| 657 AutoFillType(NAME_FIRST), ASCIIToUTF16("USA"), &matches); | |
| 658 ASSERT_EQ(0U, matches.size()); | |
| 659 | |
| 660 // |type| is UNKNOWN_TYPE. | |
| 661 matches.clear(); | |
| 662 address_.FindInfoMatches( | |
| 663 AutoFillType(UNKNOWN_TYPE), ASCIIToUTF16("123"), &matches); | |
| 664 ASSERT_EQ(2U, matches.size()); | |
| 665 EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), matches[0]); | |
| 666 EXPECT_EQ(ASCIIToUTF16("12345"), matches[1]); | |
| 667 | |
| 668 // |type| is UNKNOWN_TYPE. Exclude zip because of extra space. | |
| 669 matches.clear(); | |
| 670 address_.FindInfoMatches( | |
| 671 AutoFillType(UNKNOWN_TYPE), ASCIIToUTF16("123 "), &matches); | |
| 672 ASSERT_EQ(1U, matches.size()); | |
| 673 EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), matches[0]); | |
| 674 | |
| 675 // |type| is UNKNOWN_TYPE. Search is empty. | |
| 676 matches.clear(); | |
| 677 address_.FindInfoMatches( | |
| 678 AutoFillType(UNKNOWN_TYPE), string16(), &matches); | |
| 679 ASSERT_EQ(7U, matches.size()); | |
| 680 EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), matches[0]); | |
| 681 EXPECT_EQ(ASCIIToUTF16("Unit 6"), matches[1]); | |
| 682 EXPECT_EQ(ASCIIToUTF16("6B"), matches[2]); | |
| 683 EXPECT_EQ(ASCIIToUTF16("Paris"), matches[3]); | |
| 684 EXPECT_EQ(ASCIIToUTF16("Texas"), matches[4]); | |
| 685 EXPECT_EQ(ASCIIToUTF16("12345"), matches[5]); | |
| 686 EXPECT_EQ(ASCIIToUTF16("USA"), matches[6]); | |
| 687 } | |
| 688 | |
| 689 TEST_F(BillingAddressTest, GetFieldText) { | |
| 690 // Get the field text. | |
| 691 string16 text; | |
| 692 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE1)); | |
| 693 EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), text); | |
| 694 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE2)); | |
| 695 EXPECT_EQ(ASCIIToUTF16("Unit 6"), text); | |
| 696 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_APT_NUM)); | |
| 697 EXPECT_EQ(ASCIIToUTF16("#6"), text); | |
| 698 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_CITY)); | |
| 699 EXPECT_EQ(ASCIIToUTF16("Paris"), text); | |
| 700 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_STATE)); | |
| 701 EXPECT_EQ(ASCIIToUTF16("Texas"), text); | |
| 702 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_ZIP)); | |
| 703 EXPECT_EQ(ASCIIToUTF16("12345"), text); | |
| 704 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_COUNTRY)); | |
| 705 EXPECT_EQ(ASCIIToUTF16("USA"), text); | |
| 706 | |
| 707 // |type| is not supported by Billingaddress_. | |
| 708 text = address_.GetFieldText(AutoFillType(NAME_FIRST)); | |
| 709 EXPECT_EQ(string16(), text); | |
| 710 } | |
| 711 | |
| 712 TEST_F(BillingAddressTest, Clear) { | |
| 713 // Clear the info. | |
| 714 string16 text; | |
| 715 address_.Clear(); | |
| 716 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE1)); | |
| 717 EXPECT_EQ(string16(), text); | |
| 718 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE2)); | |
| 719 EXPECT_EQ(string16(), text); | |
| 720 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_APT_NUM)); | |
| 721 EXPECT_EQ(string16(), text); | |
| 722 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_CITY)); | |
| 723 EXPECT_EQ(string16(), text); | |
| 724 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_STATE)); | |
| 725 EXPECT_EQ(string16(), text); | |
| 726 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_ZIP)); | |
| 727 EXPECT_EQ(string16(), text); | |
| 728 text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_COUNTRY)); | |
| 729 EXPECT_EQ(string16(), text); | |
| 730 } | |
| 731 | |
| 732 TEST_F(BillingAddressTest, AddressClone) { | |
| 733 // Clone the info. | |
| 734 string16 text; | |
| 735 BillingAddress clone; | |
| 736 Address* clone_ptr = &clone; | |
| 737 clone_ptr->Clone(address_); | |
| 738 text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE1)); | |
| 739 EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), text); | |
| 740 text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE2)); | |
| 741 EXPECT_EQ(ASCIIToUTF16("Unit 6"), text); | |
| 742 text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_APT_NUM)); | |
| 743 EXPECT_EQ(ASCIIToUTF16("#6"), text); | |
| 744 text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_CITY)); | |
| 745 EXPECT_EQ(ASCIIToUTF16("Paris"), text); | |
| 746 text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_STATE)); | |
| 747 EXPECT_EQ(ASCIIToUTF16("Texas"), text); | |
| 748 text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_ZIP)); | |
| 749 EXPECT_EQ(ASCIIToUTF16("12345"), text); | |
| 750 text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_COUNTRY)); | |
| 751 EXPECT_EQ(ASCIIToUTF16("USA"), text); | |
| 752 | |
| 753 // Verify that the clone is a copy and not a reference. | |
| 754 address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE1), | |
| 755 ASCIIToUTF16("654 Bowling Terrace")); | |
| 756 text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE1)); | |
| 757 EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), text); | |
| 758 } | |
| 759 | |
| 760 TEST_F(BillingAddressTest, BillingAddressClone) { | |
| 761 // Clone the info. | |
| 762 string16 text; | |
| 763 scoped_ptr<FormGroup> clone(address_.Clone()); | |
| 764 ASSERT_NE(static_cast<FormGroup*>(NULL), clone.get()); | |
| 765 text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_LINE1)); | |
| 766 EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), text); | |
| 767 text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_LINE2)); | |
| 768 EXPECT_EQ(ASCIIToUTF16("Unit 6"), text); | |
| 769 text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_APT_NUM)); | |
| 770 EXPECT_EQ(ASCIIToUTF16("#6"), text); | |
| 771 text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_CITY)); | |
| 772 EXPECT_EQ(ASCIIToUTF16("Paris"), text); | |
| 773 text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_STATE)); | |
| 774 EXPECT_EQ(ASCIIToUTF16("Texas"), text); | |
| 775 text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_ZIP)); | |
| 776 EXPECT_EQ(ASCIIToUTF16("12345"), text); | |
| 777 text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_COUNTRY)); | |
| 778 EXPECT_EQ(ASCIIToUTF16("USA"), text); | |
| 779 | |
| 780 // Verify that the clone is a copy and not a reference. | |
| 781 address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE1), | |
| 782 ASCIIToUTF16("654 Bowling Terrace")); | |
| 783 text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_LINE1)); | |
| 784 EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), text); | |
| 785 } | |
| 786 | |
| 787 } // namespace | |
| OLD | NEW |