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

Unified Diff: LayoutTests/fast/forms/ValidityState-tooShort-input.html

Issue 435753003: Implement minlength for <input> and <textarea>. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add layout tests for minlength & maxlength together; fix comments Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/forms/ValidityState-tooShort-input.html
diff --git a/LayoutTests/fast/forms/ValidityState-tooShort-input.html b/LayoutTests/fast/forms/ValidityState-tooShort-input.html
new file mode 100644
index 0000000000000000000000000000000000000000..a867be5213691dd7ab0b232830b8dabdd55e177c
--- /dev/null
+++ b/LayoutTests/fast/forms/ValidityState-tooShort-input.html
@@ -0,0 +1,79 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description('Tests for tooShort flag with &lt;input> elements.');
+
+var input = document.createElement('input');
+document.body.appendChild(input);
+
+debug('No minlength and no value');
+shouldBeFalse('input.validity.tooShort');
+
+debug('');
+debug('Non-dirty value');
+input.setAttribute('value', 'ab');
+input.minLength = 3;
+shouldBe('input.value.length', '2');
+shouldBeFalse('input.validity.tooShort');
+
+input.setAttribute('value', 'a');
+shouldBe('input.value.length', '1');
+shouldBeFalse('input.validity.tooShort');
+
+debug('');
+debug('Dirty value and longer than minLength');
+input = document.createElement('input');
+document.body.appendChild(input);
+input.setAttribute('value', 'ab');
+input.minLength = 3;
+input.focus();
+input.setSelectionRange(2, 2); // Move the cursor at the end.
+document.execCommand('delete');
+shouldBe('input.value.length', '1');
+shouldBeTrue('input.validity.tooShort');
+// Make the value empty, which means valid.
+document.execCommand('delete');
+shouldBe('input.value.length', '0');
+shouldBeFalse('input.validity.tooShort');
+document.execCommand('InsertText', false, 'ab');
+shouldBe('input.value.length', '2');
+shouldBeTrue('input.validity.tooShort');
+// Make the value >=minLength.
+document.execCommand('InsertText', false, 'c');
+shouldBe('input.value.length', '3');
+shouldBeFalse('input.validity.tooShort');
+
+debug('');
+debug('Sets a value via DOM property');
+input.minLength = 3;
+input.value = 'ab';
+shouldBeFalse('input.validity.tooShort');
+
+debug('');
+debug('Disabling makes the control valid');
+input.focus();
+input.setSelectionRange(2, 2);
+document.execCommand('delete');
+shouldBeTrue('input.validity.tooShort');
+shouldBeFalse('input.disabled = true; input.validity.tooShort');
+shouldBeTrue('input.disabled = false; input.validity.tooShort');
+
+debug('');
+debug('Change the type with a too long value');
+input.minLength = 3;
+input.value = 'a';
+input.type = 'search';
+input.focus();
+input.setSelectionRange(1, 1);
+document.execCommand('InsertText', false, 'b');
+shouldBeTrue('input.validity.tooShort');
+shouldBeFalse('input.type = "number"; input.validity.tooShort');
+</script>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698