Refactor common Pointer Lock test code to a harness.
authorscheib@chromium.org <scheib@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Jul 2012 21:19:26 +0000 (21:19 +0000)
committerscheib@chromium.org <scheib@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Jul 2012 21:19:26 +0000 (21:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90813

Reviewed by Adrienne Walker.

* pointer-lock/bug90391-move-then-window-open-crash-expected.txt:
* pointer-lock/bug90391-move-then-window-open-crash.html:
* pointer-lock/lock-already-locked-expected.txt:
* pointer-lock/lock-already-locked.html:
* pointer-lock/lock-fail-responses-expected.txt:
* pointer-lock/lock-fail-responses.html:
* pointer-lock/mouse-event-delivery-expected.txt:
* pointer-lock/mouse-event-delivery.html:
* pointer-lock/pointer-lock-api-expected.txt:
* pointer-lock/pointer-lock-api.html:
* pointer-lock/pointerlockchange-pointerlockerror-events-expected.txt:
* pointer-lock/pointerlockchange-pointerlockerror-events.html:
* pointer-lock/pointerlocklost-event-expected.txt:
* pointer-lock/pointerlocklost-event.html:
* pointer-lock/resources/pointer-lock-test-harness.js: Added.
(doNextStep.else):
(doNextStepWithUserGesture):
(eventExpected.targetHanderNode.eventHandlerName):
(eventExpected):
(expectOnlyChangeEvent):
(expectOnlyErrorEvent):
(expectNoEvents):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@122158 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
LayoutTests/ChangeLog
LayoutTests/pointer-lock/bug90391-move-then-window-open-crash-expected.txt
LayoutTests/pointer-lock/bug90391-move-then-window-open-crash.html
LayoutTests/pointer-lock/lock-already-locked-expected.txt
LayoutTests/pointer-lock/lock-already-locked.html
LayoutTests/pointer-lock/lock-fail-responses.html
LayoutTests/pointer-lock/mouse-event-delivery-expected.txt
LayoutTests/pointer-lock/mouse-event-delivery.html
LayoutTests/pointer-lock/pointer-lock-api-expected.txt
LayoutTests/pointer-lock/pointer-lock-api.html
LayoutTests/pointer-lock/pointerlockchange-pointerlockerror-events-expected.txt
LayoutTests/pointer-lock/pointerlockchange-pointerlockerror-events.html
LayoutTests/pointer-lock/pointerlocklost-event.html
LayoutTests/pointer-lock/resources/pointer-lock-test-harness.js [new file with mode: 0644]

index b8b51f4..78bc02b 100644 (file)
@@ -1,3 +1,33 @@
+2012-07-09  Vincent Scheib  <scheib@chromium.org>
+
+        Refactor common Pointer Lock test code to a harness.
+        https://bugs.webkit.org/show_bug.cgi?id=90813
+
+        Reviewed by Adrienne Walker.
+
+        * pointer-lock/bug90391-move-then-window-open-crash-expected.txt:
+        * pointer-lock/bug90391-move-then-window-open-crash.html:
+        * pointer-lock/lock-already-locked-expected.txt:
+        * pointer-lock/lock-already-locked.html:
+        * pointer-lock/lock-fail-responses-expected.txt:
+        * pointer-lock/lock-fail-responses.html:
+        * pointer-lock/mouse-event-delivery-expected.txt:
+        * pointer-lock/mouse-event-delivery.html:
+        * pointer-lock/pointer-lock-api-expected.txt:
+        * pointer-lock/pointer-lock-api.html:
+        * pointer-lock/pointerlockchange-pointerlockerror-events-expected.txt:
+        * pointer-lock/pointerlockchange-pointerlockerror-events.html:
+        * pointer-lock/pointerlocklost-event-expected.txt:
+        * pointer-lock/pointerlocklost-event.html:
+        * pointer-lock/resources/pointer-lock-test-harness.js: Added.
+        (doNextStep.else):
+        (doNextStepWithUserGesture):
+        (eventExpected.targetHanderNode.eventHandlerName):
+        (eventExpected):
+        (expectOnlyChangeEvent):
+        (expectOnlyErrorEvent):
+        (expectNoEvents):
+
 2012-07-09  Dean Jackson  <dino@apple.com>
 
         Tiled drawing means some elements can disappear behind the page
index ccf4131..5fbf5b3 100644 (file)
@@ -2,10 +2,10 @@
 <html>
 <head>
 <script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/pointer-lock-test-harness.js"></script>
 </head>
 <body>
 <div>
-  <button onclick="doNextStep('manual');">doNextStep for manual testing</button>
   <div id="target1"></div>
 </div>
 <script>
 
     targetdiv1 = document.getElementById("target1");
 
-    currentStep = 0;
-    function doNextStep(manual)
-    {
-        if (!window.layoutTestController && !manual)
-            return;
-        if (currentStep < todo.length)
-            setTimeout(function () { todo[currentStep++](); }, 0);
-        else if (currentStep++ == todo.length)
-            setTimeout(function () { finishJSTest(); }, 0);
-    }
     todo = [
         function () {
             debug("     Locking targetdiv1.")
@@ -31,7 +21,7 @@
             document.onwebkitpointerlockchange = function () {
                 document.onwebkitpointerlockchange = null;
                 testPassed("document.onwebkitpointerlockchange event received.");
-                doNextStep('manual');
+                doNextStep();
             };
         },
         function () {
@@ -40,7 +30,7 @@
             targetdiv1.onmousemove = function () {
                 if (++mouseMoveEvents == 2) {
                     targetdiv1.onmousemove = null;
-                    doNextStep('manual');
+                    doNextStep();
                 }
             }
             if (window.eventSender) {
             window.open();
             testPassed("Didn't crash");
             document.webkitExitPointerLock();
-            doNextStep('manual');
+            doNextStep();
         },
     ];
-    doNextStep();
+    doNextStepWithUserGesture();
 </script>
 <script src="../fast/js/resources/js-test-post.js"></script>
 </body>
index f65fc38..13d74c7 100644 (file)
@@ -31,5 +31,4 @@ PASS document.webkitPointerLockElement is targetdiv2
 PASS successfullyParsed is true
 
 TEST COMPLETE
-doNextStep for manual testing
 
index ec024f6..9f4d574 100644 (file)
@@ -2,10 +2,10 @@
 <html>
 <head>
 <script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/pointer-lock-test-harness.js"></script>
 </head>
 <body>
 <div>
-  <button onclick="doNextStep('manual');">doNextStep for manual testing</button>
   <div id="target1"></div>
   <div id="target2"></div>
 </div>
@@ -22,7 +22,7 @@
         {
             testPassed("document.onwebkitpointerlockchange event received.");
             shouldBe("document.webkitPointerLockElement", expectedTargetToBeLockedString);
-            doNextStep();
+            doNextStepWithUserGesture();
         };
     document.onwebkitpointerlockerror =
         function () { testFailed("document.onwebkitpointerlockerror event received."); finishJSTest(); };
     targetdiv2.addEventListener("webkitpointerlocklost",
         function () { shouldBe("expectTarget2Unlock", "true"); });
 
-    currentStep = 0;
-    function doNextStep(manual)
-    {
-        if (!window.layoutTestController && !manual)
-            return;
-        if (currentStep < todo.length)
-            setTimeout(function () { todo[currentStep++](); }, 0);
-        else if (currentStep++ == todo.length)
-            setTimeout(function () { finishJSTest(); }, 0);
-    }
     todo = [
         function () {
             shouldBe("document.webkitPointerLockElement", "null");
             expectedTargetToBeLockedString = "targetdiv2";
         },
     ];
-    doNextStep();
+    doNextStepWithUserGesture();
 </script>
 <script src="../fast/js/resources/js-test-post.js"></script>
 </body>
index cdf5c63..d8c2977 100644 (file)
@@ -2,6 +2,7 @@
 <html>
 <head>
 <script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/pointer-lock-test-harness.js"></script>
 </head>
 <body>
 <script>
@@ -9,10 +10,6 @@
     window.jsTestIsAsync = true;
     shouldBeDefined("window.testRunner");
 
-    currentStep = 0;
-    function doNextStep() {
-      todo[currentStep++]();
-    }
     todo = [
         function () {
             testRunner.setPointerLockWillFailSynchronously();
@@ -23,7 +20,7 @@
                 },
                 function () {
                     testPassed("Lock failed (after we called testRunner.setPointerLockWillFailSynchronously)");
-                    doNextStep();
+                    doNextStepWithUserGesture();
                 });
         },
         function () {
@@ -38,9 +35,8 @@
                     doNextStep();
                 });
         },
