Bug 1206943 - UITour: Remove the event listener in promisePanelElementEvent upon timeout. r=bgrins
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 21 Sep 2015 16:34:27 -0700
changeset 263707 65b643d6e5f35e20c456efc4aa0e9ef4ba7c74a7
parent 263706 e4e3a8b66db489efcf3a87e3c954614ed1b2b9ff
child 263708 201ca50802b26ebf9827600d8272616d8904611f
push id65396
push usercbook@mozilla.com
push dateTue, 22 Sep 2015 10:50:42 +0000
treeherdermozilla-inbound@9a5faeebdcb5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1206943
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1206943 - UITour: Remove the event listener in promisePanelElementEvent upon timeout. r=bgrins The event listener wasn't getting removed in the reject case.
browser/components/uitour/test/head.js
--- a/browser/components/uitour/test/head.js
+++ b/browser/components/uitour/test/head.js
@@ -160,27 +160,31 @@ function waitForCallbackResultPromise() 
 }
 
 function promisePanelShown(win) {
   let panelEl = win.PanelUI.panel;
   return promisePanelElementShown(win, panelEl);
 }
 
 function promisePanelElementEvent(win, aPanel, aEvent) {
-  let deferred = Promise.defer();
-  let timeoutId = win.setTimeout(() => {
-    deferred.reject("Event did not happen within 5 seconds.");
-  }, 5000);
-  aPanel.addEventListener(aEvent, function onPanelEvent(e) {
-    aPanel.removeEventListener(aEvent, onPanelEvent);
-    win.clearTimeout(timeoutId);
-    // Wait one tick to let UITour.jsm process the event as well.
-    executeSoon(deferred.resolve);
+  return new Promise((resolve, reject) => {
+    let timeoutId = win.setTimeout(() => {
+      aPanel.removeEventListener(aEvent, onPanelEvent);
+      reject("Event did not happen within 5 seconds.");
+    }, 5000);
+
+    function onPanelEvent(e) {
+      aPanel.removeEventListener(aEvent, onPanelEvent);
+      win.clearTimeout(timeoutId);
+      // Wait one tick to let UITour.jsm process the event as well.
+      executeSoon(resolve);
+    }
+
+    aPanel.addEventListener(aEvent, onPanelEvent);
   });
-  return deferred.promise;
 }
 
 function promisePanelElementShown(win, aPanel) {
   return promisePanelElementEvent(win, aPanel, "popupshown");
 }
 
 function promisePanelElementHidden(win, aPanel) {
   return promisePanelElementEvent(win, aPanel, "popuphidden");