Add new Pointer Lock spec attribute webkitPointerLockElement.
[WebKit-https.git] / LayoutTests / pointer-lock / lock-already-locked.html
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <script src="../fast/js/resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <div>
8   <div id="target1"></div>
9   <div id="target2"></div>
10 </div>
11 <script>
12     description("Test calling lock when already in a locked state.")
13     window.jsTestIsAsync = true;
14
15     targetdiv1 = document.getElementById("target1");
16     targetdiv2 = document.getElementById("target2");
17
18     // Expect change event only for all transitions below.
19     expectedTargetToBeLockedString = "";
20     document.onwebkitpointerlockchange = function ()
21         {
22             testPassed("document.onwebkitpointerlockchange event received.");
23             shouldBe("document.webkitPointerLockElement", expectedTargetToBeLockedString);
24         };
25     document.onwebkitpointerlockerror =
26         function () { testFailed("document.onwebkitpointerlockerror event received."); finishJSTest(); };
27
28     var expectTarget1Unlock = false;
29     targetdiv1.addEventListener("webkitpointerlocklost",
30         function () { shouldBe("expectTarget1Unlock", "true"); });
31
32     targetdiv2.addEventListener("webkitpointerlocklost",
33         function () { testFailed("Unexpected targetdiv2 pointerlocklost."); });
34
35     currentStep = 0;
36     function doNextStep() {
37       setTimeout(function () { todo[currentStep++](); }, 0);
38     }
39     todo = [
40         function () {
41             shouldBe("navigator.webkitPointer.isLocked", "false");
42             navigator.webkitPointer.lock(targetdiv1,
43                 function () {
44                     testPassed("Lock target1 succeeded.");
45                     shouldBe("navigator.webkitPointer.isLocked", "true");
46                     doNextStep();
47                 },
48                 function () {
49                     testFailed("Lock failed.");
50                     finishJSTest();
51                 });
52             expectedTargetToBeLockedString = "targetdiv1";
53         },
54         function () {
55             navigator.webkitPointer.lock(targetdiv1,
56                 function () {
57                     testPassed("Lock target1 succeeded again.");
58                     shouldBe("navigator.webkitPointer.isLocked", "true");
59                     doNextStep();
60                 },
61                 function () {
62                     testFailed("Lock failed.");
63                     finishJSTest();
64                 });
65             expectedTargetToBeLockedString = "targetdiv1";
66         },
67         function () {
68             expectTarget1Unlock = true;
69             navigator.webkitPointer.lock(targetdiv2,
70                 function () {
71                     testPassed("Lock target2 succeeded.");
72                     shouldBe("navigator.webkitPointer.isLocked", "true");
73                     doNextStep();
74                 },
75                 function () {
76                     testFailed("Lock failed.");
77                     finishJSTest();
78                 });
79             expectedTargetToBeLockedString = "targetdiv2";
80         },
81         finishJSTest
82     ];
83     doNextStep();
84 </script>
85 <script src="../fast/js/resources/js-test-post.js"></script>
86 </body>
87 </html>