4 <p>This test checks that typing Enter into an input element does not fire input or textInput.
<br>
5 To run manually, type enter in the input element below.
</p>
10 <div id=
"result"></div>
11 <pre id=
"console"></pre>
14 document
.getElementById('console').appendChild(document
.createTextNode(msg
+ '\n'));
17 var unexpectedEvents
= 0;
18 var enterChar
= '\r'.charCodeAt(0);
19 function fail(event
) {
20 if (lastKeyPressed
!= enterChar
) {
21 log(event
.type
+ ' fired.');
26 log('Unexpected ' + event
.type
+ ' fired.');
27 result
.innerHTML
= '<span style="padding: 5px; background-color: red">FAIL</span>';
30 var lastKeyPressed
= 0;
31 el
.addEventListener('keypress', function(event
) { lastKeyPressed
= event
.keyCode
; });
32 el
.addEventListener('input', fail
);
33 el
.addEventListener('textInput', fail
);
35 // If the form is submitted on enter and no unexpected event has been fired, success!
36 form
.addEventListener('submit', function(event
) {
37 if (!unexpectedEvents
&& !result
.hasChildNodes())
38 result
.innerHTML
= '<span style="padding: 5px; background-color: green">SUCCESS</span>';
40 event
.preventDefault();
43 if (window
.testRunner
)
44 testRunner
.dumpAsText();
47 if (window
.eventSender
) {
48 log('\nSending Enter to input element');
49 eventSender
.keyDown('\r', []);
50 } else if (window
.testRunner
)
51 log('This test requires eventSender to run in LayoutTests.');