-        finishJSTest
     ];
-    doNextStep();
+    doNextStepWithUserGesture();
 </script>
 <script src="../fast/js/resources/js-test-post.js"></script>
 </body>
index a2cfae4..1144d4a 100644 (file)
@@ -32,5 +32,4 @@ PASS event type: click, target: target2, received on: target2
 PASS successfullyParsed is true
 
 TEST COMPLETE
-doNextStep for manual testing
 
index 8d07a0a..e2f0410 100644 (file)
@@ -2,10 +2,10 @@
 <html>
 <head>
 <script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/pointer-lock-test-harness.js"></script>
 </head>
 <body id="body">
 <div>
-  <button onclick="doNextStep('manual');">doNextStep for manual testing</button>
   <div id="target1"></div>
   <div id="target2"></div>
 </div>
@@ -22,7 +22,7 @@
         {
             testPassed("document.onwebkitpointerlockchange event received.");
             shouldBe("document.webkitPointerLockElement", expectedTargetToBeLockedString);
-            doNextStep('manual');
+            doNextStep();
         };
     document.onwebkitpointerlockerror =
         function () { testFailed("document.onwebkitpointerlockerror event received."); finishJSTest(); };
       testPassed("event type: " + e.type + ", target: " + e.target.id + ", received on: " + e.currentTarget.id);
     }
 
