tor-browser

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

file_allowPointerLockSandboxFlag.html (3195B)


      1 <!DOCTYPE HTML>
      2 <html>
      3  <!--
      4  https://bugzilla.mozilla.org/show_bug.cgi?id=784402
      5  -->
      6  <head>
      7    <title>Bug 784402</title>
      8    <script src="/tests/SimpleTest/SimpleTest.js">
      9    </script>
     10    <script src="/tests/SimpleTest/EventUtils.js">
     11    </script>
     12    <script type="application/javascript" src="pointerlock_utils.js"></script>
     13    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     14  </head>
     15  <body>
     16    <a target="_blank"
     17       href="https://bugzilla.mozilla.org/show_bug.cgi?id=784402">
     18      Mozilla Bug 784402</a>
     19    <p id="display"></p>
     20 
     21    <iframe src ="iframe_differentDOM.html" allowfullscreen="true" id="iframe"
     22      onload="startTest()"
     23      sandbox="allow-scripts allow-same-origin allow-pointer-lock">
     24    </iframe>
     25 
     26    <pre id="test">
     27      <script type="application/javascript">
     28        /*
     29         * Test for Bug 784402
     30         * Test allow-pointer-lock sandbox flag.
     31         */
     32 
     33        SimpleTest.waitForExplicitFinish(1);
     34 
     35        var iframe = document.getElementById("iframe")
     36          , iframeDiv
     37          , contentDocument
     38          , pointerLocked = 0
     39          , numberOfRuns = 0;
     40 
     41        function runTests () {
     42          is(pointerLocked, 1, "Pointer should only have been locked once. " +
     43            "Without allow-pointer-lock flag, a sandboxed document should not be " +
     44            "able to lock the pointer");
     45          SimpleTest.finish();
     46        }
     47 
     48        function resetIframe () {
     49          contentDocument.exitFullscreen();
     50 
     51          // remove allow-pointer-lock sandbox flag
     52          iframe.setAttribute("sandbox", "allow-scripts allow-same-origin");
     53          // reloads the iframe, startTest function gets called again
     54          iframe.setAttribute("src", "iframe_differentDOM.html");
     55        }
     56 
     57        function startTest () {
     58          SimpleTest.waitForFocus(doStartTest, iframe.contentWindow);
     59        }
     60        function doStartTest() {
     61          contentDocument = iframe.contentDocument;
     62          iframeDiv = contentDocument.getElementById("div");
     63 
     64          numberOfRuns++;
     65 
     66          contentDocument.addEventListener("pointerlockchange", function () {
     67            if (contentDocument.pointerLockElement === iframeDiv) {
     68              pointerLocked++;
     69              contentDocument.exitFullscreen();
     70            }
     71          });
     72 
     73          contentDocument.addEventListener("pointerlockerror", function () {
     74            contentDocument.exitFullscreen();
     75          });
     76 
     77          contentDocument.addEventListener("fullscreenchange", function () {
     78            if (contentDocument.fullscreenElement) {
     79              ok(contentDocument.fullscreenElement === iframeDiv,
     80                 "Fullscreen element can only be iframe div");
     81              // during second run iframe won't have allow-pointer-lock flag and
     82              // requestPointerLock will fail, pointerlockerror should be fired
     83              iframeDiv.requestPointerLock();
     84            } else if (numberOfRuns === 1) {
     85              resetIframe();
     86            } else if (numberOfRuns === 2) {
     87              runTests();
     88            }
     89          });
     90 
     91        iframeDiv.requestFullscreen();
     92      }
     93      </script>
     94    </pre>
     95  </body>
     96 </html>