Bug 1206943 - UITour: Remove the event listener in promisePanelElementEvent upon timeout. r=bgrins

The event listener wasn't getting removed in the reject case.
This commit is contained in:
Matthew Noorenberghe 2015-09-21 16:34:27 -07:00
parent 79c77dfad2
commit 9f9d0b30ec

View File

@ -165,17 +165,21 @@ function promisePanelShown(win) {
} }
function promisePanelElementEvent(win, aPanel, aEvent) { function promisePanelElementEvent(win, aPanel, aEvent) {
let deferred = Promise.defer(); return new Promise((resolve, reject) => {
let timeoutId = win.setTimeout(() => { let timeoutId = win.setTimeout(() => {
deferred.reject("Event did not happen within 5 seconds."); aPanel.removeEventListener(aEvent, onPanelEvent);
reject("Event did not happen within 5 seconds.");
}, 5000); }, 5000);
aPanel.addEventListener(aEvent, function onPanelEvent(e) {
function onPanelEvent(e) {
aPanel.removeEventListener(aEvent, onPanelEvent); aPanel.removeEventListener(aEvent, onPanelEvent);
win.clearTimeout(timeoutId); win.clearTimeout(timeoutId);
// Wait one tick to let UITour.jsm process the event as well. // Wait one tick to let UITour.jsm process the event as well.
executeSoon(deferred.resolve); executeSoon(resolve);
}
aPanel.addEventListener(aEvent, onPanelEvent);
}); });
return deferred.promise;
} }
function promisePanelElementShown(win, aPanel) { function promisePanelElementShown(win, aPanel) {