Bug 1519107 - use promise pattern for other webconsole methods rather than callbacks; r=ochameau
authoryulia <ystartsev@mozilla.com>
Mon, 21 Jan 2019 13:49:22 +0000
changeset 454688 05ab29790c5718f31d2910f8728af5f742eaf14d
parent 454687 c367b5259d4683c8d7fcf7efdda68f6ca93f9913
child 454689 f833d5220c821a2c19c60c6ac5378c677bebbe71
push id35411
push usercsabou@mozilla.com
push dateTue, 22 Jan 2019 03:53:40 +0000
treeherdermozilla-central@ada22b635f8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1519107
milestone66.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 1519107 - use promise pattern for other webconsole methods rather than callbacks; r=ochameau Differential Revision: https://phabricator.services.mozilla.com/D16196
devtools/client/netmonitor/src/connector/firefox-connector.js
devtools/client/netmonitor/src/har/test/browser_net_har_throttle_upload.js
devtools/client/netmonitor/test/browser_net_throttle.js
devtools/client/webconsole/webconsole-frame.js
devtools/shared/webconsole/client.js
--- a/devtools/client/netmonitor/src/connector/firefox-connector.js
+++ b/devtools/client/netmonitor/src/connector/firefox-connector.js
@@ -224,27 +224,27 @@ class FirefoxConnector {
 
   /**
    * Send a HTTP request data payload
    *
    * @param {object} data data payload would like to sent to backend
    * @param {function} callback callback will be invoked after the request finished
    */
   sendHTTPRequest(data, callback) {
-    this.webConsoleClient.sendHTTPRequest(data, callback);
+    this.webConsoleClient.sendHTTPRequest(data).then(callback);
   }
 
   /**
    * Set network preferences to control network flow
    *
    * @param {object} request request payload would like to sent to backend
    * @param {function} callback callback will be invoked after the request finished
    */
-  setPreferences(request, callback) {
-    this.webConsoleClient.setPreferences(request, callback);
+  setPreferences(request) {
+    return this.webConsoleClient.setPreferences(request);
   }
 
   /**
    * Triggers a specific "activity" to be performed by the frontend.
    * This can be, for example, triggering reloads or enabling/disabling cache.
    *
    * @param {number} type The activity type. See the ACTIVITY_TYPE const.
    * @return {object} A promise resolved once the activity finishes and the frontend
--- a/devtools/client/netmonitor/src/har/test/browser_net_har_throttle_upload.js
+++ b/devtools/client/netmonitor/src/har/test/browser_net_har_throttle_upload.js
@@ -35,21 +35,17 @@ async function throttleUploadTest(actual
       downloadBPSMean: 200000,
       downloadBPSMax: 200000,
       uploadBPSMean: uploadSize,
       uploadBPSMax: uploadSize,
     },
   };
 
   info("sending throttle request");
-  await new Promise((resolve) => {
-    connector.setPreferences(request, (response) => {
-      resolve(response);
-    });
-  });
+  await connector.setPreferences(request);
 
   // Execute one POST request on the page and wait till its done.
   const onEventTimings = monitor.panelWin.api.once(EVENTS.RECEIVED_EVENT_TIMINGS);
   const wait = waitForNetworkEvents(monitor, 1);
   await ContentTask.spawn(tab.linkedBrowser, { size }, async function(args) {
     content.wrappedJSObject.executeTest2(args.size);
   });
   await wait;
--- a/devtools/client/netmonitor/test/browser_net_throttle.js
+++ b/devtools/client/netmonitor/test/browser_net_throttle.js
@@ -34,21 +34,17 @@ async function throttleTest(actuallyThro
       downloadBPSMean: size,
       downloadBPSMax: size,
       uploadBPSMean: 10000,
       uploadBPSMax: 10000,
     },
   };
 
   info("sending throttle request");
-  await new Promise((resolve) => {
-    setPreferences(request, response => {
-      resolve(response);
-    });
-  });
+  await setPreferences(request);
 
   const wait = waitForNetworkEvents(monitor, 1);
   await triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_DISABLED);
   await wait;
 
   await waitForRequestData(store, ["eventTimings"]);
 
   const requestItem = getSortedRequests(store.getState()).get(0);
--- a/devtools/client/webconsole/webconsole-frame.js
+++ b/devtools/client/webconsole/webconsole-frame.js
@@ -3,17 +3,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const {Utils: WebConsoleUtils} = require("devtools/client/webconsole/utils");
 const EventEmitter = require("devtools/shared/event-emitter");
-const promise = require("promise");
 const defer = require("devtools/shared/defer");
 const Services = require("Services");
 const { gDevTools } = require("devtools/client/framework/devtools");
 const { WebConsoleConnectionProxy } = require("devtools/client/webconsole/webconsole-connection-proxy");
 const KeyShortcuts = require("devtools/client/shared/key-shortcuts");
 const { l10n } = require("devtools/client/webconsole/utils/messages");
 
 loader.lazyRequireGetter(this, "AppConstants", "resource://gre/modules/AppConstants.jsm", true);
@@ -164,39 +163,29 @@ WebConsoleFrame.prototype = {
   },
 
   /**
    * Setter for saving of network request and response bodies.
    *
    * @param boolean value
    *        The new value you want to set.
    */
-  setSaveRequestAndResponseBodies(value) {
+  async setSaveRequestAndResponseBodies(value) {
     if (!this.webConsoleClient) {
       // Don't continue if the webconsole disconnected.
-      return promise.resolve(null);
+      return null;
     }
 
-    const deferred = defer();
     const newValue = !!value;
     const toSet = {
       "NetworkMonitor.saveRequestAndResponseBodies": newValue,
     };
 
     // Make sure the web console client connection is established first.
-    this.webConsoleClient.setPreferences(toSet, response => {
-      if (!response.error) {
-        this._saveRequestAndResponseBodies = newValue;
-        deferred.resolve(response);
-      } else {
-        deferred.reject(response.error);
-      }
-    });
-
-    return deferred.promise;
+    return this.webConsoleClient.setPreferences(toSet);
   },
 
   /**
    * Connect to the server using the remote debugging protocol.
    *
    * @private
    * @return object
    *         A promise object that is resolved/reject based on the connection
--- a/devtools/shared/webconsole/client.js
+++ b/devtools/shared/webconsole/client.js
@@ -406,47 +406,43 @@ WebConsoleClient.prototype = {
     return this._client.request(packet);
   },
 
   /**
    * Get Web Console-related preferences on the server.
    *
    * @param array preferences
    *        An array with the preferences you want to retrieve.
-   * @param function [onResponse]
-   *        Optional function to invoke when the response is received.
    * @return request
    *         Request object that implements both Promise and EventEmitter interfaces
    */
-  getPreferences: function(preferences, onResponse) {
+  getPreferences: function(preferences) {
     const packet = {
       to: this.actorID,
       type: "getPreferences",
       preferences: preferences,
     };
-    return this._client.request(packet, onResponse);
+    return this._client.request(packet);
   },
 
   /**
    * Set Web Console-related preferences on the server.
    *
    * @param object preferences
    *        An object with the preferences you want to change.
-   * @param function [onResponse]
-   *        Optional function to invoke when the response is received.
    * @return request
    *         Request object that implements both Promise and EventEmitter interfaces
    */
-  setPreferences: function(preferences, onResponse) {
+  setPreferences: function(preferences) {
     const packet = {
       to: this.actorID,
       type: "setPreferences",
       preferences: preferences,
     };
-    return this._client.request(packet, onResponse);
+    return this._client.request(packet);
   },
 
   /**
    * Retrieve the request headers from the given NetworkEventActor.
    *
    * @param string actor
    *        The NetworkEventActor ID.
    * @param function onResponse
@@ -624,49 +620,45 @@ WebConsoleClient.prototype = {
     return this._client.request(packet, onResponse);
   },
 
   /**
    * Send a HTTP request with the given data.
    *
    * @param string data
    *        The details of the HTTP request.
-   * @param function onResponse
-   *        The function invoked when the response is received.
    * @return request
    *         Request object that implements both Promise and EventEmitter interfaces
    */
-  sendHTTPRequest: function(data, onResponse) {
+  sendHTTPRequest: function(data) {
     const packet = {
       to: this.actorID,
       type: "sendHTTPRequest",
       request: data,
     };
-    return this._client.request(packet, onResponse);
+    return this._client.request(packet);
   },
 
   /**
    * Start the given Web Console listeners.
    *
    * @see this.LISTENERS
    * @param array listeners
    *        Array of listeners you want to start. See this.LISTENERS for
    *        known listeners.
-   * @param function onResponse
-   *        Function to invoke when the server response is received.
    * @return request
    *         Request object that implements both Promise and EventEmitter interfaces
    */
-  startListeners: function(listeners, onResponse) {
+  startListeners: function(listeners) {
     const packet = {
       to: this.actorID,
       type: "startListeners",
       listeners: listeners,
     };
-    return this._client.request(packet, onResponse);
+    return this._client.request(packet);
   },
 
   /**
    * Stop the given Web Console listeners.
    *
    * @see this.LISTENERS
    * @param array listeners
    *        Array of listeners you want to stop. See this.LISTENERS for