Bug 1270357 Add some test hooks to Subprocess.jsm r?kmag draft
authorAndrew Swan <aswan@mozilla.com>
Fri, 20 May 2016 15:27:43 -0700
changeset 369247 2f55b496853b3d6c20e4d93ddf146c78895b0569
parent 369246 79e24f10ab589d31e3a0f89ac6624b3029606aa0
child 369248 2a90a2fff437caf08bb18e73e97e8bf25c38f397
push id18808
push useraswan@mozilla.com
push dateFri, 20 May 2016 22:31:14 +0000
reviewerskmag
bugs1270357
milestone49.0a1
Bug 1270357 Add some test hooks to Subprocess.jsm r?kmag MozReview-Commit-ID: Or2EOAL1eC
toolkit/modules/subprocess/Subprocess.jsm
--- a/toolkit/modules/subprocess/Subprocess.jsm
+++ b/toolkit/modules/subprocess/Subprocess.jsm
@@ -95,17 +95,24 @@ var Subprocess = {
                                 .map(key => `${key}=${environment[key]}`);
 
     options.arguments = Array.from(options.arguments || []);
 
     return this.pathSearch(options.command, environment).then(command => {
       options.arguments.unshift(options.command);
       options.command = command;
 
-      return SubprocessImpl.call(options);
+      let result = SubprocessImpl.call(options);
+      result.then(proc => {
+        this._startProc();
+        proc.exitPromise.then(() => {
+          this._stopProc();
+        });
+      });
+      return result;
     });
   },
 
   /**
    * Returns an object with a key-value pair for every variable in the process's
    * current environment.
    *
    * @returns {object}
@@ -135,11 +142,31 @@ var Subprocess = {
    * @returns {Promise<string>}
    */
   pathSearch(command, environment) {
     // Promise.resolve lets us get around returning one of the Promise.jsm
     // pseudo-promises returned by Task.jsm.
     let path = SubprocessImpl.pathSearch(command, environment);
     return Promise.resolve(path);
   },
+
+  /**
+   * Things below this point are meant only for use in tests
+   */
+  _liveProcCount: 0,
+  _onLiveCountChange: null,
+
+  _startProc() {
+    this._liveProcCount++;
+    if (this._onLiveCountChange) {
+      this._onLiveCountChange(this._liveProcCount);
+    }
+  },
+
+  _stopProc() {
+    this._liveProcCount--;
+    if (this._onLiveCountChange) {
+      this._onLiveCountChange(this._liveProcCount);
+    }
+  },
 };
 
 Object.assign(Subprocess, SubprocessConstants);