Bug 1119593 - Update WebRTC data channel tests, r=drno, a=testonly
authorMartin Thomson <martin.thomson@gmail.com>
Sat, 21 Feb 2015 10:15:04 +1300
changeset 249890 474ed4d5fc658efc6f981f3ae179c01bb2b23759
parent 249889 ef853def0d3245281652ba5b4b9c6c33c76e3184
child 249891 acec3481e522c9ffeadbe8a318e99d328e4ff17f
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno, testonly
bugs1119593
milestone37.0a2
Bug 1119593 - Update WebRTC data channel tests, r=drno, a=testonly
dom/media/tests/mochitest/dataChannel.js
dom/media/tests/mochitest/head.js
dom/media/tests/mochitest/test_dataChannel_basicAudioVideoNoBundle.html
--- a/dom/media/tests/mochitest/dataChannel.js
+++ b/dom/media/tests/mochitest/dataChannel.js
@@ -1,230 +1,180 @@
 /* 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/. */
 
+/**
+ * Returns the contents of a blob as text
+ *
+ * @param {Blob} blob
+          The blob to retrieve the contents from
+ */
+function getBlobContent(blob) {
+  return new Promise(resolve => {
+    var reader = new FileReader();
+
+    // Listen for 'onloadend' which will always be called after a success or failure
+    reader.onloadend = function (event) {
+      resolve(event.target.result);
+    };
+
+    reader.readAsText(blob);
+  });
+}
+
 function addInitialDataChannel(chain) {
   chain.insertBefore('PC_LOCAL_CREATE_OFFER', [
-    ['PC_LOCAL_CREATE_DATA_CHANNEL',
-      function (test) {
-        var channel = test.pcLocal.createDataChannel({});
-
-        is(channel.binaryType, "blob", channel + " is of binary type 'blob'");
-        is(channel.readyState, "connecting", channel + " is in state: 'connecting'");
+    function PC_REMOTE_EXPECT_DATA_CHANNEL(test) {
+      test.pcRemote.expectDataChannel();
+    },
 
-        is(test.pcLocal.signalingState, STABLE,
-           "Create datachannel does not change signaling state");
+    function PC_LOCAL_CREATE_DATA_CHANNEL(test) {
+      var channel = test.pcLocal.createDataChannel({});
+      is(channel.binaryType, "blob", channel + " is of binary type 'blob'");
+      is(channel.readyState, "connecting", channel + " is in state: 'connecting'");
 
-        test.next();
-      }
-    ]
+      is(test.pcLocal.signalingState, STABLE,
+         "Create datachannel does not change signaling state");
+    }
   ]);
-  chain.insertAfter('PC_REMOTE_CREATE_ANSWER', [
-    [
-      'PC_LOCAL_SETUP_DATA_CHANNEL_CALLBACK',
-      function (test) {
-        test.waitForInitialDataChannel(test.pcLocal, function () {
-          ok(true, test.pcLocal + " dataChannels[0] switched to 'open'");
-        },
-        // At this point a timeout failure will be of no value
-        null);
-        test.next();
-      }
-    ],
-    [
-      'PC_REMOTE_SETUP_DATA_CHANNEL_CALLBACK',
-      function (test) {
-        test.waitForInitialDataChannel(test.pcRemote, function () {
-          ok(true, test.pcRemote + " dataChannels[0] switched to 'open'");
-        },
-        // At this point a timeout failure will be of no value
-        null);
-        test.next();
-      }
-    ]
-  ]);
+
   chain.insertBefore('PC_LOCAL_CHECK_MEDIA_TRACKS', [
-    [
-      'PC_LOCAL_VERIFY_DATA_CHANNEL_STATE',
-      function (test) {
-        test.waitForInitialDataChannel(test.pcLocal, function() {
-          test.next();
-        }, function() {
-          ok(false, test.pcLocal + " initial dataChannels[0] failed to switch to 'open'");
-          //TODO: use stopAndExit() once bug 1019323 has landed
-          unexpectedEventAndFinish(this, 'timeout')
-          // to prevent test framework timeouts
-          test.next();
-        });
-      }
-    ],
-    [
-      'PC_REMOTE_VERIFY_DATA_CHANNEL_STATE',
-      function (test) {
-        test.waitForInitialDataChannel(test.pcRemote, function() {
-          test.next();
-        }, function() {
-          ok(false, test.pcRemote + " initial dataChannels[0] failed to switch to 'open'");
-          //TODO: use stopAndExit() once bug 1019323 has landed
-          unexpectedEventAndFinish(this, 'timeout');
-          // to prevent test framework timeouts
-          test.next();
-        });
-      }
-    ]
+    function PC_LOCAL_VERIFY_DATA_CHANNEL_STATE(test) {
+      return test.pcLocal.dataChannels[0].opened
+        .then(() =>
+              ok(true, test.pcLocal + " dataChannels[0] switched to 'open'"));
+    },
+
+    function PC_REMOTE_VERIFY_DATA_CHANNEL_STATE(test) {
+      return test.pcRemote.nextDataChannel
+        .then(channel => channel.opened)
+        .then(channel =>
+              is(channel.readyState, "open",
+                 test.pcRemote + " dataChannels[0] switched to 'open'"));
+    }
   ]);
   chain.removeAfter('PC_REMOTE_CHECK_ICE_CONNECTIONS');
   chain.append([
-    [
-      'SEND_MESSAGE',
-      function (test) {
-        var message = "Lorem ipsum dolor sit amet";
+    function SEND_MESSAGE(test) {
+      var message = "Lorem ipsum dolor sit amet";
 
-        test.send(message, function (channel, data) {
-          is(data, message, "Message correctly transmitted from pcLocal to pcRemote.");
+      return test.send(message).then(result => {
+        is(result.data, message, "Message correctly transmitted from pcLocal to pcRemote.");
+      });
+    },
 
-          test.next();
-        });
-      }
-    ],
-    [
-      'SEND_BLOB',
-      function (test) {
-        var contents = ["At vero eos et accusam et justo duo dolores et ea rebum."];
-        var blob = new Blob(contents, { "type" : "text/plain" });
+    function SEND_BLOB(test) {
+      var contents = ["At vero eos et accusam et justo duo dolores et ea rebum."];
+      var blob = new Blob(contents, { "type" : "text/plain" });
 
-        test.send(blob, function (channel, data) {
-          ok(data instanceof Blob, "Received data is of instance Blob");
-          is(data.size, blob.size, "Received data has the correct size.");
+      return test.send(blob).then(result => {
+        ok(result.data instanceof Blob, "Received data is of instance Blob");
+        is(result.data.size, blob.size, "Received data has the correct size.");
 
-          getBlobContent(data, function (recv_contents) {
-            is(recv_contents, contents, "Received data has the correct content.");
+        return getBlobContent(result.data);
+      }).then(recv_contents =>
+              is(recv_contents, contents, "Received data has the correct content."));
+    },
 
-            test.next();
-          });
-        });
-      }
-    ],
-    [
-      'CREATE_SECOND_DATA_CHANNEL',
-      function (test) {
-        test.createDataChannel({ }, function (sourceChannel, targetChannel) {
-          is(sourceChannel.readyState, "open", sourceChannel + " is in state: 'open'");
-          is(targetChannel.readyState, "open", targetChannel + " is in state: 'open'");
+    function CREATE_SECOND_DATA_CHANNEL(test) {
+      return test.createDataChannel({ }).then(result => {
+        var sourceChannel = result.local;
+        var targetChannel = result.remote;
+        is(sourceChannel.readyState, "open", sourceChannel + " is in state: 'open'");
+        is(targetChannel.readyState, "open", targetChannel + " is in state: 'open'");
+
+        is(targetChannel.binaryType, "blob", targetChannel + " is of binary type 'blob'");
+      });
+    },
 
-          is(targetChannel.binaryType, "blob", targetChannel + " is of binary type 'blob'");
-          is(targetChannel.readyState, "open", targetChannel + " is in state: 'open'");
+    function SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL(test) {
+      var channels = test.pcRemote.dataChannels;
+      var message = "I am the Omega";
 
-          test.next();
-        });
-      }
-    ],
-    [
-      'SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL',
-      function (test) {
-        var channels = test.pcRemote.dataChannels;
-        var message = "Lorem ipsum dolor sit amet";
+      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.");
+      });
+    },
 
-        test.send(message, function (channel, data) {
-          is(channels.indexOf(channel), channels.length - 1, "Last channel used");
-          is(data, message, "Received message has the correct content.");
 
-          test.next();
-        });
-      }
-    ],
-    [
-      'SEND_MESSAGE_THROUGH_FIRST_CHANNEL',
-      function (test) {
-        var message = "Message through 1st channel";
-        var options = {
-          sourceChannel: test.pcLocal.dataChannels[0],
-          targetChannel: test.pcRemote.dataChannels[0]
-        };
+    function SEND_MESSAGE_THROUGH_FIRST_CHANNEL(test) {
+      var message = "Message through 1st channel";
+      var options = {
+        sourceChannel: test.pcLocal.dataChannels[0],
+        targetChannel: test.pcRemote.dataChannels[0]
+      };
 
-        test.send(message, function (channel, data) {
-          is(test.pcRemote.dataChannels.indexOf(channel), 0, "1st channel used");
-          is(data, message, "Received message has the correct content.");
+      return test.send(message, options).then(result => {
+        is(test.pcRemote.dataChannels.indexOf(result.channel), 0, "1st channel used");
+        is(result.data, message, "Received message has the correct content.");
+      });
+    },
+
 
-          test.next();
-        }, options);
-      }
-    ],
-    [
-      'SEND_MESSAGE_BACK_THROUGH_FIRST_CHANNEL',
-      function (test) {
-        var message = "Return a message also through 1st channel";
-        var options = {
-          sourceChannel: test.pcRemote.dataChannels[0],
-          targetChannel: test.pcLocal.dataChannels[0]
-        };
+    function SEND_MESSAGE_BACK_THROUGH_FIRST_CHANNEL(test) {
+      var message = "Return a message also through 1st channel";
+      var options = {
+        sourceChannel: test.pcRemote.dataChannels[0],
+        targetChannel: test.pcLocal.dataChannels[0]
+      };
 
-        test.send(message, function (channel, data) {
-          is(test.pcLocal.dataChannels.indexOf(channel), 0, "1st channel used");
-          is(data, message, "Return message has the correct content.");
+      return test.send(message, options).then(result => {
+        is(test.pcLocal.dataChannels.indexOf(result.channel), 0, "1st channel used");
+        is(result.data, message, "Return message has the correct content.");
+      });
+    },
 
-          test.next();
-        }, options);
-      }
-    ],
-    [
-      'CREATE_NEGOTIATED_DATA_CHANNEL',
-      function (test) {
-        var options = {negotiated:true, id: 5, protocol:"foo/bar", ordered:false,
-          maxRetransmits:500};
-        test.createDataChannel(options, function (sourceChannel2, targetChannel2) {
-          is(sourceChannel2.readyState, "open", sourceChannel2 + " is in state: 'open'");
-          is(targetChannel2.readyState, "open", targetChannel2 + " is in state: 'open'");
+    function CREATE_NEGOTIATED_DATA_CHANNEL(test) {
+      var options = {
+        negotiated:true,
+        id: 5,
+        protocol: "foo/bar",
+        ordered: false,
+        maxRetransmits: 500
+      };
+      return test.createDataChannel(options).then(result => {
+        var sourceChannel2 = result.local;
+        var targetChannel2 = result.remote;
+        is(sourceChannel2.readyState, "open", sourceChannel2 + " is in state: 'open'");
+        is(targetChannel2.readyState, "open", targetChannel2 + " is in state: 'open'");
 
-          is(targetChannel2.binaryType, "blob", targetChannel2 + " is of binary type 'blob'");
-          is(targetChannel2.readyState, "open", targetChannel2 + " is in state: 'open'");
+        is(targetChannel2.binaryType, "blob", targetChannel2 + " is of binary type 'blob'");
 
-          if (options.id != undefined) {
-            is(sourceChannel2.id, options.id, sourceChannel2 + " id is:" + sourceChannel2.id);
-          }
-          else {
-            options.id = sourceChannel2.id;
-          }
-          var reliable = !options.ordered ? false : (options.maxRetransmits || options.maxRetransmitTime);
-          is(sourceChannel2.protocol, options.protocol, sourceChannel2 + " protocol is:" + sourceChannel2.protocol);
-          is(sourceChannel2.reliable, reliable, sourceChannel2 + " reliable is:" + sourceChannel2.reliable);
-  /*
-    These aren't exposed by IDL yet
+        is(sourceChannel2.id, options.id, sourceChannel2 + " id is:" + sourceChannel2.id);
+        var reliable = !options.ordered ? false : (options.maxRetransmits || options.maxRetransmitTime);
+        is(sourceChannel2.protocol, options.protocol, sourceChannel2 + " protocol is:" + sourceChannel2.protocol);
+        is(sourceChannel2.reliable, reliable, sourceChannel2 + " reliable is:" + sourceChannel2.reliable);
+        /*
+          These aren't exposed by IDL yet
           is(sourceChannel2.ordered, options.ordered, sourceChannel2 + " ordered is:" + sourceChannel2.ordered);
           is(sourceChannel2.maxRetransmits, options.maxRetransmits, sourceChannel2 + " maxRetransmits is:" +
-       sourceChannel2.maxRetransmits);
+          sourceChannel2.maxRetransmits);
           is(sourceChannel2.maxRetransmitTime, options.maxRetransmitTime, sourceChannel2 + " maxRetransmitTime is:" +
-       sourceChannel2.maxRetransmitTime);
-  */
-
-          is(targetChannel2.id, options.id, targetChannel2 + " id is:" + targetChannel2.id);
-          is(targetChannel2.protocol, options.protocol, targetChannel2 + " protocol is:" + targetChannel2.protocol);
-          is(targetChannel2.reliable, reliable, targetChannel2 + " reliable is:" + targetChannel2.reliable);
-  /*
-    These aren't exposed by IDL yet
-         is(targetChannel2.ordered, options.ordered, targetChannel2 + " ordered is:" + targetChannel2.ordered);
-          is(targetChannel2.maxRetransmits, options.maxRetransmits, targetChannel2 + " maxRetransmits is:" +
-       targetChannel2.maxRetransmits);
-          is(targetChannel2.maxRetransmitTime, options.maxRetransmitTime, targetChannel2 + " maxRetransmitTime is:" +
-       targetChannel2.maxRetransmitTime);
-  */
+          sourceChannel2.maxRetransmitTime);
+        */
 
-          test.next();
-        });
-      }
-    ],
-    [
-      'SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL2',
-      function (test) {
-        var channels = test.pcRemote.dataChannels;
-        var message = "Lorem ipsum dolor sit amet";
+        is(targetChannel2.id, options.id, targetChannel2 + " id is:" + targetChannel2.id);
+        is(targetChannel2.protocol, options.protocol, targetChannel2 + " protocol is:" + targetChannel2.protocol);
+        is(targetChannel2.reliable, reliable, targetChannel2 + " reliable is:" + targetChannel2.reliable);
+        /*
+          These aren't exposed by IDL yet
+          is(targetChannel2.ordered, options.ordered, targetChannel2 + " ordered is:" + targetChannel2.ordered);
+          is(targetChannel2.maxRetransmits, options.maxRetransmits, targetChannel2 + " maxRetransmits is:" +
+          targetChannel2.maxRetransmits);
+          is(targetChannel2.maxRetransmitTime, options.maxRetransmitTime, targetChannel2 + " maxRetransmitTime is:" +
+          targetChannel2.maxRetransmitTime);
+        */
+      });
+    },
 
-        test.send(message, function (channel, data) {
-          is(channels.indexOf(channel), channels.length - 1, "Last channel used");
-          is(data, message, "Received message has the correct content.");
+    function SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL2(test) {
+      var channels = test.pcRemote.dataChannels;
+      var message = "I am the walrus; Goo goo g' joob";
 
-          test.next();
-        });
-      }
-    ]
+      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.");
+      });
+    }
   ]);
 }
--- a/dom/media/tests/mochitest/head.js
+++ b/dom/media/tests/mochitest/head.js
@@ -210,36 +210,16 @@ function waitUntil(func, time) {
       if (func())  {
         clearInterval(interval);
         resolve();
       }
     }, time || 200);
   });
 }
 
-
-/**
- * Returns the contents of a blob as text
- *
- * @param {Blob} blob
-          The blob to retrieve the contents from
- */
-function getBlobContent(blob) {
-  return new Promise(resolve => {
-    var reader = new FileReader();
-
-    // Listen for 'onloadend' which will always be called after a success or failure
-    reader.onloadend = function (event) {
-      resolve(event.target.result);
-    };
-
-    reader.readAsText(blob);
-  });
-}
-
 /*** Test control flow methods */
 
 /**
  * Generates a callback function fired only under unexpected circumstances
  * while running the tests. The generated function kills off the test as well
  * gracefully.
  *
  * @param {String} [message]
--- a/dom/media/tests/mochitest/test_dataChannel_basicAudioVideoNoBundle.html
+++ b/dom/media/tests/mochitest/test_dataChannel_basicAudioVideoNoBundle.html
@@ -12,33 +12,28 @@
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
     bug: "1016476",
     title: "Basic data channel audio/video connection without bundle"
   });
 
-  var test;
-  runNetworkTest(function () {
-    test = new PeerConnectionTest();
-    addInitialDataChannel(test.chain);
-    test.chain.insertAfter("PC_LOCAL_CREATE_OFFER",
-      [[
-        'PC_LOCAL_REMOVE_BUNDLE_FROM_OFFER',
-        function (test) {
-          // Just replace a=group:BUNDLE with something that will be ignored.
-          test.originalOffer.sdp = test.originalOffer.sdp.replace(
-            "a=group:BUNDLE",
-            "a=foo:");
-          test.next();
-        }
-      ]]
-      );
-    test.setMediaConstraints([{audio: true}, {video: true}],
-                             [{audio: true}, {video: true}]);
-    test.run();
-  });
-
+var test;
+runNetworkTest(function () {
+  test = new PeerConnectionTest();
+  addInitialDataChannel(test.chain);
+  test.chain.insertAfter("PC_LOCAL_CREATE_OFFER", [
+    function PC_LOCAL_REMOVE_BUNDLE_FROM_OFFER(test) {
+      // Just replace a=group:BUNDLE with something that will be ignored.
+      test.originalOffer.sdp = test.originalOffer.sdp.replace(
+        "a=group:BUNDLE",
+        "a=foo:");
+    }
+  ]);
+  test.setMediaConstraints([{audio: true}, {video: true}],
+                           [{audio: true}, {video: true}]);
+  test.run();
+});
 </script>
 </pre>
 </body>
 </html>