4 <script src=
"../resources/js-test.js"></script>
5 <script src=
"../http/tests/resources/pointer-lock/pointer-lock-test-harness.js"></script>
9 <div id=
"target1"></div>
10 <div id=
"target2"></div>
11 <iframe id=
"iframe1"></iframe>
12 <iframe id=
"iframe2"></iframe>
15 description("Test expected pointerlockchange and pointerlockerror events.")
16 window
.jsTestIsAsync
= true;
18 targetDiv1
= document
.getElementById("target1");
19 targetDiv2
= document
.getElementById("target2");
20 targetIframe1
= document
.getElementById("iframe1");
21 targetIframe2
= document
.getElementById("iframe2");
23 // Events must not bubble from document.
24 function errorIfEventsBubble() {
25 testFailed("Events must not bubble to the window.");
28 window
.addEventListener("pointerlockchange", errorIfEventsBubble
);
29 window
.addEventListener("pointerlockerror", errorIfEventsBubble
);
33 expectNoEvents("Unlock.");
34 document
.exitPointerLock();
35 doNextStepWithUserGesture();
38 expectOnlyChangeEvent("Lock targetDiv1.");
39 targetDiv1
.requestPointerLock();
42 expectOnlyChangeEvent("Unlock again.");
43 document
.exitPointerLock();
46 expectOnlyChangeEvent("Lock targetDiv1 again.");
47 targetDiv1
.requestPointerLock();
50 expectOnlyChangeEvent("Lock targetDiv2.");
51 targetDiv2
.requestPointerLock();
54 expectOnlyChangeEvent("Lock targetDiv2 again.");
55 targetDiv2
.requestPointerLock();
58 expectOnlyChangeEvent("Unlock targetDiv2.");
59 document
.exitPointerLock();
62 targetIframe1
.src
= "about:blank";
63 targetIframe1
.onload = function () { doNextStep(); }
66 targetIframe2
.src
= "about:blank";
67 targetIframe2
.onload = function () { doNextStep(); }
70 expectNoEvents("Lock targetIframe1.");
71 expectOnlyChangeEvent("Lock targetIframe1 (handler for iframe1).", targetIframe1
.contentDocument
);
72 targetIframe1
.contentDocument
.body
.requestPointerLock();
75 expectNoEvents("Lock targetIframe2.");
76 expectNoEvents("Lock targetIframe2 (handler for iframe1).", targetIframe1
.contentDocument
);
77 expectOnlyErrorEvent("Lock targetIframe2 (handler for iframe2).", targetIframe2
.contentDocument
);
78 targetIframe2
.contentDocument
.body
.requestPointerLock();
81 expectNoEvents("Unlock targetIframe2.");
82 expectOnlyChangeEvent("Unlock targetIframe2 (handler for iframe1).", targetIframe1
.contentDocument
);
83 expectNoEvents("Unlock targetIframe2 (handler for iframe2).", targetIframe2
.contentDocument
);
84 targetIframe1
.contentDocument
.exitPointerLock();
87 shouldBeDefined("testRunner.setPointerLockWillFailSynchronously");
88 testRunner
.setPointerLockWillFailSynchronously();
89 expectOnlyErrorEvent("Lock with synchronous failure.");
90 targetDiv1
.requestPointerLock();
93 shouldBeDefined("testRunner.setPointerLockWillRespondAsynchronously");
94 shouldBeDefined("testRunner.didAcquirePointerLock");
95 shouldBeDefined("testRunner.didNotAcquirePointerLock");
96 testRunner
.setPointerLockWillRespondAsynchronously();
97 expectOnlyErrorEvent("Lock with asynchronous failure.");
98 targetDiv1
.requestPointerLock();
102 testRunner
.didNotAcquirePointerLock();
105 testRunner
.setPointerLockWillRespondAsynchronously();
106 expectOnlyChangeEvent("Lock with asynchronous success.");
107 targetDiv1
.requestPointerLock();
111 testRunner
.didAcquirePointerLock();