Chromium Code Reviews| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 ASSERT_EQ(expected_num_suggestions, unique_ids.size()); | 250 ASSERT_EQ(expected_num_suggestions, unique_ids.size()); |
| 251 for (size_t i = 0; i < expected_num_suggestions; ++i) { | 251 for (size_t i = 0; i < expected_num_suggestions; ++i) { |
| 252 SCOPED_TRACE(StringPrintf("i: %" PRIuS, i)); | 252 SCOPED_TRACE(StringPrintf("i: %" PRIuS, i)); |
| 253 EXPECT_EQ(expected_values[i], values[i]); | 253 EXPECT_EQ(expected_values[i], values[i]); |
| 254 EXPECT_EQ(expected_labels[i], labels[i]); | 254 EXPECT_EQ(expected_labels[i], labels[i]); |
| 255 EXPECT_EQ(expected_icons[i], icons[i]); | 255 EXPECT_EQ(expected_icons[i], icons[i]); |
| 256 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]); | 256 EXPECT_EQ(expected_unique_ids[i], unique_ids[i]); |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 | 259 |
| 260 void ExpectFieldEquals(const webkit_glue::FormField& expected, | |
| 261 const webkit_glue::FormField& actual) { | |
| 262 EXPECT_EQ(expected.label, actual.label); | |
| 263 EXPECT_EQ(expected.name, actual.name); | |
| 264 EXPECT_EQ(expected.value, actual.value); | |
| 265 EXPECT_EQ(expected.form_control_type, actual.form_control_type); | |
| 266 EXPECT_EQ(expected.max_length, actual.max_length); | |
|
dhollowa
2011/08/08 21:40:39
This test is repeated in autofill_browsertest.cc a
Ilya Sherman
2011/08/09 00:13:43
This version is intentionally missing the |is_auto
| |
| 267 } | |
| 268 | |
| 260 // Verifies that the |filled_form| has been filled with the given data. | 269 // Verifies that the |filled_form| has been filled with the given data. |
| 261 // Verifies address fields if |has_address_fields| is true, and verifies | 270 // Verifies address fields if |has_address_fields| is true, and verifies |
| 262 // credit card fields if |has_credit_card_fields| is true. Verifies both if both | 271 // credit card fields if |has_credit_card_fields| is true. Verifies both if both |
| 263 // are true. |use_month_type| is used for credit card input month type. | 272 // are true. |use_month_type| is used for credit card input month type. |
| 264 void ExpectFilledForm(int page_id, | 273 void ExpectFilledForm(int page_id, |
| 265 const FormData& filled_form, | 274 const FormData& filled_form, |
| 266 int expected_page_id, | 275 int expected_page_id, |
| 267 const char* first, | 276 const char* first, |
| 268 const char* middle, | 277 const char* middle, |
| 269 const char* last, | 278 const char* last, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 if (has_address_fields) | 312 if (has_address_fields) |
| 304 form_size += kAddressFormSize; | 313 form_size += kAddressFormSize; |
| 305 if (has_credit_card_fields) | 314 if (has_credit_card_fields) |
| 306 form_size += kCreditCardFormSize; | 315 form_size += kCreditCardFormSize; |
| 307 ASSERT_EQ(form_size, filled_form.fields.size()); | 316 ASSERT_EQ(form_size, filled_form.fields.size()); |
| 308 | 317 |
| 309 FormField field; | 318 FormField field; |
| 310 if (has_address_fields) { | 319 if (has_address_fields) { |
| 311 autofill_test::CreateTestFormField( | 320 autofill_test::CreateTestFormField( |
| 312 "First Name", "firstname", first, "text", &field); | 321 "First Name", "firstname", first, "text", &field); |
| 313 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[0])); | 322 { |
| 323 SCOPED_TRACE("First Name"); | |
| 324 ExpectFieldEquals(field, filled_form.fields[0]); | |
| 325 } | |
| 314 autofill_test::CreateTestFormField( | 326 autofill_test::CreateTestFormField( |
| 315 "Middle Name", "middlename", middle, "text", &field); | 327 "Middle Name", "middlename", middle, "text", &field); |
| 316 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[1])); | 328 { |
| 329 SCOPED_TRACE("Middle Name"); | |
| 330 ExpectFieldEquals(field, filled_form.fields[1]); | |
| 331 } | |
| 317 autofill_test::CreateTestFormField( | 332 autofill_test::CreateTestFormField( |
| 318 "Last Name", "lastname", last, "text", &field); | 333 "Last Name", "lastname", last, "text", &field); |
| 319 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[2])); | 334 { |
| 335 SCOPED_TRACE("Last Name"); | |
| 336 ExpectFieldEquals(field, filled_form.fields[2]); | |
| 337 } | |
| 320 autofill_test::CreateTestFormField( | 338 autofill_test::CreateTestFormField( |
| 321 "Address Line 1", "addr1", address1, "text", &field); | 339 "Address Line 1", "addr1", address1, "text", &field); |
| 322 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[3])); | 340 { |
| 341 SCOPED_TRACE("Address Line 1"); | |
| 342 ExpectFieldEquals(field, filled_form.fields[3]); | |
| 343 } | |
| 323 autofill_test::CreateTestFormField( | 344 autofill_test::CreateTestFormField( |
| 324 "Address Line 2", "addr2", address2, "text", &field); | 345 "Address Line 2", "addr2", address2, "text", &field); |
| 325 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[4])); | 346 { |
| 347 SCOPED_TRACE("Address Line 2"); | |
| 348 ExpectFieldEquals(field, filled_form.fields[4]); | |
| 349 } | |
| 326 autofill_test::CreateTestFormField( | 350 autofill_test::CreateTestFormField( |
| 327 "City", "city", city, "text", &field); | 351 "City", "city", city, "text", &field); |
| 328 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[5])); | 352 { |
| 353 SCOPED_TRACE("City"); | |
| 354 ExpectFieldEquals(field, filled_form.fields[5]); | |
| 355 } | |
| 329 autofill_test::CreateTestFormField( | 356 autofill_test::CreateTestFormField( |
| 330 "State", "state", state, "text", &field); | 357 "State", "state", state, "text", &field); |
| 331 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[6])); | 358 { |
| 359 SCOPED_TRACE("State"); | |
| 360 ExpectFieldEquals(field, filled_form.fields[6]); | |
| 361 } | |
| 332 autofill_test::CreateTestFormField( | 362 autofill_test::CreateTestFormField( |
| 333 "Postal Code", "zipcode", postal_code, "text", &field); | 363 "Postal Code", "zipcode", postal_code, "text", &field); |
| 334 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[7])); | 364 { |
| 365 SCOPED_TRACE("Postal Code"); | |
| 366 ExpectFieldEquals(field, filled_form.fields[7]); | |
| 367 } | |
| 335 autofill_test::CreateTestFormField( | 368 autofill_test::CreateTestFormField( |
| 336 "Country", "country", country, "text", &field); | 369 "Country", "country", country, "text", &field); |
| 337 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[8])); | 370 { |
| 371 SCOPED_TRACE("Country"); | |
| 372 ExpectFieldEquals(field, filled_form.fields[8]); | |
| 373 } | |
| 338 autofill_test::CreateTestFormField( | 374 autofill_test::CreateTestFormField( |
| 339 "Phone Number", "phonenumber", phone, "tel", &field); | 375 "Phone Number", "phonenumber", phone, "tel", &field); |
| 340 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[9])); | 376 { |
| 377 SCOPED_TRACE("Phone Number"); | |
| 378 ExpectFieldEquals(field, filled_form.fields[9]); | |
| 379 } | |
| 341 autofill_test::CreateTestFormField( | 380 autofill_test::CreateTestFormField( |
| 342 "Fax", "fax", fax, "text", &field); | 381 "Fax", "fax", fax, "text", &field); |
| 343 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[10])); | 382 { |
| 383 SCOPED_TRACE("Fax"); | |
| 384 ExpectFieldEquals(field, filled_form.fields[10]); | |
| 385 } | |
| 344 autofill_test::CreateTestFormField( | 386 autofill_test::CreateTestFormField( |
| 345 "Email", "email", email, "email", &field); | 387 "Email", "email", email, "email", &field); |
| 346 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[11])); | 388 { |
| 389 SCOPED_TRACE("Email"); | |
| 390 ExpectFieldEquals(field, filled_form.fields[11]); | |
| 391 } | |
| 347 } | 392 } |
| 348 | 393 |
| 349 if (has_credit_card_fields) { | 394 if (has_credit_card_fields) { |
| 350 size_t offset = has_address_fields? kAddressFormSize : 0; | 395 size_t offset = has_address_fields? kAddressFormSize : 0; |
| 351 autofill_test::CreateTestFormField( | 396 autofill_test::CreateTestFormField( |
| 352 "Name on Card", "nameoncard", name_on_card, "text", &field); | 397 "Name on Card", "nameoncard", name_on_card, "text", &field); |
| 353 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 0])); | 398 { |
| 399 SCOPED_TRACE("Name on Card"); | |
| 400 ExpectFieldEquals(field, filled_form.fields[offset + 0]); | |
| 401 } | |
| 354 autofill_test::CreateTestFormField( | 402 autofill_test::CreateTestFormField( |
| 355 "Card Number", "cardnumber", card_number, "text", &field); | 403 "Card Number", "cardnumber", card_number, "text", &field); |
| 356 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 1])); | 404 { |
| 405 SCOPED_TRACE("Card Number"); | |
| 406 ExpectFieldEquals(field, filled_form.fields[offset + 1]); | |
| 407 } | |
| 357 if (use_month_type) { | 408 if (use_month_type) { |
| 358 std::string exp_year = expiration_year; | 409 std::string exp_year = expiration_year; |
| 359 std::string exp_month = expiration_month; | 410 std::string exp_month = expiration_month; |
| 360 std::string date; | 411 std::string date; |
| 361 if (!exp_year.empty() && !exp_month.empty()) | 412 if (!exp_year.empty() && !exp_month.empty()) |
| 362 date = exp_year + "-" + exp_month; | 413 date = exp_year + "-" + exp_month; |
| 363 autofill_test::CreateTestFormField( | 414 autofill_test::CreateTestFormField( |
| 364 "Expiration Date", "ccmonth", date.c_str(), "month", &field); | 415 "Expiration Date", "ccmonth", date.c_str(), "month", &field); |
| 365 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2])); | 416 { |
| 417 SCOPED_TRACE("Expiration Date"); | |
| 418 ExpectFieldEquals(field, filled_form.fields[offset + 2]); | |
| 419 } | |
| 366 } else { | 420 } else { |
| 367 autofill_test::CreateTestFormField( | 421 autofill_test::CreateTestFormField( |
| 368 "Expiration Date", "ccmonth", expiration_month, "text", &field); | 422 "Expiration Date", "ccmonth", expiration_month, "text", &field); |
| 369 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2])); | 423 { |
| 424 SCOPED_TRACE("Expiration Date"); | |
| 425 ExpectFieldEquals(field, filled_form.fields[offset + 2]); | |
| 426 } | |
| 370 autofill_test::CreateTestFormField( | 427 autofill_test::CreateTestFormField( |
| 371 "", "ccyear", expiration_year, "text", &field); | 428 "", "ccyear", expiration_year, "text", &field); |
| 372 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 3])); | 429 { |
| 430 SCOPED_TRACE("Expiration Year"); | |
| 431 ExpectFieldEquals(field, filled_form.fields[offset + 3]); | |
| 432 } | |
| 373 } | 433 } |
| 374 } | 434 } |
| 375 } | 435 } |
| 376 | 436 |
| 377 void ExpectFilledAddressFormElvis(int page_id, | 437 void ExpectFilledAddressFormElvis(int page_id, |
| 378 const FormData& filled_form, | 438 const FormData& filled_form, |
| 379 int expected_page_id, | 439 int expected_page_id, |
| 380 bool has_credit_card_fields) { | 440 bool has_credit_card_fields) { |
| 381 ExpectFilledForm(page_id, filled_form, expected_page_id, "Elvis", "Aaron", | 441 ExpectFilledForm(page_id, filled_form, expected_page_id, "Elvis", "Aaron", |
| 382 "Presley", "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", | 442 "Presley", "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", |
| (...skipping 2178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2561 const FieldTypeSet& possible_types1 = | 2621 const FieldTypeSet& possible_types1 = |
| 2562 form_structure.field(1)->possible_types(); | 2622 form_structure.field(1)->possible_types(); |
| 2563 EXPECT_EQ(1U, possible_types1.size()); | 2623 EXPECT_EQ(1U, possible_types1.size()); |
| 2564 EXPECT_TRUE(possible_types1.find(NAME_FIRST) != possible_types1.end()); | 2624 EXPECT_TRUE(possible_types1.find(NAME_FIRST) != possible_types1.end()); |
| 2565 const FieldTypeSet& possible_types2 = | 2625 const FieldTypeSet& possible_types2 = |
| 2566 form_structure.field(2)->possible_types(); | 2626 form_structure.field(2)->possible_types(); |
| 2567 EXPECT_EQ(1U, possible_types2.size()); | 2627 EXPECT_EQ(1U, possible_types2.size()); |
| 2568 EXPECT_TRUE(possible_types2.find(UNKNOWN_TYPE) != | 2628 EXPECT_TRUE(possible_types2.find(UNKNOWN_TYPE) != |
| 2569 possible_types2.end()); | 2629 possible_types2.end()); |
| 2570 } | 2630 } |
| OLD | NEW |