Bug 1019579: Check remote tracks immediately on SRD success. r=drno
MozReview-Commit-ID: B1gL2RJSszN
--- a/dom/media/tests/mochitest/dataChannel.js
+++ b/dom/media/tests/mochitest/dataChannel.js
@@ -179,13 +179,13 @@ var commandsCheckLargeXfer = [
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.insertBefore('PC_LOCAL_WAIT_FOR_MEDIA_FLOW', 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
@@ -404,16 +404,17 @@ function(peer, desc, stateExpected) {
"mismatch between event received " + state +
" and event expected " + stateExpected);
}
};
});
var stateChanged = peer.setRemoteDescription(desc).then(() => {
peer.setRemoteDescDate = new Date();
+ peer.checkMediaTracks();
});
return Promise.all([eventFired, stateChanged]);
};
/**
* Adds and removes steps to/from the execution chain based on the configured
* testOptions.
@@ -1124,38 +1125,34 @@ PeerConnectionWrapper.prototype = {
var observedKind = track.kind;
var expectedKind = expectedTrackInfoById[track.id].type;
is(observedKind, expectedKind,
"track id " + track.id + " was of kind " +
observedKind + ", which matches " + expectedKind);
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');
});
},
/**
* Either adds a given ICE candidate right away or stores it to be added
* later, depending on the state of the PeerConnection.
@@ -1327,33 +1324,28 @@ PeerConnectionWrapper.prototype = {
});
Object.keys(this.expectedLocalTrackInfoById).forEach(
id => ok(observed[id], this + " local id " + id + " was observed"));
},
/**
* 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();
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() {
var checkSdpForMsids = (desc, expectedTrackInfo, side) => {
Object.keys(expectedTrackInfo).forEach(trackId => {
var streamId = expectedTrackInfo[trackId].streamId;
ok(desc.sdp.match(new RegExp("a=msid:" + streamId + " " + trackId)),
this + ": " + side + " SDP contains stream " + streamId +
@@ -1369,17 +1361,21 @@ PeerConnectionWrapper.prototype = {
markRemoteTracksAsNegotiated: function() {
Object.values(this.observedRemoteTrackInfoById).forEach(
trackInfo => trackInfo.negotiated = true);
},
rollbackRemoteTracksIfNotNegotiated: function() {
Object.keys(this.observedRemoteTrackInfoById).forEach(
- id => delete this.observedRemoteTrackInfoById[id]);
+ id => {
+ if (!this.observedRemoteTrackInfoById[id].negotiated) {
+ delete this.observedRemoteTrackInfoById[id];
+ }
+ });
},
/**
* Check that media flow is present on the given media element by waiting for
* it to reach ready state HAVE_ENOUGH_DATA and progress time further than
* the start of the check.
*
* This ensures, that the stream being played is producing
--- a/dom/media/tests/mochitest/templates.js
+++ b/dom/media/tests/mochitest/templates.js
@@ -374,16 +374,17 @@ var commandsPeerConnectionOfferAnswer =
function PC_LOCAL_SET_REMOTE_DESCRIPTION(test) {
return test.setRemoteDescription(test.pcLocal, test._remote_answer, STABLE)
.then(() => {
is(test.pcLocal.signalingState, STABLE,
"signalingState after local setRemoteDescription is 'stable'");
})
.then(() => test.pcLocal.markRemoteTracksAsNegotiated());
},
+
function PC_REMOTE_SANE_LOCAL_SDP(test) {
test.pcRemote.localRequiresTrickleIce =
sdputils.verifySdp(test._remote_answer, "answer",
test._offer_constraints, test._offer_options,
test.testOptions);
},
function PC_LOCAL_SANE_REMOTE_SDP(test) {
test.pcLocal.remoteRequiresTrickleIce =
@@ -408,24 +409,16 @@ var commandsPeerConnectionOfferAnswer =
function PC_LOCAL_VERIFY_ICE_GATHERING(test) {
return waitForAnIceCandidate(test.pcLocal);
},
function PC_REMOTE_VERIFY_ICE_GATHERING(test) {
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();
},
function PC_REMOTE_WAIT_FOR_MEDIA_FLOW(test) {
return test.pcRemote.waitForMediaFlow();
},
--- a/dom/media/tests/mochitest/test_peerConnection_addDataChannel.html
+++ b/dom/media/tests/mochitest/test_peerConnection_addDataChannel.html
@@ -13,18 +13,18 @@
var test;
runNetworkTest(function (options) {
test = new PeerConnectionTest(options);
addRenegotiation(test.chain,
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);
test.setMediaConstraints([{audio: true}], [{audio: true}]);
test.run();
});
--- a/dom/media/tests/mochitest/test_peerConnection_addDataChannelNoBundle.html
+++ b/dom/media/tests/mochitest/test_peerConnection_addDataChannelNoBundle.html
@@ -24,18 +24,18 @@
},
function PC_REMOTE_EXPECT_ICE_CHECKING(test) {
test.pcRemote.iceCheckingRestartExpected = true;
},
]
),
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);
test.setMediaConstraints([{audio: true}], [{audio: true}]);
test.run();
});