From febff8480f15777c0ee429103488699e97ad8787 Mon Sep 17 00:00:00 2001 From: Jan-Ivar Bruaroey Date: Thu, 17 Apr 2014 12:37:13 -0400 Subject: [PATCH] Bug 907352 - Part 2: Backwards-compatible facingMode constraint on mobile. r=mt, r=drno --- dom/media/MediaManager.cpp | 24 +++++ dom/media/tests/mochitest/constraints.js | 78 ++++++++++++++++ dom/media/tests/mochitest/mochitest.ini | 4 + .../test_getUserMedia_constraints.html | 93 ++----------------- .../test_getUserMedia_constraints_mobile.html | 40 ++++++++ dom/webidl/MediaStreamTrack.webidl | 8 ++ 6 files changed, 163 insertions(+), 84 deletions(-) create mode 100644 dom/media/tests/mochitest/constraints.js create mode 100644 dom/media/tests/mochitest/test_getUserMedia_constraints_mobile.html diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index de29d7a7baca..266e753bafc8 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -1424,6 +1424,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 runnable; if (c.mFake) { diff --git a/dom/media/tests/mochitest/constraints.js b/dom/media/tests/mochitest/constraints.js new file mode 100644 index 000000000000..465996103755 --- /dev/null +++ b/dom/media/tests/mochitest/constraints.js @@ -0,0 +1,78 @@ +/* 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"] } }, + error: "NO_DEVICES_FOUND" }, + { message: "unknown required constraint on audio fails", + constraints: { audio: { somethingUnknown:0, require:["somethingUnknown"] } }, + error: "NO_DEVICES_FOUND" }, + { message: "missing required constraint on video fails", + constraints: { video: { require:["facingMode"] } }, + error: "NO_DEVICES_FOUND" }, + { message: "missing required constraint on audio fails", + constraints: { audio: { require:["facingMode"] } }, + error: "NO_DEVICES_FOUND" }, + { message: "video overconstrained by facingMode fails", + constraints: { video: { facingMode:'left', require:["facingMode"] } }, + error: "NO_DEVICES_FOUND" }, + { message: "audio overconstrained by facingMode fails", + constraints: { audio: { facingMode:'left', require:["facingMode"] } }, + 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(); + } + } +}; diff --git a/dom/media/tests/mochitest/mochitest.ini b/dom/media/tests/mochitest/mochitest.ini index 35e1a1f1d9ce..809191843682 100644 --- a/dom/media/tests/mochitest/mochitest.ini +++ b/dom/media/tests/mochitest/mochitest.ini @@ -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] diff --git a/dom/media/tests/mochitest/test_getUserMedia_constraints.html b/dom/media/tests/mochitest/test_getUserMedia_constraints.html index e76acd6206d6..2461e4ba7afd 100644 --- a/dom/media/tests/mochitest/test_getUserMedia_constraints.html +++ b/dom/media/tests/mochitest/test_getUserMedia_constraints.html @@ -9,9 +9,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=882145 + -Test mozGetUserMedia Constraints +Test mozGetUserMedia Constraints (desktop)