| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 3463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3474 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); | 3474 EXPECT_TRUE(lastname.suggestedValue().isEmpty()); |
| 3475 EXPECT_FALSE(lastname.isAutofilled()); | 3475 EXPECT_FALSE(lastname.isAutofilled()); |
| 3476 EXPECT_TRUE(email.value().isEmpty()); | 3476 EXPECT_TRUE(email.value().isEmpty()); |
| 3477 EXPECT_TRUE(email.suggestedValue().isEmpty()); | 3477 EXPECT_TRUE(email.suggestedValue().isEmpty()); |
| 3478 EXPECT_FALSE(email.isAutofilled()); | 3478 EXPECT_FALSE(email.isAutofilled()); |
| 3479 EXPECT_TRUE(phone.value().isEmpty()); | 3479 EXPECT_TRUE(phone.value().isEmpty()); |
| 3480 EXPECT_TRUE(phone.suggestedValue().isEmpty()); | 3480 EXPECT_TRUE(phone.suggestedValue().isEmpty()); |
| 3481 EXPECT_FALSE(phone.isAutofilled()); | 3481 EXPECT_FALSE(phone.isAutofilled()); |
| 3482 } | 3482 } |
| 3483 | 3483 |
| 3484 TEST_F(FormAutofillTest, FormWithNodeIsAutofilled) { | |
| 3485 LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>" | |
| 3486 " <INPUT type='text' id='firstname' value='Wyatt'/>" | |
| 3487 " <INPUT type='text' id='lastname'/>" | |
| 3488 " <INPUT type='text' id='email'/>" | |
| 3489 " <INPUT type='email' id='email2'/>" | |
| 3490 " <INPUT type='tel' id='phone'/>" | |
| 3491 " <INPUT type='submit' value='Send'/>" | |
| 3492 "</FORM>"); | |
| 3493 | |
| 3494 WebFrame* web_frame = GetMainFrame(); | |
| 3495 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | |
| 3496 | |
| 3497 FormCache form_cache; | |
| 3498 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | |
| 3499 ASSERT_EQ(1U, forms.size()); | |
| 3500 | |
| 3501 WebInputElement firstname = | |
| 3502 web_frame->document().getElementById("firstname").to<WebInputElement>(); | |
| 3503 | |
| 3504 // Auto-filled attribute not set yet. | |
| 3505 EXPECT_FALSE(FormWithElementIsAutofilled(firstname)); | |
| 3506 | |
| 3507 // Set the auto-filled attribute. | |
| 3508 firstname.setAutofilled(true); | |
| 3509 | |
| 3510 EXPECT_TRUE(FormWithElementIsAutofilled(firstname)); | |
| 3511 } | |
| 3512 | |
| 3513 // If we have multiple labels per id, the labels concatenated into label string. | 3484 // If we have multiple labels per id, the labels concatenated into label string. |
| 3514 TEST_F(FormAutofillTest, MultipleLabelsPerElement) { | 3485 TEST_F(FormAutofillTest, MultipleLabelsPerElement) { |
| 3515 std::vector<base::string16> labels, names, values; | 3486 std::vector<base::string16> labels, names, values; |
| 3516 | 3487 |
| 3517 labels.push_back(ASCIIToUTF16("First Name:")); | 3488 labels.push_back(ASCIIToUTF16("First Name:")); |
| 3518 names.push_back(ASCIIToUTF16("firstname")); | 3489 names.push_back(ASCIIToUTF16("firstname")); |
| 3519 values.push_back(ASCIIToUTF16("John")); | 3490 values.push_back(ASCIIToUTF16("John")); |
| 3520 | 3491 |
| 3521 labels.push_back(ASCIIToUTF16("Last Name:")); | 3492 labels.push_back(ASCIIToUTF16("Last Name:")); |
| 3522 names.push_back(ASCIIToUTF16("lastname")); | 3493 names.push_back(ASCIIToUTF16("lastname")); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3654 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3625 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 3655 | 3626 |
| 3656 expected.name = ASCIIToUTF16("country"); | 3627 expected.name = ASCIIToUTF16("country"); |
| 3657 expected.value = ASCIIToUTF16("AL"); | 3628 expected.value = ASCIIToUTF16("AL"); |
| 3658 expected.form_control_type = "select-one"; | 3629 expected.form_control_type = "select-one"; |
| 3659 expected.max_length = 0; | 3630 expected.max_length = 0; |
| 3660 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3631 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 3661 } | 3632 } |
| 3662 | 3633 |
| 3663 } // namespace autofill | 3634 } // namespace autofill |
| OLD | NEW |