-    currentStep = 0;
-    function doNextStep(manual)
-    {
-        if (!window.layoutTestController && !manual)
-            return;
-        if (currentStep < todo.length)
-            setTimeout(function () { todo[currentStep++](); }, 0);
-        else if (currentStep++ == todo.length)
-            setTimeout(function () { finishJSTest(); }, 0);
-    }
     todo = [
         function () {
             targetdiv1.webkitRequestPointerLock();
@@ -61,7 +51,7 @@
                 window.eventSender.mouseDown();
                 window.eventSender.mouseUp();
             }
-            doNextStep();
+            doNextStepWithUserGesture();
         },
         function () {
             targetdiv2.webkitRequestPointerLock();
@@ -78,7 +68,7 @@
                 window.eventSender.mouseDown();
                 window.eventSender.mouseUp();
             }
-            doNextStep();
+            doNextStepWithUserGesture();
         },
         function () {
             debug("     Ensure double clicks work as expected, sending 4 clicks.")
                 window.eventSender.mouseDown();
                 window.eventSender.mouseUp();
             }
-            doNextStep();
+            doNextStepWithUserGesture();
         },
     ];
-    doNextStep();
+    doNextStepWithUserGesture();
 </script>
 <script src="../fast/js/resources/js-test-post.js"></script>
 </body>
index add2aaa..eb2dc98 100644 (file)
@@ -17,4 +17,4 @@ PASS element.webkitRequestPointerLock is defined.
 PASS successfullyParsed is true
 
 TEST COMPLETE
