Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / ValidityState-tooShort-input.html
bloba867be5213691dd7ab0b232830b8dabdd55e177c
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
9 <script>
10 description('Tests for tooShort flag with &lt;input> elements.');
12 var input = document.createElement('input');
13 document.body.appendChild(input);
15 debug('No minlength and no value');
16 shouldBeFalse('input.validity.tooShort');
18 debug('');
19 debug('Non-dirty value');
20 input.setAttribute('value', 'ab');
21 input.minLength = 3;
22 shouldBe('input.value.length', '2');
23 shouldBeFalse('input.validity.tooShort');
25 input.setAttribute('value', 'a');
26 shouldBe('input.value.length', '1');
27 shouldBeFalse('input.validity.tooShort');
29 debug('');
30 debug('Dirty value and longer than minLength');
31 input = document.createElement('input');
32 document.body.appendChild(input);
33 input.setAttribute('value', 'ab');
34 input.minLength = 3;
35 input.focus();
36 input.setSelectionRange(2, 2); // Move the cursor at the end.
37 document.execCommand('delete');
38 shouldBe('input.value.length', '1');
39 shouldBeTrue('input.validity.tooShort');
40 // Make the value empty, which means valid.
41 document.execCommand('delete');
42 shouldBe('input.value.length', '0');
43 shouldBeFalse('input.validity.tooShort');
44 document.execCommand('InsertText', false, 'ab');
45 shouldBe('input.value.length', '2');
46 shouldBeTrue('input.validity.tooShort');
47 // Make the value >=minLength.
48 document.execCommand('InsertText', false, 'c');
49 shouldBe('input.value.length', '3');
50 shouldBeFalse('input.validity.tooShort');
52 debug('');
53 debug('Sets a value via DOM property');
54 input.minLength = 3;
55 input.value = 'ab';
56 shouldBeFalse('input.validity.tooShort');
58 debug('');
59 debug('Disabling makes the control valid');
60 input.focus();
61 input.setSelectionRange(2, 2);
62 document.execCommand('delete');
63 shouldBeTrue('input.validity.tooShort');
64 shouldBeFalse('input.disabled = true; input.validity.tooShort');
65 shouldBeTrue('input.disabled = false; input.validity.tooShort');
67 debug('');
68 debug('Change the type with a too long value');
69 input.minLength = 3;
70 input.value = 'a';
71 input.type = 'search';
72 input.focus();
73 input.setSelectionRange(1, 1);
74 document.execCommand('InsertText', false, 'b');
75 shouldBeTrue('input.validity.tooShort');
76 shouldBeFalse('input.type = "number"; input.validity.tooShort');
77 </script>
78 </body>
79 </html>