From 9d7be35d148ef95711906a2062d74858bcba2cb8 Mon Sep 17 00:00:00 2001 From: alwu Date: Thu, 10 Dec 2020 14:58:46 +0000 Subject: [PATCH] Bug 1677880 - waiting 'timeupdate' to ensure video is still playing after resuming decoding. r=bryce In D96896, we chose to suspend video decoding before starting video in order to avoid the race where the video decode is completed by the time it should be suspended. However, it causes another issue which is affecting the play promise, because we would only resolve the play promise when we have enough data that is related with decoding. Therefore, in this patch, I choose not to wait until video reaches to the end, instead to wait `timeupdate` to ensure that the video is still playing after resuming video decoding. If we don't rely on looping to the end, then we don't need to start video from `3` second which is used to shorten the time before video reaches to the end. That gives us more time to reach the completed state (6s, the video's duration) which should prevent us hitting the race again. Differential Revision: https://phabricator.services.mozilla.com/D97800 --- ...eo_resume_looping_video_without_audio.html | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/dom/media/test/test_background_video_resume_looping_video_without_audio.html b/dom/media/test/test_background_video_resume_looping_video_without_audio.html index d90b7f54db6e..53b380ce15e7 100644 --- a/dom/media/test/test_background_video_resume_looping_video_without_audio.html +++ b/dom/media/test/test_background_video_resume_looping_video_without_audio.html @@ -16,14 +16,10 @@ */ async function startTest() { const video = await createVisibleVideo(); - // Start and immediately suspend the video to avoid races where the video - // decode is complete by the time it should be suspended. - await Promise.all([ - suspendVideoDecoding(video), - startVideo(video), - ]); + await startVideo(video); + await suspendVideoDecoding(video); await resumeVideoDecoding(video); - await waitUntilVideoLoopAgain(video); + await checkIfVideoIsStillPlaying(video); endTestAndClearVideo(video); } @@ -44,9 +40,6 @@ async function createVisibleVideo() { video.src = "gizmo-noaudio.webm"; video.controls = true; video.loop = true; - // In order to reduce the test running time, because we don't need to acutally - // go through the whole video. - video.currentTime = 3; document.body.appendChild(video); info(`ensure video becomes visible`); await waitUntilVisible(video); @@ -73,12 +66,9 @@ async function resumeVideoDecoding(video) { info(`resumed video decoding`); } -async function waitUntilVideoLoopAgain(video) { - info(`ensure video is still playing after resuming video decoding.`); - await once(video, "seeking"); - info(`got 'seeking' event.`); - await once(video, "seeked"); - ok(!video.paused, "video is still playing and looping again.") +async function checkIfVideoIsStillPlaying(video) { + await once(video, "timeupdate"); + ok(!video.paused, "video is still playing after resuming video decoding.") } function endTestAndClearVideo(video) {