3 <script src=
"../../resources/js-test.js"></script>
7 <textarea type=
"text"></textarea>
9 <div id=
"console"></div>
13 if (window
.testRunner
)
14 testRunner
.dumpAsText();
18 var UPPER_CASE_T_KEY_CODE
= 84;
19 var LOWER_CASE_T_CHAR_CODE
= 116;
21 function keyListener(event
)
23 if (event
.keyCode
== UPPER_CASE_T_KEY_CODE
|| event
.keyCode
== LOWER_CASE_T_CHAR_CODE
)
24 event
.preventDefault();
25 event
.target
.value
= event
.target
.value
.replace('t', '');
28 function changeListener(event
)
30 events
.push(event
.type
+ ' ' + event
.target
.value
);
33 function sendKeysForString(target
, str
)
35 for (var i
= 0; i
< str
.length
; i
++) {
37 eventSender
.keyDown(str
[i
]);
42 // Replace value on keyup.
43 var inputElement
= document
.body
.getElementsByTagName('input')[0];
44 inputElement
.addEventListener('keyup', keyListener
, false);
45 inputElement
.addEventListener('change', changeListener
, false);
47 if (window
.eventSender
)
48 sendKeysForString(inputElement
, 'test');
50 shouldBe("events.length", "2");
51 shouldBe("events[0]", "'change e'");
52 shouldBe("events[1]", "'change es'");
54 var textAreaElement
= document
.body
.getElementsByTagName('textarea')[0];
55 textAreaElement
.addEventListener('keyup', keyListener
, false);
56 textAreaElement
.addEventListener('change', changeListener
, false);
59 if (window
.eventSender
)
60 sendKeysForString(textAreaElement
, 'atttbttc');
62 shouldBe("events.length", "3");
63 shouldBe("events[0]", "'change a'");
64 shouldBe("events[1]", "'change ab'");
65 shouldBe("events[2]", "'change abc'");
68 // Prevent default on keydown.
69 inputElement
.removeEventListener('keyup', keyListener
, false);
70 inputElement
.addEventListener('keydown', keyListener
, false);
71 inputElement
.value
= '';
74 if (window
.eventSender
)
75 sendKeysForString(inputElement
, 'test');
77 shouldBe("events.length", "2");
78 shouldBe("events[0]", "'change e'");
79 shouldBe("events[1]", "'change es'");
82 // Prevent default on keypress.
83 inputElement
.removeEventListener('keydown', keyListener
, false);
84 inputElement
.addEventListener('keypress', keyListener
, false);
85 inputElement
.value
= '';
88 if (window
.eventSender
)
89 sendKeysForString(inputElement
, 'test');
91 shouldBe("events.length", "2");
92 shouldBe("events[0]", "'change e'");
93 shouldBe("events[1]", "'change es'");
95 // Hide test elements after run to avoid whitespace differences across platforms in the results.
96 document
.getElementById('test').style
.display
= 'none';