Update web-platform-tests to revision 14cfa4d648cc1c853b4153268df672d21425f8c1

This commit is contained in:
Josh Matthews 2017-10-30 09:31:22 -04:00
parent 1b73cf3352
commit 75736751d9
1213 changed files with 19434 additions and 12344 deletions

View file

@ -394,3 +394,54 @@ function getTrackFromUserMedia(kind) {
return [track, mediaStream];
});
}
// Obtain |count| MediaStreamTracks of type |kind| and MediaStreams. The tracks
// do not belong to any stream and the streams are empty. Returns a Promise
// resolved with a pair of arrays [tracks, streams].
// Assumes there is at least one available device to generate the tracks and
// streams and that the getUserMedia() calls resolve.
function getUserMediaTracksAndStreams(count, type = 'audio') {
let otherTracksPromise;
if (count > 1)
otherTracksPromise = getUserMediaTracksAndStreams(count - 1, type);
else
otherTracksPromise = Promise.resolve([[], []]);
return otherTracksPromise.then(([tracks, streams]) => {
return getTrackFromUserMedia(type)
.then(([track, stream]) => {
// Remove the default stream-track relationship.
stream.removeTrack(track);
tracks.push(track);
streams.push(stream);
return [tracks, streams];
});
});
}
// Creates an offer for the caller, set it as the caller's local description and
// then sets the callee's remote description to the offer. Returns the Promise
// of the setRemoteDescription call.
function performOffer(caller, callee) {
let sessionDescription;
return caller.createOffer()
.then(offer => {
sessionDescription = offer;
return caller.setLocalDescription(offer);
}).then(() => callee.setRemoteDescription(sessionDescription));
}
// The resolver has a |promise| that can be resolved or rejected using |resolve|
// or |reject|.
class Resolver {
constructor() {
let promiseResolve;
let promiseReject;
this.promise = new Promise(function(resolve, reject) {
promiseResolve = resolve;
promiseReject = reject;
});
this.resolve = promiseResolve;
this.reject = promiseReject;
}
}

View file

