Bug 1208316 - Test active state in MediaStream constructors and clone tests. r=jib

MozReview-Commit-ID: A39coKC0KNc

--HG--
extra : rebase_source : fa8e113892ba96db4e9d15d720a2fc7a5828f084
This commit is contained in:
Andreas Pehrson 2016-11-01 14:11:03 +01:00
Родитель d77d2cc8fc
Коммит 53968f02be
2 изменённых файлов: 45 добавлений и 6 удалений

Просмотреть файл

@ -441,6 +441,8 @@ function checkMediaStreamCloneAgainstOriginal(clone, original) {
"All audio tracks should get cloned");
is(clone.getVideoTracks().length, original.getVideoTracks().length,
"All video tracks should get cloned");
is(clone.active, original.active,
"Active state should be preserved");
original.getTracks()
.forEach(t => ok(!clone.getTrackById(t.id),
"The clone's tracks should be originals"));
@ -457,6 +459,8 @@ function checkMediaStreamTrackCloneAgainstOriginal(clone, original) {
"Track clone's kind should be same as the original's");
is(clone.enabled, original.enabled,
"Track clone's kind should be same as the original's");
is(clone.readyState, original.readyState,
"Track clone's readyState should be same as the original's");
}
/*** Utility methods */

Просмотреть файл

@ -20,64 +20,95 @@
.then(() => videoElement = createMediaElement('video', 'constructorsTest'))
.then(() => getUserMedia({video: true})).then(gUMStream => {
info("Test default constructor with video");
ok(gUMStream.active, "gUMStream with one track should be active");
var track = gUMStream.getTracks()[0];
var stream = new MediaStream();
ok(!stream.active, "New MediaStream should be inactive");
checkMediaStreamContains(stream, [], "Default constructed stream");
stream.addTrack(track);
ok(stream.active, "MediaStream should be active after adding a track");
checkMediaStreamContains(stream, [track], "Added video track");
var playback = new MediaStreamPlayback(videoElement, stream);
return playback.playMedia(false).then(() => gUMStream.stop());
return playback.playMedia(false).then(() => {
ok(!gUMStream.active, "gUMStream should be inactive after stopping");
ok(!stream.active, "stream with stopped tracks should be inactive");
});
})
.then(() => getUserMedia({video: true})).then(gUMStream => {
info("Test copy constructor with gUM stream");
ok(gUMStream.active, "gUMStream with one track should be active");
var track = gUMStream.getTracks()[0];
var stream = new MediaStream(gUMStream);
ok(stream.active, "List constructed MediaStream should be active");
checkMediaStreamContains(stream, [track], "Copy constructed video track");
var playback = new MediaStreamPlayback(videoElement, stream);
return playback.playMedia(false).then(() => gUMStream.stop());
return playback.playMedia(false).then(() => {
ok(!gUMStream.active, "gUMStream should be inactive after stopping");
ok(!stream.active, "stream with stopped tracks should be inactive");
});
})
.then(() => getUserMedia({video: true})).then(gUMStream => {
info("Test list constructor with empty list");
ok(gUMStream.active, "gUMStream with one track should be active");
var track = gUMStream.getTracks()[0];
var stream = new MediaStream([]);
ok(!stream.active, "Empty-list constructed MediaStream should be inactive");
checkMediaStreamContains(stream, [], "Empty-list constructed stream");
stream.addTrack(track);
ok(stream.active, "MediaStream should be active after adding a track");
checkMediaStreamContains(stream, [track], "Added video track");
var playback = new MediaStreamPlayback(videoElement, stream);
return playback.playMedia(false).then(() => gUMStream.stop());
return playback.playMedia(false).then(() => {
ok(!gUMStream.active, "gUMStream should be inactive after stopping");
ok(!stream.active, "stream with stopped tracks should be inactive");
});
})
.then(() => getUserMedia({audio: true, video: true})).then(gUMStream => {
info("Test list constructor with a gUM audio/video stream");
ok(gUMStream.active, "gUMStream with two tracks should be active");
var audioTrack = gUMStream.getAudioTracks()[0];
var videoTrack = gUMStream.getVideoTracks()[0];
var stream = new MediaStream([audioTrack, videoTrack]);
ok(stream.active, "List constructed MediaStream should be active");
checkMediaStreamContains(stream, [audioTrack, videoTrack],
"List constructed audio and video tracks");
var playback = new MediaStreamPlayback(videoElement, stream);
return playback.playMedia(false).then(() => gUMStream.stop());
return playback.playMedia(false).then(() => {
ok(!gUMStream.active, "gUMStream should be inactive after stopping");
ok(!stream.active, "stream with stopped tracks should be inactive");
});
})
.then(() => getUserMedia({video: true})).then(gUMStream => {
info("Test list constructor with gUM-video and WebAudio tracks");
ok(gUMStream.active, "gUMStream with one track should be active");
var audioStream = createOscillatorStream(audioContext, 2000);
ok(audioStream.active, "WebAudio stream should be active");
var audioTrack = audioStream.getTracks()[0];
var videoTrack = gUMStream.getTracks()[0];
var stream = new MediaStream([audioTrack, videoTrack]);
ok(stream.active, "List constructed MediaStream should be active");
checkMediaStreamContains(stream, [audioTrack, videoTrack],
"List constructed WebAudio and gUM-video tracks");
var playback = new MediaStreamPlayback(videoElement, stream);
return playback.playMedia(false).then(() => gUMStream.stop());
// TODO (bug 1301675) When WebAudio tracks support stop(), uncomment:
// var playback = new MediaStreamPlayback(videoElement, stream);
// return playback.playMedia(false).then(() => {
gUMStream.getTracks().forEach(t => t.stop());
ok(!gUMStream.active, "gUMStream should be inactive after stopping");
// ok(!stream.active, "stream with stopped tracks should be inactive");
// });
})
.then(() => {
var osc1k = createOscillatorStream(audioContext, 1000);
@ -101,6 +132,8 @@
}).then(() => {
info("Analysing audio output with copy constructed 5k stream");
var stream = new MediaStream(osc5k);
is(stream.active, osc5k.active,
"Copy constructed MediaStream should preserve active state");
var analyser = new AudioStreamAnalyser(audioContext, stream);
return analyser.waitForAnalysisSuccess(array =>
array[analyser.binIndexForFrequency(1000)] < 50 &&
@ -119,6 +152,8 @@
}).then(() => {
info("Analysing audio output with list constructed 1k, 5k and 10k tracks");
var stream = new MediaStream([audioTrack1k, audioTrack5k, audioTrack10k]);
ok(stream.active,
"List constructed MediaStream from WebAudio should be active");
var analyser = new AudioStreamAnalyser(audioContext, stream);
return analyser.waitForAnalysisSuccess(array =>
array[analyser.binIndexForFrequency(50)] < 50 &&