1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../resources/js-test.js"></script>
7 <p id=
"description"></p>
8 <div id=
"console"></div>
10 description('Tests for tooShort flag with <textarea> elements.');
12 var textarea
= document
.createElement('textarea');
13 document
.body
.appendChild(textarea
);
15 debug('No minlength and no value');
16 shouldBeFalse('textarea.validity.tooShort');
19 debug('Non-dirty value');
20 textarea
.defaultValue
= 'ab';
21 textarea
.minLength
= 3;
22 shouldBe('textarea.value.length', '2');
23 shouldBeFalse('textarea.validity.tooShort');
25 textarea
.defaultValue
= 'a';
26 shouldBe('textarea.value.length', '1');
27 shouldBeFalse('textarea.validity.tooShort');
30 debug('Dirty value and longer than minLength');
31 textarea
= document
.createElement('textarea');
32 document
.body
.appendChild(textarea
);
33 textarea
.defaultValue
= 'ab';
34 textarea
.minLength
= 3;
36 textarea
.setSelectionRange(2, 2); // Move the cursor at the end.
37 document
.execCommand('delete');
38 shouldBe('textarea.value.length', '1');
39 shouldBeTrue('textarea.validity.tooShort');
40 // Make the value empty, which means valid.
41 document
.execCommand('delete');
42 shouldBe('textarea.value.length', '0');
43 shouldBeFalse('textarea.validity.tooShort');
44 document
.execCommand('InsertText', false, 'ab');
45 shouldBe('textarea.value.length', '2');
46 shouldBeTrue('textarea.validity.tooShort');
47 // Make the value >=minLength.
48 document
.execCommand('InsertText', false, 'c');
49 shouldBe('textarea.value.length', '3');
50 shouldBeFalse('textarea.validity.tooShort');
53 debug('Sets a value via DOM property');
54 textarea
= document
.createElement('textarea');
55 document
.body
.appendChild(textarea
);
56 textarea
.minLength
= 3;
57 textarea
.defaultValue
= 'ab';
58 shouldBeFalse('textarea.validity.tooShort');
61 debug('Disabling makes the control valid');
63 textarea
.setSelectionRange(2, 2); // Move the cursor at the end.
64 document
.execCommand('delete');
65 shouldBeTrue('textarea.validity.tooShort');
66 shouldBeFalse('textarea.disabled = true; textarea.validity.tooShort');
67 shouldBeTrue('textarea.disabled = false; textarea.validity.tooShort');
70 debug('A value set by resetting a form doesn\'t make tooShort true.');
71 // Make a dirty textarea.
72 var parent
= document
.createElement('div');
73 document
.body
.appendChild(parent
);
74 parent
.innerHTML
= '<form><textarea minlength=3>ab</textarea></form>';
75 textarea
= parent
.firstChild
.firstChild
;
77 textarea
.setSelectionRange(2, 2);
78 document
.execCommand('delete');
79 shouldBeTrue('textarea.validity.tooShort');
80 parent
.firstChild
.reset();
81 shouldBe('textarea.value', '"ab"');
82 shouldBeFalse('textarea.validity.tooShort');
85 debug('A value set by a child node change doesn\'t make tooShort true.');
86 parent
.innerHTML
= '<textarea minlength=3>ab</textarea>';
87 textarea
= parent
.firstChild
;
88 shouldBeFalse('textarea.validity.tooShort');
89 parent
.firstChild
.innerHTML
= 'a';
90 shouldBe('textarea.value', '"a"');
91 shouldBeFalse('textarea.validity.tooShort');