tor-browser

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

test_bug1581192.html (3040B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Redispatching test with PresShell</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <script src="/tests/SimpleTest/EventUtils.js"></script>
      8  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
      9 </head>
     10 <body>
     11 <p id="display"></p>
     12 <div id="content" style="display: none"></div>
     13 <pre id="test"></pre>
     14 <button>click me!</button>
     15 <script>
     16 SimpleTest.waitForExplicitFinish();
     17 SimpleTest.waitForFocus(async () => {
     18  /**
     19   * We have same tests in Event-dispatch-redispatch.html of WPT.  However,
     20   * it does not send the event to the main process.  Therefore the reported
     21   * crash couldn't reproduce.
     22   */
     23  await SpecialPowers.pushPrefEnv({set: [["test.events.async.enabled", true]]});
     24  let button = document.querySelector("button");
     25  try {
     26    await promiseElementReadyForUserInput(button, window, info);
     27  } catch (ex) {
     28    ok(false, ex.message);
     29    SimpleTest.finish();
     30    return;
     31  }
     32  let mouseupEvent;
     33  button.addEventListener("mouseup", aNativeMouseUpEvent => {
     34    ok(aNativeMouseUpEvent.isTrusted,"First mouseup event should be trusted");
     35    mouseupEvent = aNativeMouseUpEvent;
     36    try {
     37      button.dispatchEvent(aNativeMouseUpEvent);
     38      ok(false, "Dispatching trusted mouseup event which is being dispatched should throw an exception");
     39    } catch (e) {
     40      is(e.name, "InvalidStateError", "Trusted mouseup event which is being dispatched shouldn't be able to be dispatched");
     41    }
     42  }, {once: true});
     43 
     44  button.addEventListener("click", aNativeClickEvent => {
     45    ok(aNativeClickEvent.isTrusted, "First click event should be trusted");
     46    try {
     47      button.dispatchEvent(aNativeClickEvent);
     48      ok(false, "Dispatching trusted click event which is being dispatched should throw an exception");
     49    } catch (e) {
     50      is(e.name, "InvalidStateError", "Trusted click event which is being dispatched shouldn't be able to be dispatched");
     51    }
     52    let mouseupEventFired = false;
     53    button.addEventListener("mouseup", aDispatchedMouseUpEvent => {
     54      ok(!aDispatchedMouseUpEvent.isTrusted, "Redispatched mouseup event shouldn't be trusted");
     55      mouseupEventFired = true;
     56    }, {once: true});
     57    function onClick(aNonDispatchedClickEvent) {
     58      ok(false, "Redispatched mouseup event shouldn't cause dispatching another click event");
     59    }
     60    button.addEventListener("click", onClick);
     61    ok(mouseupEvent.isTrusted, "Received mouseup event should be trusted before redispatching from click event listener");
     62    button.dispatchEvent(mouseupEvent);
     63    ok(!mouseupEvent.isTrusted, "Received mouseup event shouldn't be trusted after redispatching");
     64    ok(mouseupEventFired, "Redispatched mouseup event should've been received");
     65    button.removeEventListener("click", onClick);
     66    ok(aNativeClickEvent.isTrusted, "First click event should still be trusted even after redispatching mouseup event");
     67    SimpleTest.finish();
     68  }, {once: true});
     69  synthesizeMouseAtCenter(button, {});
     70 });
     71 </script>
     72 </body>
     73 </html>