chromium/third_party/blink/web_tests/fast/forms/autofill-respects-maxlength.html

<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<input id="input" maxlength="5">
<textarea id="textarea" maxlength="5"></textarea>
<script>
// Test that previewing an autofill suggestion longer than the max length on an input and a text
// area field doesn't exceed the maxlenght limit of the field.
test(function() {
    assert_true(window.internals != null, 'This test requires internals object');
    // Preview the fields with a long value.
    var input_field = document.getElementById('input');
    var textarea_field = document.getElementById('textarea');
    internals.setSuggestedValue(input, 'MisterLongName');
    internals.setSuggestedValue(textarea, 'MisterLongName');

    // Make sure that both suggestions don't have more characters than the limit.
    assert_equals(internals.suggestedValue(input_field).length, 5, "The input suggestion should not be longer than 5 characters");
    assert_equals(internals.suggestedValue(textarea_field).length, 5, "The textarea suggestion should not be longer than 5 characters");
}, "The maxlength attribute should be respected by autofill suggestions");
// Test that  filling an autofill suggestion longer than the max length on an input and a text area
// field doesn't exceed the maxlenght limit of the field.
test(function() {
    assert_true(window.internals != null, 'This test requires internals object');
    // Fill the fields with a long value.
    var input_field = document.getElementById('input');
    var textarea_field = document.getElementById('textarea');
    internals.setAutofilledValue(input, 'MisterLongName');
    internals.setAutofilledValue(textarea, 'MisterLongName');

    // Make sure that both fill don't have more characters than the limit.
    assert_equals(input_field.value.length, 5, "The input fill should not be longer than 5 characters");
    assert_equals(textarea_field.value.length, 5, "The textarea fill should not be longer than 5 characters");
}, "The maxlength attribute should be respected by autofill fills");
</script>