DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (27a812186ff4)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=795367
-->
<head>
  <meta charset="utf-8">
  <title>Test mozGetUserMedia Exceptions</title>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="head.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=795367">Test mozGetUserMedia Exceptions</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script type="application/javascript">
/**
  These tests verify that the appropriate exception is thrown when incorrect
  values are provided to the immediate mozGetUserMedia call.
*/
var exceptionTests = [
  // Each test here verifies that a caller is required to have all
  // three arguments in order to call mozGetUserMedia
  { params: undefined,
    error: "Not enough arguments to Navigator.mozGetUserMedia.",
    message: "no arguments specified" },
  { params: [{video: true, fake: true}],
    error: "Not enough arguments to Navigator.mozGetUserMedia.",
    message: "one argument specified" },
  { params: [{video: true, fake: true}, unexpectedCall],
    error: "Not enough arguments to Navigator.mozGetUserMedia.",
    message: "two arguments specified" },

  // Each test here verifies that providing an incorret object
  // type to any mozGetUserMedia parameter should throw
  // the correct exception specified
  { params: [1, unexpectedCall, unexpectedCall],
    error: "Argument 1 of Navigator.mozGetUserMedia can't be converted to a dictionary.",
    message: "wrong object type as first parameter" },
  { params: [{video: true, fake: true}, 1, unexpectedCall],
    error: "Argument 2 of Navigator.mozGetUserMedia is not an object.",
    message: "wrong object type as second parameter" },
  { params: [{video: true, fake: true}, unexpectedCall, 1],
    error: "Argument 3 of Navigator.mozGetUserMedia is not an object.",
    message: "wrong object type as third parameter" },

  // Each test here verifies constraint syntax as defined in webidl
  { params: [{ fake: true, video: { optional: [{ facingMode:'foo' }] } },
             unexpectedCall, unexpectedCall],
    error: "'facingMode' member of MediaTrackConstraintSet 'foo' is not a valid value for enumeration VideoFacingModeEnum.",
    message: "invalid facingMode enum value" }
];

/**
 * A callback function that is only called if a particular
 * exception was not thrown, resulting in the test failing.
 *
 * @param  {MediaStream} argument ignored
 */
function unexpectedCall(obj) {
  ok(false, "Callback should not have been called");
}

/**
 * Starts the test run by running through each exception
 * test by verifying that the correct exception type specified
 * is thrown on the mozGetUserMedia call with the parameters
 * specified.
 */
runTest(function () {
  exceptionTests.forEach(function (test) {
    var exception = false;
    try {
      navigator.mozGetUserMedia.apply(navigator, test.params);
    } catch (e) {
      exception = (e.message === test.error);
      if(!exception) {
        info(e.message);
      }
    }
    ok(exception, "Exception for " + test.message);
  });

  SimpleTest.finish();
});

</script>
</pre>
</body>
</html>