Bug 907352 - Part 2: Backwards-compatible facingMode constraint on mobile. r=mt, r=drno

This commit is contained in:
Jan-Ivar Bruaroey 2014-04-18 15:14:23 -04:00
parent 2a3906470e
commit b467511cb3
6 changed files with 167 additions and 88 deletions

View File

@ -1432,6 +1432,30 @@ MediaManager::GetUserMedia(bool aPrivileged,
c.mVideo.SetAsBoolean() = false;
}
#if defined(ANDROID) || defined(MOZ_WIDGET_GONK)
// Be backwards compatible only on mobile and only for facingMode.
if (c.mVideo.IsMediaTrackConstraints()) {
auto& tc = c.mVideo.GetAsMediaTrackConstraints();
if (!tc.mRequire.WasPassed()) {
if (tc.mMandatory.mFacingMode.WasPassed() && !tc.mFacingMode.WasPassed()) {
tc.mFacingMode.Construct(tc.mMandatory.mFacingMode.Value());
tc.mRequire.Construct().AppendElement(NS_LITERAL_STRING("facingMode"));
}
}
if (tc.mOptional.WasPassed() && !tc.mAdvanced.WasPassed()) {
tc.mAdvanced.Construct();
for (uint32_t i = 0; i < tc.mOptional.Value().Length(); i++) {
if (tc.mOptional.Value()[i].mFacingMode.WasPassed()) {
MediaTrackConstraintSet n;
n.mFacingMode.Construct(tc.mOptional.Value()[i].mFacingMode.Value());
tc.mAdvanced.Value().AppendElement(n);
}
}
}
}
#endif
// Pass callbacks and MediaStreamListener along to GetUserMediaRunnable.
nsRefPtr<GetUserMediaRunnable> runnable;
if (c.mFake) {

View File

@ -0,0 +1,82 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
Tests covering gUM constraints API for audio, video and fake video. Exercise
successful parsing code and ensure that unknown required constraints and
overconstraining cases produce appropriate errors.
TODO(jib): Merge desktop and mobile version of these tests again.
*/
var common_tests = [
// Each test here tests a different constraint or codepath.
{ message: "unknown required constraint on video fails",
constraints: { video: { somethingUnknown:0, require:["somethingUnknown"] },
fake: true },
error: "NO_DEVICES_FOUND" },
{ message: "unknown required constraint on audio fails",
constraints: { audio: { somethingUnknown:0, require:["somethingUnknown"] },
fake: true },
error: "NO_DEVICES_FOUND" },
{ message: "missing required constraint on video fails",
constraints: { video: { require:["facingMode"] }, fake: true },
error: "NO_DEVICES_FOUND" },
{ message: "missing required constraint on audio fails",
constraints: { audio: { require:["facingMode"] }, fake: true },
error: "NO_DEVICES_FOUND" },
{ message: "video overconstrained by facingMode fails",
constraints: { video: { facingMode:'left', require:["facingMode"] },
fake: true },
error: "NO_DEVICES_FOUND" },
{ message: "audio overconstrained by facingMode fails",
constraints: { audio: { facingMode:'left', require:["facingMode"] },
fake: true },
error: "NO_DEVICES_FOUND" },
{ message: "Success-path: optional video facingMode + audio ignoring facingMode",
constraints: { fake: true,
audio: { facingMode:'left',
foo:0,
advanced: [{ facingMode:'environment' },
{ facingMode:'user' },
{ bar:0 }] },
video: { // TODO: Bug 767924 sequences in unions
//facingMode:['left', 'right', 'user', 'environment'],
//require:["facingMode"],
facingMode:'left',
foo:0,
advanced: [{ facingMode:'environment' },
{ facingMode:'user' },
{ bar:0 }] } },
error: null }
];
/**
* Starts the test run by running through each constraint
* test by verifying that the right callback and error message is fired.
*/
function testConstraints(tests) {
var i = 0;
next();
function Success() {
ok(!tests[i].error, tests[i].message);
i++;
next();
}
function Failure(err) {
ok(tests[i].error? (err === tests[i].error) : false,
tests[i].message + " (err=" + err + ")");
i++;
next();
}
function next() {
if (i < tests.length) {
navigator.mozGetUserMedia(tests[i].constraints, Success, Failure);
} else {
SimpleTest.finish();
}
}
};

View File

@ -1,6 +1,7 @@
[DEFAULT]
support-files =
head.js
constraints.js
mediaStreamPlayback.js
pc.js
templates.js
@ -25,6 +26,9 @@ skip-if = (toolkit == 'gonk' && debug) #debug-only failure
[test_getUserMedia_basicVideoAudio.html]
skip-if = (toolkit == 'gonk' && debug) #debug-only failure, turned an intermittent (bug 962579) into a permanant orange
[test_getUserMedia_constraints.html]
skip-if = (toolkit=='gonk' || toolkit=='android') # Bug 907352, backwards-compatible behavior on mobile only
[test_getUserMedia_constraints_mobile.html]
skip-if = (toolkit!='gonk' && toolkit!='android') # Bug 907352, backwards-compatible behavior on mobile only
[test_getUserMedia_exceptions.html]
[test_getUserMedia_gumWithinGum.html]
[test_getUserMedia_playAudioTwice.html]

View File

@ -9,9 +9,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=882145
<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>
<script type="application/javascript" src="constraints.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=882145">Test mozGetUserMedia Constraints</a>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=882145">Test mozGetUserMedia Constraints (desktop)</a>
<p id="display"></p>
<div id="content" style="display: none">
@ -19,97 +20,17 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=882145
<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 required constraints and
overconstraining cases produce appropriate errors.
See constraints.js for testConstraints() and common_tests.
TODO(jib): Merge desktop and mobile version of these tests again (Bug 997365)
*/
var tests = [
// Each test here tests a different constraint or codepath.
{ message: "unknown required constraint on video fails",
constraints: { video: { somethingUnknown:0, require:["somethingUnknown"] },
fake: true },
error: "NO_DEVICES_FOUND",
pass: false },
{ message: "unknown required constraint on audio fails",
constraints: { audio: { somethingUnknown:0, require:["somethingUnknown"] },
fake: true },
error: "NO_DEVICES_FOUND",
pass: false },
{ message: "missing required constraint on video fails",
constraints: { video: { require:["facingMode"] }, fake: true },
error: "NO_DEVICES_FOUND",
pass: false },
{ message: "missing required constraint on audio fails",
constraints: { audio: { require:["facingMode"] }, fake: true },
error: "NO_DEVICES_FOUND",
pass: false },
{ message: "video overconstrained by facingMode fails",
constraints: { video: { facingMode:'left', require:["facingMode"] },
fake: true },
error: "NO_DEVICES_FOUND",
pass: false },
{ message: "audio overconstrained by facingMode fails",
constraints: { audio: { facingMode:'left', require:["facingMode"] },
fake: true },
error: "NO_DEVICES_FOUND",
pass: false },
{ message: "Success-path: optional video facingMode + audio ignoring facingMode",
constraints: { fake: true,
audio: { facingMode:'left',
foo:0,
advanced: [{ facingMode:'environment' },
{ facingMode:'user' },
{ bar:0 }] },
video: { // TODO: Bug 767924 sequences in unions
//facingMode:['left', 'right', 'user', 'environment'],
//require:["facingMode"],
facingMode:'left',
foo:0,
advanced: [{ facingMode:'environment' },
{ facingMode:'user' },
{ bar:0 }] } },
error: null,
pass: false },
{ message: null },
var desktop_tests = [
{ message: "legacy facingMode ignored (desktop)",
constraints: { video: { mandatory: { facingMode:'left' } }, fake: true },
error: 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();
}
});
}
testConstraints(common_tests.concat(desktop_tests));
});

