lock-already-locked.html 2.33 KB
Newer Older
1 2 3
<!DOCTYPE HTML>
<html>
<head>
4 5
<script src="../http/tests/resources/js-test-pre.js"></script>
<script src="../http/tests/resources/pointer-lock/pointer-lock-test-harness.js"></script>
6 7 8 9 10 11 12 13 14 15 16 17 18
</head>
<body>
<div>
  <div id="target1"></div>
  <div id="target2"></div>
</div>
<script>
    description("Test calling lock when already in a locked state.")
    window.jsTestIsAsync = true;

    targetdiv1 = document.getElementById("target1");
    targetdiv2 = document.getElementById("target2");

19
    // Expect change event only for all transitions below.
20 21 22 23 24
    expectedTargetToBeLockedString = "";
    document.onwebkitpointerlockchange = function ()
        {
            testPassed("document.onwebkitpointerlockchange event received.");
            shouldBe("document.webkitPointerLockElement", expectedTargetToBeLockedString);
25
            doNextStepWithUserGesture();
26
        };
27 28 29
    document.onwebkitpointerlockerror =
        function () { testFailed("document.onwebkitpointerlockerror event received."); finishJSTest(); };

30 31 32 33
    var expectTarget1Unlock = false;
    targetdiv1.addEventListener("webkitpointerlocklost",
        function () { shouldBe("expectTarget1Unlock", "true"); });

34
    var expectTarget2Unlock = false;
35
    targetdiv2.addEventListener("webkitpointerlocklost",
36
        function () { shouldBe("expectTarget2Unlock", "true"); });
37 38 39

    todo = [
        function () {
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
            shouldBe("document.webkitPointerLockElement", "null");
            debug("     Locking targetdiv1.")
            targetdiv1.webkitRequestPointerLock();
            expectedTargetToBeLockedString = "targetdiv1";
            // doNextStep() called by onwebkitpointerlockchange handler.
        },
        function () {
            debug("     Locking targetdiv1, again.")
            targetdiv1.webkitRequestPointerLock();
            expectedTargetToBeLockedString = "targetdiv1";
            // doNextStep() called by onwebkitpointerlockchange handler.
        },
        function () {
            debug("     Locking targetdiv2.")
            expectTarget1Unlock = true;
            targetdiv2.webkitRequestPointerLock();
            expectedTargetToBeLockedString = "targetdiv2";
            // doNextStep() called by onwebkitpointerlockchange handler.
        },
59
    ];
60
    doNextStepWithUserGesture();
61
</script>
62
<script src="../http/tests/resources/js-test-post.js"></script>
63 64
</body>
</html>