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/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1448 // should_be_autofilled, autofill_value, expected_value | 1448 // should_be_autofilled, autofill_value, expected_value |
1449 | 1449 |
1450 // Regular empty fields (firstname & lastname) should be autofilled. | 1450 // Regular empty fields (firstname & lastname) should be autofilled. |
1451 {"text", "firstname", "", "", true, "filled firstname", | 1451 {"text", "firstname", "", "", true, "filled firstname", |
1452 "filled firstname"}, | 1452 "filled firstname"}, |
1453 {"text", "lastname", "", "", true, "filled lastname", "filled lastname"}, | 1453 {"text", "lastname", "", "", true, "filled lastname", "filled lastname"}, |
1454 // hidden fields should not be extracted to form_data. | 1454 // hidden fields should not be extracted to form_data. |
1455 // Non empty fields should not be autofilled. | 1455 // Non empty fields should not be autofilled. |
1456 {"text", "notempty", "Hi", "", false, "filled notempty", "Hi"}, | 1456 {"text", "notempty", "Hi", "", false, "filled notempty", "Hi"}, |
1457 // "noautocomplete" should not be extracted to form_data. | 1457 // "noautocomplete" should not be extracted to form_data. |
1458 // Disabled fields should not be extracted to form_data. | 1458 // Disabled fields should not be autofilled. |
1459 // Readonly fields should not be extracted to form_data. | 1459 {"text", "notenabled", "", "", false, "filled notenabled", ""}, |
| 1460 // Readonly fields should not be autofilled. |
| 1461 {"text", "readonly", "", "", false, "filled readonly", ""}, |
1460 // Fields with "visibility: hidden" should not be autofilled. | 1462 // Fields with "visibility: hidden" should not be autofilled. |
1461 {"text", "invisible", "", "", false, "filled invisible", ""}, | 1463 {"text", "invisible", "", "", false, "filled invisible", ""}, |
1462 // Fields with "display:none" should not be autofilled. | 1464 // Fields with "display:none" should not be autofilled. |
1463 {"text", "displaynone", "", "", false, "filled displaynone", ""}, | 1465 {"text", "displaynone", "", "", false, "filled displaynone", ""}, |
1464 // Regular <input type="month"> should be autofilled. | 1466 // Regular <input type="month"> should be autofilled. |
1465 {"month", "month", "", "", true, "2017-11", "2017-11"}, | 1467 {"month", "month", "", "", true, "2017-11", "2017-11"}, |
1466 // Non-empty <input type="month"> should not be autofilled. | 1468 // Non-empty <input type="month"> should not be autofilled. |
1467 {"month", "month-nonempty", "2011-12", "", false, "2017-11", "2011-12"}, | 1469 {"month", "month-nonempty", "2011-12", "", false, "2017-11", "2011-12"}, |
1468 // Regular select fields should be autofilled. | 1470 // Regular select fields should be autofilled. |
1469 {"select-one", "select", "", "", true, "TX", "TX"}, | 1471 {"select-one", "select", "", "", true, "TX", "TX"}, |
(...skipping 26 matching lines...) Expand all Loading... |
1496 | 1498 |
1497 // Regular empty fields (firstname & lastname) should be autofilled. | 1499 // Regular empty fields (firstname & lastname) should be autofilled. |
1498 {"text", "firstname", "", "", true, "filled firstname", | 1500 {"text", "firstname", "", "", true, "filled firstname", |
1499 "filled firstname"}, | 1501 "filled firstname"}, |
1500 {"text", "lastname", "", "", true, "filled lastname", "filled lastname"}, | 1502 {"text", "lastname", "", "", true, "filled lastname", "filled lastname"}, |
1501 // hidden fields should not be extracted to form_data. | 1503 // hidden fields should not be extracted to form_data. |
1502 // Non empty fields should be overriden. | 1504 // Non empty fields should be overriden. |
1503 {"text", "notempty", "Hi", "", true, "filled notempty", | 1505 {"text", "notempty", "Hi", "", true, "filled notempty", |
1504 "filled notempty"}, | 1506 "filled notempty"}, |
1505 // "noautocomplete" should not be extracted to form_data. | 1507 // "noautocomplete" should not be extracted to form_data. |
1506 // Disabled fields should not be extracted to form_data. | 1508 // Disabled fields should not be autofilled. |
1507 // Readonly fields should not be extracted to form_data. | 1509 {"text", "notenabled", "", "", false, "filled notenabled", ""}, |
| 1510 // Readonly fields should not be autofilled. |
| 1511 {"text", "readonly", "", "", false, "filled readonly", ""}, |
1508 // Fields with "visibility: hidden" should also be autofilled. | 1512 // Fields with "visibility: hidden" should also be autofilled. |
1509 {"text", "invisible", "", "", true, "filled invisible", | 1513 {"text", "invisible", "", "", true, "filled invisible", |
1510 "filled invisible"}, | 1514 "filled invisible"}, |
1511 // Fields with "display:none" should also be autofilled. | 1515 // Fields with "display:none" should also be autofilled. |
1512 {"text", "displaynone", "", "", true, "filled displaynone", | 1516 {"text", "displaynone", "", "", true, "filled displaynone", |
1513 "filled displaynone"}, | 1517 "filled displaynone"}, |
1514 // Regular <input type="month"> should be autofilled. | 1518 // Regular <input type="month"> should be autofilled. |
1515 {"month", "month", "", "", true, "2017-11", "2017-11"}, | 1519 {"month", "month", "", "", true, "2017-11", "2017-11"}, |
1516 // Non-empty <input type="month"> should be overridden. | 1520 // Non-empty <input type="month"> should be overridden. |
1517 {"month", "month-nonempty", "2011-12", "", true, "2017-11", "2017-11"}, | 1521 {"month", "month-nonempty", "2011-12", "", true, "2017-11", "2017-11"}, |
(...skipping 21 matching lines...) Expand all Loading... |
1539 static const AutofillFieldCase field_cases[] = { | 1543 static const AutofillFieldCase field_cases[] = { |
1540 // Normal empty fields should be previewed. | 1544 // Normal empty fields should be previewed. |
1541 {"text", "firstname", "", "", true, "suggested firstname", | 1545 {"text", "firstname", "", "", true, "suggested firstname", |
1542 "suggested firstname"}, | 1546 "suggested firstname"}, |
1543 {"text", "lastname", "", "", true, "suggested lastname", | 1547 {"text", "lastname", "", "", true, "suggested lastname", |
1544 "suggested lastname"}, | 1548 "suggested lastname"}, |
1545 // Hidden fields should not be extracted to form_data. | 1549 // Hidden fields should not be extracted to form_data. |
1546 // Non empty fields should not be previewed. | 1550 // Non empty fields should not be previewed. |
1547 {"text", "notempty", "Hi", "", false, "suggested notempty", ""}, | 1551 {"text", "notempty", "Hi", "", false, "suggested notempty", ""}, |
1548 // "noautocomplete" should not be extracted to form_data. | 1552 // "noautocomplete" should not be extracted to form_data. |
1549 // Disabled fields should not be extracted to form_data. | 1553 // Disabled fields should not be previewed. |
1550 // Readonly fields should not be extracted to form_data. | 1554 {"text", "notenabled", "", "", false, "suggested notenabled", ""}, |
| 1555 // Readonly fields should not be previewed. |
| 1556 {"text", "readonly", "", "", false, "suggested readonly", ""}, |
1551 // Fields with "visibility: hidden" should not be previewed. | 1557 // Fields with "visibility: hidden" should not be previewed. |
1552 {"text", "invisible", "", "", false, "suggested invisible", | 1558 {"text", "invisible", "", "", false, "suggested invisible", |
1553 ""}, | 1559 ""}, |
1554 // Fields with "display:none" should not previewed. | 1560 // Fields with "display:none" should not previewed. |
1555 {"text", "displaynone", "", "", false, "suggested displaynone", | 1561 {"text", "displaynone", "", "", false, "suggested displaynone", |
1556 ""}, | 1562 ""}, |
1557 // Regular <input type="month"> should be previewed. | 1563 // Regular <input type="month"> should be previewed. |
1558 {"month", "month", "", "", true, "2017-11", "2017-11"}, | 1564 {"month", "month", "", "", true, "2017-11", "2017-11"}, |
1559 // Non-empty <input type="month"> should not be previewed. | 1565 // Non-empty <input type="month"> should not be previewed. |
1560 {"month", "month-nonempty", "2011-12", "", false, "2017-11", ""}, | 1566 {"month", "month-nonempty", "2011-12", "", false, "2017-11", ""}, |
(...skipping 1537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3098 FormFieldData field2; | 3104 FormFieldData field2; |
3099 EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname, | 3105 EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname, |
3100 &form2, | 3106 &form2, |
3101 &field2, | 3107 &field2, |
3102 autofill::REQUIRE_NONE)); | 3108 autofill::REQUIRE_NONE)); |
3103 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 3109 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
3104 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 3110 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
3105 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 3111 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
3106 | 3112 |
3107 const std::vector<FormFieldData>& fields2 = form2.fields; | 3113 const std::vector<FormFieldData>& fields2 = form2.fields; |
3108 ASSERT_EQ(6U, fields2.size()); | 3114 ASSERT_EQ(9U, fields2.size()); |
3109 | 3115 |
3110 FormFieldData expected; | 3116 FormFieldData expected; |
3111 expected.form_control_type = "text"; | 3117 expected.form_control_type = "text"; |
3112 expected.max_length = WebInputElement::defaultMaxLength(); | 3118 expected.max_length = WebInputElement::defaultMaxLength(); |
3113 | 3119 |
3114 expected.name = ASCIIToUTF16("firstname"); | 3120 expected.name = ASCIIToUTF16("firstname"); |
3115 expected.value = base::string16(); | 3121 expected.value = base::string16(); |
3116 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); | 3122 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
3117 | 3123 |
3118 expected.name = ASCIIToUTF16("lastname"); | 3124 expected.name = ASCIIToUTF16("lastname"); |
3119 expected.value = base::string16(); | 3125 expected.value = base::string16(); |
3120 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); | 3126 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
3121 | 3127 |
3122 expected.name = ASCIIToUTF16("noAC"); | 3128 expected.name = ASCIIToUTF16("noAC"); |
3123 expected.value = ASCIIToUTF16("one"); | 3129 expected.value = ASCIIToUTF16("one"); |
3124 expected.autocomplete_attribute = "off"; | 3130 expected.autocomplete_attribute = "off"; |
3125 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 3131 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
3126 expected.autocomplete_attribute = std::string(); // reset | 3132 expected.autocomplete_attribute = std::string(); // reset |
3127 | 3133 |
| 3134 expected.name = ASCIIToUTF16("notenabled"); |
| 3135 expected.value = ASCIIToUTF16("no clear"); |
| 3136 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[3]); |
| 3137 |
3128 expected.form_control_type = "month"; | 3138 expected.form_control_type = "month"; |
3129 expected.max_length = 0; | 3139 expected.max_length = 0; |
3130 expected.name = ASCIIToUTF16("month"); | 3140 expected.name = ASCIIToUTF16("month"); |
3131 expected.value = base::string16(); | 3141 expected.value = base::string16(); |
3132 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[3]); | 3142 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[4]); |
| 3143 |
| 3144 expected.name = ASCIIToUTF16("month-disabled"); |
| 3145 expected.value = ASCIIToUTF16("2012-11"); |
| 3146 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[5]); |
3133 | 3147 |
3134 expected.form_control_type = "textarea"; | 3148 expected.form_control_type = "textarea"; |
3135 expected.name = ASCIIToUTF16("textarea"); | 3149 expected.name = ASCIIToUTF16("textarea"); |
3136 expected.value = base::string16(); | 3150 expected.value = base::string16(); |
3137 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[4]); | 3151 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[6]); |
| 3152 |
| 3153 expected.name = ASCIIToUTF16("textarea-disabled"); |
| 3154 expected.value = ASCIIToUTF16(" Banana! "); |
| 3155 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[7]); |
3138 | 3156 |
3139 expected.name = ASCIIToUTF16("textarea-noAC"); | 3157 expected.name = ASCIIToUTF16("textarea-noAC"); |
3140 expected.value = ASCIIToUTF16("Carrot?"); | 3158 expected.value = ASCIIToUTF16("Carrot?"); |
3141 expected.autocomplete_attribute = "off"; | 3159 expected.autocomplete_attribute = "off"; |
3142 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[5]); | 3160 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[8]); |
3143 expected.autocomplete_attribute = std::string(); // reset | 3161 expected.autocomplete_attribute = std::string(); // reset |
3144 | 3162 |
3145 // Verify that the cursor position has been updated. | 3163 // Verify that the cursor position has been updated. |
3146 EXPECT_EQ(0, firstname.selectionStart()); | 3164 EXPECT_EQ(0, firstname.selectionStart()); |
3147 EXPECT_EQ(0, firstname.selectionEnd()); | 3165 EXPECT_EQ(0, firstname.selectionEnd()); |
3148 } | 3166 } |
3149 | 3167 |
3150 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) { | 3168 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) { |
3151 LoadHTML( | 3169 LoadHTML( |
3152 "<FORM name='TestForm' action='http://buh.com' method='post'>" | 3170 "<FORM name='TestForm' action='http://buh.com' method='post'>" |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3656 expected.max_length = WebInputElement::defaultMaxLength(); | 3674 expected.max_length = WebInputElement::defaultMaxLength(); |
3657 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3675 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
3658 | 3676 |
3659 expected.name = ASCIIToUTF16("country"); | 3677 expected.name = ASCIIToUTF16("country"); |
3660 expected.value = ASCIIToUTF16("AL"); | 3678 expected.value = ASCIIToUTF16("AL"); |
3661 expected.form_control_type = "select-one"; | 3679 expected.form_control_type = "select-one"; |
3662 expected.max_length = 0; | 3680 expected.max_length = 0; |
3663 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3681 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
3664 } | 3682 } |
3665 } // namespace autofill | 3683 } // namespace autofill |
OLD | NEW |