Bug 1119593 - Update PeerConnection tests, r=drno,jib, a=testonly
authorMartin Thomson <martin.thomson@gmail.com>
Sat, 21 Feb 2015 10:15:04 +1300
changeset 249891 acec3481e522c9ffeadbe8a318e99d328e4ff17f
parent 249890 474ed4d5fc658efc6f981f3ae179c01bb2b23759
child 249892 a983c31d2dcde10f4c4b6c3f34de36b2e2d51b62
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, jib, testonly
bugs1119593
milestone37.0a2
Bug 1119593 - Update PeerConnection tests, r=drno,jib, a=testonly
dom/media/tests/mochitest/test_peerConnection_addCandidateInHaveLocalOffer.html
dom/media/tests/mochitest/test_peerConnection_addSecondAudioStream.html
dom/media/tests/mochitest/test_peerConnection_basicAudioVideoNoBundle.html
dom/media/tests/mochitest/test_peerConnection_bug1042791.html
dom/media/tests/mochitest/test_peerConnection_bug827843.html
dom/media/tests/mochitest/test_peerConnection_capturedVideo.html
dom/media/tests/mochitest/test_peerConnection_replaceTrack.html
dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInHaveLocalOffer.html
dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInStable.html
dom/media/tests/mochitest/test_peerConnection_setLocalOfferInHaveRemoteOffer.html
dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInHaveRemoteOffer.html
dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInStable.html
dom/media/tests/mochitest/test_peerConnection_setRemoteOfferInHaveLocalOffer.html
dom/media/tests/mochitest/test_peerConnection_syncSetDescription.html
dom/media/tests/mochitest/test_peerConnection_toJSON.html
--- a/dom/media/tests/mochitest/test_peerConnection_addCandidateInHaveLocalOffer.html
+++ b/dom/media/tests/mochitest/test_peerConnection_addCandidateInHaveLocalOffer.html
@@ -18,28 +18,26 @@
   });
 
   var test;
   runNetworkTest(function () {
     test = new PeerConnectionTest();
     test.setMediaConstraints([{audio: true}], [{audio: true}]);
     test.chain.removeAfter("PC_LOCAL_SET_LOCAL_DESCRIPTION");
 
-    test.chain.append([[
-      "PC_LOCAL_ADD_CANDIDATE",
-      function (test) {
-        test.pcLocal.addIceCandidateAndFail(
-          new mozRTCIceCandidate(
-            {candidate:"1 1 UDP 2130706431 192.168.2.1 50005 typ host",
-             sdpMLineIndex: 1}),
-          function(err) {
+    test.chain.append([
+      function PC_LOCAL_ADD_CANDIDATE(test) {
+        var candidate = new mozRTCIceCandidate(
+          {candidate:"1 1 UDP 2130706431 192.168.2.1 50005 typ host",
+           sdpMLineIndex: 1});
+        return test.pcLocal._pc.addIceCandidate(candidate).then(
+          generateErrorCallback("addIceCandidate should have failed."),
+          err => {
             is(err.name, "InvalidStateError", "Error is InvalidStateError");
-            test.next();
-          } );
-      }
-    ]]);
-
+          });
+        }
+    ]);
     test.run();
   });
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_addSecondAudioStream.html
+++ b/dom/media/tests/mochitest/test_peerConnection_addSecondAudioStream.html
@@ -16,87 +16,50 @@
     bug: "1091242",
     title: "Renegotiation: add second audio stream"
   });
 
   var test;
   runNetworkTest(function (options) {
     test = new PeerConnectionTest(options);
     test.chain.append([
-    [
-      'PC_LOCAL_SETUP_NEGOTIATION_CALLBACK',
-      function (test) {
+      function PC_LOCAL_SETUP_NEGOTIATION_CALLBACK(test) {
         test.pcLocal.onNegotiationneededFired = false;
-        test.pcLocal._pc.onnegotiationneeded = function (anEvent) {
+        test.pcLocal._pc.onnegotiationneeded = anEvent => {
           info("pcLocal.onnegotiationneeded fired");
           test.pcLocal.onNegotiationneededFired = true;
         };
-        test.next();
-      }
-    ],
-    [
-      'PC_LOCAL_ADD_SECOND_STREAM',
-      function (test) {
-        test.pcLocal.getAllUserMedia([{audio: true}], function () {
-          test.next();
+      },
+      function PC_LOCAL_ADD_SECOND_STREAM(test) {
+        return test.pcLocal.getAllUserMedia([{audio: true}]);
+      },
+      function PC_LOCAL_CREATE_NEW_OFFER(test) {
+        ok(test.pcLocal.onNegotiationneededFired, "onnegotiationneeded");
+        return test.createOffer(test.pcLocal).then(offer => {
+          test._new_offer = offer;
         });
-      }
-    ],
-    [
-      'PC_LOCAL_CREATE_NEW_OFFER',
-      function (test) {
-        ok(test.pcLocal.onNegotiationneededFired, "onnegotiationneeded");
-        test.createOffer(test.pcLocal, function (offer) {
-          test._new_offer = offer;
-          test.next();
+      },
+      function PC_LOCAL_SET_NEW_LOCAL_DESCRIPTION(test) {
+        return test.setLocalDescription(test.pcLocal, test._new_offer, HAVE_LOCAL_OFFER);
+      },
+      function PC_REMOTE_SET_NEW_REMOTE_DESCRIPTION(test) {
+        return test.setRemoteDescription(test.pcRemote, test._new_offer, HAVE_REMOTE_OFFER);
+      },
+      function PC_REMOTE_CREATE_NEW_ANSWER(test) {
+        return test.createAnswer(test.pcRemote).then(answer => {
+          test._new_answer = answer;
         });
-      }
-    ],
-    [
-      'PC_LOCAL_SET_NEW_LOCAL_DESCRIPTION',
-      function (test) {
-        test.setLocalDescription(test.pcLocal, test._new_offer, HAVE_LOCAL_OFFER, function () {
-          test.next();
-        });
+      },
+      function PC_REMOTE_SET_NEW_LOCAL_DESCRIPTION(test) {
+        return test.setLocalDescription(test.pcRemote, test._new_answer, STABLE);
+      },
+      function PC_LOCAL_SET_NEW_REMOTE_DESCRIPTION(test) {
+        return test.setRemoteDescription(test.pcLocal, test._new_answer, STABLE);
       }
-    ],
-    [
-      'PC_REMOTE_SET_NEW_REMOTE_DESCRIPTION',
-      function (test) {
-        test.setRemoteDescription(test.pcRemote, test._new_offer, HAVE_REMOTE_OFFER, function () {
-          test.next();
-        });
-      }
-    ],
-    [
-      'PC_REMOTE_CREATE_NEW_ANSWER',
-      function (test) {
-        test.createAnswer(test.pcRemote, function (answer) {
-          test._new_answer = answer;
-          test.next();
-        });
-      }
-    ],
-    [
-      'PC_REMOTE_SET_NEW_LOCAL_DESCRIPTION',
-      function (test) {
-        test.setLocalDescription(test.pcRemote, test._new_answer, STABLE, function () {
-          test.next();
-        });
-      }
-    ],
-    [
-      'PC_LOCAL_SET_NEW_REMOTE_DESCRIPTION',
-      function (test) {
-        test.setRemoteDescription(test.pcLocal, test._new_answer, STABLE, function () {
-          test.next();
-        });
-      }
-    ]
-    // TODO(bug 1093835): figure out how to verify if media flows through the new stream
+      // TODO(bug 1093835): figure out how to verify if media flows through the new stream
     ]);
     test.setMediaConstraints([{audio: true}], [{audio: true}]);
     test.run();
   });
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_basicAudioVideoNoBundle.html
+++ b/dom/media/tests/mochitest/test_peerConnection_basicAudioVideoNoBundle.html
@@ -17,27 +17,27 @@
     title: "Basic audio/video peer connection with no Bundle"
   });
 
   SimpleTest.requestFlakyTimeout("WebRTC is full of inherent timeouts");
 
   var test;
   runNetworkTest(function (options) {
     test = new PeerConnectionTest(options);
-    test.chain.insertAfter('PC_LOCAL_CREATE_OFFER',
-    [['PC_LOCAL_REMOVE_BUNDLE_FROM_OFFER',
-      function (test) {
-        test.originalOffer.sdp = test.originalOffer.sdp.replace(
-          /a=group:BUNDLE .*\r\n/g,
-          ""
-        );
-        info("Updated no bundle offer: " + JSON.stringify(test.originalOffer));
-        test.next();
-      }
-    ]]);
+    test.chain.insertAfter(
+      'PC_LOCAL_CREATE_OFFER',
+      [
+        function PC_LOCAL_REMOVE_BUNDLE_FROM_OFFER(test) {
+          test.originalOffer.sdp = test.originalOffer.sdp.replace(
+              /a=group:BUNDLE .*\r\n/g,
+            ""
+          );
+          info("Updated no bundle offer: " + JSON.stringify(test.originalOffer));
+        }
+      ]);
     test.setMediaConstraints([{audio: true}, {video: true}],
                              [{audio: true}, {video: true}]);
     test.run();
   });
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_bug1042791.html
+++ b/dom/media/tests/mochitest/test_peerConnection_bug1042791.html
@@ -20,25 +20,23 @@
   var test;
   runNetworkTest(function (options) {
     options = options || { };
     options.h264 = true;
     test = new PeerConnectionTest(options);
     test.setMediaConstraints([{video: true}], [{video: true}]);
     test.chain.removeAfter("PC_LOCAL_CREATE_OFFER");
 
-    test.chain.append([[
-      "PC_LOCAL_VERIFY_H264_OFFER",
-      function (test) {
+    test.chain.append([
+      function PC_LOCAL_VERIFY_H264_OFFER(test) {
         ok(!test.pcLocal._latest_offer.sdp.toLowerCase().contains("profile-level-id=0x42e0"),
-          "H264 offer does not contain profile-level-id=0x42e0");
+           "H264 offer does not contain profile-level-id=0x42e0");
         ok(test.pcLocal._latest_offer.sdp.toLowerCase().contains("profile-level-id=42e0"),
-          "H264 offer contains profile-level-id=42e0");
-        test.next();
+           "H264 offer contains profile-level-id=42e0");
       }
-    ]]);
+    ]);
 
     test.run();
   });
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_bug827843.html
+++ b/dom/media/tests/mochitest/test_peerConnection_bug827843.html
@@ -11,62 +11,65 @@
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
     bug: "827843",
     title: "Ensure that localDescription and remoteDescription are null after close"
   });
 
-  var steps = [
-    [
-      "CHECK_SDP_ON_CLOSED_PC",
-      function (test) {
-        var description;
-        var exception = null;
+var steps = [
+  function CHECK_SDP_ON_CLOSED_PC(test) {
+    var description;
+    var exception = null;
 
-        // handle the event which the close() triggers
-        test.pcLocal.onsignalingstatechange = function (e) {
-          is(e.target.signalingState, "closed",
-             "Received expected onsignalingstatechange event on 'closed'");
-        }
-
-        test.pcLocal.close();
+    // handle the event which the close() triggers
+    var localClosed = new Promise(resolve => {
+      test.pcLocal.onsignalingstatechange = e => {
+        is(e.target.signalingState, "closed",
+           "Received expected onsignalingstatechange event on 'closed'");
+        resolve();
+      }
+    });
 
-        try { description = test.pcLocal.localDescription; } catch (e) { exception = e; }
-        ok(exception, "Attempt to access localDescription of pcLocal after close throws exception");
-        exception = null;
+    test.pcLocal.close();
 
-        try { description = test.pcLocal.remoteDescription; } catch (e) { exception = e; }
-        ok(exception, "Attempt to access remoteDescription of pcLocal after close throws exception");
-        exception = null;
+    try { description = test.pcLocal.localDescription; } catch (e) { exception = e; }
+    ok(exception, "Attempt to access localDescription of pcLocal after close throws exception");
+    exception = null;
+
+    try { description = test.pcLocal.remoteDescription; } catch (e) { exception = e; }
+    ok(exception, "Attempt to access remoteDescription of pcLocal after close throws exception");
+    exception = null;
 
-        // handle the event which the close() triggers
-        test.pcRemote.onsignalingstatechange = function (e) {
-          is(e.target.signalingState, "closed",
-             "Received expected onsignalingstatechange event on 'closed'");
-        }
+    // handle the event which the close() triggers
+    var remoteClosed = new Promise(resolve => {
+      test.pcRemote.onsignalingstatechange = e => {
+        is(e.target.signalingState, "closed",
+           "Received expected onsignalingstatechange event on 'closed'");
+        resolve();
+      }
+    });
 
-        test.pcRemote.close();
+    test.pcRemote.close();
 
-        try  { description = test.pcRemote.localDescription; } catch (e) { exception = e; }
-        ok(exception, "Attempt to access localDescription of pcRemote after close throws exception");
-        exception = null;
+    try  { description = test.pcRemote.localDescription; } catch (e) { exception = e; }
+    ok(exception, "Attempt to access localDescription of pcRemote after close throws exception");
+    exception = null;
 
-        try  { description = test.pcRemote.remoteDescription; } catch (e) { exception = e; }
-        ok(exception, "Attempt to access remoteDescription of pcRemote after close throws exception");
+    try  { description = test.pcRemote.remoteDescription; } catch (e) { exception = e; }
+    ok(exception, "Attempt to access remoteDescription of pcRemote after close throws exception");
 
-        test.next();
-      }
-    ]
-  ];
+    return Promise.all([localClosed, remoteClosed]);
+  }
+];
 
-  var test;
-  runNetworkTest(function () {
-    test = new PeerConnectionTest();
-    test.setMediaConstraints([{audio: true}], [{audio: true}]);
-    test.chain.append(steps);
-    test.run();
-  });
+var test;
+runNetworkTest(() => {
+  test = new PeerConnectionTest();
+  test.setMediaConstraints([{audio: true}], [{audio: true}]);
+  test.chain.append(steps);
+  test.run();
+});
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_capturedVideo.html
+++ b/dom/media/tests/mochitest/test_peerConnection_capturedVideo.html
@@ -14,42 +14,38 @@
 <pre id="test">
 <script type="application/javascript;version=1.8">
   createHTML({
     bug: "1081409",
     title: "Captured video-only over peer connection",
     visible: true
   });
 
-  var metadataLoaded = new Promise(resolve => {
-    if (v1.readyState < v1.HAVE_METADATA) {
-      v1.onloadedmetadata = e => resolve();
-      return;
-    }
+var metadataLoaded = new Promise(resolve => {
+  if (v1.readyState < v1.HAVE_METADATA) {
+    v1.onloadedmetadata = resolve;
+  } else {
     resolve();
-  });
+  }
+});
 
-  runNetworkTest(function() {
-    var test = new PeerConnectionTest();
-    test.setOfferOptions({ offerToReceiveVideo: false,
-                           offerToReceiveAudio: false });
-    test.chain.insertAfter("PC_LOCAL_GUM", [["PC_LOCAL_CAPTUREVIDEO", function (test) {
-      metadataLoaded
-      .then(function() {
-        var stream = v1.mozCaptureStreamUntilEnded();
-        is(stream.getTracks().length, 2, "Captured stream has 2 tracks");
-        stream.getTracks().forEach(tr => test.pcLocal._pc.addTrack(tr, stream));
-        test.pcLocal.constraints = [{ video: true, audio:true }]; // fool tests
-        test.next();
-      })
-      .catch(function(reason) {
-        ok(false, "unexpected failure: " + reason);
-        SimpleTest.finish();
-      });
+runNetworkTest(function() {
+  var test = new PeerConnectionTest();
+  test.setOfferOptions({ offerToReceiveVideo: false,
+                         offerToReceiveAudio: false });
+  test.chain.insertAfter("PC_LOCAL_GUM", [
+    function PC_LOCAL_CAPTUREVIDEO(test) {
+      return metadataLoaded
+        .then(() => {
+          var stream = v1.mozCaptureStreamUntilEnded();
+          is(stream.getTracks().length, 2, "Captured stream has 2 tracks");
+          stream.getTracks().forEach(tr => test.pcLocal._pc.addTrack(tr, stream));
+          test.pcLocal.constraints = [{ video: true, audio:true }]; // fool tests
+        });
     }
-    ]]);
-    test.chain.removeAfter("PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT");
-    test.run();
-  });
+  ]);
+  test.chain.removeAfter("PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT");
+  test.run();
+});
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_replaceTrack.html
+++ b/dom/media/tests/mochitest/test_peerConnection_replaceTrack.html
@@ -26,37 +26,33 @@
 
   var test;
   runNetworkTest(function () {
     test = new PeerConnectionTest();
     test.setMediaConstraints([{video: true}], [{video: true}]);
     test.chain.removeAfter("PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT");
     var flowtest = test.chain.remove("PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT");
     test.chain.append(flowtest);
-    test.chain.append([["PC_LOCAL_REPLACE_VIDEOTRACK",
-      function (test) {
+    test.chain.append([
+      function PC_LOCAL_REPLACE_VIDEOTRACK(test) {
         var stream = test.pcLocal._pc.getLocalStreams()[0];
         var track = stream.getVideoTracks()[0];
         var sender = test.pcLocal._pc.getSenders().find(isSenderOfTrack, track);
         ok(sender, "track has a sender");
         var newtrack;
-        navigator.mediaDevices.getUserMedia({video:true, fake: true})
-        .then(function(newStream) {
-          newtrack = newStream.getVideoTracks()[0];
-          return sender.replaceTrack(newtrack);
-        })
-        .then(function() {
-          is(sender.track, newtrack, "sender.track has been replaced");
-        })
-        .catch(function(reason) {
-          ok(false, "unexpected error = " + reason.message);
-        })
-        .then(test.next.bind(test));
+        return navigator.mediaDevices.getUserMedia({video:true, fake: true})
+          .then(newStream => {
+            newtrack = newStream.getVideoTracks()[0];
+            return sender.replaceTrack(newtrack);
+          })
+          .then(() => {
+            is(sender.track, newtrack, "sender.track has been replaced");
+          });
       }
-    ]]);
+    ]);
     test.chain.append(flowtest);
 
     test.run();
   });
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInHaveLocalOffer.html
+++ b/dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInHaveLocalOffer.html
@@ -12,32 +12,30 @@
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
     bug: "784519",
     title: "setLocalDescription (answer) in 'have-local-offer'"
   });
 
-  var test;
-  runNetworkTest(function () {
-    test = new PeerConnectionTest();
-    test.setMediaConstraints([{audio: true}], [{audio: true}]);
-    test.chain.removeAfter("PC_LOCAL_SET_LOCAL_DESCRIPTION");
+var test;
+runNetworkTest(function () {
+  test = new PeerConnectionTest();
+  test.setMediaConstraints([{audio: true}], [{audio: true}]);
+  test.chain.removeAfter("PC_LOCAL_SET_LOCAL_DESCRIPTION");
 
-    test.chain.append([[
-      "PC_LOCAL_SET_LOCAL_ANSWER",
-      function (test) {
-        test.pcLocal._latest_offer.type="answer";
-        test.pcLocal.setLocalDescriptionAndFail(test.pcLocal._latest_offer,
-          function(err) {
-            is(err.name, "InvalidStateError", "Error is InvalidStateError");
-            test.next();
-          } );
-      }
-    ]]);
+  test.chain.append([
+    function PC_LOCAL_SET_LOCAL_ANSWER(test) {
+      test.pcLocal._latest_offer.type = "answer";
+      return test.pcLocal.setLocalDescriptionAndFail(test.pcLocal._latest_offer)
+        .then(err => {
+          is(err.name, "InvalidStateError", "Error is InvalidStateError");
+        });
+    }
+  ]);
 
-    test.run();
-  });
+  test.run();
+});
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInStable.html
+++ b/dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInStable.html
@@ -12,32 +12,30 @@
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
     bug: "784519",
     title: "setLocalDescription (answer) in 'stable'"
   });
 
