| <!DOCTYPE HTML> |
| <html> |
| <head> |
| <script src="../fast/js/resources/js-test-pre.js"></script> |
| </head> |
| <body> |
| <div> |
| <div id="target"></div> |
| </div> |
| <script> |
| // FIXME: Rename this test to pointerlockchange-event-on-lock-lost. (https://bugs.webkit.org/show_bug.cgi?id=84402) |
| |
| description("Test that pointerlocklost event is dispatched.") |
| window.jsTestIsAsync = true; |
| shouldBeDefined("window.testRunner"); |
| |
| targetdiv = document.getElementById("target"); |
| |
| // FIXME: Keep pointerlockchange and pointerlockerror event usage. (https://bugs.webkit.org/show_bug.cgi?id=84402) |
| document.onwebkitpointerlockchange = lockchangeToUnlockedHandler; |
| document.onwebkitpointerlockerror = |
| function () { testFailed("document.onwebkitpointerlockerror dispatched"); finishJSTest(); }; |
| lockchangeToUnlockedHandlers = 1; |
| |
| lockchangeToUnlockedReceipts = 0; |
| function lockchangeToUnlockedHandler() { |
| if (navigator.webkitPointer.isLocked == false) { |
| testPassed("onwebkitpointerlockchange received."); |
| lockchangeToUnlockedReceipts++; |
| if (lockchangeToUnlockedReceipts == lockchangeToUnlockedHandlers) { |
| testPassed("All expected onwebkitpointerlockchange events received."); |
| } |
| } |
| } |
| |
| // FIXME: Remove pointerlocklost usage. (https://bugs.webkit.org/show_bug.cgi?id=84402) |
| document.addEventListener("webkitpointerlocklost", locklostHandler); |
| targetdiv.addEventListener("webkitpointerlocklost", locklostHandler); |
| locklosthandlers = 2; |
| |
| locklostreceipts = 0; |
| function locklostHandler() { |
| testPassed("webkitpointerlocklost handler call " + locklostreceipts); |
| locklostreceipts++; |
| if (locklostreceipts == locklosthandlers) { |
| testPassed("All expected webkitpointerlocklost events received."); |
| doNextStep(); |
| } |
| } |
| |
| currentStep = 0; |
| function doNextStep() { |
| setTimeout(function () { todo[currentStep++](); }, 0); |
| } |
| todo = [ |
| function () { |
| navigator.webkitPointer.lock(targetdiv, |
| function () { |
| shouldBe("navigator.webkitPointer.isLocked", "true"); |
| doNextStep(); |
| }, |
| function () { |
| testFailed("Lock failed."); |
| finishJSTest(); |
| }); |
| }, |
| function () { |
| shouldBe("document.webkitPointerLockElement", "targetdiv"); |
| debug("JavaScript initiated unlock.") |
| locklostreceipts = 0; |
| navigator.webkitPointer.unlock(); |
| }, |
| function () { |
| // locklostHandler will catch unlocks and call doNextStep to bring us here. |
| shouldBe("document.webkitPointerLockElement", "null"); |
| shouldBe("navigator.webkitPointer.isLocked", "false"); |
| doNextStep(); |
| }, |
| function () { |
| navigator.webkitPointer.lock(targetdiv, |
| function () { |
| shouldBe("navigator.webkitPointer.isLocked", "true"); |
| doNextStep(); |
| }, |
| function () { |
| testFailed("Lock failed."); |
| finishJSTest(); |
| }); |
| }, |
| function () { |
| shouldBe("document.webkitPointerLockElement", "targetdiv"); |
| debug("Host initiated unlock.") |
| lockchangeToUnlockedReceipts = 0; |
| locklostreceipts = 0; |
| testRunner.didLosePointerLock(); |
| }, |
| function () { |
| // locklostHandler will catch unlocks and call doNextStep to bring us here. |
| shouldBe("navigator.webkitPointer.isLocked", "false"); |
| shouldBe("document.webkitPointerLockElement", "null"); |
| doNextStep(); |
| }, |
| finishJSTest |
| ]; |
| doNextStep(); |
| </script> |
| <script src="../fast/js/resources/js-test-post.js"></script> |
| </body> |
| </html> |
| |