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