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