1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/media/tests/mochitest/test_getUserMedia_exceptions.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=795367 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test mozGetUserMedia Exceptions</title> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.13 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.14 + <script type="application/javascript" src="head.js"></script> 1.15 +</head> 1.16 +<body> 1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=795367">Test mozGetUserMedia Exceptions</a> 1.18 +<p id="display"></p> 1.19 +<div id="content" style="display: none"> 1.20 + 1.21 +</div> 1.22 +<pre id="test"> 1.23 +<script type="application/javascript"> 1.24 +/** 1.25 + These tests verify that the appropriate exception is thrown when incorrect 1.26 + values are provided to the immediate mozGetUserMedia call. 1.27 +*/ 1.28 +var exceptionTests = [ 1.29 + // Each test here verifies that a caller is required to have all 1.30 + // three arguments in order to call mozGetUserMedia 1.31 + { params: undefined, 1.32 + error: "Not enough arguments to Navigator.mozGetUserMedia.", 1.33 + message: "no arguments specified" }, 1.34 + { params: [{video: true, fake: true}], 1.35 + error: "Not enough arguments to Navigator.mozGetUserMedia.", 1.36 + message: "one argument specified" }, 1.37 + { params: [{video: true, fake: true}, unexpectedCall], 1.38 + error: "Not enough arguments to Navigator.mozGetUserMedia.", 1.39 + message: "two arguments specified" }, 1.40 + 1.41 + // Each test here verifies that providing an incorret object 1.42 + // type to any mozGetUserMedia parameter should throw 1.43 + // the correct exception specified 1.44 + { params: [1, unexpectedCall, unexpectedCall], 1.45 + error: "Argument 1 of Navigator.mozGetUserMedia can't be converted to a dictionary.", 1.46 + message: "wrong object type as first parameter" }, 1.47 + { params: [{video: true, fake: true}, 1, unexpectedCall], 1.48 + error: "Argument 2 of Navigator.mozGetUserMedia is not an object.", 1.49 + message: "wrong object type as second parameter" }, 1.50 + { params: [{video: true, fake: true}, unexpectedCall, 1], 1.51 + error: "Argument 3 of Navigator.mozGetUserMedia is not an object.", 1.52 + message: "wrong object type as third parameter" }, 1.53 + 1.54 + // Each test here verifies constraint syntax as defined in webidl 1.55 + { params: [{ fake: true, video: { advanced: [{ facingMode:'foo' }] } }, 1.56 + unexpectedCall, unexpectedCall], 1.57 + error: "'facingMode' member of MediaTrackConstraintSet 'foo' is not a valid value for enumeration VideoFacingModeEnum.", 1.58 + message: "invalid facingMode enum value" } 1.59 +]; 1.60 + 1.61 +/** 1.62 + * A callback function that is only called if a particular 1.63 + * exception was not thrown, resulting in the test failing. 1.64 + * 1.65 + * @param {MediaStream} argument ignored 1.66 + */ 1.67 +function unexpectedCall(obj) { 1.68 + ok(false, "Callback should not have been called"); 1.69 +} 1.70 + 1.71 +/** 1.72 + * Starts the test run by running through each exception 1.73 + * test by verifying that the correct exception type specified 1.74 + * is thrown on the mozGetUserMedia call with the parameters 1.75 + * specified. 1.76 + */ 1.77 +runTest(function () { 1.78 + exceptionTests.forEach(function (test) { 1.79 + var exception = false; 1.80 + try { 1.81 + navigator.mozGetUserMedia.apply(navigator, test.params); 1.82 + } catch (e) { 1.83 + exception = (e.message === test.error); 1.84 + if(!exception) { 1.85 + info(e.message); 1.86 + } 1.87 + } 1.88 + ok(exception, "Exception for " + test.message); 1.89 + }); 1.90 + 1.91 + SimpleTest.finish(); 1.92 +}); 1.93 + 1.94 +</script> 1.95 +</pre> 1.96 +</body> 1.97 +</html>