@ -11,7 +11,6 @@
// https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html
// The following helper functions are called from RTCPeerConnection-helper.js:
// generateOffer()
// assert_session_desc_equals()
// test_state_change_event()
@ -50,41 +49,78 @@
- If description is of type "offer", set connection.pendingRemoteDescription
attribute to description and signaling state to have-remote-offer.
*/
promise_test(t => {
const pc = new RTCPeerConnection();
const pc1 = new RTCPeerConnection();
pc1.createDataChannel('datachannel');
test_state_change_event(t, pc, ['have-remote-offer']);
const pc2 = new RTCPeerConnection();
return generateOffer({ pc, data: true })
.then(offer =>
pc.setRemoteDescription(offer)
test_state_change_event(t, pc2, ['have-remote-offer']);
return pc1.createOffer()
.then(offer => {
return pc2.setRemoteDescription(offer)
.then(() => {
assert_equals(pc.signalingState, 'have-remote-offer');
assert_session_desc_equals(pc.remoteDescription, offer);
assert_session_desc_equals(pc.pendingRemoteDescription, offer);
assert_equals(pc.currentRemoteDescription, null);
}));
}, 'setRemoteDescription with valid offer should succeed');
assert_equals(pc2.signalingState, 'have-remote-offer');
assert_session_desc_equals(pc2.remoteDescription, offer);
assert_session_desc_equals(pc2.pendingRemoteDescription, offer);
assert_equals(pc2.currentRemoteDescription, null);
});
});
}, 'setRemoteDescription with valid offer should succeed');
promise_test(t => {
const pc = new RTCPeerConnection();
const pc1 = new RTCPeerConnection();
pc1.createDataChannel('datachannel');
const pc2 = new RTCPeerConnection();
// have-remote-offer event should only fire once
test_state_change_event(t, pc, ['have-remote-offer']);
test_state_change_event(t, pc2, ['have-remote-offer']);
return Promise.all([
pc.createOffer({ offerToReceiveAudio: true }),
generateOffer({ pc, data: true })
]).then(([offer1, offer2]) =>
pc.setRemoteDescription(offer1)
.then(() => pc.setRemoteDescription(offer2))
return pc1.createOffer()
.then(offer => {
return pc2.setRemoteDescription(offer)
.then(() => pc2.setRemoteDescription(offer))
.then(() => {
assert_equals(pc.signalingState, 'have-remote-offer');
assert_session_desc_equals(pc.remoteDescription, offer2);
assert_session_desc_equals(pc.pendingRemoteDescription, offer2);
assert_equals(pc.currentRemoteDescription, null);
}));
}, 'Setting remote description multiple times with different offer should succeed');
assert_equals(pc2.signalingState, 'have-remote-offer');
assert_session_desc_equals(pc2.remoteDescription, offer);
assert_session_desc_equals(pc2.pendingRemoteDescription, offer);
assert_equals(pc2.currentRemoteDescription, null);
});
});
}, 'setRemoteDescription multiple times should succeed');
promise_test(t => {
const pc1 = new RTCPeerConnection();
pc1.createDataChannel('datachannel');
const pc2 = new RTCPeerConnection();
// have-remote-offer event should only fire once
test_state_change_event(t, pc2, ['have-remote-offer']);
return pc1.createOffer()
.then(offer1 => {
return pc1.setLocalDescription(offer1)
.then(()=> {
return pc1.createOffer({ offerToReceiveAudio: true })
.then(offer2 => {
assert_session_desc_not_equals(offer1, offer2);
return pc2.setRemoteDescription(offer1)
.then(() => pc2.setRemoteDescription(offer2))
.then(() => {
assert_equals(pc2.signalingState, 'have-remote-offer');
assert_session_desc_equals(pc2.remoteDescription, offer2);
assert_session_desc_equals(pc2.pendingRemoteDescription, offer2);
assert_equals(pc2.currentRemoteDescription, null);
});
});
});
});
}, 'setRemoteDescription multiple times with different offer should succeed');
/*
4.3.1.6. Set the RTCSessionSessionDescription
@ -123,13 +159,14 @@
*/
promise_test(t => {
const pc = new RTCPeerConnection();
return pc.createOffer()
.then(offer => pc.setLocalDescription(offer))
.then(() => pc.createOffer())
.then(offer2 =>
promise_rejects(t, 'InvalidStateError',
pc.setRemoteDescription(offer2)));
}, 'Calling setRemoteDescription(offer) from have-local-offer state should reject with InvalidStateError');
.then(offer => {
return pc.setLocalDescription(offer)
.then(() => {
return promise_rejects(t, 'InvalidStateError',
pc.setRemoteDescription(offer));
});
});
}, 'setRemoteDescription(offer) from have-local-offer state should reject with InvalidStateError');
</script>

View file

