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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 using blink::WebVector; | 44 using blink::WebVector; |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 struct AutofillFieldCase { | 48 struct AutofillFieldCase { |
49 const char* const form_control_type; | 49 const char* const form_control_type; |
50 const char* const name; | 50 const char* const name; |
51 const char* const initial_value; | 51 const char* const initial_value; |
52 const char* const autocomplete_attribute; // The autocomplete attribute of | 52 const char* const autocomplete_attribute; // The autocomplete attribute of |
53 // the element. | 53 // the element. |
54 bool should_be_autofilled; // Whether the filed should be autofilled. | 54 bool is_autofilled; // Whether the FormFieldData field is autofilled. |
Ilya Sherman
2014/06/03 20:39:31
It seems like this is always identical to should_b
| |
55 bool should_be_autofilled; // Whether the filed should be autofilled. | |
55 const char* const autofill_value; // The value being used to fill the field. | 56 const char* const autofill_value; // The value being used to fill the field. |
56 const char* const expected_value; // The expected value after Autofill | 57 const char* const expected_value; // The expected value after Autofill |
57 // or Preview. | 58 // or Preview. |
58 }; | 59 }; |
59 | 60 |
60 static const char kFormHtml[] = | 61 static const char kFormHtml[] = |
61 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 62 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
62 " <INPUT type=\"text\" id=\"firstname\"/>" | 63 " <INPUT type=\"text\" id=\"firstname\"/>" |
63 " <INPUT type=\"text\" id=\"lastname\"/>" | 64 " <INPUT type=\"text\" id=\"lastname\"/>" |
64 " <INPUT type=\"hidden\" id=\"imhidden\"/>" | 65 " <INPUT type=\"hidden\" id=\"imhidden\"/>" |
65 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>" | 66 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>" |
66 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>" | 67 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>" |
67 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>" | 68 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>" |
68 " <INPUT type=\"text\" readonly id=\"readonly\"/>" | 69 " <INPUT type=\"text\" readonly id=\"readonly\"/>" |
69 " <INPUT type=\"text\" style=\"visibility: hidden\"" | 70 " <INPUT type=\"text\" style=\"visibility: hidden\"" |
70 " id=\"invisible\"/>" | 71 " id=\"invisible\"/>" |
71 " <INPUT type=\"text\" style=\"display: none\" id=\"displaynone\"/>" | 72 " <INPUT type=\"text\" style=\"display: none\" id=\"displaynone\"/>" |
72 " <INPUT type=\"month\" id=\"month\"/>" | 73 " <INPUT type=\"month\" id=\"month\"/>" |
73 " <INPUT type=\"month\" id=\"month-nonempty\" value=\"2011-12\"/>" | 74 " <INPUT type=\"month\" id=\"month-nonempty\" value=\"2011-12\"/>" |
74 " <SELECT id=\"select\">" | 75 " <SELECT id=\"select\">" |
75 " <OPTION></OPTION>" | 76 " <OPTION></OPTION>" |
76 " <OPTION value=\"CA\">California</OPTION>" | 77 " <OPTION value=\"CA\">California</OPTION>" |
77 " <OPTION value=\"TX\">Texas</OPTION>" | 78 " <OPTION value=\"TX\">Texas</OPTION>" |
78 " </SELECT>" | 79 " </SELECT>" |
79 " <SELECT id=\"select-nonempty\">" | 80 " <SELECT id=\"select-nonempty\">" |
80 " <OPTION value=\"CA\" selected>California</OPTION>" | 81 " <OPTION value=\"CA\" selected>California</OPTION>" |
81 " <OPTION value=\"TX\">Texas</OPTION>" | 82 " <OPTION value=\"TX\">Texas</OPTION>" |
82 " </SELECT>" | 83 " </SELECT>" |
84 " <SELECT id=\"select-nonewsuggestion\">" | |
Ilya Sherman
2014/06/03 20:39:31
nit: Perhaps "select-unchanged"?
| |
85 " <OPTION value=\"CA\" selected>California</OPTION>" | |
86 " <OPTION value=\"TX\">Texas</OPTION>" | |
87 " </SELECT>" | |
83 " <TEXTAREA id=\"textarea\"></TEXTAREA>" | 88 " <TEXTAREA id=\"textarea\"></TEXTAREA>" |
84 " <TEXTAREA id=\"textarea-nonempty\">Go away!</TEXTAREA>" | 89 " <TEXTAREA id=\"textarea-nonempty\">Go away!</TEXTAREA>" |
85 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 90 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
86 "</FORM>"; | 91 "</FORM>"; |
87 | 92 |
88 } // namespace | 93 } // namespace |
89 | 94 |
90 namespace autofill { | 95 namespace autofill { |
91 | 96 |
92 class FormAutofillTest : public ChromeRenderViewTest { | 97 class FormAutofillTest : public ChromeRenderViewTest { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 expected.form_control_type = field_cases[i].form_control_type; | 213 expected.form_control_type = field_cases[i].form_control_type; |
209 expected.max_length = | 214 expected.max_length = |
210 expected.form_control_type == "text" ? | 215 expected.form_control_type == "text" ? |
211 WebInputElement::defaultMaxLength() : 0; | 216 WebInputElement::defaultMaxLength() : 0; |
212 expected.name = ASCIIToUTF16(field_cases[i].name); | 217 expected.name = ASCIIToUTF16(field_cases[i].name); |
213 expected.value = ASCIIToUTF16(field_cases[i].initial_value); | 218 expected.value = ASCIIToUTF16(field_cases[i].initial_value); |
214 expected.autocomplete_attribute = field_cases[i].autocomplete_attribute; | 219 expected.autocomplete_attribute = field_cases[i].autocomplete_attribute; |
215 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[i]); | 220 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[i]); |
216 // Fill the form_data for the field. | 221 // Fill the form_data for the field. |
217 form_data.fields[i].value = ASCIIToUTF16(field_cases[i].autofill_value); | 222 form_data.fields[i].value = ASCIIToUTF16(field_cases[i].autofill_value); |
223 // Set the is_autofilled property for the field. | |
224 form_data.fields[i].is_autofilled = field_cases[i].is_autofilled; | |
218 } | 225 } |
219 | 226 |
220 // Autofill the form using the given fill form function. | 227 // Autofill the form using the given fill form function. |
221 fill_form_function(form_data, input_element); | 228 fill_form_function(form_data, input_element); |
222 | 229 |
223 // Validate Autofill or Preview results. | 230 // Validate Autofill or Preview results. |
224 for (size_t i = 0; i < number_of_field_cases; ++i) { | 231 for (size_t i = 0; i < number_of_field_cases; ++i) { |
225 ValidteFilledField(field_cases[i], get_value_function); | 232 ValidteFilledField(field_cases[i], get_value_function); |
226 } | 233 } |
227 } | 234 } |
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1317 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42"); | 1324 expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42"); |
1318 expected.form_control_type = "textarea"; | 1325 expected.form_control_type = "textarea"; |
1319 expected.max_length = 0; | 1326 expected.max_length = 0; |
1320 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); | 1327 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
1321 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); | 1328 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); |
1322 } | 1329 } |
1323 | 1330 |
1324 // Test regular FillForm function. | 1331 // Test regular FillForm function. |
1325 TEST_F(FormAutofillTest, FillForm) { | 1332 TEST_F(FormAutofillTest, FillForm) { |
1326 static const AutofillFieldCase field_cases[] = { | 1333 static const AutofillFieldCase field_cases[] = { |
1327 // fields: form_control_type, name, initial_value, autocomplete_attribute, | 1334 // fields: form_control_type, name, initial_value, |
1328 // should_be_autofilled, autofill_value, expected_value | 1335 // autocomplete_attribute, is_autofilled, should_be_autofilled, |
1336 // autofill_value, expected_value | |
1329 | 1337 |
1330 // Regular empty fields (firstname & lastname) should be autofilled. | 1338 // Regular empty fields (firstname & lastname) should be autofilled. |
1331 {"text", "firstname", "", "", true, "filled firstname", | 1339 {"text", "firstname", "", "", true, true, "filled firstname", |
1332 "filled firstname"}, | 1340 "filled firstname"}, |
1333 {"text", "lastname", "", "", true, "filled lastname", "filled lastname"}, | 1341 {"text", "lastname", "", "", true, true, "filled lastname", |
1342 "filled lastname"}, | |
1334 // hidden fields should not be extracted to form_data. | 1343 // hidden fields should not be extracted to form_data. |
1335 // Non empty fields should not be autofilled. | 1344 // Non empty fields should not be autofilled. |
1336 {"text", "notempty", "Hi", "", false, "filled notempty", "Hi"}, | 1345 {"text", "notempty", "Hi", "", false, false, "filled notempty", "Hi"}, |
1337 // "noautocomplete" should not be extracted to form_data. | 1346 // "noautocomplete" should not be extracted to form_data. |
1338 // Disabled fields should not be autofilled. | 1347 // Disabled fields should not be autofilled. |
1339 {"text", "notenabled", "", "", false, "filled notenabled", ""}, | 1348 {"text", "notenabled", "", "", false, false, "filled notenabled", ""}, |
1340 // Readonly fields should not be autofilled. | 1349 // Readonly fields should not be autofilled. |
1341 {"text", "readonly", "", "", false, "filled readonly", ""}, | 1350 {"text", "readonly", "", "", false, false, "filled readonly", ""}, |
1342 // Fields with "visibility: hidden" should not be autofilled. | 1351 // Fields with "visibility: hidden" should not be autofilled. |
1343 {"text", "invisible", "", "", false, "filled invisible", ""}, | 1352 {"text", "invisible", "", "", false, false, "filled invisible", ""}, |
1344 // Fields with "display:none" should not be autofilled. | 1353 // Fields with "display:none" should not be autofilled. |
1345 {"text", "displaynone", "", "", false, "filled displaynone", ""}, | 1354 {"text", "displaynone", "", "", false, false, "filled displaynone", ""}, |
1346 // Regular <input type="month"> should be autofilled. | 1355 // Regular <input type="month"> should be autofilled. |
1347 {"month", "month", "", "", true, "2017-11", "2017-11"}, | 1356 {"month", "month", "", "", true, true, "2017-11", "2017-11"}, |
1348 // Non-empty <input type="month"> should not be autofilled. | 1357 // Non-empty <input type="month"> should not be autofilled. |
1349 {"month", "month-nonempty", "2011-12", "", false, "2017-11", "2011-12"}, | 1358 {"month", "month-nonempty", "2011-12", "", false, false, "2017-11", |
1359 "2011-12"}, | |
1350 // Regular select fields should be autofilled. | 1360 // Regular select fields should be autofilled. |
1351 {"select-one", "select", "", "", true, "TX", "TX"}, | 1361 {"select-one", "select", "", "", true, true, "TX", "TX"}, |
1352 // Select fields should be autofilled even if they already have a | 1362 // Select fields should be autofilled even if they already have a |
1353 // non-empty value. | 1363 // non-empty value. |
1354 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"}, | 1364 {"select-one", "select-nonempty", "CA", "", true, true, "TX", "TX"}, |
1365 // Select fields should not be autofilled if no new value is passed from | |
1366 // autofill profile. The existing value should not be overriden. | |
1367 {"select-one", "select-nonewsuggestion", "CA", "", false, false, "CA", | |
1368 "CA"}, | |
1355 // Regular textarea elements should be autofilled. | 1369 // Regular textarea elements should be autofilled. |
1356 {"textarea", "textarea", "", "", true, "some multi-\nline value", | 1370 {"textarea", "textarea", "", "", true, true, "some multi-\nline value", |
1357 "some multi-\nline value"}, | 1371 "some multi-\nline value"}, |
1358 // Non-empty textarea elements should not be autofilled. | 1372 // Non-empty textarea elements should not be autofilled. |
1359 {"textarea", "textarea-nonempty", "Go\naway!", "", false, | 1373 {"textarea", "textarea-nonempty", "Go\naway!", "", false, false, |
1360 "some multi-\nline value", "Go\naway!"}, | 1374 "some multi-\nline value", "Go\naway!"}, |
1361 }; | 1375 }; |
1362 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), | 1376 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), |
1363 FillForm, &GetValueWrapper); | 1377 FillForm, &GetValueWrapper); |
1364 // Verify preview selection. | 1378 // Verify preview selection. |
1365 WebInputElement firstname = GetMainFrame()->document(). | 1379 WebInputElement firstname = GetMainFrame()->document(). |
1366 getElementById("firstname").to<WebInputElement>(); | 1380 getElementById("firstname").to<WebInputElement>(); |
1367 EXPECT_EQ(16, firstname.selectionStart()); | 1381 EXPECT_EQ(16, firstname.selectionStart()); |
1368 EXPECT_EQ(16, firstname.selectionEnd()); | 1382 EXPECT_EQ(16, firstname.selectionEnd()); |
1369 } | 1383 } |
1370 | 1384 |
1371 TEST_F(FormAutofillTest, FillFormIncludingNonFocusableElements) { | 1385 TEST_F(FormAutofillTest, FillFormIncludingNonFocusableElements) { |
1372 static const AutofillFieldCase field_cases[] = { | 1386 static const AutofillFieldCase field_cases[] = { |
1373 // fields: form_control_type, name, initial_value, autocomplete_attribute, | 1387 // fields: form_control_type, name, initial_value, |
1374 // should_be_autofilled, autofill_value, expected_value | 1388 // autocomplete_attribute, is_autofilled, should_be_autofilled, |
1389 // autofill_value, expected_value | |
1375 | 1390 |
1376 // Regular empty fields (firstname & lastname) should be autofilled. | 1391 // Regular empty fields (firstname & lastname) should be autofilled. |
1377 {"text", "firstname", "", "", true, "filled firstname", | 1392 {"text", "firstname", "", "", true, true, "filled firstname", |
1378 "filled firstname"}, | 1393 "filled firstname"}, |
1379 {"text", "lastname", "", "", true, "filled lastname", "filled lastname"}, | 1394 {"text", "lastname", "", "", true, true, "filled lastname", |
1395 "filled lastname"}, | |
1380 // hidden fields should not be extracted to form_data. | 1396 // hidden fields should not be extracted to form_data. |
1381 // Non empty fields should be overriden. | 1397 // Non empty fields should be overriden. |
1382 {"text", "notempty", "Hi", "", true, "filled notempty", | 1398 {"text", "notempty", "Hi", "", true, true, "filled notempty", |
1383 "filled notempty"}, | 1399 "filled notempty"}, |
1384 // "noautocomplete" should not be extracted to form_data. | 1400 // "noautocomplete" should not be extracted to form_data. |
1385 // Disabled fields should not be autofilled. | 1401 // Disabled fields should not be autofilled. |
1386 {"text", "notenabled", "", "", false, "filled notenabled", ""}, | 1402 {"text", "notenabled", "", "", false, false, "filled notenabled", ""}, |
1387 // Readonly fields should not be autofilled. | 1403 // Readonly fields should not be autofilled. |
1388 {"text", "readonly", "", "", false, "filled readonly", ""}, | 1404 {"text", "readonly", "", "", false, false, "filled readonly", ""}, |
1389 // Fields with "visibility: hidden" should also be autofilled. | 1405 // Fields with "visibility: hidden" should also be autofilled. |
1390 {"text", "invisible", "", "", true, "filled invisible", | 1406 {"text", "invisible", "", "", true, true, "filled invisible", |
1391 "filled invisible"}, | 1407 "filled invisible"}, |
1392 // Fields with "display:none" should also be autofilled. | 1408 // Fields with "display:none" should also be autofilled. |
1393 {"text", "displaynone", "", "", true, "filled displaynone", | 1409 {"text", "displaynone", "", "", true, true, "filled displaynone", |
1394 "filled displaynone"}, | 1410 "filled displaynone"}, |
1395 // Regular <input type="month"> should be autofilled. | 1411 // Regular <input type="month"> should be autofilled. |
1396 {"month", "month", "", "", true, "2017-11", "2017-11"}, | 1412 {"month", "month", "", "", true, true, "2017-11", "2017-11"}, |
1397 // Non-empty <input type="month"> should be overridden. | 1413 // Non-empty <input type="month"> should be overridden. |
1398 {"month", "month-nonempty", "2011-12", "", true, "2017-11", "2017-11"}, | 1414 {"month", "month-nonempty", "2011-12", "", true, true, "2017-11", |
1415 "2017-11"}, | |
1399 // Regular select fields should be autofilled. | 1416 // Regular select fields should be autofilled. |
1400 {"select-one", "select", "", "", true, "TX", "TX"}, | 1417 {"select-one", "select", "", "", true, true, "TX", "TX"}, |
1401 // Select fields should be autofilled even if they already have a | 1418 // Select fields should be autofilled even if they already have a |
1402 // non-empty value. | 1419 // non-empty value. |
1403 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"}, | 1420 {"select-one", "select-nonempty", "CA", "", true, true, "TX", "TX"}, |
1421 // Select fields should not be autofilled if no new value is passed from | |
1422 // autofill profile. The existing value should not be overriden. | |
1423 {"select-one", "select-nonewsuggestion", "CA", "", false, false, "CA", | |
1424 "CA"}, | |
1404 // Regular textarea elements should be autofilled. | 1425 // Regular textarea elements should be autofilled. |
1405 {"textarea", "textarea", "", "", true, "some multi-\nline value", | 1426 {"textarea", "textarea", "", "", true, true, "some multi-\nline value", |
1406 "some multi-\nline value"}, | 1427 "some multi-\nline value"}, |
1407 // Nonempty textarea elements should be overridden. | 1428 // Nonempty textarea elements should be overridden. |
1408 {"textarea", "textarea-nonempty", "Go\naway!", "", true, | 1429 {"textarea", "textarea-nonempty", "Go\naway!", "", true, true, |
1409 "some multi-\nline value", "some multi-\nline value"}, | 1430 "some multi-\nline value", "some multi-\nline value"}, |
1410 }; | 1431 }; |
1411 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), | 1432 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), |
1412 &FillFormIncludingNonFocusableElementsWrapper, | 1433 &FillFormIncludingNonFocusableElementsWrapper, |
1413 &GetValueWrapper); | 1434 &GetValueWrapper); |
1414 } | 1435 } |
1415 | 1436 |
1416 TEST_F(FormAutofillTest, PreviewForm) { | 1437 TEST_F(FormAutofillTest, PreviewForm) { |
1417 static const AutofillFieldCase field_cases[] = { | 1438 static const AutofillFieldCase field_cases[] = { |
1418 // Normal empty fields should be previewed. | 1439 // Normal empty fields should be previewed. |
1419 {"text", "firstname", "", "", true, "suggested firstname", | 1440 {"text", "firstname", "", "", true, true, "suggested firstname", |
1420 "suggested firstname"}, | 1441 "suggested firstname"}, |
1421 {"text", "lastname", "", "", true, "suggested lastname", | 1442 {"text", "lastname", "", "", true, true, "suggested lastname", |
1422 "suggested lastname"}, | 1443 "suggested lastname"}, |
1423 // Hidden fields should not be extracted to form_data. | 1444 // Hidden fields should not be extracted to form_data. |
1424 // Non empty fields should not be previewed. | 1445 // Non empty fields should not be previewed. |
1425 {"text", "notempty", "Hi", "", false, "suggested notempty", ""}, | 1446 {"text", "notempty", "Hi", "", false, false, "suggested notempty", ""}, |
1426 // "noautocomplete" should not be extracted to form_data. | 1447 // "noautocomplete" should not be extracted to form_data. |
1427 // Disabled fields should not be previewed. | 1448 // Disabled fields should not be previewed. |
1428 {"text", "notenabled", "", "", false, "suggested notenabled", ""}, | 1449 {"text", "notenabled", "", "", false, false, "suggested notenabled", ""}, |
1429 // Readonly fields should not be previewed. | 1450 // Readonly fields should not be previewed. |
1430 {"text", "readonly", "", "", false, "suggested readonly", ""}, | 1451 {"text", "readonly", "", "", false, false, "suggested readonly", ""}, |
1431 // Fields with "visibility: hidden" should not be previewed. | 1452 // Fields with "visibility: hidden" should not be previewed. |
1432 {"text", "invisible", "", "", false, "suggested invisible", | 1453 {"text", "invisible", "", "", false, false, "suggested invisible", |
1433 ""}, | 1454 ""}, |
1434 // Fields with "display:none" should not previewed. | 1455 // Fields with "display:none" should not previewed. |
1435 {"text", "displaynone", "", "", false, "suggested displaynone", | 1456 {"text", "displaynone", "", "", false, false, "suggested displaynone", |
1436 ""}, | 1457 ""}, |
1437 // Regular <input type="month"> should be previewed. | 1458 // Regular <input type="month"> should be previewed. |
1438 {"month", "month", "", "", true, "2017-11", "2017-11"}, | 1459 {"month", "month", "", "", true, true, "2017-11", "2017-11"}, |
1439 // Non-empty <input type="month"> should not be previewed. | 1460 // Non-empty <input type="month"> should not be previewed. |
1440 {"month", "month-nonempty", "2011-12", "", false, "2017-11", ""}, | 1461 {"month", "month-nonempty", "2011-12", "", false, false, "2017-11", ""}, |
1441 // Regular select fields should be previewed. | 1462 // Regular select fields should be previewed. |
1442 {"select-one", "select", "", "", true, "TX", "TX"}, | 1463 {"select-one", "select", "", "", true, true, "TX", "TX"}, |
1443 // Select fields should be previewed even if they already have a | 1464 // Select fields should be previewed even if they already have a |
1444 // non-empty value. | 1465 // non-empty value. |
1445 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"}, | 1466 {"select-one", "select-nonempty", "CA", "", true, true, "TX", "TX"}, |
1467 // Select fields should not be previewed if no suggestion is passed from | |
1468 // autofill profile. | |
1469 {"select-one", "select-nonewsuggestion", "CA", "", false, false, "", | |
1470 ""}, | |
1446 // Normal textarea elements should be previewed. | 1471 // Normal textarea elements should be previewed. |
1447 {"textarea", "textarea", "", "", true, "suggested multi-\nline value", | 1472 {"textarea", "textarea", "", "", true, true, |
1448 "suggested multi-\nline value"}, | 1473 "suggested multi-\nline value", "suggested multi-\nline value"}, |
1449 // Nonempty textarea elements should not be previewed. | 1474 // Nonempty textarea elements should not be previewed. |
1450 {"textarea", "textarea-nonempty", "Go\naway!", "", false, | 1475 {"textarea", "textarea-nonempty", "Go\naway!", "", false, false, |
1451 "suggested multi-\nline value", ""}, | 1476 "suggested multi-\nline value", ""}, |
1452 }; | 1477 }; |
1453 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), | 1478 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), |
1454 &PreviewForm, &GetSuggestedValueWrapper); | 1479 &PreviewForm, &GetSuggestedValueWrapper); |
1455 | 1480 |
1456 // Verify preview selection. | 1481 // Verify preview selection. |
1457 WebInputElement firstname = GetMainFrame()->document(). | 1482 WebInputElement firstname = GetMainFrame()->document(). |
1458 getElementById("firstname").to<WebInputElement>(); | 1483 getElementById("firstname").to<WebInputElement>(); |
1459 EXPECT_EQ(0, firstname.selectionStart()); | 1484 EXPECT_EQ(0, firstname.selectionStart()); |
1460 EXPECT_EQ(19, firstname.selectionEnd()); | 1485 EXPECT_EQ(19, firstname.selectionEnd()); |
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2369 | 2394 |
2370 expected.name = ASCIIToUTF16("email"); | 2395 expected.name = ASCIIToUTF16("email"); |
2371 expected.max_length = 9; | 2396 expected.max_length = 9; |
2372 expected.is_autofilled = false; | 2397 expected.is_autofilled = false; |
2373 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 2398 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
2374 | 2399 |
2375 // Fill the form. | 2400 // Fill the form. |
2376 form.fields[0].value = ASCIIToUTF16("Brother"); | 2401 form.fields[0].value = ASCIIToUTF16("Brother"); |
2377 form.fields[1].value = ASCIIToUTF16("Jonathan"); | 2402 form.fields[1].value = ASCIIToUTF16("Jonathan"); |
2378 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); | 2403 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); |
2404 form.fields[0].is_autofilled = true; | |
2405 form.fields[1].is_autofilled = true; | |
2406 form.fields[2].is_autofilled = true; | |
2379 FillForm(form, input_element); | 2407 FillForm(form, input_element); |
2380 | 2408 |
2381 // Find the newly-filled form that contains the input element. | 2409 // Find the newly-filled form that contains the input element. |
2382 FormData form2; | 2410 FormData form2; |
2383 FormFieldData field2; | 2411 FormFieldData field2; |
2384 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | 2412 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, |
2385 &form2, | 2413 &form2, |
2386 &field2, | 2414 &field2, |
2387 autofill::REQUIRE_NONE)); | 2415 autofill::REQUIRE_NONE)); |
2388 | 2416 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2635 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 2663 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
2636 | 2664 |
2637 expected.name = ASCIIToUTF16("cantelope"); | 2665 expected.name = ASCIIToUTF16("cantelope"); |
2638 expected.is_autofilled = false; | 2666 expected.is_autofilled = false; |
2639 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 2667 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
2640 | 2668 |
2641 // Fill the form. | 2669 // Fill the form. |
2642 form.fields[0].value = ASCIIToUTF16("Red"); | 2670 form.fields[0].value = ASCIIToUTF16("Red"); |
2643 form.fields[1].value = ASCIIToUTF16("Yellow"); | 2671 form.fields[1].value = ASCIIToUTF16("Yellow"); |
2644 form.fields[2].value = ASCIIToUTF16("Also Yellow"); | 2672 form.fields[2].value = ASCIIToUTF16("Also Yellow"); |
2673 form.fields[0].is_autofilled = true; | |
2674 form.fields[1].is_autofilled = true; | |
2675 form.fields[2].is_autofilled = true; | |
2645 FillForm(form, input_element); | 2676 FillForm(form, input_element); |
2646 | 2677 |
2647 // Find the newly-filled form that contains the input element. | 2678 // Find the newly-filled form that contains the input element. |
2648 FormData form2; | 2679 FormData form2; |
2649 FormFieldData field2; | 2680 FormFieldData field2; |
2650 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | 2681 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, |
2651 &form2, | 2682 &form2, |
2652 &field2, | 2683 &field2, |
2653 autofill::REQUIRE_NONE)); | 2684 autofill::REQUIRE_NONE)); |
2654 | 2685 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2861 | 2892 |
2862 expected.name = ASCIIToUTF16("email"); | 2893 expected.name = ASCIIToUTF16("email"); |
2863 expected.value = base::string16(); | 2894 expected.value = base::string16(); |
2864 expected.is_autofilled = false; | 2895 expected.is_autofilled = false; |
2865 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 2896 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
2866 | 2897 |
2867 // Preview the form and verify that the cursor position has been updated. | 2898 // Preview the form and verify that the cursor position has been updated. |
2868 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 2899 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
2869 form.fields[1].value = ASCIIToUTF16("Earp"); | 2900 form.fields[1].value = ASCIIToUTF16("Earp"); |
2870 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); | 2901 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); |
2902 form.fields[0].is_autofilled = true; | |
2903 form.fields[1].is_autofilled = true; | |
2904 form.fields[2].is_autofilled = true; | |
2871 PreviewForm(form, input_element); | 2905 PreviewForm(form, input_element); |
2872 EXPECT_EQ(2, input_element.selectionStart()); | 2906 EXPECT_EQ(2, input_element.selectionStart()); |
2873 EXPECT_EQ(5, input_element.selectionEnd()); | 2907 EXPECT_EQ(5, input_element.selectionEnd()); |
2874 | 2908 |
2875 // Fill the form. | 2909 // Fill the form. |
2876 FillForm(form, input_element); | 2910 FillForm(form, input_element); |
2877 | 2911 |
2878 // Find the newly-filled form that contains the input element. | 2912 // Find the newly-filled form that contains the input element. |
2879 FormData form2; | 2913 FormData form2; |
2880 FormFieldData field2; | 2914 FormFieldData field2; |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3472 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3506 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
3473 | 3507 |
3474 expected.name = ASCIIToUTF16("country"); | 3508 expected.name = ASCIIToUTF16("country"); |
3475 expected.value = ASCIIToUTF16("AL"); | 3509 expected.value = ASCIIToUTF16("AL"); |
3476 expected.form_control_type = "select-one"; | 3510 expected.form_control_type = "select-one"; |
3477 expected.max_length = 0; | 3511 expected.max_length = 0; |
3478 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3512 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
3479 } | 3513 } |
3480 | 3514 |
3481 } // namespace autofill | 3515 } // namespace autofill |
OLD | NEW |