Bug 950855 - Create basic getStats mochitest. r=jsmith
authorJan-Ivar Bruaroey <jib@mozilla.com>
Tue, 07 Jan 2014 10:35:06 -0500
changeset 178604 9e34b5a089e6d5aa3677e072625f5fb2465f4e3c
parent 178603 f88ff4f8581905e16be41435db360ac774a211c2
child 178605 796618164ade96ef26652d714f8db94ef698dd9d
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjsmith
bugs950855
milestone29.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 950855 - Create basic getStats mochitest. r=jsmith
dom/media/tests/mochitest/pc.js
dom/media/tests/mochitest/templates.js
--- a/dom/media/tests/mochitest/pc.js
+++ b/dom/media/tests/mochitest/pc.js
@@ -1428,16 +1428,76 @@ PeerConnectionWrapper.prototype = {
         });
       }
     }
 
     _checkMediaFlowPresent(0, onSuccess);
   },
 
   /**
+   * Check that stats are present by checking for known stats.
+   *
+   * @param {Function} onSuccess the success callback to return stats to
+   */
+  getStats : function PCW_getStats(selector, onSuccess) {
+    var self = this;
+
+    this._pc.getStats(selector, function(stats) {
+      info(self + ": Got stats: " + JSON.stringify(stats));
+      self._last_stats = stats;
+      onSuccess(stats);
+    }, unexpectedCallbackAndFinish());
+  },
+
+  /**
+   * Checks that we are getting the media streams we expect.
+   *
+   * @param {object} stats
+   *        The stats to check from this PeerConnectionWrapper
+   */
+  checkStats : function PCW_checkStats(stats) {
+    function toNum(obj) {
+      return obj? obj : 0;
+    }
+    function numTracks(streams) {
+      var n = 0;
+      streams.forEach(function(stream) {
+          n += stream.getAudioTracks().length + stream.getVideoTracks().length;
+        });
+      return n;
+    }
+
+    // Use spec way of enumerating stats
+    var counters = {};
+    for (var key in stats) {
+      if (stats.hasOwnProperty(key)) {
+        var res = stats[key];
+        counters[res.type] = toNum(counters[res.type]) + 1;
+      }
+    }
+    // Use MapClass way of enumerating stats
+    var counters2 = {};
+    stats.forEach(function(res) {
+        counters2[res.type] = toNum(counters2[res.type]) + 1;
+      });
+    is(JSON.stringify(counters), JSON.stringify(counters2),
+       "Spec and MapClass variant of RTCStatsReport enumeration agree");
+    var nin = numTracks(this._pc.getRemoteStreams());
+    var nout = numTracks(this._pc.getLocalStreams());
+
+    // TODO(Bug 957145): Restore stronger inboundrtp test once Bug 948249 is fixed
+    //is(toNum(counters["inboundrtp"]), nin, "Have " + nin + " inboundrtp stat(s)");
+    ok(toNum(counters["inboundrtp"]) >= nin, "Have at least " + nin + " inboundrtp stat(s) *");
+
+    is(toNum(counters["outboundrtp"]), nout, "Have " + nout + " outboundrtp stat(s)");
+    ok(toNum(counters["localcandidate"]), "Have localcandidate stat(s)");
+    ok(toNum(counters["remotecandidate"]), "Have remotecandidate stat(s)");
+  },
+
+  /**
    * Closes the connection
    */
   close : function PCW_close() {
     // It might be that a test has already closed the pc. In those cases
     // we should not fail.
     try {
       this._pc.close();
       info(this + ": Closed connection.");
--- a/dom/media/tests/mochitest/templates.js
+++ b/dom/media/tests/mochitest/templates.js
@@ -206,16 +206,34 @@ var commandsPeerConnection = [
   ],
   [
     'PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT',
     function (test) {
       test.pcRemote.checkMediaFlowPresent(function () {
         test.next();
       });
     }
+  ],
+  [
+    'PC_LOCAL_CHECK_STATS',
+    function (test) {
+      test.pcLocal.getStats(null, function(stats) {
+        test.pcLocal.checkStats(stats);
+        test.next();
+      });
+    }
+  ],
+  [
+    'PC_REMOTE_CHECK_STATS',
+    function (test) {
+      test.pcRemote.getStats(null, function(stats) {
+        test.pcRemote.checkStats(stats);
+        test.next();
+      });
+    }
   ]
 ];
 
 
 /**
  * Default list of commands to execute for a Datachannel test.
  */
 var commandsDataChannel = [