Refactor common Pointer Lock test code to a harness.
[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 <script src="resources/pointer-lock-test-harness.js"></script>
6 </head>
7 <body>
8 <div>
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             doNextStepWithUserGesture();
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     todo = [
39         function () {
40             shouldBe("document.webkitPointerLockElement", "null");
41             debug("     Locking targetdiv1.")
42             targetdiv1.webkitRequestPointerLock();
43             expectedTargetToBeLockedString = "targetdiv1";
44             // doNextStep() called by onwebkitpointerlockchange handler.
45         },
46         function () {
47             debug("     Locking targetdiv1, again.")
48             targetdiv1.webkitRequestPointerLock();
49             expectedTargetToBeLockedString = "targetdiv1";
50             // doNextStep() called by onwebkitpointerlockchange handler.
51         },
52         function () {
53             debug("     Locking targetdiv2.")
54             expectTarget1Unlock = true;
55             targetdiv2.webkitRequestPointerLock();
56             expectedTargetToBeLockedString = "targetdiv2";
57             // doNextStep() called by onwebkitpointerlockchange handler.
58         },
59         function () {
60             expectTarget1Unlock = false;
61             expectTarget2Unlock = true;
62             navigator.webkitPointer.lock(targetdiv1,
63                 function () {
64                     testPassed("Lock target1 succeeded.");
65                     shouldBe("navigator.webkitPointer.isLocked", "true");
66                     // doNextStep() called by onwebkitpointerlockchange handler.
67                 },
68                 function () {
69                     testFailed("Lock failed.");
70                     finishJSTest();
71                 });
72             expectedTargetToBeLockedString = "targetdiv1";
73         },
74         function () {
75             expectTarget2Unlock = false;
76             navigator.webkitPointer.lock(targetdiv1,
77                 function () {
78                     testPassed("Lock target1 succeeded again.");
79                     shouldBe("navigator.webkitPointer.isLocked", "true");
80                     // doNextStep() called by onwebkitpointerlockchange handler.
81                 },
82                 function () {
83                     testFailed("Lock failed.");
84                     finishJSTest();
85                 });
86             expectedTargetToBeLockedString = "targetdiv1";
87         },
88         function () {
89             expectTarget1Unlock = true;
90             navigator.webkitPointer.lock(targetdiv2,
91                 function () {
92                     testPassed("Lock target2 succeeded.");
93                     shouldBe("navigator.webkitPointer.isLocked", "true");
94                     // doNextStep() called by onwebkitpointerlockchange handler.
95                 },
96                 function () {
97                     testFailed("Lock failed.");
98                     finishJSTest();
99                 });
100             expectedTargetToBeLockedString = "targetdiv2";
101         },
102     ];
103     doNextStepWithUserGesture();
104 </script>
105 <script src="../fast/js/resources/js-test-post.js"></script>
106 </body>
107 </html>