[Modern Media Controls] Turn media/modern-media-controls/ios-inline-media-controls...
[WebKit-https.git] / LayoutTests / media / audio-concurrent-supported.html
1 <html>
2     <title>Test of concurrent HTML5 audio</title>
3     <body>
4
5     <p>Test that multiple audio elements can play concurrently.</p>
6
7     <script src=video-test.js></script>
8     <script src=media-file.js></script>
9     <script>
10         var maxPlayers = 2; // Number of concurrent audio elements to test. For larger values a longer media file is needed.
11         var timeupdateEventCount = 0;
12         var audioElementCount = 0;
13
14         function errorListener(event)
15         {
16              logResult(false, "Element " + audioElementCount + " caught 'error' event, audio.error.code = " + this.error.code);
17              endTest();
18         }
19
20         function canplaythroughListener(event)
21         {
22              consoleWrite("EVENT(" + audioElementCount + ", canplaythrough)");
23              testElement = this;
24              testExpected(audioElementCount + ", testElement.currentTime", 0);
25              this.play();
26         }
27
28         function playingListener(event)
29         {
30              consoleWrite("EVENT(" + audioElementCount + ", playing)");
31         }
32
33         function timeupdateListener(event)
34         {
35             ++timeupdateEventCount;
36
37             // wait 2 timeupdate events so we are sure the media engine is
38             // playing the media.
39             if (timeupdateEventCount >= 2) {
40                 // make sure time is advancing
41                 testElement = this;
42                 testExpected(audioElementCount + ", testElement.currentTime", 0, '>');
43                 this.removeEventListener('timeupdate', timeupdateListener);
44                 if (++audioElementCount >= maxPlayers) {
45                     // All audio elements have been started playing. Make sure
46                     // all of them are still playing.
47                     consoleWrite("Making sure all " + maxPlayers + " audio elements are in playing state:");
48                     for (var i = 0; i < maxPlayers; i++) {
49                         testElement = document.getElementsByTagName('audio')[i];
50                         testExpected(i + ", testElement.paused", false);
51                     }
52                     endTest();
53                 } else {
54                     // Start the next audio element
55                     testAudioElement(audioElementCount);
56                 }
57             }
58         }
59
60         function testAudioElement(count)
61         {
62             var audioElement = document.getElementsByTagName('audio')[count];
63             audioElement.addEventListener('error', errorListener);
64             audioElement.addEventListener('canplaythrough', canplaythroughListener);
65             timeupdateEventCount = 0;
66             audioElement.addEventListener('timeupdate', timeupdateListener);
67             audioElement.addEventListener('playing', playingListener);
68             audioElement.src = findMediaFile("audio", "content/silence");
69         }
70
71         consoleWrite("Starting a total of " + maxPlayers + " concurrent audio elements.");
72         for (var i = 0; i < maxPlayers; i++)
73             document.write("<audio controls></audio>");
74
75         testAudioElement(0);
76     </script>
77
78     </body>
79 </html>