|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!--https://bugzilla.mozilla.org/show_bug.cgi?id=746885--> |
|
4 <head> |
|
5 <title>Bug 746885</title> |
|
6 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
7 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
8 <script type="application/javascript" src="pointerlock_utils.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
10 </head> |
|
11 <body> |
|
12 <a target="_blank" |
|
13 href="https://bugzilla.mozilla.org/show_bug.cgi?id=746885"> |
|
14 Mozilla Bug 746885 |
|
15 </a> |
|
16 <div id="div"></div> |
|
17 <pre id="test"> |
|
18 <script type="text/javascript"> |
|
19 /* |
|
20 * Test for Bug 746885 |
|
21 * When requesting pointer lock on a domain that doesn't have fullscreen |
|
22 * permission, the pointer lock request should be delayed until approval |
|
23 * has been granted. |
|
24 */ |
|
25 |
|
26 SimpleTest.waitForExplicitFinish(); |
|
27 |
|
28 // Ensure fullscreen won't be automatically granted for this document's domain. |
|
29 SpecialPowers.removeFullscreenAllowed(document); |
|
30 |
|
31 var div = document.getElementById("div"); |
|
32 var isApproved = false; |
|
33 |
|
34 document.addEventListener("mozpointerlockchange", |
|
35 function (e) { |
|
36 is(isApproved, true, "Should only receive mozpointerlockchange when we've been approved for fullscreen."); |
|
37 document.mozCancelFullScreen(); |
|
38 }, false); |
|
39 |
|
40 function approveFullscreen() { |
|
41 isApproved = true; |
|
42 SpecialPowers.setFullscreenAllowed(document); |
|
43 } |
|
44 |
|
45 document.addEventListener("mozfullscreenchange", function(e) { |
|
46 if (document.mozFullScreenElement === div) { |
|
47 // First entered fullscreen. Request pointer lock... |
|
48 div.mozRequestPointerLock(); |
|
49 // ... But only approve fullscreen after a delay, giving the pointer |
|
50 // lock request time to run if it were going to. Note we need two timeouts |
|
51 // here to because if we were to fail and the pointer lock request were to |
|
52 // succeed without approval, we'd need to give it time to run, and time for |
|
53 // its asynchronously dispatched mozpointerlockchange to run. |
|
54 setTimeout(function(){ setTimeout(approveFullscreen, 0); }, 0); |
|
55 } else { |
|
56 SimpleTest.finish(); |
|
57 } |
|
58 }, false); |
|
59 |
|
60 function start() { |
|
61 div.mozRequestFullScreen(); |
|
62 } |
|
63 </script> |
|
64 </pre> |
|
65 </body> |
|
66 </html> |