@ -0,0 +1,222 @@
<!doctype html>
<meta charset=utf-8>
<title>RTCPeerConnection.prototype.setRemoteDescription - add/remove remote tracks</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCPeerConnection-helper.js"></script>
<script>
'use strict';
// Test is based on the following editor draft:
// https://w3c.github.io/webrtc-pc/archives/20171002/webrtc.html
// The following helper functions are called from RTCPeerConnection-helper.js:
// getUserMediaTracksAndStreams
// performOffer
// Resolver
// These tests are concerned with the observable consequences of processing
// the addition or removal of remote tracks, including events firing and the
// states of RTCPeerConnection, MediaStream and MediaStreamTrack.
async_test(t => {
const caller = new RTCPeerConnection();
const callee = new RTCPeerConnection();
return getUserMediaTracksAndStreams(1)
.then(t.step_func(([tracks, streams]) => {
let localTrack = tracks[0];
caller.addTrack(localTrack);
let offerPromise = performOffer(caller, callee);
callee.ontrack = t.step_func(trackEvent => {
let remoteTrack = trackEvent.track;
assert_equals(remoteTrack.id, localTrack.id,
'Expected local and remote track IDs to match.');
assert_equals(trackEvent.streams.length, 0,
'Expected remote track not to belong to a stream.');
t.done();
});
return offerPromise;
}))
.catch(t.step_func(reason => {
assert_unreached(reason);
}));
}, 'addTrack with a track and no stream makes ontrack fire with a track and no stream.');
async_test(t => {
const caller = new RTCPeerConnection();
const callee = new RTCPeerConnection();
return getUserMediaTracksAndStreams(1)
.then(t.step_func(([tracks, streams]) => {
let localTrack = tracks[0];
let localStream = streams[0];
caller.addTrack(localTrack, localStream);
let offerPromise = performOffer(caller, callee);
callee.ontrack = t.step_func(trackEvent => {
assert_equals(trackEvent.streams.length, 1,
'Expected track event to fire with a single stream.');
let remoteTrack = trackEvent.track;
let remoteStream = trackEvent.streams[0];
assert_equals(remoteTrack.id, localTrack.id,
'Expected local and remote track IDs to match.');
assert_equals(remoteStream.id, localStream.id,
'Expected local and remote stream IDs to match.');
assert_array_equals(remoteStream.getTracks(), [remoteTrack],
'Expected the remote stream\'s tracks to be the remote track.');
t.done();
});
return offerPromise;
}))
.catch(t.step_func(reason => {
assert_unreached(reason);
}));
}, 'addTrack with a track and a stream makes ontrack fire with a track and a stream.');
async_test(t => {
const caller = new RTCPeerConnection();
const callee = new RTCPeerConnection();
return getUserMediaTracksAndStreams(2)
.then(t.step_func(([tracks, streams]) => {
let localTrack1 = tracks[0];
let localTrack2 = tracks[1];
let localStream = streams[0];
caller.addTrack(localTrack1, localStream);
caller.addTrack(localTrack2, localStream);
let offerPromise = performOffer(caller, callee);
callee.ontrack = t.step_func(trackEvent => {
assert_equals(trackEvent.streams.length, 1,
'Expected track event to fire with a single stream.');
let remoteTrack1 = trackEvent.track;
let remoteStream = trackEvent.streams[0];
assert_equals(remoteTrack1.id, localTrack1.id,
'Expected first remote track ID to match first local track ID.');
assert_equals(remoteStream.getTracks().length, 2,
'Expected the remote stream to contain two tracks.');
callee.ontrack = t.step_func(trackEvent => {
assert_equals(trackEvent.streams.length, 1,
'Expected track event to fire with a single stream.');
let remoteTrack2 = trackEvent.track;
assert_equals(trackEvent.streams[0], remoteStream,
'Expected both track events to fire with the same remote stream.');
assert_equals(remoteTrack2.id, localTrack2.id,
'Expected second remote track ID to match second local track ID.');
assert_equals(remoteStream.getTracks().length, 2,
'Expected the remote stream to contain two tracks.');
assert_array_equals(remoteStream.getTracks(), [remoteTrack1, remoteTrack2],
'Expected the remote stream\'s tracks to be the [first, second] remote tracks.');
t.done();
});
});
return offerPromise;
}))
.catch(t.step_func(reason => {
assert_unreached(reason);
}));
}, 'addTrack with two tracks and one stream makes ontrack fire twice with the tracks and shared stream.');
async_test(t => {
const caller = new RTCPeerConnection();
const callee = new RTCPeerConnection();
return getUserMediaTracksAndStreams(2)
.then(t.step_func(([tracks, streams]) => {
let localTrack = tracks[0];
let localStreams = streams;
caller.addTrack(localTrack, localStreams[0], localStreams[1]);
let performOffer = performOffer(caller, callee);
callee.ontrack = t.step_func(trackEvent => {
assert_equals(trackEvent.streams.length, 2,
'Expected the track event to fire with two streams.');
let remoteTrack = trackEvent.track;
let remoteStreams = trackEvent.streams;
assert_equals(remoteTrack.id, localTrack.id,
'Expected local and remote track IDs to match.');
assert_equals(remoteStreams[0].id, localStreams[0].id,
'Expected the first remote stream ID to match the first local stream ID.');
assert_equals(remoteStreams[1].id, localStreams[1].id,
'Expected the second remote stream ID to match the second local stream ID.');
assert_array_equals(remoteStreams[0].getTracks(), [remoteTrack],
'Expected the remote stream\'s tracks to be the remote track.');
assert_array_equals(remoteStreams[1].getTracks(), [remoteTrack],
'Expected the remote stream\'s tracks to be the remote track.');
t.done();
});
return performOffer;
}))
.catch(t.step_func(reason => {
assert_unreached(reason);
}));
}, 'addTrack with a track and two streams makes ontrack fire with a track and two streams.');
async_test(t => {
const caller = new RTCPeerConnection();
const callee = new RTCPeerConnection();
let eventSequence = '';
return getUserMediaTracksAndStreams(1)
.then(t.step_func(([tracks, streams]) => {
caller.addTrack(tracks[0]);
let ontrackResolver = new Resolver();
callee.ontrack = () => {
eventSequence += 'ontrack;';
ontrackResolver.resolve();
}
return Promise.all([
ontrackResolver.promise,
performOffer(caller, callee).then(() => {
eventSequence += 'setRemoteDescription;';
})
]);
}))
.then(t.step_func(() => {
assert_equals(eventSequence, 'ontrack;setRemoteDescription;');
t.done();
}))
.catch(t.step_func(reason => {
assert_unreached(reason);
}));
}, 'ontrack fires before setRemoteDescription resolves.');
async_test(t => {
const caller = new RTCPeerConnection();
const callee = new RTCPeerConnection();
return getUserMediaTracksAndStreams(1)
.then(t.step_func(([tracks, streams]) => {
caller.addTrack(tracks[0]);
let offerPromise = performOffer(caller, callee);
callee.ontrack = t.step_func(trackEvent => {
assert_array_equals(callee.getReceivers(), [trackEvent.receiver]);
t.done();
});
return offerPromise;
}))
.catch(t.step_func(reason => {
assert_unreached(reason);
}));
}, 'ontrack\'s receiver matches getReceivers().');
async_test(t => {
const caller = new RTCPeerConnection();
const callee = new RTCPeerConnection();
return getUserMediaTracksAndStreams(1)
.then(t.step_func(([tracks, streams]) => {
let sender = caller.addTrack(tracks[0]);
assert_true(sender != null);
let offerPromise = performOffer(caller, callee);
callee.ontrack = t.step_func(trackEvent => {
let receivers = callee.getReceivers();
assert_equals(receivers.length, 1,
'Expected getReceivers() to be the track event\'s receiver.');
caller.removeTrack(sender);
performOffer(caller, callee)
.then(t.step_func(() => {
assert_array_equals(callee.getReceivers(), receivers,
'Expected the set of receivers to remain the same.');
t.done();
}));
});
return offerPromise;
}))
.catch(t.step_func(reason => {
assert_unreached(reason);
}));
}, 'removeTrack does not remove the receiver.');
</script>

