|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=930374 |
|
5 --> |
|
6 <head> |
|
7 <meta charset="utf-8"> |
|
8 <title>Test for Bug 930374</title> |
|
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
12 </head> |
|
13 <body> |
|
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=930374">Mozilla Bug 930374</a> |
|
15 <div id="display"> |
|
16 <input id="input-text"> |
|
17 </div> |
|
18 <div id="content" style="display: none"> |
|
19 </div> |
|
20 <pre id="test"> |
|
21 <script type="application/javascript"> |
|
22 SimpleTest.waitForExplicitFinish(); |
|
23 |
|
24 var gKeyPress = null; |
|
25 function onKeyPress(aEvent) |
|
26 { |
|
27 gKeyPress = aEvent; |
|
28 is(aEvent.target, document.getElementById("input-text"), "input element should have focus"); |
|
29 ok(!aEvent.defaultPrevented, "keypress event should be consumed before keypress event handler"); |
|
30 } |
|
31 |
|
32 function runTests() |
|
33 { |
|
34 document.addEventListener("keypress", onKeyPress, false); |
|
35 var input = document.getElementById("input-text"); |
|
36 input.focus(); |
|
37 |
|
38 input.addEventListener("input", function (aEvent) { |
|
39 input.removeEventListener("input", arguments.callee, false); |
|
40 ok(gKeyPress, |
|
41 "Test1: keypress event must be fired before an input event"); |
|
42 ok(!gKeyPress.defaultPrevented, |
|
43 "Test1: keypress event's defaultPrevented should be false even though it's consumed by the default action handler of editor"); |
|
44 gKeyPress.preventDefault(); |
|
45 ok(gKeyPress.defaultPrevented, |
|
46 "Test1: keypress event's defaultPrevented should become true because of a call of preventDefault()"); |
|
47 }, false); |
|
48 |
|
49 sendChar("a"); |
|
50 gKeyPress = null; |
|
51 |
|
52 input.addEventListener("input", function (aEvent) { |
|
53 input.removeEventListener("input", arguments.callee, false); |
|
54 ok(gKeyPress, |
|
55 "Test2: keypress event must be fired before an input event"); |
|
56 ok(!gKeyPress.defaultPrevented, |
|
57 "Test2: keypress event's defaultPrevented should be false even though it's consumed by the default action handler of editor"); |
|
58 setTimeout(function () { |
|
59 ok(!gKeyPress.defaultPrevented, |
|
60 "Test2: keypress event's defaultPrevented should not become true after event dispatching finished"); |
|
61 SimpleTest.finish(); |
|
62 }, 0); |
|
63 }, false); |
|
64 |
|
65 sendChar("b"); |
|
66 } |
|
67 |
|
68 SimpleTest.waitForFocus(runTests); |
|
69 </script> |
|
70 </pre> |
|
71 </body> |
|
72 </html> |