-doNextStep for manual testing
+
index fb14dc4..ce12db4 100644 (file)
@@ -2,23 +2,13 @@
 <html>
 <head>
 <script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/pointer-lock-test-harness.js"></script>
 </head>
 <body>
-<button onclick="doNextStep('manual');">doNextStep for manual testing</button>
 <script>
     description("Basic API existence test for Pointer Lock.")
     window.jsTestIsAsync = true;
 
-    currentStep = 0;
-    function doNextStep(manual)
-    {
-        if (!window.testRunner && !manual)
-            return;
-        if (currentStep < todo.length)
-            setTimeout(function () { todo[currentStep++](); }, 0);
-        else if (currentStep++ == todo.length)
-            setTimeout(function () { finishJSTest(); }, 0);
-    }
     todo = [
         function () {
             shouldBeDefined("navigator.webkitPointer");
@@ -43,7 +33,7 @@
             doNextStep();
         },
     ];
-    doNextStep();
+    doNextStepWithUserGesture();
 </script>
 <script src="../fast/js/resources/js-test-post.js"></script>
 </body>
index 69c6633..c5b13e0 100644 (file)
@@ -36,5 +36,4 @@ PASS onwebkitpointerlockerror received after: Lock with asynchronous failure.
 PASS successfullyParsed is true
 
 TEST COMPLETE
-doNextStep for manual testing
   
index 20c13b5..9a101c4 100644 (file)
@@ -2,10 +2,10 @@
 <html>
 <head>
 <script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/pointer-lock-test-harness.js"></script>
 </head>
 <body>
 <div>
-  <button onclick="doNextStep('manual');">doNextStep for manual testing</button>
   <div id="target1"></div>
   <div id="target2"></div>
   <iframe id="iframe1"></iframe>
     targetIframe1 = document.getElementById("iframe1");
     targetIframe2 = document.getElementById("iframe2");
 
-    function eventExpected(eventHandlerName, message, expectedCalls, targetHanderNode)
-    {
-        targetHanderNode[eventHandlerName] = function ()
-            {
-                switch (expectedCalls--) {
-                case 0:
-                    testFailed(eventHandlerName + " received after: " + message);
-                    finishJSTest();
-                    break;
-                case 1:
-                    doNextStep();
-                default:
-                    testPassed(eventHandlerName + " received after: " + message);
-                };
-            };
-    };
-
-    function expectOnlyChangeEvent(message, targetDocument) {
-        debug("     " + message);
-        targetDocument = targetDocument !== undefined ? targetDocument : document;
-        eventExpected("onwebkitpointerlockchange", message, 1, targetDocument);
-        eventExpected("onwebkitpointerlockerror", message, 0, targetDocument);
-    };
-
-    function expectOnlyErrorEvent(message, targetDocument) {
-        debug("     " + message);
-        targetDocument = targetDocument !== undefined ? targetDocument : document;
-        eventExpected("onwebkitpointerlockchange", message, 0, targetDocument);
-        eventExpected("onwebkitpointerlockerror", message, 1, targetDocument);
-    };
-
-    function expectNoEvents(message, targetDocument) {
-        debug("     " + message);
-        targetDocument = targetDocument !== undefined ? targetDocument : document;
-        eventExpected("onwebkitpointerlockchange", message, 0, targetDocument);
-        eventExpected("onwebkitpointerlockerror", message, 0, targetDocument);
-    };
-
-    currentStep = 0;
-    function doNextStep(manual)
-    {
-        if (!window.testRunner && !manual)
-            return;
-        if (currentStep < todo.length)
-            setTimeout(function () { todo[currentStep++](); }, 0);
-        else if (currentStep++ == todo.length)
-            setTimeout(function () { finishJSTest(); }, 0);
-    }
     todo = [
         function () {
             expectNoEvents("Unlock.");
             document.webkitExitPointerLock();
-            doNextStep();
+            doNextStepWithUserGesture();
         },
         function () {
             expectOnlyChangeEvent("Lock targetDiv1.");
index 2adc1b7..3bc316f 100644 (file)
@@ -2,6 +2,7 @@
 <html>
 <head>
 <script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/pointer-lock-test-harness.js"></script>
 </head>
 <body>
 <div>
         }
     }
 
