tor-browser

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

file_pointerlock-api-with-shadow.html (3941B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--https://bugzilla.mozilla.org/show_bug.cgi?id=633602-->
      4 <head>
      5  <title>Bug 633602</title>
      6  <script src="/tests/SimpleTest/EventUtils.js">
      7  </script>
      8  <script src="/tests/SimpleTest/SimpleTest.js">
      9  </script>
     10  <script type="application/javascript" src="pointerlock_utils.js"></script>
     11  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     12 </head>
     13 <body>
     14  <a target="_blank"
     15    href="https://bugzilla.mozilla.org/show_bug.cgi?id=633602">
     16    Mozilla Bug 633602
     17  </a>
     18  <div id="host"></div>
     19  <pre id="test">
     20    <script type="text/javascript">
     21      /*
     22       * Test for Bug 1430303
     23       * Make sure DOM API is correct.
     24       */
     25 
     26      SimpleTest.waitForExplicitFinish();
     27 
     28      var div,
     29        host,
     30        hasRequestPointerLock = false,
     31        pointerLockChangeEventFired = false,
     32        pointerUnlocked = false,
     33        pointerLocked = false,
     34        hasExitPointerLock = false,
     35        pointerLockElement = false,
     36        hasMovementX = false,
     37        hasMovementY = false;
     38        gotContextMenuEvent = false;
     39 
     40      function runTests () {
     41        ok(hasRequestPointerLock, "Element should have requestPointerLock.");
     42        ok(pointerLockChangeEventFired, "pointerlockchange event should fire.");
     43        ok(pointerUnlocked, "Should be able to unlock pointer locked element.");
     44        ok(pointerLocked, "Requested element should be able to lock.");
     45        ok(hasExitPointerLock, "Document should have exitPointerLock");
     46        ok(pointerLockElement, "Document should keep track of correct pointer locked element");
     47        ok(hasMovementX, "Mouse Event should have movementX.");
     48        ok(hasMovementY, "Mouse Event should have movementY.");
     49        ok(!gotContextMenuEvent, "Shouldn't have got a contextmenu event.");
     50      }
     51 
     52      function mouseMoveHandler(e) {
     53        info("Got mousemove");
     54        document.removeEventListener("mousemove", mouseMoveHandler);
     55 
     56        hasMovementX = "movementX" in e;
     57        hasMovementY = "movementY" in e;
     58 
     59        hasExitPointerLock = "exitPointerLock" in document;
     60        document.exitPointerLock();
     61      }
     62 
     63      document.addEventListener("pointerlockchange", function (e) {
     64        pointerLockChangeEventFired = true;
     65 
     66        if (document.pointerLockElement) {
     67          info("Got pointerlockchange for entering");
     68          pointerLocked = true;
     69          pointerLockElement = document.pointerLockElement === host;
     70          is(host.shadowRoot.firstChild, host.shadowRoot.pointerLockElement,
     71             "ShadowRoot's pointerLockElement shouldn't be retargeted.");
     72 
     73          window.addEventListener("contextmenu",
     74                                  function() { gotContextMenuEvent = true; },
     75                                  true);
     76          synthesizeMouse(document.body, 4, 4,
     77                          { type: "contextmenu", button: 2 },
     78                          window);
     79 
     80          document.addEventListener("mousemove", mouseMoveHandler);
     81          synthesizeMouseAtCenter(host, {type: "mousemove"}, window);
     82        } else {
     83          info("Got pointerlockchange for exiting");
     84          pointerUnlocked = true;
     85          addFullscreenChangeContinuation("exit", function() {
     86            info("Got fullscreenchange for exiting");
     87            runTests();
     88            SimpleTest.finish();
     89          });
     90          document.exitFullscreen();
     91        }
     92      });
     93 
     94      function start() {
     95        host = document.getElementById("host");
     96        var sr = host.attachShadow({mode: "open"});
     97        sr.innerHTML = "<div><div>";
     98        div = sr.firstChild;
     99        info("Requesting fullscreen on parent");
    100        addFullscreenChangeContinuation("enter", function() {
    101          info("Got fullscreenchange for entering");
    102          hasRequestPointerLock = "requestPointerLock" in div;
    103          div.requestPointerLock();
    104        });
    105        host.requestFullscreen();
    106      }
    107    </script>
    108  </pre>
    109 </body>
    110 </html>