dom/events/test/test_bug493251.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_bug493251.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,193 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=493251
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 493251</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=493251">Mozilla Bug 493251</a>
    1.16 +<p id="display">
    1.17 +</p>
    1.18 +<div id="content" style="display: none">
    1.19 +  
    1.20 +</div>
    1.21 +<pre id="test">
    1.22 +<script type="application/javascript">
    1.23 +
    1.24 +/** Test for Bug 493251 **/
    1.25 +
    1.26 +  var win;
    1.27 +
    1.28 +  var mouseDown = 0;
    1.29 +  var mouseUp = 0;
    1.30 +  var mouseClick = 0;
    1.31 +
    1.32 +  var keyDown = 0;
    1.33 +  var keyPress = 0;
    1.34 +  var keyUp = 0;
    1.35 +
    1.36 +  function suppressEventHandling(aSuppress) {
    1.37 +    var utils = SpecialPowers.getDOMWindowUtils(win);
    1.38 +    ok(true, "suppressEventHandling: aSuppress=" + aSuppress);
    1.39 +    utils.suppressEventHandling(aSuppress);
    1.40 +  }
    1.41 +
    1.42 +  function dispatchKeyEvent(type) {
    1.43 +    var utils = SpecialPowers.getDOMWindowUtils(win);
    1.44 +    ok(true, "Dipatching key event: type=" + type);
    1.45 +    utils.sendKeyEvent(type, 
    1.46 +                       SpecialPowers.Ci.nsIDOMKeyEvent.DOM_VK_A,
    1.47 +                       0, 0);
    1.48 +  }
    1.49 +
    1.50 +  function dispatchMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers) {
    1.51 +    var utils = SpecialPowers.getDOMWindowUtils(win);
    1.52 +    ok(true, "Dipatching mouse event: aType=" + aType + ", aX=" + aX + ", aY" +
    1.53 +               aY + ", aButton=" + aButton + ", aClickCount=" + aClickCount +
    1.54 +               ", aModifiers=" + aModifiers);
    1.55 +    utils.sendMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers);
    1.56 +  }
    1.57 +
    1.58 +  function dumpEvent(aEvent) {
    1.59 +    var detail = "target=" + aEvent.target + ", originalTarget=" +
    1.60 +                 aEvent.originalTarget + ", defaultPrevented=" +
    1.61 +                 aEvent.defaultPrevented + ", isTrusted=" + aEvent.isTrusted;
    1.62 +    switch (aEvent.type) {
    1.63 +      case "keydown":
    1.64 +      case "keypress":
    1.65 +      case "keyup":
    1.66 +        detail += ", charCode=0x" + aEvent.charCode.toString(16) +
    1.67 +          ", keyCode=0x" + aEvent.keyCode.toString(16) +
    1.68 +          ", altKey=" + (aEvent.altKey ? "PRESSED" : "no") +
    1.69 +          ", ctrlKey=" + (aEvent.ctrlKey ? "PRESSED" : "no") +
    1.70 +          ", shiftKey=" + (aEvent.shiftKey ? "PRESSED" : "no") +
    1.71 +          ", metaKey=" + (aEvent.metaKey ? "PRESSED" : "no");
    1.72 +        break;
    1.73 +      case "mousedown":
    1.74 +      case "mouseup":
    1.75 +      case "click":
    1.76 +        detail += ", screenX=" + aEvent.screenX + ", screenY=" + aEvent.screenY +
    1.77 +          ", clientX=" + aEvent.clientX + ", clientY=" + aEvent.clientY +
    1.78 +          ", altKey=" + (aEvent.altKey ? "PRESSED" : "no") +
    1.79 +          ", ctrlKey=" + (aEvent.ctrlKey ? "PRESSED" : "no") +
    1.80 +          ", shiftKey=" + (aEvent.shiftKey ? "PRESSED" : "no") +
    1.81 +          ", metaKey=" + (aEvent.metaKey ? "PRESSED" : "no") +
    1.82 +          ", button=" + aEvent.button +
    1.83 +          ", relatedTarget=" + aEvent.relatedTarget;
    1.84 +        break;
    1.85 +    }
    1.86 +    ok(true, aEvent.type + " event is handled: " + detail);
    1.87 +
    1.88 +    var fm = SpecialPowers.Cc["@mozilla.org/focus-manager;1"].
    1.89 +                        getService(SpecialPowers.Ci.nsIFocusManager);
    1.90 +    ok(true, "focused element is \"" + fm.focusedElement +
    1.91 +             "\" and focused window is \"" + fm.focusedWindow +
    1.92 +             "\" (the testing window is \"" + win + "\"");
    1.93 +  }
    1.94 +
    1.95 +  function doTest() {
    1.96 +    win.document.getElementsByTagName("input")[0].focus();
    1.97 +    win.addEventListener("keydown",
    1.98 +                         function(e) { dumpEvent(e); ++keyDown; }, true);
    1.99 +    win.addEventListener("keypress",
   1.100 +                         function(e) { dumpEvent(e); ++keyPress; }, true);
   1.101 +    win.addEventListener("keyup",
   1.102 +                         function(e) { dumpEvent(e); ++keyUp; }, true);
   1.103 +    win.addEventListener("mousedown",
   1.104 +                         function(e) { dumpEvent(e); ++mouseDown; }, true);
   1.105 +    win.addEventListener("mouseup",
   1.106 +                         function(e) { dumpEvent(e); ++mouseUp; }, true);
   1.107 +    win.addEventListener("click",
   1.108 +                         function(e) { dumpEvent(e); ++mouseClick; }, true);
   1.109 +
   1.110 +    ok(true, "doTest #1...");
   1.111 +    dispatchKeyEvent("keydown");
   1.112 +    dispatchKeyEvent("keypress");
   1.113 +    dispatchKeyEvent("keyup");
   1.114 +    is(keyDown, 1, "Wrong number events (1)");
   1.115 +    is(keyPress, 1, "Wrong number events (2)");
   1.116 +    is(keyUp, 1, "Wrong number events (3)");
   1.117 +
   1.118 +    ok(true, "doTest #2...");
   1.119 +    suppressEventHandling(true);
   1.120 +    dispatchKeyEvent("keydown");
   1.121 +    dispatchKeyEvent("keypress");
   1.122 +    dispatchKeyEvent("keyup");
   1.123 +    is(keyDown, 1, "Wrong number events (4)");
   1.124 +    is(keyPress, 1, "Wrong number events (5)");
   1.125 +    is(keyUp, 1, "Wrong number events (6)");
   1.126 +    suppressEventHandling(false);
   1.127 +    is(keyDown, 1, "Wrong number events (7)");
   1.128 +    is(keyPress, 1, "Wrong number events (8)");
   1.129 +    is(keyUp, 1, "Wrong number events (9)");
   1.130 +
   1.131 +    setTimeout(continueTest1, 0);
   1.132 +    }
   1.133 +
   1.134 +  function continueTest1() {
   1.135 +    ok(true, "continueTest1...");
   1.136 +    dispatchKeyEvent("keydown");
   1.137 +    suppressEventHandling(true);
   1.138 +    dispatchKeyEvent("keypress");
   1.139 +    dispatchKeyEvent("keyup");
   1.140 +    is(keyDown, 2, "Wrong number events (10)");
   1.141 +    is(keyPress, 1, "Wrong number events (11)");
   1.142 +    is(keyUp, 1, "Wrong number events (12)");
   1.143 +    suppressEventHandling(false);
   1.144 +    setTimeout(continueTest2, 0);
   1.145 +  }
   1.146 +
   1.147 +  function continueTest2() {
   1.148 +    ok(true, "continueTest2 #1...");
   1.149 +    is(keyDown, 2, "Wrong number events (13)");
   1.150 +    is(keyPress, 2, "Wrong number events (14)");
   1.151 +    is(keyUp, 2, "Wrong number events (15)");
   1.152 +
   1.153 +    dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
   1.154 +    dispatchMouseEvent("mouseup", 5, 5, 0, 1, 0);
   1.155 +    is(mouseDown, 1, "Wrong number events (16)");
   1.156 +    is(mouseUp, 1, "Wrong number events (17)");
   1.157 +    is(mouseClick, 1, "Wrong number events (18)");
   1.158 +
   1.159 +    ok(true, "continueTest2 #2...");
   1.160 +    suppressEventHandling(true);
   1.161 +    dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
   1.162 +    dispatchMouseEvent("mouseup", 5, 5, 0, 1, 0);
   1.163 +    suppressEventHandling(false);
   1.164 +    is(mouseDown, 1, "Wrong number events (19)");
   1.165 +    is(mouseUp, 1, "Wrong number events (20)");
   1.166 +    is(mouseClick, 1, "Wrong number events (21)");
   1.167 +
   1.168 +    setTimeout(continueTest3, 0);
   1.169 +  }
   1.170 +
   1.171 +  function continueTest3() {
   1.172 +    ok(true, "continueTest3...");
   1.173 +    dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
   1.174 +    suppressEventHandling(true);
   1.175 +    dispatchMouseEvent("mouseup", 5, 5, 0, 1, 0);
   1.176 +    suppressEventHandling(false);
   1.177 +    setTimeout(continueTest4, 1000);
   1.178 +  }
   1.179 +
   1.180 +  function continueTest4() {
   1.181 +    ok(true, "continueTest4...");
   1.182 +    is(mouseDown, 2, "Wrong number events (19)");
   1.183 +    is(mouseUp, 2, "Wrong number events (20)");
   1.184 +    is(mouseClick, 2, "Wrong number events (21)");
   1.185 +    win.close();
   1.186 +    SimpleTest.finish();
   1.187 +  }
   1.188 +
   1.189 +
   1.190 +  SimpleTest.waitForExplicitFinish();
   1.191 +  win = window.open("window_bug493251.html", "_blank" , "width=500,height=500");
   1.192 +
   1.193 +</script>
   1.194 +</pre>
   1.195 +</body>
   1.196 +</html>

mercurial