Make captureCanvas-webrtc.html more robust
[WebKit-https.git] / LayoutTests / webrtc / audio-peer-connection-webaudio.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4     <meta charset="utf-8">
5     <title>Testing local audio capture playback causes "playing" event to fire</title>
6     <script src="../resources/testharness.js"></script>
7     <script src="../resources/testharnessreport.js"></script>
8     <script src ="routines.js"></script>
9     <script>
10     var context = new webkitAudioContext();
11     var remoteStream;
12
13     async function checkForHumBipBop(stream, previousResults, counter)
14     {
15         if (!previousResults)
16             previousResults = {
17                 heardHum : false,
18                 heardBip : false,
19                 heardBop : false
20         };
21         if (!counter)
22             counter = 1;
23         else if (++counter > 4)
24             return Promise.resolve(false);
25         results = await analyseAudio(stream, 1000, context);
26         previousResults.heardHum |= results.heardHum;
27         previousResults.heardBip |= results.heardBip;
28         previousResults.heardBop |= results.heardBop;
29         if (previousResults.heardHum && previousResults.heardBip && previousResults.heardBop)
30             return Promise.resolve(true);
31         var results = await checkForHumBipBop(stream, previousResults, counter);
32         return results;
33     }
34
35     promise_test((test) => {
36         if (window.testRunner)
37             testRunner.setUserMediaPermission(true);
38
39         return navigator.mediaDevices.getUserMedia({audio: true}).then((stream) => {
40             return new Promise((resolve, reject) => {
41                 createConnections((firstConnection) => {
42                     firstConnection.addTrack(stream.getAudioTracks()[0], stream);
43                 }, (secondConnection) => {
44                     secondConnection.ontrack = (event) => { resolve(event.streams[0]); };
45                 });
46                 setTimeout(() => reject("Test timed out"), 5000);
47             });
48         }).then((stream) => {
49             return checkForHumBipBop(stream);
50         }).then((results) => {
51             assert_true(results, "heard hum bip bop");
52         }).then(() => {
53             return context.close();
54         });
55     }, "Basic audio playback through a peer connection");
56     </script>
57 </head>
58 <body>
59 </body>
60 </html>