1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/media/tests/mochitest/constraints.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +/** 1.9 + Tests covering gUM constraints API for audio, video and fake video. Exercise 1.10 + successful parsing code and ensure that unknown required constraints and 1.11 + overconstraining cases produce appropriate errors. 1.12 + 1.13 + TODO(jib): Merge desktop and mobile version of these tests again. 1.14 +*/ 1.15 +var common_tests = [ 1.16 + // Each test here tests a different constraint or codepath. 1.17 + { message: "unknown required constraint on video fails", 1.18 + constraints: { video: { somethingUnknown:0, require:["somethingUnknown"] }, 1.19 + fake: true }, 1.20 + error: "NO_DEVICES_FOUND" }, 1.21 + { message: "unknown required constraint on audio fails", 1.22 + constraints: { audio: { somethingUnknown:0, require:["somethingUnknown"] }, 1.23 + fake: true }, 1.24 + error: "NO_DEVICES_FOUND" }, 1.25 + { message: "video overconstrained by facingMode fails", 1.26 + constraints: { video: { facingMode:'left', require:["facingMode"] }, 1.27 + fake: true }, 1.28 + error: "NO_DEVICES_FOUND" }, 1.29 + { message: "audio overconstrained by facingMode fails", 1.30 + constraints: { audio: { facingMode:'left', require:["facingMode"] }, 1.31 + fake: true }, 1.32 + error: "NO_DEVICES_FOUND" }, 1.33 + { message: "Success-path: optional video facingMode + audio ignoring facingMode", 1.34 + constraints: { fake: true, 1.35 + audio: { facingMode:'left', 1.36 + foo:0, 1.37 + advanced: [{ facingMode:'environment' }, 1.38 + { facingMode:'user' }, 1.39 + { bar:0 }] }, 1.40 + video: { // TODO: Bug 767924 sequences in unions 1.41 + //facingMode:['left', 'right', 'user', 'environment'], 1.42 + //require:["facingMode"], 1.43 + facingMode:'left', 1.44 + foo:0, 1.45 + advanced: [{ facingMode:'environment' }, 1.46 + { facingMode:'user' }, 1.47 + { bar:0 }] } }, 1.48 + error: null } 1.49 +]; 1.50 + 1.51 + 1.52 +/** 1.53 + * Starts the test run by running through each constraint 1.54 + * test by verifying that the right callback and error message is fired. 1.55 + */ 1.56 + 1.57 +function testConstraints(tests) { 1.58 + var i = 0; 1.59 + next(); 1.60 + 1.61 + function Success() { 1.62 + ok(!tests[i].error, tests[i].message); 1.63 + i++; 1.64 + next(); 1.65 + } 1.66 + function Failure(err) { 1.67 + ok(tests[i].error? (err === tests[i].error) : false, 1.68 + tests[i].message + " (err=" + err + ")"); 1.69 + i++; 1.70 + next(); 1.71 + } 1.72 + function next() { 1.73 + if (i < tests.length) { 1.74 + navigator.mozGetUserMedia(tests[i].constraints, Success, Failure); 1.75 + } else { 1.76 + SimpleTest.finish(); 1.77 + } 1.78 + } 1.79 +};