OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <script src=../../resources/testharness.js></script> | |
3 <script src=../../resources/testharnessreport.js></script> | |
4 <script> | |
5 | |
Peter Beverloo
2015/11/20 14:05:02
nit: I realize you're mostly copying this, but cou
ajose
2015/11/20 21:37:06
Done.
| |
6 var checkStreamTracks = function(stream, has_video, has_audio) { | |
7 if (has_video) { | |
8 assert_equals(stream.getVideoTracks().length, 1); | |
9 assert_equals(stream.getVideoTracks()[0].readyState, 'live'); | |
10 } else { | |
11 assert_equals(stream.getVideoTracks().length, 0); | |
12 } | |
13 | |
14 if (has_audio) { | |
15 assert_equals(stream.getAudioTracks().length, 1); | |
16 assert_equals(stream.getAudioTracks()[0].readyState, 'live'); | |
17 } else { | |
18 assert_equals(stream.getAudioTracks().length, 0); | |
19 } | |
20 }; | |
21 | |
22 var makeAsyncTest = function(value, expected) { | |
23 var recorder; | |
24 var has_video = value['video'] || false; | |
25 var has_audio = value['audio'] || false; | |
26 | |
27 async_test(function() { | |
28 recorderOnDataAvailable = this.step_func(function(event) { | |
Peter Beverloo
2015/11/20 14:05:02
nit: const recorderOnDataAvailable = ...
(Same fo
ajose
2015/11/20 21:37:06
Neat! I'll have to read more about 'const' and 'le
| |
29 if (event) { | |
30 assert_greater_than(event.data.size, 0, | |
31 'Recorded data size should be > 0'); | |
32 assert_equals(recorder.state, "recording"); | |
33 } else { | |
34 assert_equals(recorder.state, "inactive"); | |
35 } | |
36 | |
37 // TODO(mcasas): Let the test record for a while. | |
38 // TODO(mcasas): Consider storing recorded data and playing it back. | |
39 | |
40 recorder.onstop = recorderOnStopExpected; | |
41 recorder.stop(); | |
42 }); | |
43 | |
44 recorderOnStopExpected = this.step_func_done(); | |
45 | |
46 recorderOnStopUnexpected = this.step_func(function() { | |
47 assert_unreached('Recording stopped.'); | |
48 }); | |
49 | |
50 recorderOnError = this.step_func(function() { | |
51 assert_unreached('Recording error.'); | |
52 }); | |
53 | |
54 gotStream = this.step_func_done(function(stream) { | |
55 checkStreamTracks(stream, has_video, has_audio) | |
56 | |
57 try { | |
58 recorder = new MediaRecorder(stream); | |
59 } catch (e) { | |
60 assert_unreached('Exception while creating MediaRecorder: ' | |
Peter Beverloo
2015/11/20 14:05:02
nit: your preference, but there's no line length l
ajose
2015/11/20 21:37:06
Awesome.
| |
61 + e); | |
62 } | |
63 | |
64 assert_equals(recorder.state, "inactive"); | |
65 recorder.ondataavailable = recorderOnDataAvailable; | |
66 recorder.onstop = recorderOnStopUnexpected; | |
67 recorder.onerror = recorderOnError; | |
68 recorder.start(); | |
69 | |
70 assert_equals(recorder.state, "recording"); | |
71 }); | |
72 | |
73 onError = this.step_func(function() { | |
74 assert_unreached('Error creating MediaRecorder.'); | |
75 }); | |
76 | |
77 try { | |
78 navigator.webkitGetUserMedia(value, gotStream, onError); | |
79 } catch(e) { | |
80 assert_unreached('Exception launching getUserMedia(): ' + e); | |
81 } | |
82 }); | |
83 }; | |
84 | |
85 generate_tests(makeAsyncTest, | |
86 [["video-only", {video:true}], | |
Peter Beverloo
2015/11/20 14:05:01
nit: I'd prefer these to be explicit, rather than
ajose
2015/11/20 21:37:06
Done.
| |
87 ["audio-only", {audio:true}], | |
88 ["audio-video", {video:true, audio:true}]]); | |
89 | |
90 </script> | |
OLD | NEW |