<!DOCTYPE html>
<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>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<audio></audio>
<script>
async_test(function(t) {
var loop = true;
var audio = document.querySelector("audio");
audio.src = "content/silence.oga";
var watcher = new EventWatcher(t, audio, ["loadedmetadata", "playing", "pause", "ended"]);
watcher.wait_for("loadedmetadata").then(t.step_func(function() {
audio.play();
return watcher.wait_for("playing");
})).then(t.step_func(function() {
audio.currentTime = audio.duration - 0.2;
return watcher.wait_for("playing");
})).then(t.step_func(function() {
return watcher.wait_for("pause");
})).then(t.step_func(function() {
assert_true(audio.paused);
return watcher.wait_for("ended");
})).then(t.step_func(function() {
assert_true(audio.ended);
audio.play();
return watcher.wait_for("playing");
})).then(t.step_func(function() {
audio.currentTime = audio.duration - 0.2;
return watcher.wait_for("playing");
})).then(t.step_func(function() {
return watcher.wait_for("pause");
})).then(t.step_func(function() {
assert_true(audio.paused);
return watcher.wait_for("ended");
})).then(t.step_func_done());
});
</script>