-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13602 from youennf/mediarecorder-error
WPT test for w3c/mediacapture-record#152
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>MediaRecorder Error</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> | ||
function createAudioStream() { | ||
let ac = new AudioContext(); | ||
let osc = ac.createOscillator(); | ||
let dest = ac.createMediaStreamDestination(); | ||
osc.connect(dest); | ||
return dest.stream; | ||
} | ||
|
||
function createVideoStream() { | ||
let canvas = document.getElementById("canvas"); | ||
canvas.getContext('2d').lineTo(10, 10); | ||
return canvas.captureStream(); | ||
} | ||
|
||
async_test(t => { | ||
let video = createVideoStream(); | ||
let audio = createAudioStream(); | ||
let recorder = new MediaRecorder(video); | ||
recorder.onerror = t.step_func(mediaRecorderErrorEvent => { | ||
assert_true(mediaRecorderErrorEvent instanceof MediaRecorderErrorEvent, 'the type of event should be MediaRecorderErrorEvent'); | ||
assert_equals(mediaRecorderErrorEvent.error.name, 'UnknownError', 'the type of error should be UnknownError when track has been added or removed'); | ||
assert_true(mediaRecorderErrorEvent.isTrusted, 'isTrusted should be true when the event is created by C++'); | ||
assert_equals(recorder.state, "inactive", "MediaRecorder has been stopped after adding a track to stream"); | ||
t.done(); | ||
}); | ||
recorder.start(); | ||
assert_equals(recorder.state, "recording", "MediaRecorder has been started successfully"); | ||
video.addTrack(audio.getAudioTracks()[0]); | ||
t.step_timeout(() => { | ||
assert_unreached("error event is not fired after 2 seconds"); | ||
}, 2000); | ||
}, "MediaRecorder will stop recording when any of track is added and error event will be fired"); | ||
|
||
async_test(t => { | ||
let video = createVideoStream(); | ||
let recorder = new MediaRecorder(video); | ||
recorder.onerror = t.step_func(mediaRecorderErrorEvent => { | ||
assert_true(mediaRecorderErrorEvent instanceof MediaRecorderErrorEvent, 'the type of event should be MediaRecorderErrorEvent'); | ||
assert_equals(mediaRecorderErrorEvent.error.name, 'UnknownError', 'the type of error should be UnknownError when track has been added or removed'); | ||
assert_true(mediaRecorderErrorEvent.isTrusted, 'isTrusted should be true when the event is created by C++'); | ||
assert_equals(recorder.state, "inactive", "MediaRecorder has been stopped after removing a track from stream"); | ||
t.done(); | ||
}); | ||
recorder.start(); | ||
assert_equals(recorder.state, "recording", "MediaRecorder has been started successfully"); | ||
video.removeTrack(video.getVideoTracks()[0]); | ||
t.step_timeout(() => { | ||
assert_unreached("error event is not fired after 2 seconds"); | ||
}, 2000); | ||
}, "MediaRecorder will stop recording when any of track is removed and error event will be fired"); | ||
|
||
test(t => { | ||
let video = createVideoStream(); | ||
let recorder = new MediaRecorder(video); | ||
recorder.start(); | ||
assert_equals(recorder.state, "recording", "MediaRecorder has been started successfully"); | ||
assert_throws("InvalidStateError", function() { | ||
recorder.start(); | ||
}); | ||
}, "MediaRecorder cannot start recording when MediaRecorder' state is not inactive and an InvalidStateError should be thrown"); | ||
</script> | ||
</body> | ||
</html> |