-  var test;
-  runNetworkTest(function () {
-    test = new PeerConnectionTest();
-    test.setMediaConstraints([{audio: true}], [{audio: true}]);
-    test.chain.removeAfter("PC_LOCAL_CREATE_OFFER");
+var test;
+runNetworkTest(function () {
+  test = new PeerConnectionTest();
+  test.setMediaConstraints([{audio: true}], [{audio: true}]);
+  test.chain.removeAfter("PC_LOCAL_CREATE_OFFER");
 
-    test.chain.append([[
-      "PC_LOCAL_SET_LOCAL_ANSWER",
-      function (test) {
-        test.pcLocal._latest_offer.type="answer";
-        test.pcLocal.setLocalDescriptionAndFail(test.pcLocal._latest_offer,
-          function(err) {
-            is(err.name, "InvalidStateError", "Error is InvalidStateError");
-            test.next();
-          } );
-      }
-    ]]);
+  test.chain.append([
+    function PC_LOCAL_SET_LOCAL_ANSWER(test) {
+      test.pcLocal._latest_offer.type = "answer";
+      return test.pcLocal.setLocalDescriptionAndFail(test.pcLocal._latest_offer)
+        .then(err => {
+          is(err.name, "InvalidStateError", "Error is InvalidStateError");
+        });
+    }
+  ]);
 
-    test.run();
-  });
+  test.run();
+});
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_setLocalOfferInHaveRemoteOffer.html
+++ b/dom/media/tests/mochitest/test_peerConnection_setLocalOfferInHaveRemoteOffer.html
@@ -12,31 +12,29 @@
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
     bug: "784519",
     title: "setLocalDescription (offer) in 'have-remote-offer'"
   });
 
