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 tooLong flag with <textarea> elements.');
12 var textarea = document.createElement('textarea');
13 document.body.appendChild(textarea);
15 debug('No maxlength and no value');
16 shouldBeFalse('textarea.validity.tooLong');
19 debug('Non-dirty value');
20 textarea.defaultValue = 'abcde';
21 textarea.maxLength = 3;
22 shouldBe('textarea.value.length', '5');
23 shouldBeFalse('textarea.validity.tooLong');
25 textarea.defaultValue = 'abcdef';
26 shouldBe('textarea.value.length', '6');
27 shouldBeFalse('textarea.validity.tooLong');
30 debug('Dirty value and longer than maxLength');
31 textarea = document.createElement('textarea');
32 document.body.appendChild(textarea);
33 textarea.defaultValue = 'abcde';
34 textarea.maxLength = 3;
36 textarea.setSelectionRange(5, 5); // Move the cursor at the end.
37 document.execCommand('delete');
38 shouldBe('textarea.value.length', '4');
39 shouldBeTrue('textarea.validity.tooLong');
40 // Make the value <=maxLength.
41 document.execCommand('delete');
42 shouldBeFalse('textarea.validity.tooLong');
45 debug('Sets a value via DOM property');
46 textarea = document.createElement('textarea');
47 document.body.appendChild(textarea);
48 textarea.maxLength = 3;
49 textarea.value = 'abcde';
50 shouldBeFalse('textarea.validity.tooLong');
54 textarea.disabled = true;
55 shouldBeFalse('textarea.validity.tooLong');
56 textarea.disabled = false;
59 debug('Grapheme length is not greater than maxLength though character length is greater');
60 // fancyX should be treated as 1 grapheme.
61 // U+0305 COMBINING OVERLINE
62 // U+0332 COMBINING LOW LINE
63 var fancyX = "x\u0305\u0332";
64 textarea = document.createElement('textarea');
65 document.body.appendChild(textarea);
66 textarea.value = fancyX; // 3 characters, 1 grapheme cluster.
67 textarea.maxLength = 1;
68 shouldBeFalse('textarea.validity.tooLong');
71 debug('A value set by resetting a form doesn\'t make tooLong true.');
72 // Make a dirty textarea.
73 var parent = document.createElement('div');
74 document.body.appendChild(parent);
75 parent.innerHTML = '<form><textarea maxlength=2>abcdef</textarea></form>';
76 textarea = parent.firstChild.firstChild;
78 textarea.setSelectionRange(6, 6);
79 document.execCommand('delete');
80 shouldBeTrue('textarea.validity.tooLong');
81 parent.firstChild.reset();
82 shouldBe('textarea.value', '"abcdef"');
83 shouldBeFalse('textarea.validity.tooLong');
86 debug('A value set by a child node change doesn\'t make tooLong true.');
87 parent.innerHTML = '<textarea maxlength=2>abc</textarea>';
88 textarea = parent.firstChild;
89 shouldBeFalse('textarea.validity.tooLong');
90 parent.firstChild.innerHTML = 'abcdef';
91 shouldBe('textarea.value', '"abcdef"');
92 shouldBeFalse('textarea.validity.tooLong');