View file

@ -68,11 +68,14 @@ This test uses data only, and thus does not require fake media devices.
}
showStats.innerHTML = JSON.stringify(reportDictionary, null, 2);
// Check the stats properties.
assert_not_equals(report, null);
assert_not_equals(report, null, 'No report');
let sessionStat = getStatsRecordByType(report, 'peer-connection');
assert_not_equals(sessionStat, null, 'Did not find peer-connection stats');
assert_exists(sessionStat, 'dataChannelsOpened');
assert_equals(sessionStat.dataChannelsOpened, 1);
assert_exists(sessionStat, 'dataChannelsOpened', 'no dataChannelsOpened stat');
// Once every 4000 or so tests, the datachannel won't be opened when the getStats
// function is done, so allow both 0 and 1 datachannels.
assert_true(sessionStat.dataChannelsOpened == 1 || sessionStat.dataChannelsOpened == 0,
'dataChannelsOpened count wrong');
test.done();
})
.catch(test.step_func(function(e) {
@ -93,7 +96,6 @@ This test uses data only, and thus does not require fake media devices.
// The createDataChannel is necessary and sufficient to make
// sure the ICE connection be attempted.
gFirstConnection.createDataChannel('channel');
var atStep = 'Create offer';
gFirstConnection.createOffer()