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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/pointerlock/test_pointerlock-api.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,117 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=633602
     1.8 +-->
     1.9 +  <head>
    1.10 +    <title>Test for Bug 633602</title>
    1.11 +    <script type="application/javascript"  src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +    <script type="application/javascript"  src="/tests/SimpleTest/EventUtils.js"></script>
    1.13 +    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +  </head>
    1.15 +  <body>
    1.16 +    <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633602">
    1.17 +      Mozilla Bug 633602
    1.18 +    </a>
    1.19 +    <div id="content">
    1.20 +    </div>
    1.21 +    <pre id="test">
    1.22 +      <script type="application/javascript">
    1.23 +
    1.24 +        /**
    1.25 +         * Pointer Lock tests for bug 633602.  These depend on the fullscreen api
    1.26 +         * which doesn't work when run in the mochitests' iframe, since the
    1.27 +         * mochitests' iframe doesn't have an allowfullscreen attribute.  To get
    1.28 +         * around this, all tests are run in a child window, which can go fullscreen.
    1.29 +         * This method is borrowed from content/html/content/test/test_fullscreen-api.html.
    1.30 +         **/
    1.31 +
    1.32 +        SimpleTest.waitForExplicitFinish();
    1.33 +
    1.34 +        // Ensure the full-screen api is enabled, and will be disabled on test exit.
    1.35 +        SpecialPowers.setBoolPref("full-screen-api.enabled", true);
    1.36 +
    1.37 +        // Disable the requirement for trusted contexts only, so the tests are easier to write.
    1.38 +        SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", false);
    1.39 +
    1.40 +        // Grant "fullscreen" permission on the test domain. This means fullscreen will be
    1.41 +        // automatically approved, so pointer lock in the tests will be too.
    1.42 +        SpecialPowers.setFullscreenAllowed(document);
    1.43 +
    1.44 +        // Run the tests which go full-screen in new window, as Mochitests
    1.45 +        // normally run in an iframe, which by default will not have the
    1.46 +        // allowfullscreen attribute set, so full-screen won't work.
    1.47 +        var gTestFiles = [
    1.48 +          "file_approval.html",
    1.49 +          "file_screenClientXYConst.html",
    1.50 +          "file_childIframe.html",
    1.51 +          "file_doubleLock.html",
    1.52 +          "file_escapeKey.html",
    1.53 +          "file_infiniteMovement.html",
    1.54 +          "file_locksvgelement.html",
    1.55 +          "file_movementXY.html",
    1.56 +          "file_nestedFullScreen.html",
    1.57 +          "file_pointerlock-api.html",
    1.58 +          "file_pointerlockerror.html",
    1.59 +          "file_pointerLockPref.html",
    1.60 +          "file_removedFromDOM.html",
    1.61 +          "file_retargetMouseEvents.html",
    1.62 +          "file_suppressSomeMouseEvents.html",
    1.63 +          "file_targetOutOfFocus.html",
    1.64 +          "file_withoutDOM.html",
    1.65 +          "file_allowPointerLockSandboxFlag.html"
    1.66 +        ];
    1.67 +
    1.68 +        var gTestWindow = null;
    1.69 +        var gTestIndex = 0;
    1.70 +
    1.71 +        // TODO: if ever we remove these checks for XP and Lion, we should do the same
    1.72 +        // in content/html/content/test/test_fullscreen-api.html, which uses the same pattern.
    1.73 +        const isWinXP = navigator.userAgent.indexOf("Windows NT 5.1") != -1;
    1.74 +        const isOSXLion = navigator.userAgent.indexOf("Mac OS X 10.7") != -1;
    1.75 +        const isOSXMtnLion = navigator.userAgent.indexOf("Mac OS X 10.8") != -1;
    1.76 +        const isWin8 = navigator.userAgent.indexOf("Windows NT 6.2") != -1;
    1.77 +
    1.78 +        function finish() {
    1.79 +          SpecialPowers.clearUserPref("full-screen-api.enabled");
    1.80 +          SpecialPowers.clearUserPref("full-screen-api.allow-trusted-requests-only");
    1.81 +          SpecialPowers.removeFullscreenAllowed(document)
    1.82 +          SimpleTest.finish();
    1.83 +        }
    1.84 +
    1.85 +        function nextTest() {
    1.86 +          if (isWinXP) {
    1.87 +            todo(false, "Can't reliably run full-screen tests on Windows XP due to bug 704010");
    1.88 +            finish();
    1.89 +            return;
    1.90 +          }
    1.91 +          if (isWin8) {
    1.92 +            todo(false, "Can't reliably run full-screen + pointer lock tests on Windows 8");
    1.93 +            finish();
    1.94 +            return;
    1.95 +          }
    1.96 +          if (isOSXLion || isOSXMtnLion) {
    1.97 +            todo(false, "Can't reliably run full-screen tests on OS X Lion or Mountain Lion, see bug 744125");
    1.98 +            finish();
    1.99 +            return;
   1.100 +          }
   1.101 +          if (gTestWindow) {
   1.102 +            gTestWindow.close();
   1.103 +          }
   1.104 +          SimpleTest.waitForFocus(runNextTest);
   1.105 +        }
   1.106 +
   1.107 +        function runNextTest() {
   1.108 +          if (gTestIndex < gTestFiles.length) {
   1.109 +            gTestWindow = window.open(gTestFiles[gTestIndex], "", "width=500,height=500");
   1.110 +            gTestIndex++;
   1.111 +          } else {
   1.112 +            finish();
   1.113 +          }
   1.114 +        }
   1.115 +
   1.116 +        addLoadEvent(nextTest);
   1.117 +      </script>
   1.118 +    </pre>
   1.119 +  </body>
   1.120 +</html>

mercurial