Bug 1033885 - tests for mediaDevices.getUserMedia. r=drno

This commit is contained in:
Jan-Ivar Bruaroey 2014-10-27 15:48:37 -04:00
parent 94d8f2565d
commit 974c22c19d
3 changed files with 39 additions and 40 deletions

View File

@ -48,29 +48,27 @@ var common_tests = [
/**
* Starts the test run by running through each constraint
* test by verifying that the right callback and error message is fired.
* test by verifying that the right resolution and rejection is fired.
*/
function testConstraints(tests) {
var i = 0;
next();
function testgum(p, test) {
return p.then(function() {
return navigator.mediaDevices.getUserMedia(test.constraints);
})
.then(function() {
is(null, test.error, test.message);
}, function(reason) {
is(reason.name, test.error, test.message + ": " + reason.message);
});
}
function Success() {
ok(!tests[i].error, tests[i].message);
i++;
next();
}
function Failure(err) {
ok(tests[i].error? (err.name == tests[i].error) : false,
tests[i].message + " (err=" + err.name + ")");
i++;
next();
}
function next() {
if (i < tests.length) {
navigator.mozGetUserMedia(tests[i].constraints, Success, Failure);
} else {
SimpleTest.finish();
}
}
};
var p = new Promise(function(resolve) { resolve(); });
tests.forEach(function(test) {
p = testgum(p, test);
});
p.catch(function(reason) {
ok(false, "Unexpected failure: " + reason.message);
})
.then(SimpleTest.finish);
}

View File

@ -26,7 +26,7 @@ function theTest() {
config.peerIdentity = 'user@example.com';
}
info('getting media with constraints: ' + JSON.stringify(config));
navigator.mozGetUserMedia(config, function(stream) {
navigator.mediaDevices.getUserMedia(config).then(function(stream) {
var oneDone = false;
function checkDone() {
if (oneDone) {
@ -38,7 +38,8 @@ function theTest() {
var cancelVideoCheck = videoIsBlack(withConstraint, stream, checkDone);
setTimeout(cancelAudioCheck, 3*60*1000);
setTimeout(cancelVideoCheck, 3*60*1000);
}, function(e) {
})
.catch(function(e) {
ok(false, 'gUM error: ' + e);
});
};

View File

@ -37,23 +37,23 @@
var track = stream.getVideoTracks()[0];
var sender = test.pcLocal._pc.getSenders().find(isSenderOfTrack, track);
ok(sender, "track has a sender");
navigator.mozGetUserMedia({video:true, fake: true}, function(newStream) {
navigator.mediaDevices.getUserMedia({video:true, fake: true})
.then(function(newStream) {
var newtrack = newStream.getVideoTracks()[0];
sender.replaceTrack(newtrack,
function() {
ok(true, "replaceTrack success callback is called");
is(sender.track, newtrack, "sender.track has been replaced");
test.next();
},
function(err) {
ok(false, "replaceTrack failed with error = " + err);
test.next();
});
},
function(err) {
ok(false, "mozGetUserMedia failed. error = " + err);
test.next();
});
return new Promise(function(resolve, reject) {
sender.replaceTrack(newtrack, function() {
resolve(newtrack);
}, reject);
});
})
.then(function(newtrack) {
ok(true, "replaceTrack success callback is called");
is(sender.track, newtrack, "sender.track has been replaced");
})
.catch(function(reason) {
ok(false, "unexpected error = " + reason.message);
})
.then(test.next.bind(test));
}
]]);
test.chain.append(flowtest);