dom/tests/mochitest/pointerlock/file_allowPointerLockSandboxFlag.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=784402
     5   -->
     6   <head>
     7     <title>Bug 784402</title>
     8     <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js">
     9     </script>
    10     <script type="application/javascript" 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>
    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>
    26     <pre id="test">
    27       <script type="application/javascript">
    28         /*
    29          * Test for Bug 784402
    30          * Test allow-pointer-lock sandbox flag.
    31          */
    33         SimpleTest.waitForExplicitFinish(1);
    35         var iframe
    36           , iframeDiv
    37           , contentDocument
    38           , pointerLocked = 0
    39           , numberOfRuns = 0;
    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         }
    48         function resetIframe () {
    49           contentDocument.mozCancelFullScreen();
    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         }
    57         function startTest () {
    58           iframe = document.getElementById("iframe");
    59           contentDocument = iframe.contentDocument;
    60           iframeDiv = contentDocument.getElementById("div");
    62           numberOfRuns++;
    64           contentDocument.addEventListener("mozpointerlockchange", function () {
    65             if (contentDocument.mozPointerLockElement === iframeDiv) {
    66               pointerLocked++;
    67               resetIframe();
    68             }
    69           });
    71           contentDocument.addEventListener("mozpointerlockerror", function () {
    72             contentDocument.mozCancelFullScreen();
    73           });
    75           contentDocument.addEventListener("mozfullscreenchange", function () {
    76             if (contentDocument.mozFullScreen &&
    77               contentDocument.mozFullScreenElement === iframeDiv) {
    78               // during second run iframe won't have allow-pointer-lock flag and
    79               // mozRequestPointerLock will fail, mozpointerlockerror should be fired
    80               iframeDiv.mozRequestPointerLock();
    81             } else if (numberOfRuns === 2) {
    82               runTests();
    83             }
    84           });
    86         iframeDiv.mozRequestFullScreen();
    87       }
    88       </script>
    89     </pre>
    90   </body>
    91 </html>

mercurial