Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | /** |
michael@0 | 6 | Tests covering gUM constraints API for audio, video and fake video. Exercise |
michael@0 | 7 | successful parsing code and ensure that unknown required constraints and |
michael@0 | 8 | overconstraining cases produce appropriate errors. |
michael@0 | 9 | |
michael@0 | 10 | TODO(jib): Merge desktop and mobile version of these tests again. |
michael@0 | 11 | */ |
michael@0 | 12 | var common_tests = [ |
michael@0 | 13 | // Each test here tests a different constraint or codepath. |
michael@0 | 14 | { message: "unknown required constraint on video fails", |
michael@0 | 15 | constraints: { video: { somethingUnknown:0, require:["somethingUnknown"] }, |
michael@0 | 16 | fake: true }, |
michael@0 | 17 | error: "NO_DEVICES_FOUND" }, |
michael@0 | 18 | { message: "unknown required constraint on audio fails", |
michael@0 | 19 | constraints: { audio: { somethingUnknown:0, require:["somethingUnknown"] }, |
michael@0 | 20 | fake: true }, |
michael@0 | 21 | error: "NO_DEVICES_FOUND" }, |
michael@0 | 22 | { message: "video overconstrained by facingMode fails", |
michael@0 | 23 | constraints: { video: { facingMode:'left', require:["facingMode"] }, |
michael@0 | 24 | fake: true }, |
michael@0 | 25 | error: "NO_DEVICES_FOUND" }, |
michael@0 | 26 | { message: "audio overconstrained by facingMode fails", |
michael@0 | 27 | constraints: { audio: { facingMode:'left', require:["facingMode"] }, |
michael@0 | 28 | fake: true }, |
michael@0 | 29 | error: "NO_DEVICES_FOUND" }, |
michael@0 | 30 | { message: "Success-path: optional video facingMode + audio ignoring facingMode", |
michael@0 | 31 | constraints: { fake: true, |
michael@0 | 32 | audio: { facingMode:'left', |
michael@0 | 33 | foo:0, |
michael@0 | 34 | advanced: [{ facingMode:'environment' }, |
michael@0 | 35 | { facingMode:'user' }, |
michael@0 | 36 | { bar:0 }] }, |
michael@0 | 37 | video: { // TODO: Bug 767924 sequences in unions |
michael@0 | 38 | //facingMode:['left', 'right', 'user', 'environment'], |
michael@0 | 39 | //require:["facingMode"], |
michael@0 | 40 | facingMode:'left', |
michael@0 | 41 | foo:0, |
michael@0 | 42 | advanced: [{ facingMode:'environment' }, |
michael@0 | 43 | { facingMode:'user' }, |
michael@0 | 44 | { bar:0 }] } }, |
michael@0 | 45 | error: null } |
michael@0 | 46 | ]; |
michael@0 | 47 | |
michael@0 | 48 | |
michael@0 | 49 | /** |
michael@0 | 50 | * Starts the test run by running through each constraint |
michael@0 | 51 | * test by verifying that the right callback and error message is fired. |
michael@0 | 52 | */ |
michael@0 | 53 | |
michael@0 | 54 | function testConstraints(tests) { |
michael@0 | 55 | var i = 0; |
michael@0 | 56 | next(); |
michael@0 | 57 | |
michael@0 | 58 | function Success() { |
michael@0 | 59 | ok(!tests[i].error, tests[i].message); |
michael@0 | 60 | i++; |
michael@0 | 61 | next(); |
michael@0 | 62 | } |
michael@0 | 63 | function Failure(err) { |
michael@0 | 64 | ok(tests[i].error? (err === tests[i].error) : false, |
michael@0 | 65 | tests[i].message + " (err=" + err + ")"); |
michael@0 | 66 | i++; |
michael@0 | 67 | next(); |
michael@0 | 68 | } |
michael@0 | 69 | function next() { |
michael@0 | 70 | if (i < tests.length) { |
michael@0 | 71 | navigator.mozGetUserMedia(tests[i].constraints, Success, Failure); |
michael@0 | 72 | } else { |
michael@0 | 73 | SimpleTest.finish(); |
michael@0 | 74 | } |
michael@0 | 75 | } |
michael@0 | 76 | }; |