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.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=795367
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test mozGetUserMedia Exceptions</title>
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
10 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
11 <script type="application/javascript" src="head.js"></script>
12 </head>
13 <body>
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=795367">Test mozGetUserMedia Exceptions</a>
15 <p id="display"></p>
16 <div id="content" style="display: none">
18 </div>
19 <pre id="test">
20 <script type="application/javascript">
21 /**
22 These tests verify that the appropriate exception is thrown when incorrect
23 values are provided to the immediate mozGetUserMedia call.
24 */
25 var exceptionTests = [
26 // Each test here verifies that a caller is required to have all
27 // three arguments in order to call mozGetUserMedia
28 { params: undefined,
29 error: "Not enough arguments to Navigator.mozGetUserMedia.",
30 message: "no arguments specified" },
31 { params: [{video: true, fake: true}],
32 error: "Not enough arguments to Navigator.mozGetUserMedia.",
33 message: "one argument specified" },
34 { params: [{video: true, fake: true}, unexpectedCall],
35 error: "Not enough arguments to Navigator.mozGetUserMedia.",
36 message: "two arguments specified" },
38 // Each test here verifies that providing an incorret object
39 // type to any mozGetUserMedia parameter should throw
40 // the correct exception specified
41 { params: [1, unexpectedCall, unexpectedCall],
42 error: "Argument 1 of Navigator.mozGetUserMedia can't be converted to a dictionary.",
43 message: "wrong object type as first parameter" },
44 { params: [{video: true, fake: true}, 1, unexpectedCall],
45 error: "Argument 2 of Navigator.mozGetUserMedia is not an object.",
46 message: "wrong object type as second parameter" },
47 { params: [{video: true, fake: true}, unexpectedCall, 1],
48 error: "Argument 3 of Navigator.mozGetUserMedia is not an object.",
49 message: "wrong object type as third parameter" },
51 // Each test here verifies constraint syntax as defined in webidl
52 { params: [{ fake: true, video: { advanced: [{ facingMode:'foo' }] } },
53 unexpectedCall, unexpectedCall],
54 error: "'facingMode' member of MediaTrackConstraintSet 'foo' is not a valid value for enumeration VideoFacingModeEnum.",
55 message: "invalid facingMode enum value" }
56 ];
58 /**
59 * A callback function that is only called if a particular
60 * exception was not thrown, resulting in the test failing.
61 *
62 * @param {MediaStream} argument ignored
63 */
64 function unexpectedCall(obj) {
65 ok(false, "Callback should not have been called");
66 }
68 /**
69 * Starts the test run by running through each exception
70 * test by verifying that the correct exception type specified
71 * is thrown on the mozGetUserMedia call with the parameters
72 * specified.
73 */
74 runTest(function () {
75 exceptionTests.forEach(function (test) {
76 var exception = false;
77 try {
78 navigator.mozGetUserMedia.apply(navigator, test.params);
79 } catch (e) {
80 exception = (e.message === test.error);
81 if(!exception) {
82 info(e.message);
83 }
84 }
85 ok(exception, "Exception for " + test.message);
86 });
88 SimpleTest.finish();
89 });
91 </script>
92 </pre>
93 </body>
94 </html>