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