<!DOCTYPE HTML>
<html>
<head>
  <title>Test MediaRecorder Record with media.ogg.enabled = false</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <script type="text/javascript" src="manifest.js"></script>
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
function testThrows(stream, options, errorName, message, testName) {
  try {
    new MediaRecorder(stream, options);
  } catch(e) {
    is(e.name, errorName, testName);
    is(e.message, message, testName);
    return;
  }
  ok(!errorName, testName);
}
(async () => {
  SimpleTest.waitForExplicitFinish();
  await SpecialPowers.pushPrefEnv({set: [
      ["media.ogg.enabled", false],
      ["media.encoder.webm.enabled", false],
    ]});
  const stream = new AudioContext().createMediaStreamDestination().stream;
  testThrows(
    stream, {mimeType: "audio/ogg"}, "NotSupportedError",
    "MediaRecorder constructor: audio/ogg indicates an unsupported container",
    "Creating an ogg recorder without ogg support throws");
  testThrows(
    stream, {mimeType: "audio/webm"}, "NotSupportedError",
    "MediaRecorder constructor: audio/webm indicates an unsupported container",
    "Creating a webm recorder without webm support throws");
  testThrows(
    stream, {mimeType: "video/webm"}, "NotSupportedError",
    "MediaRecorder constructor: video/webm indicates an unsupported container",
    "Creating a webm recorder without webm support throws");
  testThrows(
    stream, {mimeType: "apa/bepa"}, "NotSupportedError",
    "MediaRecorder constructor: apa/bepa is not a valid media type",
    "Creating a recorder for a bogus mime type throws");
  testThrows(
    stream, {}, null, null,
    "Creating a default recorder never throws, even without container support");
  const recorder = new MediaRecorder(stream);
  try {
    recorder.start();
    ok(false, "Starting a recorder without container support should throw");
  } catch(e) {
    is(e.name, "NotSupportedError",
      "Starting a recorder without container support throws");
  }
  SimpleTest.finish();
})();
</script>
</pre>
</body>
</html>