-  var test;
-  runNetworkTest(function () {
-    test = new PeerConnectionTest();
-    test.setMediaConstraints([{audio: true}], [{audio: true}]);
-    test.chain.removeAfter("PC_REMOTE_SET_REMOTE_DESCRIPTION");
+var test;
+runNetworkTest(function () {
+  test = new PeerConnectionTest();
+  test.setMediaConstraints([{audio: true}], [{audio: true}]);
+  test.chain.removeAfter("PC_REMOTE_SET_REMOTE_DESCRIPTION");
 
-    test.chain.append([[
-      "PC_REMOTE_SET_LOCAL_OFFER",
-      function (test) {
-        test.pcRemote.setLocalDescriptionAndFail(test.pcLocal._latest_offer,
-          function(err) {
-            is(err.name, "InvalidStateError", "Error is InvalidStateError");
-            test.next();
-          } );
-      }
-    ]]);
+  test.chain.append([
+    function PC_REMOTE_SET_LOCAL_OFFER(test) {
+      test.pcRemote.setLocalDescriptionAndFail(test.pcLocal._latest_offer)
+        .then(err => {
+          is(err.name, "InvalidStateError", "Error is InvalidStateError");
+        });
+    }
+  ]);
 
-    test.run();
-  });
+  test.run();
+});
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInHaveRemoteOffer.html
+++ b/dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInHaveRemoteOffer.html
@@ -12,32 +12,30 @@
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
     bug: "784519",
     title: "setRemoteDescription (answer) in 'have-remote-offer'"
   });
 
