OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>Test "ended" event fires again after changing source after "ended" event.
</title> |
3 <head> | 3 <script src="../resources/testharness.js"></script> |
4 <script src=media-file.js></script> | 4 <script src="../resources/testharnessreport.js"></script> |
5 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 | 5 <script src="media-file.js"></script> |
6 (Please avoid writing new tests using video-test.js) --> | 6 <audio autoplay></audio> |
7 <script src=video-test.js></script> | 7 <script> |
| 8 async_test(function(t) { |
| 9 var endedCount = 0; |
| 10 var audio = document.querySelector("audio"); |
8 | 11 |
9 <script> | 12 audio.onended = t.step_func(function() { |
10 var endedCount = 0; | 13 switch (++endedCount) |
11 var canplaythroughCount = 0; | 14 { |
12 var audio; | 15 case 1: |
| 16 assert_greater_than(audio.playbackRate, 0); |
| 17 assert_true(audio.ended); |
13 | 18 |
14 function start() | 19 // Verify ended stays true even if playbackRate == 0 |
15 { | 20 // since that is technically still "forward". |
16 audio = document.querySelector("audio"); | 21 audio.playbackRate = 0; |
17 waitForEvent("ended", ended); | 22 assert_true(audio.ended); |
18 | 23 |
19 audio.src = findMediaFile("audio", "content/silence") | 24 // Verify "backward" playback causes ended to become false. |
20 } | 25 audio.playbackRate = -0.1; |
| 26 assert_false(audio.ended); |
21 | 27 |
22 function ended() | 28 // Change src but don't seek so that internal state isn't reset. |
23 { | 29 audio.src = findMediaFile("audio", "content/silence"); |
24 switch (++endedCount) | 30 assert_false(audio.ended); |
25 { | |
26 case 1: | |
27 testExpected("audio.playbackRate", 0, ">"); | |
28 testExpected("audio.ended", true); | |
29 | 31 |
30 // Verify ended stays true even if playbackRate == 0 | 32 break; |
31 // since that is technically still "forward". | 33 case 2: |
32 run("audio.playbackRate = 0"); | 34 assert_true(audio.ended); |
33 testExpected("audio.ended", true); | 35 t.done(); |
| 36 break; |
| 37 } |
| 38 }); |
34 | 39 |
35 // Verify "backward" playback causes ended to become fal
se. | 40 audio.src = findMediaFile("audio", "content/silence") |
36 run("audio.playbackRate = -0.1"); | 41 }); |
37 testExpected("audio.ended", false); | 42 </script> |
38 | |
39 | |
40 // Change src but don't seek so that internal state isn'
t reset. | |
41 audio.src = findMediaFile("audio", "content/silence") | |
42 testExpected("audio.ended", false); | |
43 | |
44 consoleWrite(""); | |
45 break; | |
46 case 2: | |
47 testExpected("audio.ended", true); | |
48 endTest(); | |
49 break; | |
50 } | |
51 } | |
52 </script> | |
53 </head> | |
54 <body onload="start()"> | |
55 <audio controls autoplay></audio> | |
56 <p><b>Test ended by:</b> | |
57 <ol> | |
58 <li>Play to the end.</li> | |
59 <li>When 'ended' event fires, change the source.</li> | |
60 <li>Verify that 'ended' event fires again on different source.</li> | |
61 </ol> | |
62 </p> | |
63 </body> | |
64 </html> | |
OLD | NEW |