Bug 1355473 - convert uses of 'defer' to 'new Promise' in client/responsivedesign; r?tromey draft
authorMatt R <matthieu.rigolot@gmail.com>
Sun, 21 May 2017 12:54:48 +0100
changeset 582098 2d7f02dae9b6
parent 582001 5b74bbf20e80
child 629672 8700b11eda27
push id59973
push userbmo:matthieu.rigolot@gmail.com
push dateSun, 21 May 2017 12:08:14 +0000
reviewerstromey
bugs1355473
milestone55.0a1
Bug 1355473 - convert uses of 'defer' to 'new Promise' in client/responsivedesign; r?tromey MozReview-Commit-ID: L9tNE28knjF
devtools/client/responsivedesign/test/browser_responsiveui_touch.js
devtools/client/responsivedesign/test/head.js
--- a/devtools/client/responsivedesign/test/browser_responsiveui_touch.js
+++ b/devtools/client/responsivedesign/test/browser_responsiveui_touch.js
@@ -137,12 +137,12 @@ function synthesizeClick(element) {
   BrowserTestUtils.synthesizeMouseAtCenter(element, { type: "mousedown", isSynthesized: false },
         gBrowser.selectedBrowser);
   BrowserTestUtils.synthesizeMouseAtCenter(element, { type: "mouseup", isSynthesized: false },
         gBrowser.selectedBrowser);
   return waitForClickEvent;
 }
 
 function pushPrefs(...aPrefs) {
-  let deferred = promise.defer();
-  SpecialPowers.pushPrefEnv({"set": aPrefs}, deferred.resolve);
-  return deferred.promise;
+  return new Promise(resolve => {
+    SpecialPowers.pushPrefEnv({"set": aPrefs}, resolve);
+  });
 }
--- a/devtools/client/responsivedesign/test/head.js
+++ b/devtools/client/responsivedesign/test/head.js
@@ -125,19 +125,19 @@ var closeToolbox = Task.async(function* 
 
 /**
  * Wait for the toolbox frame to receive focus after it loads
  * @param {Toolbox} toolbox
  * @return a promise that resolves when focus has been received
  */
 function waitForToolboxFrameFocus(toolbox) {
   info("Making sure that the toolbox's frame is focused");
-  let def = promise.defer();
-  waitForFocus(def.resolve, toolbox.win);
-  return def.promise;
+  return new Promise(resolve => {
+    waitForFocus(resolve, toolbox.win);
+  });
 }
 
 /**
  * Open the toolbox, with the inspector tool visible, and the sidebar that
  * corresponds to the given id selected
  * @return a promise that resolves when the inspector is ready and the sidebar
  * view is visible and ready
  */
@@ -205,37 +205,37 @@ var addTab = Task.async(function* (url) 
 });
 
 /**
  * Waits for the next load to complete in the current browser.
  *
  * @return promise
  */
 function waitForDocLoadComplete(aBrowser = gBrowser) {
-  let deferred = promise.defer();
-  let progressListener = {
-    onStateChange: function (webProgress, req, flags, status) {
-      let docStop = Ci.nsIWebProgressListener.STATE_IS_NETWORK |
-                    Ci.nsIWebProgressListener.STATE_STOP;
-      info(`Saw state ${flags.toString(16)} and status ${status.toString(16)}`);
+  return new Promise(resolve => {
+    let progressListener = {
+      onStateChange: function (webProgress, req, flags, status) {
+        let docStop = Ci.nsIWebProgressListener.STATE_IS_NETWORK |
+                      Ci.nsIWebProgressListener.STATE_STOP;
+        info(`Saw state ${flags.toString(16)} and status ${status.toString(16)}`);
 
-      // When a load needs to be retargetted to a new process it is cancelled
-      // with NS_BINDING_ABORTED so ignore that case
-      if ((flags & docStop) == docStop && status != Cr.NS_BINDING_ABORTED) {
-        aBrowser.removeProgressListener(progressListener);
-        info("Browser loaded");
-        deferred.resolve();
-      }
-    },
-    QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
+        // When a load needs to be retargetted to a new process it is cancelled
+        // with NS_BINDING_ABORTED so ignore that case
+        if ((flags & docStop) == docStop && status != Cr.NS_BINDING_ABORTED) {
+          aBrowser.removeProgressListener(progressListener);
+          info("Browser loaded");
+          resolve();
+        }
+      },
+      QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
                                            Ci.nsISupportsWeakReference])
-  };
-  aBrowser.addProgressListener(progressListener);
-  info("Waiting for browser load");
-  return deferred.promise;
+    };
+    aBrowser.addProgressListener(progressListener);
+    info("Waiting for browser load");
+  });
 }
 
 /**
  * Get the NodeFront for a node that matches a given css selector, via the
  * protocol.
  * @param {String|NodeFront} selector
  * @param {InspectorPanel} inspector The instance of InspectorPanel currently
  * loaded in the toolbox