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

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

mercurial