OLD | NEW |
1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
2 | 2 <title>Tests that we don't garbage collect audio object while it is still playin
g.</title> |
3 <html> | 3 <script src="media-file.js"></script> |
4 <body> | 4 <script src="../resources/gc.js"></script> |
5 | 5 <script src="../resources/testharness.js"></script> |
6 <p>Tests that we don't garbage collect playing audio object or event listener.</
p> | 6 <script src="../resources/testharnessreport.js"></script> |
7 <p>According to http://www.whatwg.org/specs/web-apps/current-work/multipage/the-
video-element.html,<br /> | 7 <script> |
8 "4.8.10.8 Playing the media resource",<br /> | 8 // According to http://www.whatwg.org/specs/web-apps/current-work/multipage/the-
video-element.html, |
9 "Media elements must not stop playing just because all references to them have | 9 // 4.8.10.8 Playing the media resource, |
10 been removed; only once a media element is in a state where no further audio | 10 // Media elements must not stop playing just because all references to them have |
11 could ever be played by that element may the element be garbage collected."<br /
><br /> | 11 // been removed; only once a media element is in a state where no further audio |
12 (see https://bugs.webkit.org/show_bug.cgi?id=66878, https://bugs.webkit.org/show
_bug.cgi?id=70421, and http://crbug.com/62604 for more details).</p> | 12 // could ever be played by that element may the element be garbage collected. |
13 <p id="result"> | 13 // see https://bugs.webkit.org/show_bug.cgi?id=66878, https://bugs.webkit.org/sh
ow_bug.cgi?id=70421, |
14 FAIL: Test either still running or stopped prematurely. | 14 // and http://crbug.com/62604 for more details). |
15 </p> | 15 async_test(function(t) { |
16 | 16 var audioPlayers = 4; |
17 <script src=../resources/gc.js></script> | 17 var playedCount = 0; |
18 <script src=media-file.js></script> | |
19 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 | |
20 (Please avoid writing new tests using video-test.js) --> | |
21 <script src=video-test.js></script> | |
22 <script type="text/javascript"> | |
23 | |
24 var num_players = 4; | |
25 var play_times = 5; | |
26 | |
27 function finish() { | |
28 document.getElementById("result").innerText = "PASS"; | |
29 if (window.testRunner) { | |
30 testRunner.notifyDone(); | |
31 } | |
32 } | |
33 | |
34 function start() { | |
35 var num_played = 0; | |
36 var audioFile = findMediaFile("audio", "content/silence"); | 18 var audioFile = findMediaFile("audio", "content/silence"); |
37 var a = new Audio(audioFile); | 19 var audio = new Audio(audioFile); |
38 a.addEventListener('ended', function() { | 20 |
39 num_played ++; | 21 audio.onended = t.step_func(function() { |
40 if (num_played < play_times) { | 22 playedCount ++; |
41 a.currentTime = a.duration - 0.35; | 23 if (playedCount <= audioPlayers) { |
42 a.play(); | 24 audio.currentTime = audio.duration - 0.35; |
43 if (num_played == play_times - 1) { | 25 audio.play(); |
44 a = null; | 26 if (playedCount == audioPlayers) { |
| 27 audio = null; |
45 gc(); | 28 gc(); |
46 } | 29 } |
47 } else { | 30 } else { |
48 num_players --; | 31 t.done(); |
49 if (num_players == 0) | |
50 start(); | |
51 else | |
52 finish(); | |
53 } | 32 } |
54 }); | 33 }); |
55 | 34 |
56 waitForEvent('canplaythrough', function() { | 35 audio.oncanplaythrough = t.step_func(function() { |
57 a.currentTime = a.duration - 0.35; | 36 audio.oncanplaythrough = null; |
58 a.play(); | 37 audio.currentTime = audio.duration - 0.35; |
59 }, false, true, a, true); | 38 audio.play(); |
60 } | 39 }); |
61 | 40 }); |
62 start(); | 41 </script> |
63 | |
64 </script> | |
65 </body> | |
66 </html> | |
OLD | NEW |