tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug545268.html (4184B)


      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 src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="/tests/SimpleTest/EventUtils.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=545268">Mozilla Bug 545268</a>
     14 <p id="display">
     15 </p>
     16 <div id="content" style="display: none">
     17  
     18 </div>
     19 <pre id="test">
     20 <script type="application/javascript">
     21 
     22 /**
     23 * Test for Bug 545268
     24 * Like the test for bug 493251, but we test that suppressing events in
     25 * a parent window stops the events from reaching the child window.
     26 */
     27 
     28  var win;
     29  var subwin;
     30 
     31  var mouseDown = 0;
     32  var mouseUp = 0;
     33  var mouseClick = 0;
     34 
     35  var keyDown = 0;
     36  var keyPress = 0;
     37  var keyUp = 0;
     38 
     39  function doTest() {
     40    var utils = SpecialPowers.getDOMWindowUtils(win);
     41    var f = win.document.getElementById("f");
     42    subwin = f.contentWindow;
     43    subwin.document.getElementsByTagName("input")[0].focus();
     44    subwin.addEventListener("keydown", function(e) { ++keyDown; }, true);
     45    subwin.addEventListener("keypress", function(e) { ++keyPress; }, true);
     46    subwin.addEventListener("keyup", function(e) { ++keyUp; }, true);
     47    subwin.addEventListener("mousedown", function(e) { ++mouseDown; }, true);
     48    subwin.addEventListener("mouseup", function(e) { ++mouseUp; }, true);
     49    subwin.addEventListener("click", function(e) { ++mouseClick; }, true);
     50 
     51    synthesizeKey("a", {}, subwin);
     52    is(keyDown, 1, "Wrong number events (1)");
     53    is(keyPress, 1, "Wrong number events (2)");
     54    is(keyUp, 1, "Wrong number events (3)");
     55 
     56    // Test that suppressing events on the parent window prevents key
     57    // events in the subdocument window
     58    utils.suppressEventHandling(true);
     59    synthesizeKey("a", {}, subwin);
     60    is(keyDown, 1, "Wrong number events (4)");
     61    is(keyPress, 1, "Wrong number events (5)");
     62    is(keyUp, 1, "Wrong number events (6)");
     63    utils.suppressEventHandling(false);
     64    is(keyDown, 1, "Wrong number events (7)");
     65    is(keyPress, 1, "Wrong number events (8)");
     66    is(keyUp, 1, "Wrong number events (9)");
     67 
     68    setTimeout(continueTest1, 0);
     69    }
     70 
     71  function continueTest1() {
     72    var utils = SpecialPowers.getDOMWindowUtils(win);
     73    subwin.addEventListener("keydown", () => { utils.suppressEventHandling(true); }, {once: true});
     74    synthesizeKey("a", {}, subwin);
     75    is(keyDown, 2, "Wrong number events (10)");
     76    is(keyPress, 1, "Wrong number events (11)");
     77    is(keyUp, 1, "Wrong number events (12)");
     78    utils.suppressEventHandling(false);
     79    setTimeout(continueTest2, 0);
     80  }
     81 
     82  function continueTest2() {
     83    var utils = SpecialPowers.getDOMWindowUtils(win);
     84    is(keyDown, 2, "Wrong number events (13)");
     85    is(keyPress, 2, "Wrong number events (14)");
     86    is(keyUp, 2, "Wrong number events (15)");
     87 
     88    synthesizeMouseAtPoint(5, 5, {}, win);
     89    is(mouseDown, 1, "Wrong number events (16)");
     90    is(mouseUp, 1, "Wrong number events (17)");
     91    is(mouseClick, 1, "Wrong number events (18)");
     92 
     93    utils.suppressEventHandling(true);
     94    synthesizeMouseAtPoint(5, 5, {}, win);
     95    utils.suppressEventHandling(false);
     96    is(mouseDown, 1, "Wrong number events (19)");
     97    is(mouseUp, 1, "Wrong number events (20)");
     98    is(mouseClick, 1, "Wrong number events (21)");
     99 
    100    setTimeout(continueTest3, 0);
    101  }
    102 
    103  function continueTest3() {
    104    var utils = SpecialPowers.getDOMWindowUtils(win);
    105    synthesizeMouseAtPoint(5, 5, { type: "mousedown" }, win);
    106    utils.suppressEventHandling(true);
    107    synthesizeMouseAtPoint(5, 5, { type: "mouseup" }, win);
    108    utils.suppressEventHandling(false);
    109    setTimeout(continueTest4, 1000);
    110  }
    111 
    112  function continueTest4() {
    113    is(mouseDown, 2, "Wrong number events (19)");
    114    is(mouseUp, 2, "Wrong number events (20)");
    115    is(mouseClick, 2, "Wrong number events (21)");
    116    win.close();
    117    SimpleTest.finish();
    118  }
    119 
    120 
    121  SimpleTest.waitForExplicitFinish();
    122  SimpleTest.requestFlakyTimeout("untriaged");
    123  win = window.open("bug545268.html", "" , "");
    124  win.onload = doTest;
    125 
    126 </script>
    127 </pre>
    128 </body>
    129 </html>