OLD | NEW |
1 <html> | 1 <!DOCTYPE html> |
2 <title>Test of concurrent HTML5 audio</title> | 2 <title>Test that multiple audio elements can play concurrently.</title> |
3 <body> | 3 <script src="../resources/testharness.js"></script> |
| 4 <script src="../resources/testharnessreport.js"></script> |
| 5 <script src="media-file.js"></script> |
| 6 <script> |
| 7 async_test(function(t) { |
| 8 // Number of concurrent audio elements to test. |
| 9 // For larger values a longer media file is needed. |
| 10 var maxPlayers = 2; |
| 11 var audioElementCount = 0; |
4 | 12 |
5 <p>Test that multiple audio elements can play concurrently.</p> | 13 for (var i = 0; i < maxPlayers; i++) { |
| 14 var audio = document.createElement("audio"); |
| 15 document.documentElement.appendChild(audio); |
| 16 } |
6 | 17 |
7 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 | 18 testAudioElement(0); |
8 (Please avoid writing new tests using video-test.js) --> | |
9 <script src=video-test.js></script> | |
10 <script src=media-file.js></script> | |
11 <script> | |
12 var maxPlayers = 2; // Number of concurrent audio elements to test. For
larger values a longer media file is needed. | |
13 var audioElementCount = 0; | |
14 | 19 |
15 function errorListener(event) | 20 function testAudioElement(count) { |
16 { | 21 var audioElement = document.querySelectorAll("audio")[count]; |
17 logResult(false, "Element " + audioElementCount + " caught 'error'
event, audio.error.code = " + this.error.code); | 22 audioElement.onerror = t.unreached_func(); |
18 endTest(); | 23 audioElement.onplaying = t.step_func(function() {}); |
19 } | |
20 | 24 |
21 function canplaythroughListener(event) | 25 audioElement.oncanplaythrough = t.step_func(function(event) { |
22 { | 26 var currentAudio = event.target; |
23 consoleWrite("EVENT(" + audioElementCount + ", canplaythrough)"); | 27 assert_equals(currentAudio.currentTime, 0, "audio element " + (audi
oElementCount + 1) + " at start of playback"); |
24 testElement = this; | 28 currentAudio.play(); |
25 testExpected(audioElementCount + ", testElement.currentTime", 0); | 29 }); |
26 this.play(); | |
27 } | |
28 | 30 |
29 function playingListener(event) | 31 audioElement.ontimeupdate = t.step_func(function(event) { |
30 { | 32 var currentAudio = event.target; |
31 consoleWrite("EVENT(" + audioElementCount + ", playing)"); | 33 assert_greater_than(currentAudio.currentTime, 0, "audio element " +
(audioElementCount + 1) + " during playback"); |
32 } | 34 currentAudio.ontimeupdate = null; |
33 | 35 if (++audioElementCount == maxPlayers) { |
34 function timeupdateListener(event) | 36 // All audio elements have been started playing. |
35 { | 37 // Make sure all of them are still playing. |
36 testElement = this; | |
37 testExpected(audioElementCount + ", testElement.currentTime", 0, '>'
); | |
38 this.removeEventListener('timeupdate', timeupdateListener); | |
39 if (++audioElementCount >= maxPlayers) { | |
40 // All audio elements have been started playing. Make sure | |
41 // all of them are still playing. | |
42 consoleWrite("Making sure all " + maxPlayers + " audio elements
are in playing state:"); | |
43 for (var i = 0; i < maxPlayers; i++) { | 38 for (var i = 0; i < maxPlayers; i++) { |
44 testElement = document.getElementsByTagName('audio')[i]; | 39 currentAudio = document.getElementsByTagName('audio')[i]; |
45 testExpected(i + ", testElement.paused", false); | 40 assert_false(currentAudio.paused, "audio element " + (i + 1)
+ " during playback"); |
46 } | 41 } |
47 endTest(); | 42 t.done(); |
48 } else { | 43 } else { |
49 // Start the next audio element | 44 // Start the next audio element. |
50 testAudioElement(audioElementCount); | 45 testAudioElement(audioElementCount); |
51 } | 46 } |
52 } | 47 }); |
53 | 48 |
54 function testAudioElement(count) | 49 audioElement.src = findMediaFile("audio", "content/silence"); |
55 { | 50 } |
56 var audioElement = document.getElementsByTagName('audio')[count]; | 51 }); |
57 audioElement.addEventListener('error', errorListener); | 52 </script> |
58 audioElement.addEventListener('canplaythrough', canplaythroughListen
er); | |
59 audioElement.addEventListener('timeupdate', timeupdateListener); | |
60 audioElement.addEventListener('playing', playingListener); | |
61 audioElement.src = findMediaFile("audio", "content/silence"); | |
62 } | |
63 | |
64 consoleWrite("Starting a total of " + maxPlayers + " concurrent audio el
ements."); | |
65 for (var i = 0; i < maxPlayers; i++) | |
66 document.write("<audio controls></audio>"); | |
67 | |
68 testAudioElement(0); | |
69 </script> | |
70 | |
71 </body> | |
72 </html> | |
OLD | NEW |