Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / mediarecorder / MediaRecorder-creation.html
blobf6e32d45869b669d624276c5f57bb03cf8cded81
1 <!DOCTYPE html>
2 <script src=../../resources/testharness.js></script>
3 <script src=../../resources/testharnessreport.js></script>
4 <script>
5 // This test verifies that MediaRecorder can be created with different Media
6 // Stream Track combinations: 1 Video Track only, 1 Audio Track only and finally
7 // a Media Stream with both a Video and an Audio Track. Note that recording is
8 // _not_ started in this test, see MediaRecorder-basic-video.html for it.
10 function makeAsyncTest(constraints, verifyStream, message) {
11 return async_test(function(test) {
13 var gotStream = test.step_func(function(stream) {
14 verifyStream(stream);
16 try {
17 recorder = new MediaRecorder(stream);
18 } catch (e) {
19 assert_unreached('Exception while creating MediaRecorder: ' + e);
21 assert_equals(recorder.state, "inactive");
22 test.done();
23 });
25 var onError = test.step_func(function() {
26 assert_unreached('Error creating MediaRecorder.');
27 });
29 try {
30 navigator.webkitGetUserMedia(constraints, gotStream, onError);
31 } catch(e) {
32 assert_unreached('Exception launching getUserMedia(): ' + e);
34 }, message);
37 function verifyVideoOnlyStream(stream) {
38 assert_equals(stream.getAudioTracks().length, 0);
39 assert_equals(stream.getVideoTracks().length, 1);
40 assert_equals(stream.getVideoTracks()[0].readyState, 'live');
42 function verifyAudioOnlyStream(stream) {
43 assert_equals(stream.getAudioTracks().length, 1);
44 assert_equals(stream.getVideoTracks().length, 0);
45 assert_equals(stream.getAudioTracks()[0].readyState, 'live');
47 function verifyAudioVideoStream(stream) {
48 assert_equals(stream.getAudioTracks().length, 1);
49 assert_equals(stream.getVideoTracks().length, 1);
50 assert_equals(stream.getVideoTracks()[0].readyState, 'live');
51 assert_equals(stream.getAudioTracks()[0].readyState, 'live');
54 // Note: webkitGetUserMedia() must be called with at least video or audio true.
55 makeAsyncTest({video:true}, verifyVideoOnlyStream, 'Video only MediaRecorder');
56 makeAsyncTest({audio:true}, verifyAudioOnlyStream, 'Audio only MediaRecorder');
57 makeAsyncTest({audio:true, video:true}, verifyAudioVideoStream, 'Video and Audio MediaRecorder');
59 </script>