dom/media/tests/mochitest/constraints.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:01ed31e1c87c
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/. */
4
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.
9
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 ];
47
48
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 */
53
54 function testConstraints(tests) {
55 var i = 0;
56 next();
57
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