-  var test;
-  runNetworkTest(function () {
-    test = new PeerConnectionTest();
-    test.setMediaConstraints([{audio: true}], [{audio: true}]);
-    test.chain.removeAfter("PC_REMOTE_SET_REMOTE_DESCRIPTION");
+var test;
+runNetworkTest(function () {
+  test = new PeerConnectionTest();
+  test.setMediaConstraints([{audio: true}], [{audio: true}]);
+  test.chain.removeAfter("PC_REMOTE_SET_REMOTE_DESCRIPTION");
 
-    test.chain.append([[
-      "PC_REMOTE_SET_REMOTE_ANSWER",
-      function (test) {
-        test.pcLocal._latest_offer.type="answer";
-        test.pcRemote.setRemoteDescriptionAndFail(test.pcLocal._latest_offer,
-          function(err) {
-            is(err.name, "InvalidStateError", "Error is InvalidStateError");
-            test.next();
-          } );
-      }
-    ]]);
+  test.chain.append([
+    function PC_REMOTE_SET_REMOTE_ANSWER(test) {
+      test.pcLocal._latest_offer.type = "answer";
+      test.pcRemote._pc.setRemoteDescription(test.pcLocal._latest_offer)
+        .then(generateErrorCallback('setRemoteDescription should fail'),
+              err =>
+              is(err.name, "InvalidStateError", "Error is InvalidStateError"));
+    }
+  ]);
 
-    test.run();
-  });
+  test.run();
+});
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInStable.html
+++ b/dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInStable.html
@@ -12,32 +12,30 @@
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
     bug: "784519",
     title: "setRemoteDescription (answer) in 'stable'"
   });
 
