Bug 917298: Mochitests for testing gum constraints. r=jesup, jsmith

This commit is contained in:
Jan-Ivar Bruaroey 2013-09-18 17:56:29 -04:00
parent a8202c7357
commit 1234350e5d
3 changed files with 107 additions and 1 deletions

View File

@ -23,6 +23,7 @@ MOCHITEST_FILES = \
test_getUserMedia_stopVideoAudioStreamWithFollowupVideoAudio.html \
test_getUserMedia_stopVideoStream.html \
test_getUserMedia_stopVideoAudioStream.html \
test_getUserMedia_constraints.html \
test_peerConnection_basicAudio.html \
test_peerConnection_basicAudioVideo.html \
test_peerConnection_basicAudioVideoCombined.html \

View File

@ -0,0 +1,96 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=882145
-->
<head>
<meta charset="utf-8">
<title>Test mozGetUserMedia Constraints</title>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="head.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=882145">Test mozGetUserMedia Constraints</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/**
Tests covering gUM constraints API for audio, video and fake video. Exercise
successful parsing code and ensure that unknown mandatory constraints and
overconstraining cases produce appropriate errors.
*/
var tests = [
// Each test here tests a different constraint or codepath.
{ message: "unknown mandatory constraint on video fails",
constraints: { video: { mandatory: { somethingUnknown:0 } } },
error: "NOT_SUPPORTED_ERR: somethingUnknown",
pass: false },
{ message: "unknown mandatory constraint on audio fails",
constraints: { audio: { mandatory: { somethingUnknown:0 } } },
error: "NOT_SUPPORTED_ERR: somethingUnknown",
pass: false },
{ message: "video overconstrained by facingMode fails",
constraints: { video: { mandatory: { facingMode:'left' } } },
error: "NO_DEVICES_FOUND",
pass: false },
{ message: "Success-path: optional video facingMode + audio ignoring facingMode",
constraints: { fake: true,
audio: { mandatory: { facingMode:'left' } },
video: { optional: [{ facingMode:'left' },
{ facingMode:'right' },
{ facingMode:'environment' },
{ facingMode:'user' },
{ foo:0 }] } },
error: null,
pass: false },
{ message: null },
];
/**
* Starts the test run by running through each constraint
* test by verifying that the right callback and error message is fired.
*/
runTest(function () {
var i = 0;
next();
function Success() {
info("successcallback");
tests[i].pass = !tests[i].error;
i++;
next();
}
function Failure(err) {
info("errcallback: " + err);
tests[i].pass = tests[i].error? (err === tests[i].error) : false;
i++;
next();
}
function next() {
if (tests[i].message) {
navigator.mozGetUserMedia(tests[i].constraints, Success, Failure);
} else {
finish();
}
}
function finish() {
tests.forEach(function (test) {
if (test.message) {
ok(test.pass, test.message);
} else {
SimpleTest.finish();
}
});
}
});
</script>
</pre>
</body>
</html>

View File

@ -46,7 +46,13 @@ var exceptionTests = [
message: "wrong object type as second parameter" },
{ params: [{video: true, fake: true}, unexpectedCall, 1],
error: "Argument 3 of Navigator.mozGetUserMedia is not an object.",
message: "wrong object type as third parameter" }
message: "wrong object type as third parameter" },
// Each test here verifies constraint syntax as defined in webidl
{ params: [{ fake: true, video: { optional: [{ facingMode:'foo' }] } },
unexpectedCall, unexpectedCall],
error: "'facingMode' member of MediaTrackConstraintSet 'foo' is not a valid value for enumeration VideoFacingModeEnum.",
message: "invalid facingMode enum value" }
];
/**
@ -72,6 +78,9 @@ runTest(function () {
navigator.mozGetUserMedia.apply(navigator, test.params);
} catch (e) {
exception = (e.message === test.error);
if(!exception) {
info(e.message);
}
}
ok(exception, "Exception for " + test.message);
});