-    currentStep = 0;
-    function doNextStep() {
-      setTimeout(function () { todo[currentStep++](); }, 0);
-    }
     todo = [
         function () {
             navigator.webkitPointer.lock(targetdiv,
@@ -74,7 +71,7 @@
             // locklostHandler will catch unlocks and call doNextStep to bring us here.
             shouldBe("document.webkitPointerLockElement", "null");
             shouldBe("navigator.webkitPointer.isLocked", "false");
-            doNextStep();
+            doNextStepWithUserGesture();
         },
         function () {
             navigator.webkitPointer.lock(targetdiv,
             shouldBe("document.webkitPointerLockElement", "null");
             doNextStep();
         },
-        finishJSTest
     ];
-    doNextStep();
+    doNextStepWithUserGesture();
 </script>
 <script src="../fast/js/resources/js-test-post.js"></script>
 </body>
diff --git a/LayoutTests/pointer-lock/resources/pointer-lock-test-harness.js b/LayoutTests/pointer-lock/resources/pointer-lock-test-harness.js
new file mode 100644 (file)
index 0000000..48a1be5
--- /dev/null
@@ -0,0 +1,64 @@
+// Automatically add doNextStepButton to document for manual tests.
+if (!window.testRunner) {
+    setTimeout(function () {
+        doNextStepButton = document.body.insertBefore(document.createElement("button"), document.body.firstChild);
+        doNextStepButton.onclick = doNextStep;
+        doNextStepButton.innerText = "doNextStep button for manual testing. Use keyboard to select button and press (TAB, then SPACE).";
+    }, 0);
+}
+
+function doNextStep()
+{
+    if (typeof(currentStep) == "undefined")
+        currentStep = 0;
+
+    if (currentStep < todo.length)
+        setTimeout(function () { todo[currentStep++](); }, 0);
+    else if (currentStep++ == todo.length)
+        setTimeout(function () { finishJSTest(); }, 0);
+}
+
+function doNextStepWithUserGesture()
+{
+    if (!window.testRunner)
+        return; // Wait for human to press doNextStep button.
+    doNextStep();
+}
+
+function eventExpected(eventHandlerName, message, expectedCalls, targetHanderNode)
+{
+    targetHanderNode[eventHandlerName] = function () {
+        switch (expectedCalls--) {
+        case 0:
+            testFailed(eventHandlerName + " received after: " + message);
+            finishJSTest();
+            break;
+        case 1:
+            doNextStep();
+        default:
+            testPassed(eventHandlerName + " received after: " + message);
+        };
+    };
+};
+
+function expectOnlyChangeEvent(message, targetDocument) {
+    debug("     " + message);
+    targetDocument = targetDocument !== undefined ? targetDocument : document;
+    eventExpected("onwebkitpointerlockchange", message, 1, targetDocument);
+    eventExpected("onwebkitpointerlockerror", message, 0, targetDocument);
+};
+
+function expectOnlyErrorEvent(message, targetDocument) {
+    debug("     " + message);
+    targetDocument = targetDocument !== undefined ? targetDocument : document;
+    eventExpected("onwebkitpointerlockchange", message, 0, targetDocument);
+    eventExpected("onwebkitpointerlockerror", message, 1, targetDocument);
+};
+
+function expectNoEvents(message, targetDocument) {
+    debug("     " + message);
+    targetDocument = targetDocument !== undefined ? targetDocument : document;
+    eventExpected("onwebkitpointerlockchange", message, 0, targetDocument);
+    eventExpected("onwebkitpointerlockerror", message, 0, targetDocument);
+};
+