2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
9 "<body onpointerdown='this.requestPointerLock()' style='width: 100px; height: 100px;'></body>";
11 const TEST_URL
= "data:text/html," + BODY_URL
;
13 const FRAME_TEST_URL
=
14 'data:text/html,<body><iframe src="http://example.org/document-builder.sjs?html=' +
18 function checkWarningState(aWarningElement
, aExpectedState
, aMsg
) {
19 ["hidden", "ontop", "onscreen"].forEach(state
=> {
21 aWarningElement
.hasAttribute(state
),
22 state
== aExpectedState
,
23 `${aMsg} - check ${state} attribute.`
28 async
function waitForWarningState(aWarningElement
, aExpectedState
) {
29 await BrowserTestUtils
.waitForAttribute(aExpectedState
, aWarningElement
, "");
33 `Wait for ${aExpectedState} state`
37 // Make sure the pointerlock warning is shown and exited with the escape key
38 add_task(async
function show_pointerlock_warning_escape() {
39 let urls
= [TEST_URL
, FRAME_TEST_URL
];
40 for (let url
of urls
) {
41 info("Pointerlock warning test for " + url
);
43 let tab
= await BrowserTestUtils
.openNewForegroundTab(gBrowser
, url
);
45 let warning
= document
.getElementById("pointerlock-warning");
46 let warningShownPromise
= waitForWarningState(warning
, "onscreen");
48 let expectedWarningText
;
50 let bc
= tab
.linkedBrowser
.browsingContext
;
51 if (bc
.children
.length
) {
52 // use the subframe if it exists
54 expectedWarningText
= "example.org";
56 expectedWarningText
= "This document";
58 expectedWarningText
+=
59 " has control of your pointer. Press Esc to take back control.";
61 await BrowserTestUtils
.synthesizeMouse("body", 4, 4, {}, bc
);
63 await warningShownPromise
;
65 ok(true, "Pointerlock warning shown");
67 let warningHiddenPromise
= waitForWarningState(warning
, "hidden");
69 await BrowserTestUtils
.waitForCondition(
70 () => warning
.innerText
== expectedWarningText
,
74 EventUtils
.synthesizeKey("KEY_Escape");
75 await warningHiddenPromise
;
77 ok(true, "Pointerlock warning hidden");
79 // Pointerlock should be released after escape is pressed.
80 await SpecialPowers
.spawn(tab
.linkedBrowser
, [], async
function () {
81 Assert
.equal(content
.document
.pointerLockElement
, null);
84 await BrowserTestUtils
.removeTab(tab
);
89 // XXX Bug 1580961 - this part of the test is disabled.
91 // Make sure the pointerlock warning is shown, but this time escape is not pressed until after the
92 // notification is closed via the timeout.
93 add_task(async function show_pointerlock_warning_timeout() {
94 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL);
96 let warning = document.getElementById("pointerlock-warning");
97 let warningShownPromise = BrowserTestUtils.waitForAttribute(
102 let warningHiddenPromise = BrowserTestUtils.waitForAttribute(
107 await BrowserTestUtils.synthesizeMouse("body", 4, 4, {}, tab.linkedBrowser);
109 await warningShownPromise;
110 ok(true, "Pointerlock warning shown");
111 await warningHiddenPromise;
113 // The warning closes after a few seconds, but this does not exit pointerlock mode.
114 await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
115 Assert.equal(content.document.pointerLockElement, content.document.body);
118 EventUtils.synthesizeKey("KEY_Escape");
120 ok(true, "Pointerlock warning hidden");
122 // Pointerlock should now be released.
123 await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
124 Assert.equal(content.document.pointerLockElement, null);
127 await BrowserTestUtils.removeTab(tab);