dom/tests/mochitest/pointerlock/test_pointerlock-api.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=633602
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 633602</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633602">
michael@0 14 Mozilla Bug 633602
michael@0 15 </a>
michael@0 16 <div id="content">
michael@0 17 </div>
michael@0 18 <pre id="test">
michael@0 19 <script type="application/javascript">
michael@0 20
michael@0 21 /**
michael@0 22 * Pointer Lock tests for bug 633602. These depend on the fullscreen api
michael@0 23 * which doesn't work when run in the mochitests' iframe, since the
michael@0 24 * mochitests' iframe doesn't have an allowfullscreen attribute. To get
michael@0 25 * around this, all tests are run in a child window, which can go fullscreen.
michael@0 26 * This method is borrowed from content/html/content/test/test_fullscreen-api.html.
michael@0 27 **/
michael@0 28
michael@0 29 SimpleTest.waitForExplicitFinish();
michael@0 30
michael@0 31 // Ensure the full-screen api is enabled, and will be disabled on test exit.
michael@0 32 SpecialPowers.setBoolPref("full-screen-api.enabled", true);
michael@0 33
michael@0 34 // Disable the requirement for trusted contexts only, so the tests are easier to write.
michael@0 35 SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", false);
michael@0 36
michael@0 37 // Grant "fullscreen" permission on the test domain. This means fullscreen will be
michael@0 38 // automatically approved, so pointer lock in the tests will be too.
michael@0 39 SpecialPowers.setFullscreenAllowed(document);
michael@0 40
michael@0 41 // Run the tests which go full-screen in new window, as Mochitests
michael@0 42 // normally run in an iframe, which by default will not have the
michael@0 43 // allowfullscreen attribute set, so full-screen won't work.
michael@0 44 var gTestFiles = [
michael@0 45 "file_approval.html",
michael@0 46 "file_screenClientXYConst.html",
michael@0 47 "file_childIframe.html",
michael@0 48 "file_doubleLock.html",
michael@0 49 "file_escapeKey.html",
michael@0 50 "file_infiniteMovement.html",
michael@0 51 "file_locksvgelement.html",
michael@0 52 "file_movementXY.html",
michael@0 53 "file_nestedFullScreen.html",
michael@0 54 "file_pointerlock-api.html",
michael@0 55 "file_pointerlockerror.html",
michael@0 56 "file_pointerLockPref.html",
michael@0 57 "file_removedFromDOM.html",
michael@0 58 "file_retargetMouseEvents.html",
michael@0 59 "file_suppressSomeMouseEvents.html",
michael@0 60 "file_targetOutOfFocus.html",
michael@0 61 "file_withoutDOM.html",
michael@0 62 "file_allowPointerLockSandboxFlag.html"
michael@0 63 ];
michael@0 64
michael@0 65 var gTestWindow = null;
michael@0 66 var gTestIndex = 0;
michael@0 67
michael@0 68 // TODO: if ever we remove these checks for XP and Lion, we should do the same
michael@0 69 // in content/html/content/test/test_fullscreen-api.html, which uses the same pattern.
michael@0 70 const isWinXP = navigator.userAgent.indexOf("Windows NT 5.1") != -1;
michael@0 71 const isOSXLion = navigator.userAgent.indexOf("Mac OS X 10.7") != -1;
michael@0 72 const isOSXMtnLion = navigator.userAgent.indexOf("Mac OS X 10.8") != -1;
michael@0 73 const isWin8 = navigator.userAgent.indexOf("Windows NT 6.2") != -1;
michael@0 74
michael@0 75 function finish() {
michael@0 76 SpecialPowers.clearUserPref("full-screen-api.enabled");
michael@0 77 SpecialPowers.clearUserPref("full-screen-api.allow-trusted-requests-only");
michael@0 78 SpecialPowers.removeFullscreenAllowed(document)
michael@0 79 SimpleTest.finish();
michael@0 80 }
michael@0 81
michael@0 82 function nextTest() {
michael@0 83 if (isWinXP) {
michael@0 84 todo(false, "Can't reliably run full-screen tests on Windows XP due to bug 704010");
michael@0 85 finish();
michael@0 86 return;
michael@0 87 }
michael@0 88 if (isWin8) {
michael@0 89 todo(false, "Can't reliably run full-screen + pointer lock tests on Windows 8");
michael@0 90 finish();
michael@0 91 return;
michael@0 92 }
michael@0 93 if (isOSXLion || isOSXMtnLion) {
michael@0 94 todo(false, "Can't reliably run full-screen tests on OS X Lion or Mountain Lion, see bug 744125");
michael@0 95 finish();
michael@0 96 return;
michael@0 97 }
michael@0 98 if (gTestWindow) {
michael@0 99 gTestWindow.close();
michael@0 100 }
michael@0 101 SimpleTest.waitForFocus(runNextTest);
michael@0 102 }
michael@0 103
michael@0 104 function runNextTest() {
michael@0 105 if (gTestIndex < gTestFiles.length) {
michael@0 106 gTestWindow = window.open(gTestFiles[gTestIndex], "", "width=500,height=500");
michael@0 107 gTestIndex++;
michael@0 108 } else {
michael@0 109 finish();
michael@0 110 }
michael@0 111 }
michael@0 112
michael@0 113 addLoadEvent(nextTest);
michael@0 114 </script>
michael@0 115 </pre>
michael@0 116 </body>
michael@0 117 </html>

mercurial