Bug 1208373 - Test that a peerConnection's received tracks end on close(). r?jib draft
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 12 May 2016 14:30:51 +0200
changeset 376726 4a4c3d223e52922f932e116d1f12fa7fd931366f
parent 376725 081f423177574ecf38af670a25775e3d82549c77
child 376727 5a0e00713d39664af7ca2064e72c4a9c50ed0a4d
push id20652
push userpehrsons@gmail.com
push dateWed, 08 Jun 2016 15:10:47 +0000
reviewersjib
bugs1208373
milestone50.0a1
Bug 1208373 - Test that a peerConnection's received tracks end on close(). r?jib MozReview-Commit-ID: 1iVTt6XBRpZ
dom/media/tests/mochitest/pc.js
--- a/dom/media/tests/mochitest/pc.js
+++ b/dom/media/tests/mochitest/pc.js
@@ -129,23 +129,39 @@ function timerGuard(p, time, message) {
 PeerConnectionTest.prototype.closePC = function() {
   info("Closing peer connections");
 
   var closeIt = pc => {
     if (!pc || pc.signalingState === "closed") {
       return Promise.resolve();
     }
 
-    return new Promise(resolve => {
-      pc.onsignalingstatechange = e => {
-        is(e.target.signalingState, "closed", "signalingState is closed");
-        resolve();
-      };
-      pc.close();
-    });
+    var promise = Promise.all([
+      new Promise(resolve => {
+        pc.onsignalingstatechange = e => {
+          is(e.target.signalingState, "closed", "signalingState is closed");
+          resolve();
+        };
+      }),
+      Promise.all(pc._pc.getReceivers()
+        .filter(receiver => receiver.track.readyState == "live")
+        .map(receiver => {
+          info("Waiting for track " + receiver.track.id + " (" +
+               receiver.track.kind + ") to end.");
+          return haveEvent(receiver.track, "ended", wait(50000))
+            .then(event => {
+              is(event.target, receiver.track, "Event target should be the correct track");
+              info("ended fired for track " + receiver.track.id);
+            }, e => e ? Promise.reject(e)
+                      : ok(false, "ended never fired for track " +
+                                    receiver.track.id));
+        }))
+    ]);
+    pc.close();
+    return promise;
   };
 
   return timerGuard(Promise.all([
     closeIt(this.pcLocal),
     closeIt(this.pcRemote)
   ]), 60000, "failed to close peer connection");
 };
 
@@ -445,29 +461,32 @@ PeerConnectionTest.prototype.updateChain
 
 /**
  * Start running the tests as assigned to the command chain.
  */
 PeerConnectionTest.prototype.run = function() {
   /* We have to modify the chain here to allow tests which modify the default
    * test chain instantiating a PeerConnectionTest() */
   this.updateChainSteps();
+  var finished = () => {
+    if (window.SimpleTest) {
+      networkTestFinished();
+    } else {
+      finish();
+    }
+  };
   return this.chain.execute()
     .then(() => this.close())
-    .then(() => {
-      if (window.SimpleTest) {
-        networkTestFinished();
-      } else {
-        finish();
-      }
-    })
     .catch(e =>
-           ok(false, 'Error in test execution: ' + e +
-              ((typeof e.stack === 'string') ?
-               (' ' + e.stack.split('\n').join(' ... ')) : '')));
+      ok(false, 'Error in test execution: ' + e +
+         ((typeof e.stack === 'string') ?
+          (' ' + e.stack.split('\n').join(' ... ')) : '')))
+    .then(() => finished())
+    .catch(e =>
+      ok(false, "Error in finished()"));
 };
 
 /**
  * Routes ice candidates from one PCW to the other PCW
  */
 PeerConnectionTest.prototype.iceCandidateHandler = function(caller, candidate) {
   info("Received: " + JSON.stringify(candidate) + " from " + caller);