-  var test;
-  runNetworkTest(function () {
-    test = new PeerConnectionTest();
-    test.setMediaConstraints([{audio: true}], [{audio: true}]);
-    test.chain.removeAfter("PC_LOCAL_CREATE_OFFER");
+var test;
+runNetworkTest(function () {
+  test = new PeerConnectionTest();
+  test.setMediaConstraints([{audio: true}], [{audio: true}]);
+  test.chain.removeAfter("PC_LOCAL_CREATE_OFFER");
 
-    test.chain.append([[
-      "PC_LOCAL_SET_REMOTE_ANSWER",
-      function (test) {
-        test.pcLocal._latest_offer.type="answer";
-        test.pcLocal.setRemoteDescriptionAndFail(test.pcLocal._latest_offer,
-          function(err) {
-            is(err.name, "InvalidStateError", "Error is InvalidStateError");
-            test.next();
-          } );
-      }
-    ]]);
+  test.chain.append([
+    function PC_LOCAL_SET_REMOTE_ANSWER(test) {
+      test.pcLocal._latest_offer.type = "answer";
+      test.pcLocal._pc.setRemoteDescription(test.pcLocal._latest_offer)
+        .then(generateErrorCallback('setRemoteDescription should fail'),
+              err =>
+              is(err.name, "InvalidStateError", "Error is InvalidStateError"));
+    }
+  ]);
 
-    test.run();
-  });
+  test.run();
+});
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_setRemoteOfferInHaveLocalOffer.html
+++ b/dom/media/tests/mochitest/test_peerConnection_setRemoteOfferInHaveLocalOffer.html
@@ -12,31 +12,29 @@
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
     bug: "784519",
     title: "setRemoteDescription (offer) in 'have-local-offer'"
   });
 
