1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/pointerlock/file_allowPointerLockSandboxFlag.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 + <!-- 1.7 + https://bugzilla.mozilla.org/show_bug.cgi?id=784402 1.8 + --> 1.9 + <head> 1.10 + <title>Bug 784402</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"> 1.12 + </script> 1.13 + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"> 1.14 + </script> 1.15 + <script type="application/javascript" src="pointerlock_utils.js"></script> 1.16 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.17 + </head> 1.18 + <body> 1.19 + <a target="_blank" 1.20 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=784402"> 1.21 + Mozilla Bug 784402</a> 1.22 + <p id="display"></p> 1.23 + 1.24 + <iframe src ="iframe_differentDOM.html" allowfullscreen="true" id="iframe" 1.25 + onload="startTest()" 1.26 + sandbox="allow-scripts allow-same-origin allow-pointer-lock"> 1.27 + </iframe> 1.28 + 1.29 + <pre id="test"> 1.30 + <script type="application/javascript"> 1.31 + /* 1.32 + * Test for Bug 784402 1.33 + * Test allow-pointer-lock sandbox flag. 1.34 + */ 1.35 + 1.36 + SimpleTest.waitForExplicitFinish(1); 1.37 + 1.38 + var iframe 1.39 + , iframeDiv 1.40 + , contentDocument 1.41 + , pointerLocked = 0 1.42 + , numberOfRuns = 0; 1.43 + 1.44 + function runTests () { 1.45 + is(pointerLocked, 1, "Pointer should only have been locked once. " + 1.46 + "Without allow-pointer-lock flag, a sandboxed document should not be " + 1.47 + "able to lock the pointer"); 1.48 + SimpleTest.finish(); 1.49 + } 1.50 + 1.51 + function resetIframe () { 1.52 + contentDocument.mozCancelFullScreen(); 1.53 + 1.54 + // remove allow-pointer-lock sandbox flag 1.55 + iframe.setAttribute("sandbox", "allow-scripts allow-same-origin"); 1.56 + // reloads the iframe, startTest function gets called again 1.57 + iframe.setAttribute("src", "iframe_differentDOM.html"); 1.58 + } 1.59 + 1.60 + function startTest () { 1.61 + iframe = document.getElementById("iframe"); 1.62 + contentDocument = iframe.contentDocument; 1.63 + iframeDiv = contentDocument.getElementById("div"); 1.64 + 1.65 + numberOfRuns++; 1.66 + 1.67 + contentDocument.addEventListener("mozpointerlockchange", function () { 1.68 + if (contentDocument.mozPointerLockElement === iframeDiv) { 1.69 + pointerLocked++; 1.70 + resetIframe(); 1.71 + } 1.72 + }); 1.73 + 1.74 + contentDocument.addEventListener("mozpointerlockerror", function () { 1.75 + contentDocument.mozCancelFullScreen(); 1.76 + }); 1.77 + 1.78 + contentDocument.addEventListener("mozfullscreenchange", function () { 1.79 + if (contentDocument.mozFullScreen && 1.80 + contentDocument.mozFullScreenElement === iframeDiv) { 1.81 + // during second run iframe won't have allow-pointer-lock flag and 1.82 + // mozRequestPointerLock will fail, mozpointerlockerror should be fired 1.83 + iframeDiv.mozRequestPointerLock(); 1.84 + } else if (numberOfRuns === 2) { 1.85 + runTests(); 1.86 + } 1.87 + }); 1.88 + 1.89 + iframeDiv.mozRequestFullScreen(); 1.90 + } 1.91 + </script> 1.92 + </pre> 1.93 + </body> 1.94 +</html>