dom/tests/mochitest/pointerlock/file_allowPointerLockSandboxFlag.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:845c5d1f70f3
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>
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
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.mozCancelFullScreen();
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 iframe = document.getElementById("iframe");
59 contentDocument = iframe.contentDocument;
60 iframeDiv = contentDocument.getElementById("div");
61
62 numberOfRuns++;
63
64 contentDocument.addEventListener("mozpointerlockchange", function () {
65 if (contentDocument.mozPointerLockElement === iframeDiv) {
66 pointerLocked++;
67 resetIframe();
68 }
69 });
70
71 contentDocument.addEventListener("mozpointerlockerror", function () {
72 contentDocument.mozCancelFullScreen();
73 });
74
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 });
85
86 iframeDiv.mozRequestFullScreen();
87 }
88 </script>
89 </pre>
90 </body>
91 </html>

mercurial