4 <p>This tests changing the focus on keypress event. The character typed by user should be inserted into input. This test only runs in DRT.
</p>
7 function runTest(name
, shouldChangeSelection
) {
8 var dummy
= document
.createElement('input');
9 document
.body
.appendChild(dummy
);
11 var element
= document
.createElement(name
);
12 document
.body
.appendChild(element
);
13 element
.addEventListener('keypress', function() {
14 if (element
.value
.length
>= 2)
18 document
.writeln(name
+ (shouldChangeSelection
? ' with selectionchange' : ' without selectionchange'));
21 eventSender
.keyDown('a');
22 eventSender
.leapForward(100);
23 eventSender
.keyDown(name
== 'textarea' ? '\n' : 'b');
24 eventSender
.leapForward(100);
25 if (shouldChangeSelection
) {
26 element
.selectionStart
= 1;
27 element
.selectionEnd
= 1;
29 eventSender
.keyDown('c');
30 eventSender
.leapForward(100);
33 if (name
== 'textarea')
34 expected
= shouldChangeSelection
? 'ac\n' : 'a\nc';
36 expected
= shouldChangeSelection
? 'acb' : 'abc';
38 if (element
.value
== expected
)
39 document
.writeln('PASS');
41 document
.writeln('FAIL: value was "' + element
.value
+ '" but expected "' + expected
+ '"');
45 if (window
.testRunner
&& window
.eventSender
) {
46 testRunner
.dumpAsText();
48 runTest('input', false);
49 runTest('input', true);
50 runTest('textarea', false);
51 runTest('textarea', true);
53 document
.writeln('DONE');