Add new Pointer Lock spec webkitRequestPointerLock and webkitExitPointerLock methods.
[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   <button onclick="doNextStep('manual');">doNextStep for manual testing</button>
9   <div id="target1"></div>
10   <div id="target2"></div>
11 </div>
12 <script>
13     description("Test calling lock when already in a locked state.")
14     window.jsTestIsAsync = true;
15
16     targetdiv1 = document.getElementById("target1");
17     targetdiv2 = document.getElementById("target2");
18
19     // Expect change event only for all transitions below.
20     expectedTargetToBeLockedString = "";
21     document.onwebkitpointerlockchange = function ()
22         {
23             testPassed("document.onwebkitpointerlockchange event received.");
24             shouldBe("document.webkitPointerLockElement", expectedTargetToBeLockedString);
25             doNextStep();
26         };
27     document.onwebkitpointerlockerror =
28         function () { testFailed("document.onwebkitpointerlockerror event received."); finishJSTest(); };
29
30     var expectTarget1Unlock = false;
31     targetdiv1.addEventListener("webkitpointerlocklost",
32         function () { shouldBe("expectTarget1Unlock", "true"); });
33
34     var expectTarget2Unlock = false;
35     targetdiv2.addEventListener("webkitpointerlocklost",
36         function () { shouldBe("expectTarget2Unlock", "true"); });
37
38     currentStep = 0;
39     function doNextStep(manual)
40     {
41         if (!window.layoutTestController && !manual)
42             return;
43         if (currentStep < todo.length)
44             setTimeout(function () { todo[currentStep++](); }, 0);
45         else if (currentStep++ == todo.length)
46             setTimeout(function () { finishJSTest(); }, 0);
47     }
48     todo = [
49         function () {
50             shouldBe("document.webkitPointerLockElement", "null");
51             debug("     Locking targetdiv1.")
52             targetdiv1.webkitRequestPointerLock();
53             expectedTargetToBeLockedString = "targetdiv1";
54             // doNextStep() called by onwebkitpointerlockchange handler.
55         },
56         function () {
57             debug("     Locking targetdiv1, again.")
58             targetdiv1.webkitRequestPointerLock();
59             expectedTargetToBeLockedString = "targetdiv1";
60             // doNextStep() called by onwebkitpointerlockchange handler.
61         },
62         function () {
63             debug("     Locking targetdiv2.")
64             expectTarget1Unlock = true;
65             targetdiv2.webkitRequestPointerLock();
66             expectedTargetToBeLockedString = "targetdiv2";
67             // doNextStep() called by onwebkitpointerlockchange handler.
68         },
69         function () {
70             expectTarget1Unlock = false;
71             expectTarget2Unlock = true;
72             navigator.webkitPointer.lock(targetdiv1,
73                 function () {
74                     testPassed("Lock target1 succeeded.");
75                     shouldBe("navigator.webkitPointer.isLocked", "true");
76                     // doNextStep() called by onwebkitpointerlockchange handler.
77                 },
78                 function () {
79                     testFailed("Lock failed.");
80                     finishJSTest();
81                 });
82             expectedTargetToBeLockedString = "targetdiv1";
83         },
84         function () {
85             expectTarget2Unlock = false;
86             navigator.webkitPointer.lock(targetdiv1,
87                 function () {
88                     testPassed("Lock target1 succeeded again.");
89                     shouldBe("navigator.webkitPointer.isLocked", "true");
90                     // doNextStep() called by onwebkitpointerlockchange handler.
91                 },
92                 function () {
93                     testFailed("Lock failed.");
94                     finishJSTest();
95                 });
96             expectedTargetToBeLockedString = "targetdiv1";
97         },
98         function () {
99             expectTarget1Unlock = true;
100             navigator.webkitPointer.lock(targetdiv2,
101                 function () {
102                     testPassed("Lock target2 succeeded.");
103                     shouldBe("navigator.webkitPointer.isLocked", "true");
104                     // doNextStep() called by onwebkitpointerlockchange handler.
105                 },
106                 function () {
107                     testFailed("Lock failed.");
108                     finishJSTest();
109                 });
110             expectedTargetToBeLockedString = "targetdiv2";
111         },
112     ];
113     doNextStep();
114 </script>
115 <script src="../fast/js/resources/js-test-post.js"></script>
116 </body>
117 </html>