Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / onchange-text-form-field.html
blobb887e834914de1269e2a306190c894903d0e8c53
1 <html>
2 <head>
3 <script src="../../resources/js-test.js"></script>
4 <body>
5 <div id="test">
6 <input type="text">
7 <input type="text"value="foo">
8 <textarea></textarea>
9 <textarea>foo</textarea>
10 <input type="text">
11 </div>
12 <div id="console"></div>
13 </body>
14 <script>
16 var BEFORE = 1;
17 var AFTER = 2;
19 function simulateTextEntry(element, text, opt_clear)
21 if (!window.eventSender)
22 return null;
24 var firedEvent = false;
25 function listener(event) {
26 firedEvent = true;
28 element.addEventListener('change', listener, false);
29 element.focus();
30 if (opt_clear & BEFORE) {
31 element.select();
32 eventSender.keyDown('delete');
34 for (var i = 0; i < text.length; i++) {
35 eventSender.keyDown(text.charAt(i));
37 if (opt_clear & AFTER) {
38 element.select();
39 eventSender.keyDown('delete');
41 element.blur();
42 element.removeEventListener('change', listener, false);
43 return firedEvent;
47 function setTextValue(element, text)
49 var firedEvent = false;
50 function listener(event) {
51 firedEvent = true;
53 element.addEventListener('change', listener, false);
54 element.focus();
55 element.value = text;
56 element.blur();
57 element.removeEventListener('change', listener, false);
58 return firedEvent;
61 var elements = document.getElementById('test').getElementsByTagName('*');
63 shouldBe("simulateTextEntry(elements[0], '', BEFORE);", "false");
64 shouldBe("simulateTextEntry(elements[0], 'fo', BEFORE);", "true");
65 shouldBe("simulateTextEntry(elements[0], 'o');", "true");
66 shouldBe("simulateTextEntry(elements[0], 'foo', BEFORE);", "false");
67 shouldBe("simulateTextEntry(elements[0], 'foo', BEFORE);", "false");
68 shouldBe("simulateTextEntry(elements[0], ' ');", "true");
69 shouldBe("simulateTextEntry(elements[0], 'foo bar', BEFORE);", "true");
70 shouldBe("simulateTextEntry(elements[0], 'foo bar', BEFORE);", "false");
71 shouldBe("setTextValue(elements[0], 'foo');", "false");
72 shouldBe("simulateTextEntry(elements[0], 'foo bar', BEFORE);", "true");
74 shouldBe("simulateTextEntry(elements[1], '', BEFORE);", "true");
75 shouldBe("simulateTextEntry(elements[1], 'fo', BEFORE);", "true");
76 shouldBe("simulateTextEntry(elements[1], 'o');", "true");
77 shouldBe("simulateTextEntry(elements[1], 'foo', BEFORE);", "false");
79 shouldBe("simulateTextEntry(elements[2], 'wee', AFTER);", "false");
80 shouldBe("simulateTextEntry(elements[2], 'foo', BEFORE | AFTER);", "false");
81 shouldBe("simulateTextEntry(elements[2], 'fo', BEFORE);", "true");
82 shouldBe("simulateTextEntry(elements[2], 'o');", "true");
83 shouldBe("simulateTextEntry(elements[2], 'foo', BEFORE);", "false");
85 shouldBe("simulateTextEntry(elements[3], 'foo', BEFORE);", "false");
86 shouldBe("simulateTextEntry(elements[3], 'foo', BEFORE);", "false");
87 shouldBe("setTextValue(elements[3], '');", "false");
88 shouldBe("simulateTextEntry(elements[3], 'fo', BEFORE);", "true");
89 shouldBe("simulateTextEntry(elements[3], 'o');", "true");
90 shouldBe("simulateTextEntry(elements[3], 'foo', BEFORE);", "false");
92 shouldBe("simulateTextEntry(elements[4], 'foo', AFTER);", "false");
93 shouldBe("simulateTextEntry(elements[4], 'foo');", "true");
94 shouldBe("simulateTextEntry(elements[4], 'foo', BEFORE);", "false");
95 shouldBe("simulateTextEntry(elements[4], 'foo', BEFORE | AFTER);", "true");
96 shouldBe("simulateTextEntry(elements[4], '', AFTER);", "false");
97 shouldBe("simulateTextEntry(elements[4], 'foo', AFTER);", "false");
99 // Hide test elements after run to avoid whitespace differences across platforms in the results.
100 document.getElementById('test').style.display = 'none';
101 </script>
102 </html>