dom/tests/mochitest/pointerlock/file_approval.html
author Nils Maier <maierman@web.de>
Wed, 28 Nov 2012 13:13:13 -0500
changeset 114378 0e5ca55005ae8ef9002ac12472740104fb79fd47
parent 93511 14018c3a1a237b2c3e0b0b12e70cb9aee44c57ee
permissions -rw-r--r--
Bug 719180: Part 2 - Add jar channel unit tests; r=taras

<!DOCTYPE HTML>
<html>
<!--https://bugzilla.mozilla.org/show_bug.cgi?id=746885-->
<head>
  <title>Bug 746885</title>
  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="pointerlock_utils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
  <a target="_blank"
    href="https://bugzilla.mozilla.org/show_bug.cgi?id=746885">
    Mozilla Bug 746885
  </a>
  <div id="div"></div>
  <pre id="test">
    <script type="text/javascript">
      /*
       * Test for Bug 746885
       * When requesting pointer lock on a domain that doesn't have fullscreen
       * permission, the pointer lock request should be delayed until approval
       * has been granted.
       */

      SimpleTest.waitForExplicitFinish();
      
      // Ensure fullscreen won't be automatically granted for this document's domain.
      SpecialPowers.removeFullscreenAllowed(document);

      var div = document.getElementById("div");
      var isApproved = false;

      document.addEventListener("mozpointerlockchange",
        function (e) {
          is(isApproved, true, "Should only receive mozpointerlockchange when we've been approved for fullscreen.");
          document.mozCancelFullScreen();
        }, false);

      function approveFullscreen() {
        isApproved = true;
        SpecialPowers.setFullscreenAllowed(document);
      }
      
      document.addEventListener("mozfullscreenchange", function(e) {
        if (document.mozFullScreenElement === div) {
          // First entered fullscreen. Request pointer lock...
          div.mozRequestPointerLock();
          // ... But only approve fullscreen after a delay, giving the pointer
          // lock request time to run if it were going to. Note we need two timeouts
          // here to because if we were to fail and the pointer lock request were to
          // succeed without approval, we'd need to give it time to run, and time for
          // its asynchronously dispatched mozpointerlockchange to run.
          setTimeout(function(){ setTimeout(approveFullscreen, 0); }, 0);
        } else {
          SimpleTest.finish();
        }
      }, false);
      
      function start() {
        div.mozRequestFullScreen();
      }
    </script>
  </pre>
</body>
</html>