-  var test;
-  runNetworkTest(function () {
-    test = new PeerConnectionTest();
-    test.setMediaConstraints([{audio: true}], [{audio: true}]);
-    test.chain.removeAfter("PC_LOCAL_SET_LOCAL_DESCRIPTION");
+var test;
+runNetworkTest(function () {
+  test = new PeerConnectionTest();
+  test.setMediaConstraints([{audio: true}], [{audio: true}]);
+  test.chain.removeAfter("PC_LOCAL_SET_LOCAL_DESCRIPTION");
 
-    test.chain.append([[
-      "PC_LOCAL_SET_REMOTE_OFFER",
-      function (test) {
-        test.pcLocal.setRemoteDescriptionAndFail(test.pcLocal._latest_offer,
-          function(err) {
-            is(err.name, "InvalidStateError", "Error is InvalidStateError");
-            test.next();
-          } );
-      }
-    ]]);
+  test.chain.append([
+    function PC_LOCAL_SET_REMOTE_OFFER(test) {
+      test.pcLocal._pc.setRemoteDescription(test.pcLocal._latest_offer)
+        .then(generateErrorCallback('setRemoteDescription should fail'),
+              err =>
+              is(err.name, "InvalidStateError", "Error is InvalidStateError"));
+    }
+  ]);
 
-    test.run();
-  });
+  test.run();
+});
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_syncSetDescription.html
+++ b/dom/media/tests/mochitest/test_peerConnection_syncSetDescription.html
@@ -13,68 +13,46 @@
 <pre id="test">
 <script type="application/javascript;version=1.8">
   createHTML({
     bug: "1063971",
     title: "Legacy sync setDescription calls",
     visible: true
   });
 
