| 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 ExpectFilledField(const char* expected_label, |
| 261 const char* expected_name, |
| 262 const char* expected_value, |
| 263 const char* expected_form_control_type, |
| 264 const webkit_glue::FormField& field) { |
| 265 SCOPED_TRACE(expected_label); |
| 266 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); |
| 267 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); |
| 268 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); |
| 269 EXPECT_EQ(UTF8ToUTF16(expected_form_control_type), field.form_control_type); |
| 270 } |
| 271 |
| 260 // Verifies that the |filled_form| has been filled with the given data. | 272 // Verifies that the |filled_form| has been filled with the given data. |
| 261 // Verifies address fields if |has_address_fields| is true, and verifies | 273 // 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 | 274 // 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. | 275 // are true. |use_month_type| is used for credit card input month type. |
| 264 void ExpectFilledForm(int page_id, | 276 void ExpectFilledForm(int page_id, |
| 265 const FormData& filled_form, | 277 const FormData& filled_form, |
| 266 int expected_page_id, | 278 int expected_page_id, |
| 267 const char* first, | 279 const char* first, |
| 268 const char* middle, | 280 const char* middle, |
| 269 const char* last, | 281 const char* last, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 313 |
| 302 size_t form_size = 0; | 314 size_t form_size = 0; |
| 303 if (has_address_fields) | 315 if (has_address_fields) |
| 304 form_size += kAddressFormSize; | 316 form_size += kAddressFormSize; |
| 305 if (has_credit_card_fields) | 317 if (has_credit_card_fields) |
| 306 form_size += kCreditCardFormSize; | 318 form_size += kCreditCardFormSize; |
| 307 ASSERT_EQ(form_size, filled_form.fields.size()); | 319 ASSERT_EQ(form_size, filled_form.fields.size()); |
| 308 | 320 |
| 309 FormField field; | 321 FormField field; |
| 310 if (has_address_fields) { | 322 if (has_address_fields) { |
| 311 autofill_test::CreateTestFormField( | 323 ExpectFilledField("First Name", "firstname", first, "text", |
| 312 "First Name", "firstname", first, "text", &field); | 324 filled_form.fields[0]); |
| 313 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[0])); | 325 ExpectFilledField("Middle Name", "middlename", middle, "text", |
| 314 autofill_test::CreateTestFormField( | 326 filled_form.fields[1]); |
| 315 "Middle Name", "middlename", middle, "text", &field); | 327 ExpectFilledField("Last Name", "lastname", last, "text", |
| 316 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[1])); | 328 filled_form.fields[2]); |
| 317 autofill_test::CreateTestFormField( | 329 ExpectFilledField("Address Line 1", "addr1", address1, "text", |
| 318 "Last Name", "lastname", last, "text", &field); | 330 filled_form.fields[3]); |
| 319 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[2])); | 331 ExpectFilledField("Address Line 2", "addr2", address2, "text", |
| 320 autofill_test::CreateTestFormField( | 332 filled_form.fields[4]); |
| 321 "Address Line 1", "addr1", address1, "text", &field); | 333 ExpectFilledField("City", "city", city, "text", |
| 322 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[3])); | 334 filled_form.fields[5]); |
| 323 autofill_test::CreateTestFormField( | 335 ExpectFilledField("State", "state", state, "text", |
| 324 "Address Line 2", "addr2", address2, "text", &field); | 336 filled_form.fields[6]); |
| 325 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[4])); | 337 ExpectFilledField("Postal Code", "zipcode", postal_code, "text", |
| 326 autofill_test::CreateTestFormField( | 338 filled_form.fields[7]); |
| 327 "City", "city", city, "text", &field); | 339 ExpectFilledField("Country", "country", country, "text", |
| 328 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[5])); | 340 filled_form.fields[8]); |
| 329 autofill_test::CreateTestFormField( | 341 ExpectFilledField("Phone Number", "phonenumber", phone, "tel", |
| 330 "State", "state", state, "text", &field); | 342 filled_form.fields[9]); |
| 331 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[6])); | 343 ExpectFilledField("Fax", "fax", fax, "text", |
| 332 autofill_test::CreateTestFormField( | 344 filled_form.fields[10]); |
| 333 "Postal Code", "zipcode", postal_code, "text", &field); | 345 ExpectFilledField("Email", "email", email, "email", |
| 334 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[7])); | 346 filled_form.fields[11]); |
| 335 autofill_test::CreateTestFormField( | |
| 336 "Country", "country", country, "text", &field); | |
| 337 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[8])); | |
| 338 autofill_test::CreateTestFormField( | |
| 339 "Phone Number", "phonenumber", phone, "tel", &field); | |
| 340 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[9])); | |
| 341 autofill_test::CreateTestFormField( | |
| 342 "Fax", "fax", fax, "text", &field); | |
| 343 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[10])); | |
| 344 autofill_test::CreateTestFormField( | |
| 345 "Email", "email", email, "email", &field); | |
| 346 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[11])); | |
| 347 } | 347 } |
| 348 | 348 |
| 349 if (has_credit_card_fields) { | 349 if (has_credit_card_fields) { |
| 350 size_t offset = has_address_fields? kAddressFormSize : 0; | 350 size_t offset = has_address_fields? kAddressFormSize : 0; |
| 351 autofill_test::CreateTestFormField( | 351 ExpectFilledField("Name on Card", "nameoncard", name_on_card, "text", |
| 352 "Name on Card", "nameoncard", name_on_card, "text", &field); | 352 filled_form.fields[offset + 0]); |
| 353 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 0])); | 353 ExpectFilledField("Card Number", "cardnumber", card_number, "text", |
| 354 autofill_test::CreateTestFormField( | 354 filled_form.fields[offset + 1]); |
| 355 "Card Number", "cardnumber", card_number, "text", &field); | |
| 356 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 1])); | |
| 357 if (use_month_type) { | 355 if (use_month_type) { |
| 358 std::string exp_year = expiration_year; | 356 std::string exp_year = expiration_year; |
| 359 std::string exp_month = expiration_month; | 357 std::string exp_month = expiration_month; |
| 360 std::string date; | 358 std::string date; |
| 361 if (!exp_year.empty() && !exp_month.empty()) | 359 if (!exp_year.empty() && !exp_month.empty()) |
| 362 date = exp_year + "-" + exp_month; | 360 date = exp_year + "-" + exp_month; |
| 363 autofill_test::CreateTestFormField( | 361 |
| 364 "Expiration Date", "ccmonth", date.c_str(), "month", &field); | 362 ExpectFilledField("Expiration Date", "ccmonth", date.c_str(), "month", |
| 365 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2])); | 363 filled_form.fields[offset + 2]); |
| 366 } else { | 364 } else { |
| 367 autofill_test::CreateTestFormField( | 365 ExpectFilledField("Expiration Date", "ccmonth", expiration_month, "text", |
| 368 "Expiration Date", "ccmonth", expiration_month, "text", &field); | 366 filled_form.fields[offset + 2]); |
| 369 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 2])); | 367 ExpectFilledField("", "ccyear", expiration_year, "text", |
| 370 autofill_test::CreateTestFormField( | 368 filled_form.fields[offset + 3]); |
| 371 "", "ccyear", expiration_year, "text", &field); | |
| 372 EXPECT_TRUE(field.StrictlyEqualsHack(filled_form.fields[offset + 3])); | |
| 373 } | 369 } |
| 374 } | 370 } |
| 375 } | 371 } |
| 376 | 372 |
| 377 void ExpectFilledAddressFormElvis(int page_id, | 373 void ExpectFilledAddressFormElvis(int page_id, |
| 378 const FormData& filled_form, | 374 const FormData& filled_form, |
| 379 int expected_page_id, | 375 int expected_page_id, |
| 380 bool has_credit_card_fields) { | 376 bool has_credit_card_fields) { |
| 381 ExpectFilledForm(page_id, filled_form, expected_page_id, "Elvis", "Aaron", | 377 ExpectFilledForm(page_id, filled_form, expected_page_id, "Elvis", "Aaron", |
| 382 "Presley", "3734 Elvis Presley Blvd.", "Apt. 10", "Memphis", | 378 "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 = | 2557 const FieldTypeSet& possible_types1 = |
| 2562 form_structure.field(1)->possible_types(); | 2558 form_structure.field(1)->possible_types(); |
| 2563 EXPECT_EQ(1U, possible_types1.size()); | 2559 EXPECT_EQ(1U, possible_types1.size()); |
| 2564 EXPECT_TRUE(possible_types1.find(NAME_FIRST) != possible_types1.end()); | 2560 EXPECT_TRUE(possible_types1.find(NAME_FIRST) != possible_types1.end()); |
| 2565 const FieldTypeSet& possible_types2 = | 2561 const FieldTypeSet& possible_types2 = |
| 2566 form_structure.field(2)->possible_types(); | 2562 form_structure.field(2)->possible_types(); |
| 2567 EXPECT_EQ(1U, possible_types2.size()); | 2563 EXPECT_EQ(1U, possible_types2.size()); |
| 2568 EXPECT_TRUE(possible_types2.find(UNKNOWN_TYPE) != | 2564 EXPECT_TRUE(possible_types2.find(UNKNOWN_TYPE) != |
| 2569 possible_types2.end()); | 2565 possible_types2.end()); |
| 2570 } | 2566 } |
| OLD | NEW |