Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / forms / ValidityState-tooLong-textarea.html
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 tooLong flag with &lt;textarea> elements.');
11
12 var textarea = document.createElement('textarea');
13 document.body.appendChild(textarea);
14
15 debug('No maxlength and no value');
16 shouldBeFalse('textarea.validity.tooLong');
17
18 debug('');
19 debug('Non-dirty value');
20 textarea.defaultValue = 'abcde';
21 textarea.maxLength = 3;
22 shouldBe('textarea.value.length', '5');
23 shouldBeFalse('textarea.validity.tooLong');
24
25 textarea.defaultValue = 'abcdef';
26 shouldBe('textarea.value.length', '6');
27 shouldBeFalse('textarea.validity.tooLong');
28
29 debug('');
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;
35 textarea.focus();
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');
43
44 debug('');
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');
51
52 debug('');
53 debug('Disabled');
54 textarea.disabled = true;
55 shouldBeFalse('textarea.validity.tooLong');
56 textarea.disabled = false;
57
58 debug('');
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');
69
70 debug('');
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;
77 textarea.focus();
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');
84
85 debug('');
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');
93 </script>
94 </body>
95 </html>