diff --git a/dom/media/test/background_video.js b/dom/media/test/background_video.js index 90922a1ebfb1..66b36e58a9e8 100644 --- a/dom/media/test/background_video.js +++ b/dom/media/test/background_video.js @@ -48,6 +48,26 @@ function appendVideoToDoc(url, token, width, height) { return v; } +function appendVideoToDocWithoutLoad(token, width, height) { + // Default size of (160, 120) is used by other media tests. + if (width === undefined) { width = 160; } + if (height === undefined) { height = 3*width/4; } + + let v = document.createElement('video'); + v.token = token; + document.body.appendChild(v); + v.width = width; + v.height = height; + return v; +} + +function loadAndWaitUntilLoadedmetadata(video, url, preloadType = "metadata") { + return new Promise((resolve, reject) => { + video.preload = preloadType; + video.addEventListener("loadedmetadata", () => { resolve(); }, true); + video.src = url; + }); +} /** * @param {HTMLMediaElement} video Video element with under test. diff --git a/dom/media/test/test_background_video_resume_after_end_show_last_frame.html b/dom/media/test/test_background_video_resume_after_end_show_last_frame.html index 1fd5a2f1897b..df668fbb95c3 100644 --- a/dom/media/test/test_background_video_resume_after_end_show_last_frame.html +++ b/dom/media/test/test_background_video_resume_after_end_show_last_frame.html @@ -89,27 +89,6 @@ function waitUntilSeekToLastFrame(video) { }); } -function appendVideoToDocWithoutLoad(token, width, height) { - // Default size of (160, 120) is used by other media tests. - if (width === undefined) { width = 160; } - if (height === undefined) { height = 3*width/4; } - - let v = document.createElement('video'); - v.token = token; - document.body.appendChild(v); - v.width = width; - v.height = height; - return v; -} - -function loadAndWaitUntilLoadedmetadata(video, url, preloadType = "metadata") { - return new Promise((resolve, reject) => { - video.preload = preloadType; - video.addEventListener("loadedmetadata", () => { resolve(); }, true); - video.src = url; - }); -} - startTest({ desc: "Test resume an ended video shows the last frame.", prefs: [ diff --git a/dom/media/test/test_background_video_suspend.html b/dom/media/test/test_background_video_suspend.html index 786d4f9c058b..c5461c2eb84a 100644 --- a/dom/media/test/test_background_video_suspend.html +++ b/dom/media/test/test_background_video_suspend.html @@ -19,10 +19,10 @@ } async function runTest(test, token) { - let video = appendVideoToDoc(test.name, token); + let video = appendVideoToDocWithoutLoad(token); manager.started(token); - let visible = waitUntilVisible(video) + let visible = waitUntilVisible(video); let ended = nextVideoEnded(video); let playing = nextVideoPlaying(video); let resumes = nextVideoResumes(video); @@ -31,6 +31,9 @@ Log(token, "Waiting until video becomes visible"); await visible; + Log(token, "Waiting for metadata loaded"); + await loadAndWaitUntilLoadedmetadata(video, test.name); + Log(token, "Start playing"); video.play();