tizen beta release
[framework/web/webkit-efl.git] / LayoutTests / fast / forms / script-tests / ValidityState-tooLong-textarea.js
1 description('Tests for tooLong flag with <textarea> elements.');
2
3 var textarea = document.createElement('textarea');
4 document.body.appendChild(textarea);
5
6 debug('No maxlength and no value');
7 shouldBeFalse('textarea.validity.tooLong');
8
9 debug('');
10 debug('Non-dirty value');
11 textarea.defaultValue = 'abcde';
12 textarea.maxLength = 3;
13 shouldBe('textarea.value.length', '5');
14 shouldBeFalse('textarea.validity.tooLong');
15
16 textarea.defaultValue = 'abcdef';
17 shouldBe('textarea.value.length', '6');
18 shouldBeFalse('textarea.validity.tooLong');
19
20 debug('');
21 debug('Dirty value and longer than maxLength');
22 textarea = document.createElement('textarea');
23 document.body.appendChild(textarea);
24 textarea.defaultValue = 'abcde';
25 textarea.maxLength = 3;
26 textarea.focus();
27 textarea.setSelectionRange(5, 5);  // Move the cursor at the end.
28 document.execCommand('delete');
29 shouldBe('textarea.value.length', '4');
30 shouldBeTrue('textarea.validity.tooLong');
31 // Make the value <=maxLength.
32 document.execCommand('delete');
33 shouldBeFalse('textarea.validity.tooLong');
34
35 debug('');
36 debug('Sets a value via DOM property');
37 textarea = document.createElement('textarea');
38 document.body.appendChild(textarea);
39 textarea.maxLength = 3;
40 textarea.value = 'abcde';
41 shouldBeFalse('textarea.validity.tooLong');
42
43 debug('');
44 debug('Disabled');
45 textarea.disabled = true;
46 shouldBeFalse('textarea.validity.tooLong');
47 textarea.disabled = false;
48
49 debug('');
50 debug('Grapheme length is not greater than maxLength though character length is greater');
51 // fancyX should be treated as 1 grapheme.
52 // U+0305 COMBINING OVERLINE
53 // U+0332 COMBINING LOW LINE
54 var fancyX = "x\u0305\u0332";
55 textarea = document.createElement('textarea');
56 document.body.appendChild(textarea);
57 textarea.value = fancyX; // 3 characters, 1 grapheme cluster.
58 textarea.maxLength = 1;
59 shouldBeFalse('textarea.validity.tooLong');
60
61 debug('');
62 debug('A value set by resetting a form doesn\'t make tooLong true.');
63 // Make a dirty textarea.
64 var parent = document.createElement('div');
65 document.body.appendChild(parent);
66 parent.innerHTML = '<form><textarea maxlength=2>abcdef</textarea></form>';
67 textarea = parent.firstChild.firstChild;
68 textarea.focus();
69 textarea.setSelectionRange(6, 6);
70 document.execCommand('delete');
71 shouldBeTrue('textarea.validity.tooLong');
72 parent.firstChild.reset();
73 shouldBe('textarea.value', '"abcdef"');
74 shouldBeFalse('textarea.validity.tooLong');
75
76 debug('');
77 debug('A value set by a child node change doesn\'t make tooLong true.');
78 parent.innerHTML = '<textarea maxlength=2>abc</textarea>';
79 textarea = parent.firstChild;
80 shouldBeFalse('textarea.validity.tooLong');
81 parent.firstChild.innerHTML = 'abcdef';
82 shouldBe('textarea.value', '"abcdef"');
83 shouldBeFalse('textarea.validity.tooLong');