dom/events/test/test_bug493251.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=493251
     5 -->
     6 <head>
     7   <title>Test for Bug 493251</title>
     8   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    10 </head>
    11 <body>
    12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=493251">Mozilla Bug 493251</a>
    13 <p id="display">
    14 </p>
    15 <div id="content" style="display: none">
    17 </div>
    18 <pre id="test">
    19 <script type="application/javascript">
    21 /** Test for Bug 493251 **/
    23   var win;
    25   var mouseDown = 0;
    26   var mouseUp = 0;
    27   var mouseClick = 0;
    29   var keyDown = 0;
    30   var keyPress = 0;
    31   var keyUp = 0;
    33   function suppressEventHandling(aSuppress) {
    34     var utils = SpecialPowers.getDOMWindowUtils(win);
    35     ok(true, "suppressEventHandling: aSuppress=" + aSuppress);
    36     utils.suppressEventHandling(aSuppress);
    37   }
    39   function dispatchKeyEvent(type) {
    40     var utils = SpecialPowers.getDOMWindowUtils(win);
    41     ok(true, "Dipatching key event: type=" + type);
    42     utils.sendKeyEvent(type, 
    43                        SpecialPowers.Ci.nsIDOMKeyEvent.DOM_VK_A,
    44                        0, 0);
    45   }
    47   function dispatchMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers) {
    48     var utils = SpecialPowers.getDOMWindowUtils(win);
    49     ok(true, "Dipatching mouse event: aType=" + aType + ", aX=" + aX + ", aY" +
    50                aY + ", aButton=" + aButton + ", aClickCount=" + aClickCount +
    51                ", aModifiers=" + aModifiers);
    52     utils.sendMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers);
    53   }
    55   function dumpEvent(aEvent) {
    56     var detail = "target=" + aEvent.target + ", originalTarget=" +
    57                  aEvent.originalTarget + ", defaultPrevented=" +
    58                  aEvent.defaultPrevented + ", isTrusted=" + aEvent.isTrusted;
    59     switch (aEvent.type) {
    60       case "keydown":
    61       case "keypress":
    62       case "keyup":
    63         detail += ", charCode=0x" + aEvent.charCode.toString(16) +
    64           ", keyCode=0x" + aEvent.keyCode.toString(16) +
    65           ", altKey=" + (aEvent.altKey ? "PRESSED" : "no") +
    66           ", ctrlKey=" + (aEvent.ctrlKey ? "PRESSED" : "no") +
    67           ", shiftKey=" + (aEvent.shiftKey ? "PRESSED" : "no") +
    68           ", metaKey=" + (aEvent.metaKey ? "PRESSED" : "no");
    69         break;
    70       case "mousedown":
    71       case "mouseup":
    72       case "click":
    73         detail += ", screenX=" + aEvent.screenX + ", screenY=" + aEvent.screenY +
    74           ", clientX=" + aEvent.clientX + ", clientY=" + aEvent.clientY +
    75           ", altKey=" + (aEvent.altKey ? "PRESSED" : "no") +
    76           ", ctrlKey=" + (aEvent.ctrlKey ? "PRESSED" : "no") +
    77           ", shiftKey=" + (aEvent.shiftKey ? "PRESSED" : "no") +
    78           ", metaKey=" + (aEvent.metaKey ? "PRESSED" : "no") +
    79           ", button=" + aEvent.button +
    80           ", relatedTarget=" + aEvent.relatedTarget;
    81         break;
    82     }
    83     ok(true, aEvent.type + " event is handled: " + detail);
    85     var fm = SpecialPowers.Cc["@mozilla.org/focus-manager;1"].
    86                         getService(SpecialPowers.Ci.nsIFocusManager);
    87     ok(true, "focused element is \"" + fm.focusedElement +
    88              "\" and focused window is \"" + fm.focusedWindow +
    89              "\" (the testing window is \"" + win + "\"");
    90   }
    92   function doTest() {
    93     win.document.getElementsByTagName("input")[0].focus();
    94     win.addEventListener("keydown",
    95                          function(e) { dumpEvent(e); ++keyDown; }, true);
    96     win.addEventListener("keypress",
    97                          function(e) { dumpEvent(e); ++keyPress; }, true);
    98     win.addEventListener("keyup",
    99                          function(e) { dumpEvent(e); ++keyUp; }, true);
   100     win.addEventListener("mousedown",
   101                          function(e) { dumpEvent(e); ++mouseDown; }, true);
   102     win.addEventListener("mouseup",
   103                          function(e) { dumpEvent(e); ++mouseUp; }, true);
   104     win.addEventListener("click",
   105                          function(e) { dumpEvent(e); ++mouseClick; }, true);
   107     ok(true, "doTest #1...");
   108     dispatchKeyEvent("keydown");
   109     dispatchKeyEvent("keypress");
   110     dispatchKeyEvent("keyup");
   111     is(keyDown, 1, "Wrong number events (1)");
   112     is(keyPress, 1, "Wrong number events (2)");
   113     is(keyUp, 1, "Wrong number events (3)");
   115     ok(true, "doTest #2...");
   116     suppressEventHandling(true);
   117     dispatchKeyEvent("keydown");
   118     dispatchKeyEvent("keypress");
   119     dispatchKeyEvent("keyup");
   120     is(keyDown, 1, "Wrong number events (4)");
   121     is(keyPress, 1, "Wrong number events (5)");
   122     is(keyUp, 1, "Wrong number events (6)");
   123     suppressEventHandling(false);
   124     is(keyDown, 1, "Wrong number events (7)");
   125     is(keyPress, 1, "Wrong number events (8)");
   126     is(keyUp, 1, "Wrong number events (9)");
   128     setTimeout(continueTest1, 0);
   129     }
   131   function continueTest1() {
   132     ok(true, "continueTest1...");
   133     dispatchKeyEvent("keydown");
   134     suppressEventHandling(true);
   135     dispatchKeyEvent("keypress");
   136     dispatchKeyEvent("keyup");
   137     is(keyDown, 2, "Wrong number events (10)");
   138     is(keyPress, 1, "Wrong number events (11)");
   139     is(keyUp, 1, "Wrong number events (12)");
   140     suppressEventHandling(false);
   141     setTimeout(continueTest2, 0);
   142   }
   144   function continueTest2() {
   145     ok(true, "continueTest2 #1...");
   146     is(keyDown, 2, "Wrong number events (13)");
   147     is(keyPress, 2, "Wrong number events (14)");
   148     is(keyUp, 2, "Wrong number events (15)");
   150     dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
   151     dispatchMouseEvent("mouseup", 5, 5, 0, 1, 0);
   152     is(mouseDown, 1, "Wrong number events (16)");
   153     is(mouseUp, 1, "Wrong number events (17)");
   154     is(mouseClick, 1, "Wrong number events (18)");
   156     ok(true, "continueTest2 #2...");
   157     suppressEventHandling(true);
   158     dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
   159     dispatchMouseEvent("mouseup", 5, 5, 0, 1, 0);
   160     suppressEventHandling(false);
   161     is(mouseDown, 1, "Wrong number events (19)");
   162     is(mouseUp, 1, "Wrong number events (20)");
   163     is(mouseClick, 1, "Wrong number events (21)");
   165     setTimeout(continueTest3, 0);
   166   }
   168   function continueTest3() {
   169     ok(true, "continueTest3...");
   170     dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
   171     suppressEventHandling(true);
   172     dispatchMouseEvent("mouseup", 5, 5, 0, 1, 0);
   173     suppressEventHandling(false);
   174     setTimeout(continueTest4, 1000);
   175   }
   177   function continueTest4() {
   178     ok(true, "continueTest4...");
   179     is(mouseDown, 2, "Wrong number events (19)");
   180     is(mouseUp, 2, "Wrong number events (20)");
   181     is(mouseClick, 2, "Wrong number events (21)");
   182     win.close();
   183     SimpleTest.finish();
   184   }
   187   SimpleTest.waitForExplicitFinish();
   188   win = window.open("window_bug493251.html", "_blank" , "width=500,height=500");
   190 </script>
   191 </pre>
   192 </body>
   193 </html>

mercurial