OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>This test ensures that media element fires the "playing" event every time
it starts playing after eos. It also ensure that "pause" and "ended" events are
fired when media playback ends.</title> | 2 <title>This test ensures that media element fires the "playing" event every time
it starts playing after eos. It also ensure that "pause" and "ended" events are
fired when media playback ends.</title> |
3 <script src="../resources/testharness.js"></script> | 3 <script src="../resources/testharness.js"></script> |
4 <script src="../resources/testharnessreport.js"></script> | 4 <script src="../resources/testharnessreport.js"></script> |
5 <script src="media-file.js"></script> | 5 <script src="media-file.js"></script> |
6 <audio></audio> | 6 <audio></audio> |
7 <script> | 7 <script> |
8 // TODO(srirama.m): Modify the test to record events and check for order | |
9 // at the end of test. See autoplay-with-preload-none.html for help. | |
10 async_test(function(t) { | 8 async_test(function(t) { |
11 var loop = true; | 9 var loop = true; |
12 var audio = document.querySelector("audio"); | 10 var audio = document.querySelector("audio"); |
13 audio.src = findMediaFile("audio", "content/silence"); | 11 audio.src = findMediaFile("audio", "content/silence"); |
14 | 12 |
15 audio.onloadedmetadata = t.step_func(function() { | 13 var watcher = new EventWatcher(t, audio, ["loadedmetadata", "playing", "paus
e", "ended"]); |
16 audio.onplaying = t.step_func(mediaPlaying); | 14 watcher.wait_for("loadedmetadata").then(t.step_func(function() { |
17 | |
18 audio.onpause = t.step_func(function() { | |
19 assert_true(audio.paused); | |
20 }); | |
21 | |
22 audio.onended = t.step_func(function() { | |
23 assert_true(audio.ended, true); | |
24 | |
25 if (!loop) { | |
26 t.done(); | |
27 return; | |
28 } | |
29 | |
30 loop = false; | |
31 audio.onplaying = t.step_func(mediaPlaying); | |
32 audio.play(); | |
33 }); | |
34 | |
35 audio.play(); | 15 audio.play(); |
36 }); | 16 return watcher.wait_for("playing"); |
37 | 17 })).then(t.step_func(function() { |
38 function mediaPlaying() { | |
39 audio.onplaying = null; | |
40 audio.currentTime = audio.duration - 0.2; | 18 audio.currentTime = audio.duration - 0.2; |
41 } | 19 return watcher.wait_for("playing"); |
| 20 })).then(t.step_func(function() { |
| 21 return watcher.wait_for("pause"); |
| 22 })).then(t.step_func(function() { |
| 23 assert_true(audio.paused); |
| 24 return watcher.wait_for("ended"); |
| 25 })).then(t.step_func(function() { |
| 26 assert_true(audio.ended); |
| 27 audio.play(); |
| 28 return watcher.wait_for("playing"); |
| 29 })).then(t.step_func(function() { |
| 30 audio.currentTime = audio.duration - 0.2; |
| 31 return watcher.wait_for("playing"); |
| 32 })).then(t.step_func(function() { |
| 33 return watcher.wait_for("pause"); |
| 34 })).then(t.step_func(function() { |
| 35 assert_true(audio.paused); |
| 36 return watcher.wait_for("ended"); |
| 37 })).then(t.step_func_done()); |
42 }); | 38 }); |
43 </script> | 39 </script> |
OLD | NEW |