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 (053b0bb00fed)

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
<!doctype html>
<html>
<head>
    <title>MediaRecorder Pause and Resume</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>
<canvas id="canvas" width="200" height="200">
</canvas>
<script>
    function createVideoStream() {
        const canvas = document.getElementById("canvas");
        const ctx = canvas.getContext('2d');
        ctx.fillStyle = 'green';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
        return canvas.captureStream();
    }

    function recordEvents(target, events) {
        let arr = [];
        for (let ev of events) {
            target.addEventListener(ev, _ => arr.push(ev));
        }
        return arr;
    }

    promise_test(async () => {
        let video = createVideoStream();
        let recorder = new MediaRecorder(video);
        let events = recordEvents(recorder,
            ["start", "stop", "dataavailable", "pause", "resume", "error"]);

        recorder.start();
        assert_equals(recorder.state, "recording", "MediaRecorder has been started successfully");
        await new Promise(r => recorder.onstart = r);

        recorder.pause();
        assert_equals(recorder.state, "paused", "MediaRecorder should be paused immediately following pause()");

        // A second call to pause should be idempotent
        recorder.pause();
        assert_equals(recorder.state, "paused", "MediaRecorder should be paused immediately following pause()");

        let event = await new Promise(r => recorder.onpause = r);
        assert_equals(event.type, "pause", "the event type should be pause");
        assert_true(event.isTrusted, "isTrusted should be true when the event is created by C++");

        recorder.resume();
        assert_equals(recorder.state, "recording", "MediaRecorder state should be recording immediately following resume() call");

        // A second call to resume should be idempotent
        recorder.resume();
        assert_equals(recorder.state, "recording", "MediaRecorder state should be recording immediately following resume() call");

        event = await new Promise(r => recorder.onresume = r);
        assert_equals(event.type, "resume", "the event type should be resume");
        assert_true(event.isTrusted, "isTrusted should be true when the event is created by C++");

        recorder.stop();
        await new Promise(r => recorder.onstop = r);

        assert_array_equals(events, ["start", "pause", "resume", "dataavailable", "stop"],
            "Should have gotten expected events");
    }, "MediaRecorder handles pause() and resume() calls appropriately in state and events");
</script>
</body>
</html>