mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1521707 - Move promisePopupEvent to BrowserTestUtils.jsm. r=mak
Differential Revision: https://phabricator.services.mozilla.com/D17259 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
d13fd4f699
commit
15b881a65f
@ -76,15 +76,15 @@ function checkBookmarksPanel(phase) {
|
||||
switch (phase) {
|
||||
case 1:
|
||||
case 3:
|
||||
return promisePopupEvent(popupElement, "shown");
|
||||
return promisePopupShown(popupElement);
|
||||
case 2:
|
||||
initialValue = titleElement.value;
|
||||
initialRemoveHidden = removeElement.hidden;
|
||||
return promisePopupEvent(popupElement, "hidden");
|
||||
return promisePopupHidden(popupElement);
|
||||
case 4:
|
||||
Assert.equal(titleElement.value, initialValue, "The bookmark panel's title should be the same");
|
||||
Assert.equal(removeElement.hidden, initialRemoveHidden, "The bookmark panel's visibility should not change");
|
||||
return promisePopupEvent(popupElement, "hidden");
|
||||
return promisePopupHidden(popupElement);
|
||||
}
|
||||
return Promise.reject(new Error("Unknown phase"));
|
||||
}
|
||||
|
@ -423,27 +423,12 @@ function is_element_hidden(element, msg) {
|
||||
ok(is_hidden(element), msg || "Element should be hidden");
|
||||
}
|
||||
|
||||
function promisePopupEvent(popup, eventSuffix) {
|
||||
let endState = {shown: "open", hidden: "closed"}[eventSuffix];
|
||||
|
||||
if (popup.state == endState)
|
||||
return Promise.resolve();
|
||||
|
||||
let eventType = "popup" + eventSuffix;
|
||||
return new Promise(resolve => {
|
||||
popup.addEventListener(eventType, function(event) {
|
||||
resolve();
|
||||
}, {once: true});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function promisePopupShown(popup) {
|
||||
return promisePopupEvent(popup, "shown");
|
||||
return BrowserTestUtils.waitForPopupEvent(popup, "shown");
|
||||
}
|
||||
|
||||
function promisePopupHidden(popup) {
|
||||
return promisePopupEvent(popup, "hidden");
|
||||
return BrowserTestUtils.waitForPopupEvent(popup, "hidden");
|
||||
}
|
||||
|
||||
function promiseNotificationShown(notification) {
|
||||
|
@ -160,27 +160,13 @@ async function assertWebRTCIndicatorStatus(expected) {
|
||||
}
|
||||
}
|
||||
|
||||
function promisePopupEvent(popup, eventSuffix) {
|
||||
let endState = {shown: "open", hidden: "closed"}[eventSuffix];
|
||||
|
||||
if (popup.state == endState)
|
||||
return Promise.resolve();
|
||||
|
||||
let eventType = "popup" + eventSuffix;
|
||||
return new Promise(resolve => {
|
||||
popup.addEventListener(eventType, function(event) {
|
||||
executeSoon(resolve);
|
||||
}, {once: true});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function promiseNotificationShown(notification) {
|
||||
let win = notification.browser.ownerGlobal;
|
||||
if (win.PopupNotifications.panel.state == "open") {
|
||||
return Promise.resolve();
|
||||
}
|
||||
let panelPromise = promisePopupEvent(win.PopupNotifications.panel, "shown");
|
||||
let panelPromise =
|
||||
BrowserTestUtils.waitForPopupEvent(win.PopupNotifications.panel, "shown");
|
||||
notification.reshow();
|
||||
return panelPromise;
|
||||
}
|
||||
|
@ -409,40 +409,11 @@ function promiseAttributeMutation(aNode, aAttribute, aFilterFn) {
|
||||
}
|
||||
|
||||
function popupShown(aPopup) {
|
||||
return promisePopupEvent(aPopup, "shown");
|
||||
return BrowserTestUtils.waitForPopupEvent(aPopup, "shown");
|
||||
}
|
||||
|
||||
function popupHidden(aPopup) {
|
||||
return promisePopupEvent(aPopup, "hidden");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Promise that resolves when aPopup fires an event of type
|
||||
* aEventType. Times out and rejects after 20 seconds.
|
||||
*
|
||||
* @param aPopup the popup to monitor for events.
|
||||
* @param aEventSuffix the _suffix_ for the popup event type to watch for.
|
||||
*
|
||||
* Example usage:
|
||||
* let popupShownPromise = promisePopupEvent(somePopup, "shown");
|
||||
* // ... something that opens a popup
|
||||
* yield popupShownPromise;
|
||||
*
|
||||
* let popupHiddenPromise = promisePopupEvent(somePopup, "hidden");
|
||||
* // ... something that hides a popup
|
||||
* yield popupHiddenPromise;
|
||||
*/
|
||||
function promisePopupEvent(aPopup, aEventSuffix) {
|
||||
return new Promise(resolve => {
|
||||
let eventType = "popup" + aEventSuffix;
|
||||
|
||||
function onPopupEvent(e) {
|
||||
aPopup.removeEventListener(eventType, onPopupEvent);
|
||||
resolve();
|
||||
}
|
||||
|
||||
aPopup.addEventListener(eventType, onPopupEvent);
|
||||
});
|
||||
return BrowserTestUtils.waitForPopupEvent(aPopup, "hidden");
|
||||
}
|
||||
|
||||
// This is a simpler version of the context menu check that
|
||||
|
@ -36,27 +36,12 @@ function runHttpServer(scheme, host, port = -1) {
|
||||
return httpserver;
|
||||
}
|
||||
|
||||
function promisePopupEvent(popup, eventSuffix) {
|
||||
let endState = {shown: "open", hidden: "closed"}[eventSuffix];
|
||||
|
||||
if (popup.state == endState)
|
||||
return Promise.resolve();
|
||||
|
||||
let eventType = "popup" + eventSuffix;
|
||||
return new Promise(resolve => {
|
||||
popup.addEventListener(eventType, function(event) {
|
||||
resolve();
|
||||
}, {once: true});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function promisePopupShown(popup) {
|
||||
return promisePopupEvent(popup, "shown");
|
||||
return BrowserTestUtils.waitForPopupEvent(popup, "shown");
|
||||
}
|
||||
|
||||
function promisePopupHidden(popup) {
|
||||
return promisePopupEvent(popup, "hidden");
|
||||
return BrowserTestUtils.waitForPopupEvent(popup, "hidden");
|
||||
}
|
||||
|
||||
function promiseSearchComplete(win = window, dontAnimate = false) {
|
||||
|
@ -956,6 +956,25 @@ var BrowserTestUtils = {
|
||||
/* eslint-enable no-eval */
|
||||
},
|
||||
|
||||
/**
|
||||
* Like waitForEvent, but acts on a popup. It ensures the popup is not already
|
||||
* in the expected state.
|
||||
*
|
||||
* @param {Element} popup
|
||||
* The popup element that should receive the event.
|
||||
* @param {string} eventSuffix
|
||||
* The event suffix expected to be received, one of "shown" or "hidden".
|
||||
* @returns {Promise}
|
||||
*/
|
||||
waitForPopupEvent(popup, eventSuffix) {
|
||||
let endState = {shown: "open", hidden: "closed"}[eventSuffix];
|
||||
|
||||
if (popup.state == endState) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return this.waitForEvent(popup, "popup" + eventSuffix);
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a content event listener on the given browser
|
||||
* element. Similar to waitForContentEvent, but the listener will
|
||||
|
Loading…
Reference in New Issue
Block a user