Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/renderer/autofill/form_autofill_browsertest.cc

Issue 309063006: Do not autofill element when there is no autofill suggestion from profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update code as per further review comments. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill/content/browser/request_autocomplete_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 " <INPUT type=\"month\" id=\"month-nonempty\" value=\"2011-12\"/>" 73 " <INPUT type=\"month\" id=\"month-nonempty\" value=\"2011-12\"/>"
74 " <SELECT id=\"select\">" 74 " <SELECT id=\"select\">"
75 " <OPTION></OPTION>" 75 " <OPTION></OPTION>"
76 " <OPTION value=\"CA\">California</OPTION>" 76 " <OPTION value=\"CA\">California</OPTION>"
77 " <OPTION value=\"TX\">Texas</OPTION>" 77 " <OPTION value=\"TX\">Texas</OPTION>"
78 " </SELECT>" 78 " </SELECT>"
79 " <SELECT id=\"select-nonempty\">" 79 " <SELECT id=\"select-nonempty\">"
80 " <OPTION value=\"CA\" selected>California</OPTION>" 80 " <OPTION value=\"CA\" selected>California</OPTION>"
81 " <OPTION value=\"TX\">Texas</OPTION>" 81 " <OPTION value=\"TX\">Texas</OPTION>"
82 " </SELECT>" 82 " </SELECT>"
83 " <SELECT id=\"select-unchanged\">"
84 " <OPTION value=\"CA\" selected>California</OPTION>"
85 " <OPTION value=\"TX\">Texas</OPTION>"
86 " </SELECT>"
83 " <TEXTAREA id=\"textarea\"></TEXTAREA>" 87 " <TEXTAREA id=\"textarea\"></TEXTAREA>"
84 " <TEXTAREA id=\"textarea-nonempty\">Go&#10;away!</TEXTAREA>" 88 " <TEXTAREA id=\"textarea-nonempty\">Go&#10;away!</TEXTAREA>"
85 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" 89 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
86 "</FORM>"; 90 "</FORM>";
87 91
88 } // namespace 92 } // namespace
89 93
90 namespace autofill { 94 namespace autofill {
91 95
92 class FormAutofillTest : public ChromeRenderViewTest { 96 class FormAutofillTest : public ChromeRenderViewTest {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 expected.form_control_type = field_cases[i].form_control_type; 212 expected.form_control_type = field_cases[i].form_control_type;
209 expected.max_length = 213 expected.max_length =
210 expected.form_control_type == "text" ? 214 expected.form_control_type == "text" ?
211 WebInputElement::defaultMaxLength() : 0; 215 WebInputElement::defaultMaxLength() : 0;
212 expected.name = ASCIIToUTF16(field_cases[i].name); 216 expected.name = ASCIIToUTF16(field_cases[i].name);
213 expected.value = ASCIIToUTF16(field_cases[i].initial_value); 217 expected.value = ASCIIToUTF16(field_cases[i].initial_value);
214 expected.autocomplete_attribute = field_cases[i].autocomplete_attribute; 218 expected.autocomplete_attribute = field_cases[i].autocomplete_attribute;
215 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[i]); 219 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[i]);
216 // Fill the form_data for the field. 220 // Fill the form_data for the field.
217 form_data.fields[i].value = ASCIIToUTF16(field_cases[i].autofill_value); 221 form_data.fields[i].value = ASCIIToUTF16(field_cases[i].autofill_value);
222 // Set the is_autofilled property for the field.
223 form_data.fields[i].is_autofilled = field_cases[i].should_be_autofilled;
218 } 224 }
219 225
220 // Autofill the form using the given fill form function. 226 // Autofill the form using the given fill form function.
221 fill_form_function(form_data, input_element); 227 fill_form_function(form_data, input_element);
222 228
223 // Validate Autofill or Preview results. 229 // Validate Autofill or Preview results.
224 for (size_t i = 0; i < number_of_field_cases; ++i) { 230 for (size_t i = 0; i < number_of_field_cases; ++i) {
225 ValidteFilledField(field_cases[i], get_value_function); 231 ValidteFilledField(field_cases[i], get_value_function);
226 } 232 }
227 } 233 }
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 {"text", "displaynone", "", "", false, "filled displaynone", ""}, 1351 {"text", "displaynone", "", "", false, "filled displaynone", ""},
1346 // Regular <input type="month"> should be autofilled. 1352 // Regular <input type="month"> should be autofilled.
1347 {"month", "month", "", "", true, "2017-11", "2017-11"}, 1353 {"month", "month", "", "", true, "2017-11", "2017-11"},
1348 // Non-empty <input type="month"> should not be autofilled. 1354 // Non-empty <input type="month"> should not be autofilled.
1349 {"month", "month-nonempty", "2011-12", "", false, "2017-11", "2011-12"}, 1355 {"month", "month-nonempty", "2011-12", "", false, "2017-11", "2011-12"},
1350 // Regular select fields should be autofilled. 1356 // Regular select fields should be autofilled.
1351 {"select-one", "select", "", "", true, "TX", "TX"}, 1357 {"select-one", "select", "", "", true, "TX", "TX"},
1352 // Select fields should be autofilled even if they already have a 1358 // Select fields should be autofilled even if they already have a
1353 // non-empty value. 1359 // non-empty value.
1354 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"}, 1360 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"},
1361 // Select fields should not be autofilled if no new value is passed from
1362 // autofill profile. The existing value should not be overriden.
1363 {"select-one", "select-unchanged", "CA", "", false, "CA", "CA"},
1355 // Regular textarea elements should be autofilled. 1364 // Regular textarea elements should be autofilled.
1356 {"textarea", "textarea", "", "", true, "some multi-\nline value", 1365 {"textarea", "textarea", "", "", true, "some multi-\nline value",
1357 "some multi-\nline value"}, 1366 "some multi-\nline value"},
1358 // Non-empty textarea elements should not be autofilled. 1367 // Non-empty textarea elements should not be autofilled.
1359 {"textarea", "textarea-nonempty", "Go\naway!", "", false, 1368 {"textarea", "textarea-nonempty", "Go\naway!", "", false,
1360 "some multi-\nline value", "Go\naway!"}, 1369 "some multi-\nline value", "Go\naway!"},
1361 }; 1370 };
1362 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), 1371 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases),
1363 FillForm, &GetValueWrapper); 1372 FillForm, &GetValueWrapper);
1364 // Verify preview selection. 1373 // Verify preview selection.
(...skipping 29 matching lines...) Expand all
1394 "filled displaynone"}, 1403 "filled displaynone"},
1395 // Regular <input type="month"> should be autofilled. 1404 // Regular <input type="month"> should be autofilled.
1396 {"month", "month", "", "", true, "2017-11", "2017-11"}, 1405 {"month", "month", "", "", true, "2017-11", "2017-11"},
1397 // Non-empty <input type="month"> should be overridden. 1406 // Non-empty <input type="month"> should be overridden.
1398 {"month", "month-nonempty", "2011-12", "", true, "2017-11", "2017-11"}, 1407 {"month", "month-nonempty", "2011-12", "", true, "2017-11", "2017-11"},
1399 // Regular select fields should be autofilled. 1408 // Regular select fields should be autofilled.
1400 {"select-one", "select", "", "", true, "TX", "TX"}, 1409 {"select-one", "select", "", "", true, "TX", "TX"},
1401 // Select fields should be autofilled even if they already have a 1410 // Select fields should be autofilled even if they already have a
1402 // non-empty value. 1411 // non-empty value.
1403 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"}, 1412 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"},
1413 // Select fields should not be autofilled if no new value is passed from
1414 // autofill profile. The existing value should not be overriden.
1415 {"select-one", "select-unchanged", "CA", "", false, "CA", "CA"},
1404 // Regular textarea elements should be autofilled. 1416 // Regular textarea elements should be autofilled.
1405 {"textarea", "textarea", "", "", true, "some multi-\nline value", 1417 {"textarea", "textarea", "", "", true, "some multi-\nline value",
1406 "some multi-\nline value"}, 1418 "some multi-\nline value"},
1407 // Nonempty textarea elements should be overridden. 1419 // Nonempty textarea elements should be overridden.
1408 {"textarea", "textarea-nonempty", "Go\naway!", "", true, 1420 {"textarea", "textarea-nonempty", "Go\naway!", "", true,
1409 "some multi-\nline value", "some multi-\nline value"}, 1421 "some multi-\nline value", "some multi-\nline value"},
1410 }; 1422 };
1411 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), 1423 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases),
1412 &FillFormIncludingNonFocusableElementsWrapper, 1424 &FillFormIncludingNonFocusableElementsWrapper,
1413 &GetValueWrapper); 1425 &GetValueWrapper);
(...skipping 22 matching lines...) Expand all
1436 ""}, 1448 ""},
1437 // Regular <input type="month"> should be previewed. 1449 // Regular <input type="month"> should be previewed.
1438 {"month", "month", "", "", true, "2017-11", "2017-11"}, 1450 {"month", "month", "", "", true, "2017-11", "2017-11"},
1439 // Non-empty <input type="month"> should not be previewed. 1451 // Non-empty <input type="month"> should not be previewed.
1440 {"month", "month-nonempty", "2011-12", "", false, "2017-11", ""}, 1452 {"month", "month-nonempty", "2011-12", "", false, "2017-11", ""},
1441 // Regular select fields should be previewed. 1453 // Regular select fields should be previewed.
1442 {"select-one", "select", "", "", true, "TX", "TX"}, 1454 {"select-one", "select", "", "", true, "TX", "TX"},
1443 // Select fields should be previewed even if they already have a 1455 // Select fields should be previewed even if they already have a
1444 // non-empty value. 1456 // non-empty value.
1445 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"}, 1457 {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"},
1458 // Select fields should not be previewed if no suggestion is passed from
1459 // autofill profile.
1460 {"select-one", "select-unchanged", "CA", "", false, "", ""},
1446 // Normal textarea elements should be previewed. 1461 // Normal textarea elements should be previewed.
1447 {"textarea", "textarea", "", "", true, "suggested multi-\nline value", 1462 {"textarea", "textarea", "", "", true, "suggested multi-\nline value",
1448 "suggested multi-\nline value"}, 1463 "suggested multi-\nline value"},
1449 // Nonempty textarea elements should not be previewed. 1464 // Nonempty textarea elements should not be previewed.
1450 {"textarea", "textarea-nonempty", "Go\naway!", "", false, 1465 {"textarea", "textarea-nonempty", "Go\naway!", "", false,
1451 "suggested multi-\nline value", ""}, 1466 "suggested multi-\nline value", ""},
1452 }; 1467 };
1453 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), 1468 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases),
1454 &PreviewForm, &GetSuggestedValueWrapper); 1469 &PreviewForm, &GetSuggestedValueWrapper);
1455 1470
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
2369 2384
2370 expected.name = ASCIIToUTF16("email"); 2385 expected.name = ASCIIToUTF16("email");
2371 expected.max_length = 9; 2386 expected.max_length = 9;
2372 expected.is_autofilled = false; 2387 expected.is_autofilled = false;
2373 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 2388 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
2374 2389
2375 // Fill the form. 2390 // Fill the form.
2376 form.fields[0].value = ASCIIToUTF16("Brother"); 2391 form.fields[0].value = ASCIIToUTF16("Brother");
2377 form.fields[1].value = ASCIIToUTF16("Jonathan"); 2392 form.fields[1].value = ASCIIToUTF16("Jonathan");
2378 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); 2393 form.fields[2].value = ASCIIToUTF16("brotherj@example.com");
2394 form.fields[0].is_autofilled = true;
2395 form.fields[1].is_autofilled = true;
2396 form.fields[2].is_autofilled = true;
2379 FillForm(form, input_element); 2397 FillForm(form, input_element);
2380 2398
2381 // Find the newly-filled form that contains the input element. 2399 // Find the newly-filled form that contains the input element.
2382 FormData form2; 2400 FormData form2;
2383 FormFieldData field2; 2401 FormFieldData field2;
2384 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, 2402 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
2385 &form2, 2403 &form2,
2386 &field2, 2404 &field2,
2387 autofill::REQUIRE_NONE)); 2405 autofill::REQUIRE_NONE));
2388 2406
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2635 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); 2653 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
2636 2654
2637 expected.name = ASCIIToUTF16("cantelope"); 2655 expected.name = ASCIIToUTF16("cantelope");
2638 expected.is_autofilled = false; 2656 expected.is_autofilled = false;
2639 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 2657 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
2640 2658
2641 // Fill the form. 2659 // Fill the form.
2642 form.fields[0].value = ASCIIToUTF16("Red"); 2660 form.fields[0].value = ASCIIToUTF16("Red");
2643 form.fields[1].value = ASCIIToUTF16("Yellow"); 2661 form.fields[1].value = ASCIIToUTF16("Yellow");
2644 form.fields[2].value = ASCIIToUTF16("Also Yellow"); 2662 form.fields[2].value = ASCIIToUTF16("Also Yellow");
2663 form.fields[0].is_autofilled = true;
2664 form.fields[1].is_autofilled = true;
2665 form.fields[2].is_autofilled = true;
2645 FillForm(form, input_element); 2666 FillForm(form, input_element);
2646 2667
2647 // Find the newly-filled form that contains the input element. 2668 // Find the newly-filled form that contains the input element.
2648 FormData form2; 2669 FormData form2;
2649 FormFieldData field2; 2670 FormFieldData field2;
2650 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, 2671 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
2651 &form2, 2672 &form2,
2652 &field2, 2673 &field2,
2653 autofill::REQUIRE_NONE)); 2674 autofill::REQUIRE_NONE));
2654 2675
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2861 2882
2862 expected.name = ASCIIToUTF16("email"); 2883 expected.name = ASCIIToUTF16("email");
2863 expected.value = base::string16(); 2884 expected.value = base::string16();
2864 expected.is_autofilled = false; 2885 expected.is_autofilled = false;
2865 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 2886 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
2866 2887
2867 // Preview the form and verify that the cursor position has been updated. 2888 // Preview the form and verify that the cursor position has been updated.
2868 form.fields[0].value = ASCIIToUTF16("Wyatt"); 2889 form.fields[0].value = ASCIIToUTF16("Wyatt");
2869 form.fields[1].value = ASCIIToUTF16("Earp"); 2890 form.fields[1].value = ASCIIToUTF16("Earp");
2870 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); 2891 form.fields[2].value = ASCIIToUTF16("wyatt@example.com");
2892 form.fields[0].is_autofilled = true;
2893 form.fields[1].is_autofilled = true;
2894 form.fields[2].is_autofilled = true;
2871 PreviewForm(form, input_element); 2895 PreviewForm(form, input_element);
2872 EXPECT_EQ(2, input_element.selectionStart()); 2896 EXPECT_EQ(2, input_element.selectionStart());
2873 EXPECT_EQ(5, input_element.selectionEnd()); 2897 EXPECT_EQ(5, input_element.selectionEnd());
2874 2898
2875 // Fill the form. 2899 // Fill the form.
2876 FillForm(form, input_element); 2900 FillForm(form, input_element);
2877 2901
2878 // Find the newly-filled form that contains the input element. 2902 // Find the newly-filled form that contains the input element.
2879 FormData form2; 2903 FormData form2;
2880 FormFieldData field2; 2904 FormFieldData field2;
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
3472 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); 3496 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
3473 3497
3474 expected.name = ASCIIToUTF16("country"); 3498 expected.name = ASCIIToUTF16("country");
3475 expected.value = ASCIIToUTF16("AL"); 3499 expected.value = ASCIIToUTF16("AL");
3476 expected.form_control_type = "select-one"; 3500 expected.form_control_type = "select-one";
3477 expected.max_length = 0; 3501 expected.max_length = 0;
3478 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); 3502 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
3479 } 3503 }
3480 3504
3481 } // namespace autofill 3505 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/browser/request_autocomplete_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698