dom/events/test/test_bug545268.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=545268
     5 -->
     6 <head>
     7   <title>Test for Bug 545268</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=545268">Mozilla Bug 545268</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 545268
    22     Like the test for bug 493251, but we test that suppressing events in
    23     a parent window stops the events from reaching the child window. */
    25   var win;
    26   var subwin;
    28   var mouseDown = 0;
    29   var mouseUp = 0;
    30   var mouseClick = 0;
    32   var keyDown = 0;
    33   var keyPress = 0;
    34   var keyUp = 0;
    36   function dispatchKeyEvent(type) {
    37     var utils = SpecialPowers.getDOMWindowUtils(subwin);
    38     utils.sendKeyEvent(type, 
    39                        SpecialPowers.Ci.nsIDOMKeyEvent.DOM_VK_A,
    40                        0, 0);
    41   }
    43   function doTest() {
    44     var utils = SpecialPowers.getDOMWindowUtils(win);
    45     var f = win.document.getElementById("f");
    46     subwin = f.contentWindow;
    47     subwin.document.getElementsByTagName("input")[0].focus();
    48     subwin.addEventListener("keydown", function(e) { ++keyDown; }, true);
    49     subwin.addEventListener("keypress", function(e) { ++keyPress; }, true);
    50     subwin.addEventListener("keyup", function(e) { ++keyUp; }, true);
    51     subwin.addEventListener("mousedown", function(e) { ++mouseDown; }, true);
    52     subwin.addEventListener("mouseup", function(e) { ++mouseUp; }, true);
    53     subwin.addEventListener("click", function(e) { ++mouseClick; }, true);
    55     dispatchKeyEvent("keydown");
    56     dispatchKeyEvent("keypress");
    57     dispatchKeyEvent("keyup");
    58     is(keyDown, 1, "Wrong number events (1)");
    59     is(keyPress, 1, "Wrong number events (2)");
    60     is(keyUp, 1, "Wrong number events (3)");
    62     // Test that suppressing events on the parent window prevents key
    63     // events in the subdocument window
    64     utils.suppressEventHandling(true);
    65     dispatchKeyEvent("keydown");
    66     dispatchKeyEvent("keypress");
    67     dispatchKeyEvent("keyup");
    68     is(keyDown, 1, "Wrong number events (4)");
    69     is(keyPress, 1, "Wrong number events (5)");
    70     is(keyUp, 1, "Wrong number events (6)");
    71     utils.suppressEventHandling(false);
    72     is(keyDown, 1, "Wrong number events (7)");
    73     is(keyPress, 1, "Wrong number events (8)");
    74     is(keyUp, 1, "Wrong number events (9)");
    76     setTimeout(continueTest1, 0);
    77     }
    79   function continueTest1() {
    80     var utils = SpecialPowers.getDOMWindowUtils(win);
    81     dispatchKeyEvent("keydown");
    82     utils.suppressEventHandling(true);
    83     dispatchKeyEvent("keypress");
    84     dispatchKeyEvent("keyup");
    85     is(keyDown, 2, "Wrong number events (10)");
    86     is(keyPress, 1, "Wrong number events (11)");
    87     is(keyUp, 1, "Wrong number events (12)");
    88     utils.suppressEventHandling(false);
    89     setTimeout(continueTest2, 0);
    90   }
    92   function continueTest2() {
    93     var utils = SpecialPowers.getDOMWindowUtils(win);
    94     is(keyDown, 2, "Wrong number events (13)");
    95     is(keyPress, 2, "Wrong number events (14)");
    96     is(keyUp, 2, "Wrong number events (15)");
    98     utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
    99     utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
   100     is(mouseDown, 1, "Wrong number events (16)");
   101     is(mouseUp, 1, "Wrong number events (17)");
   102     is(mouseClick, 1, "Wrong number events (18)");
   104     utils.suppressEventHandling(true);
   105     utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
   106     utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
   107     utils.suppressEventHandling(false);
   108     is(mouseDown, 1, "Wrong number events (19)");
   109     is(mouseUp, 1, "Wrong number events (20)");
   110     is(mouseClick, 1, "Wrong number events (21)");
   112     setTimeout(continueTest3, 0);
   113   }
   115   function continueTest3() {
   116     var utils = SpecialPowers.getDOMWindowUtils(win);
   117     utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
   118     utils.suppressEventHandling(true);
   119     utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
   120     utils.suppressEventHandling(false);
   121     setTimeout(continueTest4, 1000);
   122   }
   124   function continueTest4() {
   125     is(mouseDown, 2, "Wrong number events (19)");
   126     is(mouseUp, 2, "Wrong number events (20)");
   127     is(mouseClick, 2, "Wrong number events (21)");
   128     win.close();
   129     SimpleTest.finish();
   130   }
   133   SimpleTest.waitForExplicitFinish();
   134   win = window.open("data:text/html,<iframe id='f' style='position:absolute; border:none; width:100%; height:100%; left:0; top:0' src='data:text/html,&lt;input&gt;'>", "" , "");
   135   win.onload = doTest;
   137 </script>
   138 </pre>
   139 </body>
   140 </html>

mercurial