diff --git a/dom/media/tests/mochitest/dataChannel.js b/dom/media/tests/mochitest/dataChannel.js index f34ad89b73da..fc02514698d3 100644 --- a/dom/media/tests/mochitest/dataChannel.js +++ b/dom/media/tests/mochitest/dataChannel.js @@ -184,7 +184,7 @@ var commandsCheckLargeXfer = [ function addInitialDataChannel(chain) { chain.insertBefore('PC_LOCAL_CREATE_OFFER', commandsCreateDataChannel); - chain.insertBefore('PC_LOCAL_CHECK_MEDIA_TRACKS', commandsWaitForDataChannel); + chain.insertBefore('PC_LOCAL_WAIT_FOR_MEDIA_FLOW', commandsWaitForDataChannel); chain.removeAfter('PC_REMOTE_CHECK_ICE_CONNECTIONS'); chain.append(commandsCheckLargeXfer); chain.append(commandsCheckDataChannel); diff --git a/dom/media/tests/mochitest/pc.js b/dom/media/tests/mochitest/pc.js index b9f35f58e792..3ac58155855e 100644 --- a/dom/media/tests/mochitest/pc.js +++ b/dom/media/tests/mochitest/pc.js @@ -409,6 +409,7 @@ function(peer, desc, stateExpected) { var stateChanged = peer.setRemoteDescription(desc).then(() => { peer.setRemoteDescDate = new Date(); + peer.checkMediaTracks(); }); return Promise.all([eventFired, stateChanged]); @@ -1129,28 +1130,24 @@ PeerConnectionWrapper.prototype = { observedTrackInfoById[track.id] = expectedTrackInfoById[track.id]; }, + isTrackOnPC: function(track) { + return this._pc.getRemoteStreams().some(stream => { + return stream.getTracks().some(pcTrack => pcTrack.id == track.id); + }); + }, + allExpectedTracksAreObserved: function(expected, observed) { return Object.keys(expected).every(trackId => observed[trackId]); }, setupTrackEventHandler: function() { - var resolveAllTrackEventsDone; - - // checkMediaTracks waits on this promise later on in the test. - this.allTrackEventsDonePromise = - new Promise(resolve => resolveAllTrackEventsDone = resolve); - this._pc.addEventListener('track', event => { info(this + ": 'ontrack' event fired for " + JSON.stringify(event.track)); this.checkTrackIsExpected(event.track, this.expectedRemoteTrackInfoById, this.observedRemoteTrackInfoById); - - if (this.allExpectedTracksAreObserved(this.expectedRemoteTrackInfoById, - this.observedRemoteTrackInfoById)) { - resolveAllTrackEventsDone(); - } + ok(this.isTrackOnPC(event.track), "Found track " + event.track.id); this.ensureMediaElement(event.track, event.streams[0], 'remote'); }); @@ -1332,9 +1329,6 @@ PeerConnectionWrapper.prototype = { /** * Checks that we are getting the media tracks we expect. - * - * @param {object} constraints - * The media constraints of the remote peer connection object */ checkMediaTracks : function() { this.checkLocalMediaTracks(); @@ -1342,13 +1336,11 @@ PeerConnectionWrapper.prototype = { info(this + " Checking remote tracks " + JSON.stringify(this.expectedRemoteTrackInfoById)); - // No tracks are expected - if (this.allExpectedTracksAreObserved(this.expectedRemoteTrackInfoById, - this.observedRemoteTrackInfoById)) { - return; - } - - return timerGuard(this.allTrackEventsDonePromise, 60000, "The expected ontrack events never fired"); + ok(this.allExpectedTracksAreObserved(this.expectedRemoteTrackInfoById, + this.observedRemoteTrackInfoById), + "All expected tracks have been observed" + + "\nexpected: " + JSON.stringify(this.expectedRemoteTrackInfoById) + + "\nobserved: " + JSON.stringify(this.observedRemoteTrackInfoById)); }, checkMsids: function() { @@ -1374,7 +1366,11 @@ PeerConnectionWrapper.prototype = { rollbackRemoteTracksIfNotNegotiated: function() { Object.keys(this.observedRemoteTrackInfoById).forEach( - id => delete this.observedRemoteTrackInfoById[id]); + id => { + if (!this.observedRemoteTrackInfoById[id].negotiated) { + delete this.observedRemoteTrackInfoById[id]; + } + }); }, /** diff --git a/dom/media/tests/mochitest/templates.js b/dom/media/tests/mochitest/templates.js index f60963ab81a0..fd7d0715ed12 100644 --- a/dom/media/tests/mochitest/templates.js +++ b/dom/media/tests/mochitest/templates.js @@ -379,6 +379,7 @@ var commandsPeerConnectionOfferAnswer = [ }) .then(() => test.pcLocal.markRemoteTracksAsNegotiated()); }, + function PC_REMOTE_SANE_LOCAL_SDP(test) { test.pcRemote.localRequiresTrickleIce = sdputils.verifySdp(test._remote_answer, "answer", @@ -413,14 +414,6 @@ var commandsPeerConnectionOfferAnswer = [ return waitForAnIceCandidate(test.pcRemote); }, - function PC_LOCAL_CHECK_MEDIA_TRACKS(test) { - return test.pcLocal.checkMediaTracks(); - }, - - function PC_REMOTE_CHECK_MEDIA_TRACKS(test) { - return test.pcRemote.checkMediaTracks(); - }, - function PC_LOCAL_WAIT_FOR_MEDIA_FLOW(test) { return test.pcLocal.waitForMediaFlow(); }, diff --git a/dom/media/tests/mochitest/test_peerConnection_addDataChannel.html b/dom/media/tests/mochitest/test_peerConnection_addDataChannel.html index cde653eb5dca..366e8fe413a7 100644 --- a/dom/media/tests/mochitest/test_peerConnection_addDataChannel.html +++ b/dom/media/tests/mochitest/test_peerConnection_addDataChannel.html @@ -18,8 +18,8 @@ commandsCreateDataChannel, commandsCheckDataChannel); - // Insert before the second PC_LOCAL_CHECK_MEDIA_TRACKS - test.chain.insertBefore('PC_LOCAL_CHECK_MEDIA_TRACKS', + // Insert before the second PC_LOCAL_WAIT_FOR_MEDIA_FLOW + test.chain.insertBefore('PC_LOCAL_WAIT_FOR_MEDIA_FLOW', commandsWaitForDataChannel, false, 1); diff --git a/dom/media/tests/mochitest/test_peerConnection_addDataChannelNoBundle.html b/dom/media/tests/mochitest/test_peerConnection_addDataChannelNoBundle.html index 5182aa56495d..70369ebdcd7b 100644 --- a/dom/media/tests/mochitest/test_peerConnection_addDataChannelNoBundle.html +++ b/dom/media/tests/mochitest/test_peerConnection_addDataChannelNoBundle.html @@ -29,8 +29,8 @@ ), commandsCheckDataChannel); - // Insert before the second PC_LOCAL_CHECK_MEDIA_TRACKS - test.chain.insertBefore('PC_LOCAL_CHECK_MEDIA_TRACKS', + // Insert before the second PC_LOCAL_WAIT_FOR_MEDIA_FLOW + test.chain.insertBefore('PC_LOCAL_WAIT_FOR_MEDIA_FLOW', commandsWaitForDataChannel, false, 1);