1<!DOCTYPE HTML>
2
3<html>
4<body>
5
6<p>Tests that we don't garbage collect playing audio object or event listener.</p>
7<p>According to http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html,<br />
8"4.8.10.8 Playing the media resource",<br />
9"Media elements must not stop playing just because all references to them have
10been removed; only once a media element is in a state where no further audio
11could ever be played by that element may the element be garbage collected."<br /><br />
12(see https://bugs.webkit.org/show_bug.cgi?id=66878 and http://crbug.com/62604 for more details).</p>
13<p id="result">
14 FAIL: Test either still running or stopped prematurely.
15</p>
16
17<script src=media-file.js></script>
18<script src=video-test.js></script>
19<script type="text/javascript">
20
21var num_players = 4;
22var play_times = 5;
23
24var a;
25var num_played;
26var total_played = 0;
27
28function forceGC() {
29 if (window.GCController)
30 return GCController.collect();
31
32 // Force garbage collection
33 for (var ndx = 0; ndx < 99000; ndx ++)
34 var str = new String("1234");
35}
36
37function finish() {
38 document.getElementById("result").innerText = "PASS";
39 if (window.layoutTestController) {
40 layoutTestController.notifyDone();
41 }
42}
43
44function start() {
45 num_played = 0;
46 var audioFile = findMediaFile("audio", "content/click2");
47 a = new Audio(audioFile);
48 a.addEventListener('ended', function() {
49 num_played ++;
50 if (num_played < play_times) {
51 a.currentTime = 0;
52 a.play();
53 if (num_played == play_times - 1) {
54 a = null;
55 forceGC();
56 }
57 } else {
58 total_played ++;
59 if (total_played < num_players)
60 start();
61 else
62 finish();
63 }
64 });
65 a.addEventListener('canplaythrough', function() {
66 a.play();
67 });
68}
69
70start();
71
72</script>
73
74</body>
75</html>