diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /accessible/tests/browser/head.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'accessible/tests/browser/head.js')
-rw-r--r-- | accessible/tests/browser/head.js | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/accessible/tests/browser/head.js b/accessible/tests/browser/head.js new file mode 100644 index 0000000000..e7645f7f1c --- /dev/null +++ b/accessible/tests/browser/head.js @@ -0,0 +1,146 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/* exported initAccService, shutdownAccService, waitForEvent, setE10sPrefs, + unsetE10sPrefs, accConsumersChanged */ + +// Load the shared-head file first. +Services.scriptloader.loadSubScript( + "chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js", + this +); + +const { CommonUtils } = ChromeUtils.importESModule( + "chrome://mochitests/content/browser/accessible/tests/browser/Common.sys.mjs" +); + +/** + * Set e10s related preferences in the test environment. + * @return {Promise} promise that resolves when preferences are set. + */ +function setE10sPrefs() { + return new Promise(resolve => + SpecialPowers.pushPrefEnv( + { + set: [["browser.tabs.remote.autostart", true]], + }, + resolve + ) + ); +} + +/** + * Unset e10s related preferences in the test environment. + * @return {Promise} promise that resolves when preferences are unset. + */ +function unsetE10sPrefs() { + return new Promise(resolve => { + SpecialPowers.popPrefEnv(resolve); + }); +} + +/** + * Capture when 'a11y-consumers-changed' event is fired. + * + * @param {?Object} target + * [optional] browser object that indicates that accessibility service + * is in content process. + * @return {Array} + * List of promises where first one is the promise for when the event + * observer is added and the second one for when the event is observed. + */ +function accConsumersChanged(target) { + return target + ? [ + SpecialPowers.spawn(target, [], () => + content.CommonUtils.addAccConsumersChangedObserver() + ), + SpecialPowers.spawn(target, [], () => + content.CommonUtils.observeAccConsumersChanged() + ), + ] + : [ + CommonUtils.addAccConsumersChangedObserver(), + CommonUtils.observeAccConsumersChanged(), + ]; +} + +/** + * Capture when accessibility service is initialized. + * + * @param {?Object} target + * [optional] browser object that indicates that accessibility service + * is expected to be initialized in content process. + * @return {Array} + * List of promises where first one is the promise for when the event + * observer is added and the second one for when the event is observed. + */ +function initAccService(target) { + return target + ? [ + SpecialPowers.spawn(target, [], () => + content.CommonUtils.addAccServiceInitializedObserver() + ), + SpecialPowers.spawn(target, [], () => + content.CommonUtils.observeAccServiceInitialized() + ), + ] + : [ + CommonUtils.addAccServiceInitializedObserver(), + CommonUtils.observeAccServiceInitialized(), + ]; +} + +/** + * Capture when accessibility service is shutdown. + * + * @param {?Object} target + * [optional] browser object that indicates that accessibility service + * is expected to be shutdown in content process. + * @return {Array} + * List of promises where first one is the promise for when the event + * observer is added and the second one for when the event is observed. + */ +function shutdownAccService(target) { + return target + ? [ + SpecialPowers.spawn(target, [], () => + content.CommonUtils.addAccServiceShutdownObserver() + ), + SpecialPowers.spawn(target, [], () => + content.CommonUtils.observeAccServiceShutdown() + ), + ] + : [ + CommonUtils.addAccServiceShutdownObserver(), + CommonUtils.observeAccServiceShutdown(), + ]; +} + +/** + * Simpler verions of waitForEvent defined in + * accessible/tests/browser/events.js + */ +function waitForEvent(eventType, expectedId) { + return new Promise(resolve => { + let eventObserver = { + observe(subject) { + let event = subject.QueryInterface(Ci.nsIAccessibleEvent); + let id; + try { + id = event.accessible.id; + } catch (e) { + // This can throw NS_ERROR_FAILURE. + } + if (event.eventType === eventType && id === expectedId) { + Services.obs.removeObserver(this, "accessible-event"); + resolve(event); + } + }, + }; + Services.obs.addObserver(eventObserver, "accessible-event"); + }); +} |