Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / forms / ValidityState-tooShort-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 tooShort flag with &lt;textarea> elements.');
11
12 var textarea = document.createElement('textarea');
13 document.body.appendChild(textarea);
14
15 debug('No minlength and no value');
16 shouldBeFalse('textarea.validity.tooShort');
17
18 debug('');
19 debug('Non-dirty value');
20 textarea.defaultValue = 'ab';
21 textarea.minLength = 3;
22 shouldBe('textarea.value.length', '2');
23 shouldBeFalse('textarea.validity.tooShort');
24
25 textarea.defaultValue = 'a';
26 shouldBe('textarea.value.length', '1');
27 shouldBeFalse('textarea.validity.tooShort');
28
29 debug('');
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;
35 textarea.focus();
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');
51
52 debug('');
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');
59
60 debug('');
61 debug('Disabling makes the control valid');
62 textarea.focus();
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');
68
69 debug('');
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;
76 textarea.focus();
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');
83
84 debug('');
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');
92 </script>
93 </body>
94 </html>