Bug 1175390 - Rewrite escapeKey test in pointer lock tests. r=smaug
authorXidorn Quan <quanxunzhen@gmail.com>
Wed, 17 Jun 2015 19:20:01 +1000
changeset 249323 6e3419fdcd80f97c025f05f3f699ffde9575d57d
parent 249322 65e6e21a47251b33d2b0a131530333707bde5ad9
child 249324 e8d2c117e4b194f0d3154d51b367af567f8ecd1d
push id28923
push userryanvm@gmail.com
push dateWed, 17 Jun 2015 18:57:11 +0000
treeherdermozilla-central@099d6cd6725e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1175390
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1175390 - Rewrite escapeKey test in pointer lock tests. r=smaug
dom/tests/mochitest/pointerlock/file_escapeKey.html
--- a/dom/tests/mochitest/pointerlock/file_escapeKey.html
+++ b/dom/tests/mochitest/pointerlock/file_escapeKey.html
@@ -23,39 +23,57 @@
        * Escape key should unlock the pointer
        */
 
       SimpleTest.waitForExplicitFinish();
 
       var div = document.getElementById("div")
         , pointerUnLocked = false;
 
-      function runTests () {
-        ok(pointerUnLocked, "Pressing Escape key should unlock the pointer");
+      function start() {
+        document.addEventListener("mozfullscreenchange", enteredFullscreen);
+        div.mozRequestFullScreen();
+      }
+
+      function enteredFullscreen(e) {
+        document.removeEventListener("mozfullscreenchange", enteredFullscreen);
+        is(document.mozFullScreenElement, div, "Element #div should entered fullscreen");
+        ok(!document.mozPointerLockElement, "Pointer shouldn't have been locked");
+        document.addEventListener("mozpointerlockchange", lockedPointer);
+        div.mozRequestPointerLock();
+      }
+
+      function lockedPointer(e) {
+        document.removeEventListener("mozpointerlockchange", lockedPointer);
+        is(document.mozPointerLockElement, div, "Pointer should have been locked on #div");
+        document.addEventListener("mozpointerlockchange", unlockedPointer);
+        document.addEventListener("mozfullscreenchange", leavedFullscreen);
+        SimpleTest.executeSoon(() => synthesizeKey("VK_ESCAPE", {}));
       }
 
-      document.addEventListener("mozpointerlockchange", function (e) {
-        if (document.mozPointerLockElement === div) {
-          synthesizeKey("VK_ESCAPE", {});
-        }
-        else {
-          pointerUnLocked = true;
-          document.mozCancelFullScreen();
-        }
-      }, false);
+      var pointerUnlocked = false;
+      var exitedFullscreen = false;
+
+      function unlockedPointer() {
+        document.removeEventListener("mozpointerlockchange", unlockedPointer);
+        ok(!pointerUnlocked, "Shouldn't have unlocked pointer before");
+        ok(!document.mozPointerLockElement, "Pointer should have been unlocked now");
+        pointerUnlocked = true;
+        finishTest();
+      }
 
-      document.addEventListener("mozfullscreenchange", function(e) {
-        if (document.mozFullScreenElement === div) {
-          div.mozRequestPointerLock();
-        }
-        else {
-          runTests();
+      function leavedFullscreen() {
+        document.removeEventListener("mozfullscreenchange", leavedFullscreen);
+        ok(!exitedFullscreen, "Shouldn't have exited fullscreen before");
+        ok(!document.mozFullScreenElement, "Should have exited fullscreen now");
+        exitedFullscreen = true;
+        finishTest();
+      }
+
+      function finishTest() {
+        if (pointerUnlocked && exitedFullscreen) {
           SimpleTest.finish();
         }
-      }, false);
-
-      function start() {
-        div.mozRequestFullScreen();
       }
     </script>
   </pre>
 </body>
 </html>