-  // Test setDescription without callbacks, which many webrtc examples still do
+// Test setDescription without callbacks, which many webrtc examples still do
 
-  var pc1_local =
-  [[
-    'PC_LOCAL_SET_LOCAL_DESCRIPTION_SYNC',
-    function (test) {
-      test.pcLocal.onsignalingstatechange = function() {};
-      test.pcLocal.setLocalDescription(test.originalOffer);
-      test.next();
-    }
-  ]];
-
-  var pc2_remote =
-  [[
-    'PC_REMOTE_SET_REMOTE_DESCRIPTION_SYNC',
-    function (test) {
-      test.pcRemote.onsignalingstatechange = function() {};
-      test.pcRemote.setRemoteDescription(test._local_offer);
-      test.next();
-    }
-  ]];
+function PC_LOCAL_SET_LOCAL_DESCRIPTION_SYNC(test) {
+  test.pcLocal.onsignalingstatechange = function() {};
+  test.pcLocal._pc.setLocalDescription(test.originalOffer);
+}
 
-  var pc2_local =
-  [[
-    'PC_REMOTE_SET_LOCAL_DESCRIPTION_SYNC',
-    function (test) {
-      test.pcRemote.onsignalingstatechange = function() {};
-      test.pcRemote.setLocalDescription(test.originalAnswer);
-      test.next();
-    }
-  ]];
+function PC_REMOTE_SET_REMOTE_DESCRIPTION_SYNC(test) {
+  test.pcRemote.onsignalingstatechange = function() {};
+  test.pcRemote._pc.setRemoteDescription(test._local_offer);
+}
+function PC_REMOTE_SET_LOCAL_DESCRIPTION_SYNC(test) {
+  test.pcRemote.onsignalingstatechange = function() {};
+  test.pcRemote._pc.setLocalDescription(test.originalAnswer);
+}
+function PC_LOCAL_SET_REMOTE_DESCRIPTION_SYNC(test) {
+  test.pcLocal.onsignalingstatechange = function() {};
+  test.pcLocal._pc.setRemoteDescription(test._remote_answer);
+}
 
