Assert play promise rejected caused by pause()

This commit is contained in:
CYBAI 2018-10-14 15:03:06 +08:00
parent 445c1d0706
commit 0284afc51a
4 changed files with 29 additions and 25 deletions

View file

@ -14,26 +14,28 @@
</video>
<div id="log"></div>
<script>
test(function() {
var t = async_test("calling play() then pause() on non-autoplay audio should trigger pause event", {timeout:5000});
promise_test(function(t) {
var async_t = async_test("calling play() then pause() on non-autoplay audio should trigger pause event", {timeout:5000});
var a = document.getElementById("a");
a.addEventListener("pause", function() {
t.done();
async_t.done();
}, false);
a.src = getAudioURI("/media/sound_5") + "?" + new Date() + Math.random();
a.play();
var play_promise = a.play();
a.pause();
return promise_rejects(t, "AbortError", play_promise, "pause() should reject all pending play Promises");
}, "audio events - pause");
test(function() {
var t = async_test("calling play() then pause() on non-autoplay video should trigger pause event", {timeout:5000});
promise_test(function(t) {
var async_t = async_test("calling play() then pause() on non-autoplay video should trigger pause event", {timeout:5000});
var v = document.getElementById("v");
v.addEventListener("pause", function() {
t.done();
async_t.done();
}, false);
v.src = getVideoURI("/media/movie_5") + "?" + new Date() + Math.random();
v.play();
var play_promise = v.play()
v.pause();
return promise_rejects(t, "AbortError", play_promise, "pause() should reject all pending play Promises");
}, "video events - pause");
</script>
</body>

View file

@ -14,26 +14,26 @@
</video>
<div id="log"></div>
<script>
test(function() {
var t = async_test("calling play() on audio should trigger play event", {timeout:5000});
promise_test(function(t) {
var async_t = async_test("calling play() on audio should trigger play event", {timeout:5000});
var a = document.getElementById("a");
a.addEventListener("play", function() {
t.done();
a.addEventListener("play", async_t.step_func(function() {
a.pause();
}, false);
async_t.done();
}), false);
a.src = getAudioURI("/media/sound_5") + "?" + new Date() + Math.random();
a.play();
return promise_rejects(t, "AbortError", a.play(), "pause() should reject all pending play Promises");
}, "audio events - play");
test(function() {
var t = async_test("calling play() on video should trigger play event", {timeout:5000});
promise_test(function(t) {
var async_t = async_test("calling play() on video should trigger play event", {timeout:5000});
var v = document.getElementById("v");
v.addEventListener("play", function() {
t.done();
v.addEventListener("play", async_t.step_func(function() {
v.pause();
}, false);
async_t.done();
}), false);
v.src = getVideoURI("/media/movie_5") + "?" + new Date() + Math.random();
v.play();
return promise_rejects(t, "AbortError", v.play(), "pause() should reject all pending play Promises");
}, "video events - play");
</script>
</body>

View file

@ -21,10 +21,11 @@ test(function() {
t.step(function() {
assert_true(a.paused);
});
t.done();
}, false);
a.src = getAudioURI("/media/sound_5") + "?" + new Date() + Math.random();
a.play();
a.play().catch(() => {});
a.pause();
}, "audio events - paused property");
@ -35,10 +36,11 @@ test(function() {
t.step(function() {
assert_true(v.paused);
});
t.done();
}, false);
v.src = getVideoURI("/media/movie_5") + "?" + new Date() + Math.random();
v.play();
v.play().catch(() => {});
v.pause();
}, "video events - paused property");
</script>