mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 1716982 - Use BrowserTestUtils.waitForEvent in preferences tests. r=Standard8,preferences-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D118254
This commit is contained in:
parent
bd258ee9db
commit
855a6df6a6
@ -1296,7 +1296,7 @@ add_task(async function testExtensionControlledProxyConfig() {
|
||||
|
||||
async function openProxyPanel() {
|
||||
let panel = await openAndLoadSubDialog(PANEL_URL);
|
||||
let closingPromise = waitForEvent(
|
||||
let closingPromise = BrowserTestUtils.waitForEvent(
|
||||
panel.document.getElementById("ConnectionsDialog"),
|
||||
"dialogclosing"
|
||||
);
|
||||
|
@ -1,7 +1,6 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
const { Promise } = ChromeUtils.import("resource://gre/modules/Promise.jsm");
|
||||
const { PermissionTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/PermissionTestUtils.jsm"
|
||||
);
|
||||
@ -95,54 +94,6 @@ function promiseLoadSubDialog(aURL) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits a specified number of miliseconds for a specified event to be
|
||||
* fired on a specified element.
|
||||
*
|
||||
* Usage:
|
||||
* let receivedEvent = waitForEvent(element, "eventName");
|
||||
* // Do some processing here that will cause the event to be fired
|
||||
* // ...
|
||||
* // Now yield until the Promise is fulfilled
|
||||
* yield receivedEvent;
|
||||
* if (receivedEvent && !(receivedEvent instanceof Error)) {
|
||||
* receivedEvent.msg == "eventName";
|
||||
* // ...
|
||||
* }
|
||||
*
|
||||
* @param aSubject the element that should receive the event
|
||||
* @param aEventName the event to wait for
|
||||
* @param aTimeoutMs the number of miliseconds to wait before giving up
|
||||
* @returns a Promise that resolves to the received event, or to an Error
|
||||
*/
|
||||
function waitForEvent(aSubject, aEventName, aTimeoutMs, aTarget) {
|
||||
let eventDeferred = Promise.defer();
|
||||
let timeoutMs = aTimeoutMs || kDefaultWait;
|
||||
let stack = new Error().stack;
|
||||
let timerID = setTimeout(function wfe_canceller() {
|
||||
aSubject.removeEventListener(aEventName, listener);
|
||||
eventDeferred.reject(new Error(aEventName + " event timeout at " + stack));
|
||||
}, timeoutMs);
|
||||
|
||||
var listener = function(aEvent) {
|
||||
if (aTarget && aTarget !== aEvent.target) {
|
||||
return;
|
||||
}
|
||||
|
||||
// stop the timeout clock and resume
|
||||
clearTimeout(timerID);
|
||||
eventDeferred.resolve(aEvent);
|
||||
};
|
||||
|
||||
function cleanup(aEventOrError) {
|
||||
// unhook listener in case of success or failure
|
||||
aSubject.removeEventListener(aEventName, listener);
|
||||
return aEventOrError;
|
||||
}
|
||||
aSubject.addEventListener(aEventName, listener);
|
||||
return eventDeferred.promise.then(cleanup, cleanup);
|
||||
}
|
||||
|
||||
async function openPreferencesViaOpenPreferencesAPI(aPane, aOptions) {
|
||||
let finalPaneEvent = Services.prefs.getBoolPref("identity.fxaccounts.enabled")
|
||||
? "sync-pane-loaded"
|
||||
|
Loading…
Reference in New Issue
Block a user