-  var pc1_remote =
-  [[
-    'PC_LOCAL_SET_REMOTE_DESCRIPTION_SYNC',
-    function (test) {
-      test.pcLocal.onsignalingstatechange = function() {};
-      test.pcLocal.setRemoteDescription(test._remote_answer);
-      test.next();
-    }
-  ]];
+runNetworkTest(() => {
+  var replace = (test, name, command) => {
+    test.chain.insertAfter(name, command);
+    test.chain.remove(name);
+  }
 
-  runNetworkTest(function () {
-    function replace(test, name, command) {
-      test.chain.insertAfter(name, command);
-      test.chain.remove(name);
-    }
-
-    var test = new PeerConnectionTest();
-    test.setMediaConstraints([{video: true}], [{video: true}]);
-    replace(test, "PC_LOCAL_SET_LOCAL_DESCRIPTION", pc1_local);
-    replace(test, "PC_REMOTE_SET_REMOTE_DESCRIPTION", pc2_remote);
-    replace(test, "PC_REMOTE_SET_LOCAL_DESCRIPTION", pc2_local);
-    replace(test, "PC_LOCAL_SET_REMOTE_DESCRIPTION", pc1_remote);
-    test.run();
-  });
+  var test = new PeerConnectionTest();
+  test.setMediaConstraints([{video: true}], [{video: true}]);
+  test.chain.replace(test, "PC_LOCAL_SET_LOCAL_DESCRIPTION", PC_LOCAL_SET_LOCAL_DESCRIPTION_SYNC);
+  test.chain.replace(test, "PC_REMOTE_SET_REMOTE_DESCRIPTION", PC_REMOTE_SET_REMOTE_DESCRIPTION_SYNC);
+  test.chain.replace(test, "PC_REMOTE_SET_LOCAL_DESCRIPTION", PC_REMOTE_SET_LOCAL_DESCRIPTION_SYNC);
+  test.chain.replace(test, "PC_LOCAL_SET_REMOTE_DESCRIPTION", PC_LOCAL_SET_REMOTE_DESCRIPTION_SYNC);
+  test.run();
+});
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_toJSON.html
+++ b/dom/media/tests/mochitest/test_peerConnection_toJSON.html
@@ -24,19 +24,19 @@ https://bugzilla.mozilla.org/show_bug.cg
 
     var rtcSession = new mozRTCSessionDescription({ sdp: "Picklechips!",
                                                     type: "offer" });
     var jsonCopy = JSON.parse(JSON.stringify(rtcSession));
     for (key in rtcSession) {
       if (typeof(rtcSession[key]) == "function") continue;
       is(rtcSession[key], jsonCopy[key], "key " + key + " should match.");
     }
-  
+
     /** Test for Bug 928304 **/
-  
+
     var rtcIceCandidate = new mozRTCIceCandidate({ candidate: "dummy",
                                                    sdpMid: "test",
                                                    sdpMLineIndex: 3 });
     jsonCopy = JSON.parse(JSON.stringify(rtcIceCandidate));
     for (key in rtcIceCandidate) {
       if (typeof(rtcIceCandidate[key]) == "function") continue;
       is(rtcIceCandidate[key], jsonCopy[key], "key " + key + " should match.");
     }