5b175daf35feadede9c658824ef4cbd40461e9af
[WebKit-https.git] / LayoutTests / http / wpt / mediarecorder / MediaRecorder-AV-audio-only-dataavailable.html
1 <!doctype html>
2 <html>
3 <head>
4     <title>MediaRecorder can successfully record the audio for a audio-only stream</title>
5     <link rel="help" href="https://w3c.github.io/mediacapture-record/MediaRecorder.html#mediarecorder">
6     <script src="/resources/testharness.js"></script>
7     <script src="/resources/testharnessreport.js"></script>
8 </head>
9 <body>
10 <audio id="player">
11 </audio>
12 <script>
13
14     const ac = new webkitAudioContext();
15     const osc = ac.createOscillator();
16     const dest = ac.createMediaStreamDestination();
17     const audio = dest.stream;
18     osc.connect(dest);
19     const recorder = new MediaRecorder(audio);
20     recorder.ondataavailable = (blobEvent) => {
21         assert_true(blobEvent instanceof BlobEvent, 'the type of event should be BlobEvent');
22         assert_equals(blobEvent.type, 'dataavailable', 'the event type should be dataavailable');
23         assert_true(blobEvent.isTrusted, 'isTrusted should be true when the event is created by C++');
24         assert_true(blobEvent.data instanceof Blob, 'the type of data should be Blob');
25         assert_true(blobEvent.data.size > 0, 'the blob should contain some buffers');
26         const player = document.getElementById("player");
27         player.src = window.URL.createObjectURL(blobEvent.data);
28         player.oncanplay = () => {
29             assert_greater_than(player.duration, 0, 'the duration should be greater than 0');
30             done();
31         };
32         player.load();
33     };
34
35     recorder.start();
36     osc.start();
37     assert_equals(recorder.state, 'recording', 'MediaRecorder has been started successfully');
38     setTimeout(() => {
39         recorder.stop();
40         osc.stop();
41     }, 500);
42
43 </script>
44 </body>
45 </html>