Bug 1343774 - remove unused functions;r=honza draft
authorFred Lin <gasolin@mozilla.com>
Fri, 07 Apr 2017 11:55:13 +0800
changeset 559383 2237482cfabc48b937463778f59d0c0fb20c7daf
parent 559365 45692c884fdd5136a64fb2f8a61a0c8183b69331
child 559384 96d5ebf98d8239a60e3c210d3586eecc41609950
push id53066
push userbmo:gasolin@mozilla.com
push dateMon, 10 Apr 2017 01:49:00 +0000
reviewershonza
bugs1343774
milestone55.0a1
Bug 1343774 - remove unused functions;r=honza MozReview-Commit-ID: CCB8o7mXOPR
devtools/client/netmonitor/src/netmonitor-controller.js
testing/talos/talos/tests/devtools/addon/content/damp.js
--- a/devtools/client/netmonitor/src/netmonitor-controller.js
+++ b/devtools/client/netmonitor/src/netmonitor-controller.js
@@ -121,17 +121,17 @@ var NetMonitorController = {
    * Disconnects the debugger client and removes event handlers as necessary.
    */
   disconnect() {
     if (this._disconnection) {
       return this._disconnection;
     }
     this._disconnection = new Promise(async (resolve) => {
       // Wait for the connection to finish first.
-      if (!this.isConnected()) {
+      if (!this._connected) {
         await this._connection;
       }
 
       // When debugging local or a remote instance, the connection is closed by
       // the RemoteTarget. The webconsole actor is stopped on disconnect.
       this.tabClient = null;
       this.webConsoleClient = null;
 
@@ -144,32 +144,16 @@ var NetMonitorController = {
 
       resolve();
       this._connected = false;
     });
     return this._disconnection;
   },
 
   /**
-   * Checks whether the netmonitor connection is active.
-   * @return boolean
-   */
-  isConnected: function () {
-    return !!this._connected;
-  },
-
-  /**
-   * Gets the activity currently performed by the frontend.
-   * @return number
-   */
-  getCurrentActivity: function () {
-    return this._currentActivity || ACTIVITY_TYPE.NONE;
-  },
-
-  /**
    * 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
    *         is back into "standby" mode.
@@ -283,95 +267,37 @@ var NetMonitorController = {
   },
 
   /**
    * Getter that tells if the server supports sending custom network requests.
    * @type boolean
    */
   get supportsCustomRequest() {
     return this.webConsoleClient &&
-           (this.webConsoleClient.traits.customNetworkRequest ||
-            !this._target.isApp);
-  },
-
-  /**
-   * Getter that tells if the server includes the transferred (compressed /
-   * encoded) response size.
-   * @type boolean
-   */
-  get supportsTransferredResponseSize() {
-    return this.webConsoleClient &&
-           this.webConsoleClient.traits.transferredResponseSize;
+       (this.webConsoleClient.traits.customNetworkRequest ||
+        !this._target.isApp);
   },
 
   /**
    * Getter that tells if the server can do network performance statistics.
    * @type boolean
    */
   get supportsPerfStats() {
     return this.tabClient &&
-           (this.tabClient.traits.reconfigure || !this._target.isApp);
+      (this.tabClient.traits.reconfigure || !this._target.isApp);
   },
 
   /**
    * Open a given source in Debugger
    */
   viewSourceInDebugger(sourceURL, sourceLine) {
     if (this.toolbox) {
       this.toolbox.viewSourceInDebugger(sourceURL, sourceLine);
     }
   },
-
-  /**
-   * Start monitoring all incoming update events about network requests and wait until
-   * a complete info about all requests is received. (We wait for the timings info
-   * explicitly, because that's always the last piece of information that is received.)
-   *
-   * This method is designed to wait for network requests that are issued during a page
-   * load, when retrieving page resources (scripts, styles, images). It has certain
-   * assumptions that can make it unsuitable for other types of network communication:
-   * - it waits for at least one network request to start and finish before returning
-   * - it waits only for request that were issued after it was called. Requests that are
-   *   already in mid-flight will be ignored.
-   * - the request start and end times are overlapping. If a new request starts a moment
-   *   after the previous one was finished, the wait will be ended in the "interim"
-   *   period.
-   * @returns a promise that resolves when the wait is done.
-   * TODO: should be unified with whenDataAvailable in netmonitor-view.js
-   */
-  waitForAllRequestsFinished() {
-    return new Promise(resolve => {
-      // Key is the request id, value is a boolean - is request finished or not?
-      let requests = new Map();
-
-      function onRequest(_, id) {
-        requests.set(id, false);
-      }
-
-      function onTimings(_, id) {
-        requests.set(id, true);
-        maybeResolve();
-      }
-
-      function maybeResolve() {
-        // Have all the requests in the map finished yet?
-        if (![...requests.values()].every(finished => finished)) {
-          return;
-        }
-
-        // All requests are done - unsubscribe from events and resolve!
-        window.off(EVENTS.NETWORK_EVENT, onRequest);
-        window.off(EVENTS.RECEIVED_EVENT_TIMINGS, onTimings);
-        resolve();
-      }
-
-      window.on(EVENTS.NETWORK_EVENT, onRequest);
-      window.on(EVENTS.RECEIVED_EVENT_TIMINGS, onTimings);
-    });
-  },
 };
 
 /**
  * Functions handling target network events.
  */
 function NetworkEventsHandler() {
   this.addRequest = this.addRequest.bind(this);
   this.updateRequest = this.updateRequest.bind(this);
--- a/testing/talos/talos/tests/devtools/addon/content/damp.js
+++ b/testing/talos/talos/tests/devtools/addon/content/damp.js
@@ -1,17 +1,18 @@
 Components.utils.import("resource://devtools/client/framework/gDevTools.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
-const {devtools} =
+const { devtools } =
   Components.utils.import("resource://devtools/shared/Loader.jsm", {});
 const { getActiveTab } = devtools.require("sdk/tabs/utils");
 const { getMostRecentBrowserWindow } = devtools.require("sdk/window/utils");
 const ThreadSafeChromeUtils = devtools.require("ThreadSafeChromeUtils");
-const {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
+const { EVENTS } = devtools.require("devtools/client/netmonitor/src/constants");
+const { Task } = Cu.import("resource://gre/modules/Task.jsm", {});
 
 const webserver = Services.prefs.getCharPref("addon.test.damp.webserver");
 
 const SIMPLE_URL = webserver + "/tests/devtools/addon/content/pages/simple.html";
 const COMPLICATED_URL = webserver + "/tests/tp5n/bild.de/www.bild.de/index.html";
 
 function Damp() {
   // Path to the temp file where the heap snapshot file is saved. Set by
@@ -110,19 +111,18 @@ Damp.prototype = {
     this._results.push({
       name: label + ".readHeapSnapshot",
       value: end - start
     });
     return Promise.resolve();
   },
 
   waitForNetworkRequests: Task.async(function*(label, toolbox) {
-    const { NetMonitorController } = toolbox.getCurrentPanel().panelWin;
     const start = performance.now();
-    yield NetMonitorController.waitForAllRequestsFinished();
+    yield this.waitForAllRequestsFinished();
     const end = performance.now();
     this._results.push({
       name: label + ".requestsFinished.DAMP",
       value: end - start
     });
   }),
 
   _consoleBulkLoggingTest: Task.async(function*() {
@@ -439,16 +439,68 @@ Damp.prototype = {
     this._reportAllResults();
     this._win.gBrowser.selectedTab = this._dampTab;
 
     if (this._onTestComplete) {
       this._onTestComplete(JSON.parse(JSON.stringify(this._results))); // Clone results
     }
   },
 
+  /**
+   * Start monitoring all incoming update events about network requests and wait until
+   * a complete info about all requests is received. (We wait for the timings info
+   * explicitly, because that's always the last piece of information that is received.)
+   *
+   * This method is designed to wait for network requests that are issued during a page
+   * load, when retrieving page resources (scripts, styles, images). It has certain
+   * assumptions that can make it unsuitable for other types of network communication:
+   * - it waits for at least one network request to start and finish before returning
+   * - it waits only for request that were issued after it was called. Requests that are
+   *   already in mid-flight will be ignored.
+   * - the request start and end times are overlapping. If a new request starts a moment
+   *   after the previous one was finished, the wait will be ended in the "interim"
+   *   period.
+   * @returns a promise that resolves when the wait is done.
+   */
+  waitForAllRequestsFinished() {
+    let tab = getActiveTab(getMostRecentBrowserWindow());
+    let target = devtools.TargetFactory.forTab(tab);
+    let toolbox = gDevTools.getToolbox(target);
+    let window = toolbox.getCurrentPanel().panelWin;
+
+    return new Promise(resolve => {
+      // Key is the request id, value is a boolean - is request finished or not?
+      let requests = new Map();
+
+      function onRequest(_, id) {
+        requests.set(id, false);
+      }
+
+      function onTimings(_, id) {
+        requests.set(id, true);
+        maybeResolve();
+      }
+
+      function maybeResolve() {
+        // Have all the requests in the map finished yet?
+        if (![...requests.values()].every(finished => finished)) {
+          return;
+        }
+
+        // All requests are done - unsubscribe from events and resolve!
+        window.off(EVENTS.NETWORK_EVENT, onRequest);
+        window.off(EVENTS.RECEIVED_EVENT_TIMINGS, onTimings);
+        resolve();
+      }
+
+      window.on(EVENTS.NETWORK_EVENT, onRequest);
+      window.on(EVENTS.RECEIVED_EVENT_TIMINGS, onTimings);
+    });
+  },
+
   startTest: function(doneCallback, config) {
     this._onTestComplete = function (results) {
       Profiler.mark("DAMP - end", true);
       doneCallback(results);
     };
     this._config = config;
 
     const Ci = Components.interfaces;