dom/media/tests/mochitest/constraints.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial