3 <script src=
"../../resources/js-test.js"></script>
7 <input type=
"text"value=
"foo">
9 <textarea>foo
</textarea>
12 <div id=
"console"></div>
19 function simulateTextEntry(element
, text
, opt_clear
)
21 if (!window
.eventSender
)
24 var firedEvent
= false;
25 function listener(event
) {
28 element
.addEventListener('change', listener
, false);
30 if (opt_clear
& BEFORE
) {
32 eventSender
.keyDown('delete');
34 for (var i
= 0; i
< text
.length
; i
++) {
35 eventSender
.keyDown(text
.charAt(i
));
37 if (opt_clear
& AFTER
) {
39 eventSender
.keyDown('delete');
42 element
.removeEventListener('change', listener
, false);
47 function setTextValue(element
, text
)
49 var firedEvent
= false;
50 function listener(event
) {
53 element
.addEventListener('change', listener
, false);
57 element
.removeEventListener('change', listener
, false);
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';