dom/events/test/test_bug930374-content.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_bug930374-content.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=930374
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 930374</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.15 +</head>
    1.16 +<body>
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=930374">Mozilla Bug 930374</a>
    1.18 +<div id="display">
    1.19 +  <input id="input-text">
    1.20 +</div>
    1.21 +<div id="content" style="display: none">
    1.22 +</div>
    1.23 +<pre id="test">
    1.24 +  <script type="application/javascript">
    1.25 +    SimpleTest.waitForExplicitFinish();
    1.26 +
    1.27 +    var gKeyPress = null;
    1.28 +    function onKeyPress(aEvent)
    1.29 +    {
    1.30 +      gKeyPress = aEvent;
    1.31 +      is(aEvent.target, document.getElementById("input-text"), "input element should have focus");
    1.32 +      ok(!aEvent.defaultPrevented, "keypress event should be consumed before keypress event handler");
    1.33 +    }
    1.34 +
    1.35 +    function runTests()
    1.36 +    {
    1.37 +      document.addEventListener("keypress", onKeyPress, false);
    1.38 +      var input = document.getElementById("input-text");
    1.39 +      input.focus();
    1.40 +
    1.41 +      input.addEventListener("input", function (aEvent) {
    1.42 +          input.removeEventListener("input", arguments.callee, false);
    1.43 +          ok(gKeyPress,
    1.44 +             "Test1: keypress event must be fired before an input event");
    1.45 +          ok(!gKeyPress.defaultPrevented,
    1.46 +             "Test1: keypress event's defaultPrevented should be false even though it's consumed by the default action handler of editor");
    1.47 +          gKeyPress.preventDefault();
    1.48 +          ok(gKeyPress.defaultPrevented,
    1.49 +             "Test1: keypress event's defaultPrevented should become true because of a call of preventDefault()");
    1.50 +        }, false);
    1.51 +
    1.52 +      sendChar("a");
    1.53 +      gKeyPress = null;
    1.54 +
    1.55 +      input.addEventListener("input", function (aEvent) {
    1.56 +          input.removeEventListener("input", arguments.callee, false);
    1.57 +          ok(gKeyPress,
    1.58 +             "Test2: keypress event must be fired before an input event");
    1.59 +          ok(!gKeyPress.defaultPrevented,
    1.60 +             "Test2: keypress event's defaultPrevented should be false even though it's consumed by the default action handler of editor");
    1.61 +          setTimeout(function () {
    1.62 +            ok(!gKeyPress.defaultPrevented,
    1.63 +               "Test2: keypress event's defaultPrevented should not become true after event dispatching finished");
    1.64 +            SimpleTest.finish();
    1.65 +          }, 0);
    1.66 +        }, false);
    1.67 +
    1.68 +      sendChar("b");
    1.69 +    }
    1.70 +
    1.71 +    SimpleTest.waitForFocus(runTests);
    1.72 +  </script>
    1.73 +</pre>
    1.74 +</body>
    1.75 +</html>

mercurial