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