Bug 1178091: tests for large DataChannel transfers and onbufferedamountlow event r=drno
authorRandell Jesup <rjesup@jesup.org>
Mon, 28 Sep 2015 19:02:58 -0400
changeset 264860 40e2d33b759e2032d2bbde4aa70427c0e52eedbb
parent 264859 23cd3f0edf0af2974c1c53a6e8f913733561be53
child 264861 f4eba21be138e39ecf979bb7a9039633f2281bda
push id29450
push usercbook@mozilla.com
push dateTue, 29 Sep 2015 10:00:39 +0000
treeherdermozilla-central@acdb22976ff8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno
bugs1178091
milestone44.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 1178091: tests for large DataChannel transfers and onbufferedamountlow event r=drno
dom/media/tests/mochitest/dataChannel.js
dom/media/tests/mochitest/pc.js
--- a/dom/media/tests/mochitest/dataChannel.js
+++ b/dom/media/tests/mochitest/dataChannel.js
@@ -163,14 +163,29 @@ var commandsCheckDataChannel = [
 
     return test.send(message).then(result => {
       is(channels.indexOf(result.channel), channels.length - 1, "Last channel used");
       is(result.data, message, "Received message has the correct content.");
     });
   }
 ];
 
+var commandsCheckLargeXfer = [
+  function SEND_BIG_BUFFER(test) {
+    var size = 512*1024; // SCTP internal buffer is 256K, so we'll have ~256K queued
+    var buffer = new ArrayBuffer(size);
+    // note: type received is always blob for binary data
+    var options = {};
+    options.bufferedAmountLowThreshold = 64*1024;
+    return test.send(buffer, options).then(result => {
+      ok(result.data instanceof Blob, "Received data is of instance Blob");
+      is(result.data.size, size, "Received data has the correct size.");
+    });
+  },
+];
+
 function addInitialDataChannel(chain) {
   chain.insertBefore('PC_LOCAL_CREATE_OFFER', commandsCreateDataChannel);
   chain.insertBefore('PC_LOCAL_CHECK_MEDIA_TRACKS', commandsWaitForDataChannel);
   chain.removeAfter('PC_REMOTE_CHECK_ICE_CONNECTIONS');
+  chain.append(commandsCheckLargeXfer);
   chain.append(commandsCheckDataChannel);
 }
--- a/dom/media/tests/mochitest/pc.js
+++ b/dom/media/tests/mochitest/pc.js
@@ -209,21 +209,31 @@ PeerConnectionTest.prototype.closeDataCh
  *        Data channel to use for receiving the message
  */
 PeerConnectionTest.prototype.send = function(data, options) {
   options = options || { };
   var source = options.sourceChannel ||
            this.pcLocal.dataChannels[this.pcLocal.dataChannels.length - 1];
   var target = options.targetChannel ||
            this.pcRemote.dataChannels[this.pcRemote.dataChannels.length - 1];
+  var bufferedamount = options.bufferedAmountLowThreshold || 0;
+  var bufferlow_fired = true; // to make testing later easier
+  if (bufferedamount != 0) {
+    source.bufferedAmountLowThreshold = bufferedamount;
+    bufferlow_fired = false;
+    source.onbufferedamountlow = function() {
+      bufferlow_fired = true;
+    };
+  }
 
   return new Promise(resolve => {
     // Register event handler for the target channel
-    target.onmessage = e => {
-      resolve({ channel: target, data: e.data });
+      target.onmessage = e => {
+        ok(bufferlow_fired, "bufferedamountlow event fired");
+	resolve({ channel: target, data: e.data });
     };
 
     source.send(data);
   });
 };
 
 /**
  * Create a data channel
@@ -558,16 +568,17 @@ function DataChannelWrapper(dataChannel,
   info("Creating " + this);
 
   /**
    * Setup appropriate callbacks
    */
   createOneShotEventWrapper(this, this._channel, 'close');
   createOneShotEventWrapper(this, this._channel, 'error');
   createOneShotEventWrapper(this, this._channel, 'message');
+  createOneShotEventWrapper(this, this._channel, 'bufferedamountlow');
 
   this.opened = timerGuard(new Promise(resolve => {
     this._channel.onopen = () => {
       this._channel.onopen = unexpectedEvent(this, 'onopen');
       is(this.readyState, "open", "data channel is 'open' after 'onopen'");
       resolve(this);
     };
   }), 180000, "channel didn't open in time");
@@ -636,16 +647,26 @@ DataChannelWrapper.prototype = {
    *
    * @returns {String} The state of the channel
    */
   get readyState() {
     return this._channel.readyState;
   },
 
   /**
+   * Sets the bufferlowthreshold of the channel
+   *
+   * @param {integer} amoutn
+   *        The new threshold for the chanel
+   */
+  set bufferedAmountLowThreshold(amount) {
+    this._channel.bufferedAmountLowThreshold = amount;
+  },
+
+  /**
    * Close the data channel
    */
   close : function () {
     info(this + ": Closing channel");
     this._channel.close();
   },
 
   /**