From f00a06829cf8a5c052bcd117694933d5f4f1ad32 Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Thu, 12 Sep 2019 12:08:41 +0000 Subject: [PATCH] Bug 1580506, fix incorrect pointerlock message names, r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D45577 --HG-- extra : moz-landing-system : lando --- browser/actors/BrowserTabParent.jsm | 4 +- dom/tests/browser/browser.ini | 1 + .../browser/browser_pointerlock_warning.js | 66 +++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 dom/tests/browser/browser_pointerlock_warning.js diff --git a/browser/actors/BrowserTabParent.jsm b/browser/actors/BrowserTabParent.jsm index e6fb6d3d60aa..b2523a00b225 100644 --- a/browser/actors/BrowserTabParent.jsm +++ b/browser/actors/BrowserTabParent.jsm @@ -43,12 +43,12 @@ class BrowserTabParent extends JSWindowActorParent { break; } - case "MozDOMPointerLock:Entered": { + case "PointerLock:Entered": { browser.ownerGlobal.PointerLock.entered(message.data.originNoSuffix); break; } - case "MozDOMPointerLock:Exited": + case "PointerLock:Exited": browser.ownerGlobal.PointerLock.exited(); break; } diff --git a/dom/tests/browser/browser.ini b/dom/tests/browser/browser.ini index fc611239721a..d49e3ab0c108 100644 --- a/dom/tests/browser/browser.ini +++ b/dom/tests/browser/browser.ini @@ -77,6 +77,7 @@ skip-if = fission support-files = test_mixed_content_image.html dummy.png +[browser_pointerlock_warning.js] [browser_test_focus_after_modal_state.js] skip-if = verify support-files = diff --git a/dom/tests/browser/browser_pointerlock_warning.js b/dom/tests/browser/browser_pointerlock_warning.js new file mode 100644 index 000000000000..e873965e503f --- /dev/null +++ b/dom/tests/browser/browser_pointerlock_warning.js @@ -0,0 +1,66 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +"use strict"; + +const TEST_URL = "data:text/html,"; + +// Make sure the pointerlock warning is shown and exited with the escape key +add_task(async function show_pointerlock_warning_escape() { + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL); + + let warning = document.getElementById("pointerlock-warning"); + let warningShownPromise = BrowserTestUtils.waitForAttribute("onscreen", warning, "true"); + await BrowserTestUtils.synthesizeMouse("body", 4, 4, {}, tab.linkedBrowser); + + await warningShownPromise; + + ok(true, "Pointerlock warning shown"); + + let warningHiddenPromise = BrowserTestUtils.waitForAttribute("hidden", warning, "true"); + EventUtils.synthesizeKey("KEY_Escape"); + await warningHiddenPromise; + + ok(true, "Pointerlock warning hidden"); + + // Pointerlock should be released after escape is pressed. + await ContentTask.spawn(tab.linkedBrowser, null, async function() { + Assert.equal(content.document.pointerLockElement, null); + }); + + await BrowserTestUtils.removeTab(tab); +}); + +// Make sure the pointerlock warning is shown, but this time escape is not pressed until after the +// notification is closed via the timeout. +add_task(async function show_pointerlock_warning_timeout() { + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL); + + let warning = document.getElementById("pointerlock-warning"); + let warningShownPromise = BrowserTestUtils.waitForAttribute("onscreen", warning, "true"); + let warningHiddenPromise = BrowserTestUtils.waitForAttribute("hidden", warning, "true"); + await BrowserTestUtils.synthesizeMouse("body", 4, 4, {}, tab.linkedBrowser); + + await warningShownPromise; + ok(true, "Pointerlock warning shown"); + await warningHiddenPromise; + + // The warning closes after a few seconds, but this does not exit pointerlock mode. + await ContentTask.spawn(tab.linkedBrowser, null, async function() { + Assert.equal(content.document.pointerLockElement, content.document.body); + }); + + EventUtils.synthesizeKey("KEY_Escape"); + + ok(true, "Pointerlock warning hidden"); + + // Pointerlock should now be released. + await ContentTask.spawn(tab.linkedBrowser, null, async function() { + Assert.equal(content.document.pointerLockElement, null); + }); + + await BrowserTestUtils.removeTab(tab); +}); +