View File

@ -0,0 +1,40 @@
<!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>
<script type="application/javascript" src="constraints.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=882145">Test mozGetUserMedia Constraints (mobile)</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/**
See constraints.js for testConstraints() and common_tests.
TODO(jib): Merge desktop and mobile version of these tests again (Bug 997365)
*/
var mobile_tests = [
{ message: "legacy facingMode overconstrains video (mobile)",
constraints: { video: { mandatory: { facingMode:'left' } }, fake: true },
error: "NO_DEVICES_FOUND" },
];
runTest(function () {
testConstraints(common_tests.concat(mobile_tests));
});
</script>
</pre>
</body>
</html>

View File

@ -32,9 +32,17 @@ dictionary MediaTrackConstraintSet {
ConstrainVideoFacingMode facingMode;
};
dictionary MobileLegacyMediaTrackConstraintSet {
VideoFacingModeEnum facingMode;
};
dictionary MediaTrackConstraints : MediaTrackConstraintSet {
sequence<DOMString> require;
sequence<MediaTrackConstraintSet> advanced;
// mobile-only backwards-compatibility for facingMode
MobileLegacyMediaTrackConstraintSet mandatory;
sequence<MobileLegacyMediaTrackConstraintSet> _optional;
};
typedef VideoFacingModeEnum ConstrainVideoFacingMode;