Commit 4b771b2b authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

MediaRecorder: Upstream some moarrrr web_tests to WPT

This CL moves MediaRecorder-events-and-exceptions.html to the wpt/
folder, and refactors it to use canvas.captureStream() (ISO the
Chrome-specific blink_test_runner.cc thing).

It also fixes partially MediaRecorder-error.html: a new method
drawSomethingOnCanvas() is introduced and called to guarantee
that the canvas produces some captured VideoFrame, kicking the
event(s) generation. This fix is partial because Chrome doesn't
have MediaRecorderErrorEvent, but at least we verify that an
error event is thrown.

Bug: 919951
Change-Id: Ie9d7cfeeb2bf4452f4b5928eb2a7c644778751a7
Reviewed-on: https://chromium-review.googlesource.com/c/1406150Reviewed-by: default avatarEmircan Uysaler <emircan@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#622121}
parent 386e1858
This is a testharness.js-based test. This is a testharness.js-based test.
FAIL MediaRecorder will stop recording when any of track is added and error event will be fired assert_unreached: error event is not fired after 2 seconds Reached unreachable code FAIL MediaRecorder will stop recording when any of track is added and error event will be fired MediaRecorderErrorEvent is not defined
FAIL MediaRecorder will stop recording when any of track is removed and error event will be fired assert_unreached: error event is not fired after 2 seconds Reached unreachable code FAIL MediaRecorder will stop recording when any of track is removed and error event will be fired MediaRecorderErrorEvent is not defined
PASS MediaRecorder cannot start recording when MediaRecorder' state is not inactive and an InvalidStateError should be thrown PASS MediaRecorder cannot start recording when MediaRecorder' state is not inactive and an InvalidStateError should be thrown
Harness: the test ran to completion. Harness: the test ran to completion.
...@@ -24,6 +24,14 @@ ...@@ -24,6 +24,14 @@
return canvas.captureStream(); return canvas.captureStream();
} }
function drawSomethingOnCanvas() {
let canvas = document.getElementById("canvas");
// Drawing something on the canvas generates a frame in its captured stream.
let context = canvas.getContext("2d");
context.fillStyle = "red";
context.fillRect(0, 0, 10, 10);
}
async_test(t => { async_test(t => {
let video = createVideoStream(); let video = createVideoStream();
let audio = createAudioStream(); let audio = createAudioStream();
...@@ -38,6 +46,7 @@ ...@@ -38,6 +46,7 @@
recorder.start(); recorder.start();
assert_equals(recorder.state, "recording", "MediaRecorder has been started successfully"); assert_equals(recorder.state, "recording", "MediaRecorder has been started successfully");
video.addTrack(audio.getAudioTracks()[0]); video.addTrack(audio.getAudioTracks()[0]);
drawSomethingOnCanvas();
t.step_timeout(() => { t.step_timeout(() => {
assert_unreached("error event is not fired after 2 seconds"); assert_unreached("error event is not fired after 2 seconds");
}, 2000); }, 2000);
...@@ -56,6 +65,7 @@ ...@@ -56,6 +65,7 @@
recorder.start(); recorder.start();
assert_equals(recorder.state, "recording", "MediaRecorder has been started successfully"); assert_equals(recorder.state, "recording", "MediaRecorder has been started successfully");
video.removeTrack(video.getVideoTracks()[0]); video.removeTrack(video.getVideoTracks()[0]);
drawSomethingOnCanvas();
t.step_timeout(() => { t.step_timeout(() => {
assert_unreached("error event is not fired after 2 seconds"); assert_unreached("error event is not fired after 2 seconds");
}, 2000); }, 2000);
......
<!doctype html>
<html>
<head>
<title>MediaRecorder events and exceptions</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="320" height="320"></canvas>
<script>
// This test exercises the MediaRecorder API event sequence:
// onStart -> onPause -> onResume -> onDataAvailable -> onStop
// verifying the |state| and a few exceptions that are supposed to be thrown
// when doing the wrong thing.
function createVideoStream() {
let canvas = document.getElementById("canvas");
canvas.getContext('2d').lineTo(10, 10);
return canvas.captureStream();
}
function drawSomethingOnCanvas() {
let canvas = document.getElementById("canvas");
// Drawing something on the canvas generates a frame in its captured stream.
let context = canvas.getContext("2d");
context.fillStyle = "red";
context.fillRect(0, 0, 10, 10);
}
async_test(test => {
recorderOnUnexpectedEvent = test.step_func(() => {
assert_unreached('Unexpected event.');
});
recorderOnDataAvailable = test.step_func(event => {
// TODO(mcasas): ondataavailable might never be pinged with an empty Blob
// data on recorder.stop(), see http://crbug.com/54428
assert_equals(recorder.state, "inactive");
assert_equals(event.data.size, 0, 'We should have gotten an empty Blob');
});
recorderOnStop = test.step_func(function() {
assert_equals(recorder.state, "inactive");
assert_throws("InvalidStateError", function() { recorder.stop() },
"recorder cannot be stop()ped in |inactive| state");
assert_throws("InvalidStateError", function() { recorder.pause() },
"recorder cannot be pause()ed in |inactive| state");
assert_throws("InvalidStateError", function() { recorder.resume() },
"recorder cannot be resume()d in |inactive| state");
assert_throws("InvalidStateError", function() { recorder.requestData() },
"cannot requestData() if recorder is in |inactive| state");
recorder.onstop = recorderOnUnexpectedEvent;
test.done();
});
recorderOnResume = test.step_func(function() {
assert_equals(recorder.state, "recording");
recorder.onresume = recorderOnUnexpectedEvent;
recorder.onstop = recorderOnStop;
recorder.stop();
});
recorderOnPause = test.step_func(function() {
assert_equals(recorder.state, "paused");
recorder.onpause = recorderOnUnexpectedEvent;
recorder.onresume = recorderOnResume;
recorder.resume();
});
recorderOnStart = test.step_func(function() {
assert_equals(recorder.state, "recording");
recorder.onstart = recorderOnUnexpectedEvent;
recorder.onpause = recorderOnPause;
recorder.pause();
});
let stream = createVideoStream();
assert_equals(stream.getAudioTracks().length, 0);
assert_equals(stream.getVideoTracks().length, 1);
assert_equals(stream.getVideoTracks()[0].readyState, 'live');
assert_throws("NotSupportedError",
function() {
recorder =
new MediaRecorder(stream, {mimeType : "video/invalid"});
},
"recorder should throw() with unsupported mimeType");
let recorder = new MediaRecorder(stream);
assert_equals(recorder.state, "inactive");
assert_throws("InvalidStateError", function(){recorder.stop()},
"recorder cannot be stop()ped in |inactive| state");
assert_throws("InvalidStateError", function(){recorder.pause()},
"recorder cannot be pause()ed in |inactive| state");
assert_throws("InvalidStateError", function(){recorder.resume()},
"recorder cannot be resume()d in |inactive| state");
assert_throws("InvalidStateError", function(){recorder.requestData()},
"cannot requestData() if recorder is in |inactive| state");
drawSomethingOnCanvas();
recorder.onstop = recorderOnUnexpectedEvent;
recorder.onpause = recorderOnUnexpectedEvent;
recorder.onresume = recorderOnUnexpectedEvent;
recorder.onerror = recorderOnUnexpectedEvent;
recorder.ondataavailable = recorderOnDataAvailable;
recorder.onstart = recorderOnStart;
recorder.start();
assert_equals(recorder.state, "recording");
});
</script>
<!DOCTYPE html>
<script src=../../resources/testharness.js></script>
<script src=../../resources/testharnessreport.js></script>
<script>
var test = async_test('exercises the MediaRecorder API event chain: ' +
'onstart->onpaused->onresumed->onstopped in sequence, and also potential ' +
'exceptions that are thrown underway.');
var recorder;
recorderOnUnexpectedEvent = test.step_func(function() {
assert_unreached('Unexpected event.');
});
recorderOnDataAvailable = test.step_func(function(event) {
// TODO(mcasas): ondataavailable might never be pinged with an empty Blob
// data on recorder.stop(), see http://crbug.com/54428
assert_equals(recorder.state, "inactive");
assert_equals(event.data.size, 0, 'We should have gotten an empty Blob');
});
recorderOnStop = test.step_func(function() {
assert_equals(recorder.state, "inactive");
assert_throws("InvalidStateError", function() { recorder.stop() },
"recorder cannot be stop()ped in |inactive| state");
assert_throws("InvalidStateError", function() { recorder.pause() },
"recorder cannot be pause()ed in |inactive| state");
assert_throws("InvalidStateError", function() { recorder.resume() },
"recorder cannot be resume()d in |inactive| state");
assert_throws("InvalidStateError", function() { recorder.requestData() },
"cannot requestData() if recorder is in |inactive| state");
recorder.onstop = recorderOnUnexpectedEvent;
test.done();
});
recorderOnResume = test.step_func(function() {
assert_equals(recorder.state, "recording");
recorder.onresume = recorderOnUnexpectedEvent;
recorder.onstop = recorderOnStop;
recorder.stop();
});
recorderOnPause = test.step_func(function() {
assert_equals(recorder.state, "paused");
recorder.onpause = recorderOnUnexpectedEvent;
recorder.onresume = recorderOnResume;
recorder.resume();
});
recorderOnStart = test.step_func(function() {
assert_equals(recorder.state, "recording");
recorder.onstart = recorderOnUnexpectedEvent;
recorder.onpause = recorderOnPause;
recorder.pause();
});
gotStream = test.step_func(function(stream) {
assert_equals(stream.getAudioTracks().length, 0);
assert_equals(stream.getVideoTracks().length, 1);
assert_equals(stream.getVideoTracks()[0].readyState, 'live');
assert_throws("NotSupportedError",
function() {
recorder =
new MediaRecorder(stream, {mimeType : "video/invalid"});
},
"recorder should throw() with unsupported mimeType");
recorder = new MediaRecorder(stream);
assert_equals(recorder.state, "inactive");
assert_throws("InvalidStateError", function(){recorder.stop()},
"recorder cannot be stop()ped in |inactive| state");
assert_throws("InvalidStateError", function(){recorder.pause()},
"recorder cannot be pause()ed in |inactive| state");
assert_throws("InvalidStateError", function(){recorder.resume()},
"recorder cannot be resume()d in |inactive| state");
assert_throws("InvalidStateError", function(){recorder.requestData()},
"cannot requestData() if recorder is in |inactive| state");
recorder.onstop = recorderOnUnexpectedEvent;
recorder.onpause = recorderOnUnexpectedEvent;
recorder.onresume = recorderOnUnexpectedEvent;
recorder.onerror = recorderOnUnexpectedEvent;
recorder.ondataavailable = recorderOnDataAvailable;
recorder.onstart = recorderOnStart;
recorder.start();
assert_equals(recorder.state, "recording");
});
navigator.webkitGetUserMedia({video:true}, gotStream, recorderOnUnexpectedEvent);
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment