<!doctype html>
<html>
<head>
    <title>MediaRecorder mimeType handling</title
    <link rel="help" href="https://w3c.github.io/mediacapture-record/MediaRecorder.html#mediarecorder">
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
const mimeTypeTests = [
    ['auDio/mp4', true],
    ['video/mp4', true],
    ['audio/MP4;codecs=" avc1.4d002a   ,mp4a.40.1"', true],
    ['video/mp4;codecs="AVC1.4d002a,   mp4a.40.1"', true],
    ['video/mp4;codecs="mP4a.40.1"', true],
    ['audio/mp4;codecs="avc1.4d002a, opus"', false],
    ['audio/mp4;codecs="opus"', false],
    ['audio/webm', false],
    ['video/webm', false],
];

mimeTypeTests.forEach(mimeTypeTest => {
    test(() => {
        assert_equals(MediaRecorder.isTypeSupported(mimeTypeTest[0]), mimeTypeTest[1]);
    }, "MediaRecorder.isTypeSupported - '" + mimeTypeTest[0] + "'");
});

promise_test(async () => {
    const mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true });

    let recorder = new MediaRecorder(mediaStream);
    assert_equals(recorder.mimeType, "");
    recorder.start();
    await new Promise(resolve => recorder.onstart = resolve);
    assert_equals(recorder.mimeType, "video/mp4", "test 1 mime type");

    recorder = new MediaRecorder(new MediaStream([mediaStream.getVideoTracks()[0]]));
    assert_equals(recorder.mimeType, "");
    recorder.start();
    await new Promise(resolve => recorder.onstart = resolve);
    assert_equals(recorder.mimeType, "video/mp4", "test 2 mime type");

    recorder = new MediaRecorder(new MediaStream([mediaStream.getAudioTracks()[0]]));
    assert_equals(recorder.mimeType, "");
    recorder.start();
    await new Promise(resolve => recorder.onstart = resolve);
    assert_equals(recorder.mimeType, "audio/mp4");
}, "MediaRecorder mimeType");
</script>
</body>
</html>
