| <!doctype html> |
| <html> |
| <head> |
| <title>MediaRecorder Stop</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() { |
| let canvas = document.getElementById("canvas"); |
| canvas.getContext('2d'); |
| return canvas.captureStream(); |
| } |
| |
| async_test(t => { |
| let video = createVideoStream(); |
| let recorder = new MediaRecorder(video); |
| recorder.onstop = t.step_func(errorEvent => { |
| assert_equals(errorEvent.type, 'stop', 'the error type should be stop'); |
| assert_true(errorEvent.isTrusted, 'isTrusted should be true when the event is created by C++'); |
| assert_equals(recorder.state, "inactive", "MediaRecorder has been stopped when all tracks are ended"); |
| t.done(); |
| }); |
| assert_equals(video.getVideoTracks().length, 1, "video mediastream starts with one track"); |
| recorder.start(); |
| assert_equals(recorder.state, "recording", "MediaRecorder has been started successfully"); |
| video.getVideoTracks()[0].stop(); |
| }, "MediaRecorder will stop recording and fire a stop event when all tracks are ended"); |
| |
| async_test(t => { |
| let video = createVideoStream(); |
| let recorder = new MediaRecorder(video); |
| recorder.onstop = t.step_func(errorEvent => { |
| assert_equals(errorEvent.type, 'stop', 'the error type should be stop'); |
| assert_true(errorEvent.isTrusted, 'isTrusted should be true when the event is created by C++'); |
| assert_equals(recorder.state, "inactive", "MediaRecorder has been stopped when stop() is called"); |
| t.done(); |
| }); |
| recorder.start(); |
| assert_equals(recorder.state, "recording", "MediaRecorder has been started successfully"); |
| recorder.stop(); |
| assert_equals(recorder.state, "recording", "State should remain the same until stop event is fired"); |
| }, "MediaRecorder will stop recording and fire a stop event when stop() is called"); |
| </script> |
| </body> |
| </html> |