Bug 866514 - Basic gUM mochitests for media stream tracks. r=roc

This commit is contained in:
Jason Smith 2013-05-05 19:48:37 -07:00
parent c67430662e
commit 14acd9b57d
4 changed files with 50 additions and 6 deletions

View File

@ -127,6 +127,44 @@ function runTest(aCallback) {
});
}
/**
* Checks that the media stream tracks have the expected amount of tracks
* with the correct kind and id based on the type and constraints given.
*
* @param {Object} constraints specifies whether the stream should have
* audio, video, or both
* @param {String} type the type of media stream tracks being checked
* @param {sequence<MediaStreamTrack>} mediaStreamTracks the media stream
* tracks being checked
*/
function checkMediaStreamTracksByType(constraints, type, mediaStreamTracks) {
if(constraints[type]) {
is(mediaStreamTracks.length, 1, 'One ' + type + ' track shall be present');
if(mediaStreamTracks.length) {
is(mediaStreamTracks[0].kind, type, 'Track kind should be ' + type);
ok(mediaStreamTracks[0].id, 'Track id should be defined');
}
} else {
is(mediaStreamTracks.length, 0, 'No ' + type + ' tracks shall be present');
}
}
/**
* Check that the given media stream contains the expected media stream
* tracks given the associated audio & video constraints provided.
*
* @param {Object} constraints specifies whether the stream should have
* audio, video, or both
* @param {MediaStream} mediaStream the media stream being checked
*/
function checkMediaStreamTracks(constraints, mediaStream) {
checkMediaStreamTracksByType(constraints, 'audio',
mediaStream.getAudioTracks());
checkMediaStreamTracksByType(constraints, 'video',
mediaStream.getVideoTracks());
}
/**
* Generates a callback function fired only under unexpected circumstances
* while running the tests. The generated function kills off the test as well

View File

@ -25,10 +25,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=781534
*/
runTest(function () {
var testAudio = document.getElementById('testAudio');
var constraints = {audio: true};
getUserMedia(constraints, function (aStream) {
checkMediaStreamTracks(constraints, aStream);
getUserMedia({audio: true}, function (aStream) {
var playback = new LocalMediaStreamPlayback(testAudio, aStream);
playback.playMedia(false, function () {
aStream.stop();
SimpleTest.finish();

View File

@ -25,10 +25,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=781534
*/
runTest(function () {
var testVideo = document.getElementById('testVideo');
var constraints = {video: true};
getUserMedia(constraints, function (aStream) {
checkMediaStreamTracks(constraints, aStream);
getUserMedia({video: true}, function (aStream) {
var playback = new LocalMediaStreamPlayback(testVideo, aStream);
playback.playMedia(false, function () {
aStream.stop();
SimpleTest.finish();

View File

@ -25,10 +25,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=781534
*/
runTest(function () {
var testVideoAudio = document.getElementById('testVideoAudio');
var constraints = {video: true, audio: true};
getUserMedia(constraints, function (aStream) {
checkMediaStreamTracks(constraints, aStream);
getUserMedia({video: true, audio: true}, function (aStream) {
var playback = new LocalMediaStreamPlayback(testVideoAudio, aStream);
playback.playMedia(false, function () {
aStream.stop();
SimpleTest.finish();