diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
commit | da4c7e7ed675c3bf405668739c3012d140856109 (patch) | |
tree | cdd868dba063fecba609a1d819de271f0d51b23e /dom/media/test/browser | |
parent | Adding upstream version 125.0.3. (diff) | |
download | firefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip |
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/test/browser')
-rw-r--r-- | dom/media/test/browser/browser_glean_first_frame_loaded_time.js | 12 | ||||
-rw-r--r-- | dom/media/test/browser/head.js | 118 |
2 files changed, 91 insertions, 39 deletions
diff --git a/dom/media/test/browser/browser_glean_first_frame_loaded_time.js b/dom/media/test/browser/browser_glean_first_frame_loaded_time.js index 1acfa9957e..2ee5274dae 100644 --- a/dom/media/test/browser/browser_glean_first_frame_loaded_time.js +++ b/dom/media/test/browser/browser_glean_first_frame_loaded_time.js @@ -17,7 +17,7 @@ const testCases = [ key_system: undefined, }, async run(tab) { - await loadVideo(tab); + await loadVideo(tab, "mozfirstframeloadedprobe"); }, }, { @@ -28,7 +28,7 @@ const testCases = [ key_system: undefined, }, async run(tab) { - await loadMseVideo(tab); + await loadMseVideo(tab, "mozfirstframeloadedprobe"); }, }, { @@ -39,11 +39,17 @@ const testCases = [ key_system: "org.w3.clearkey", }, async run(tab) { - await loadEmeVideo(tab); + await loadEmeVideo(tab, "mozfirstframeloadedprobe"); }, }, ]; +add_task(async function setTestPref() { + await SpecialPowers.pushPrefEnv({ + set: [["media.testing-only-events", true]], + }); +}); + add_task(async function testGleanMediaPlayackFirstFrameLoaded() { for (let test of testCases) { Services.fog.testResetFOG(); diff --git a/dom/media/test/browser/head.js b/dom/media/test/browser/head.js index 7ef578a804..489d107be5 100644 --- a/dom/media/test/browser/head.js +++ b/dom/media/test/browser/head.js @@ -13,60 +13,94 @@ function openTab() { // Creates and configures a video element for non-MSE playback in `tab`. Does not // start playback for the element. Returns a promise that will resolve once // the element is setup and ready for playback. -function loadVideo(tab) { - return SpecialPowers.spawn(tab.linkedBrowser, [], async _ => { - let video = content.document.createElement("video"); - video.id = "media"; - content.document.body.appendChild(video); +function loadVideo(tab, extraEvent = undefined) { + return SpecialPowers.spawn( + tab.linkedBrowser, + [extraEvent], + async _extraEvent => { + let video = content.document.createElement("video"); + video.id = "media"; + content.document.body.appendChild(video); - video.src = "gizmo.mp4"; - video.load(); + video.src = "gizmo.mp4"; + video.load(); - info(`waiting 'loadeddata' event to ensure playback is ready`); - await new Promise(r => (video.onloadeddata = r)); - }); + info(`waiting 'loadeddata' event to ensure playback is ready`); + let promises = []; + promises.push(new Promise(r => (video.onloadeddata = r))); + if (_extraEvent != undefined) { + info( + `waiting '${_extraEvent}' event to ensure the probe has been recorded` + ); + promises.push( + new Promise(r => + video.addEventListener(_extraEvent, r, { once: true }) + ) + ); + } + await Promise.allSettled(promises); + } + ); } // Creates and configures a video element for MSE playback in `tab`. Does not // start playback for the element. Returns a promise that will resolve once // the element is setup and ready for playback. -function loadMseVideo(tab) { - return SpecialPowers.spawn(tab.linkedBrowser, [], async _ => { - async function once(target, name) { - return new Promise(r => target.addEventListener(name, r, { once: true })); - } +function loadMseVideo(tab, extraEvent = undefined) { + return SpecialPowers.spawn( + tab.linkedBrowser, + [extraEvent], + async _extraEvent => { + async function once(target, name) { + return new Promise(r => + target.addEventListener(name, r, { once: true }) + ); + } - let video = content.document.createElement("video"); - video.id = "media"; - content.document.body.appendChild(video); + let video = content.document.createElement("video"); + video.id = "media"; + content.document.body.appendChild(video); - info(`starting setup MSE`); - const ms = new content.wrappedJSObject.MediaSource(); - video.src = content.wrappedJSObject.URL.createObjectURL(ms); - await once(ms, "sourceopen"); - const sb = ms.addSourceBuffer("video/mp4"); - const videoFile = "bipbop2s.mp4"; - let fetchResponse = await content.fetch(videoFile); - sb.appendBuffer(await fetchResponse.arrayBuffer()); - await once(sb, "updateend"); - ms.endOfStream(); - await once(ms, "sourceended"); + info(`starting setup MSE`); + const ms = new content.wrappedJSObject.MediaSource(); + video.src = content.wrappedJSObject.URL.createObjectURL(ms); + await once(ms, "sourceopen"); + const sb = ms.addSourceBuffer("video/mp4"); + const videoFile = "bipbop2s.mp4"; + let fetchResponse = await content.fetch(videoFile); + sb.appendBuffer(await fetchResponse.arrayBuffer()); + await once(sb, "updateend"); + ms.endOfStream(); + await once(ms, "sourceended"); - info(`waiting 'loadeddata' event to ensure playback is ready`); - await once(video, "loadeddata"); - }); + info(`waiting 'loadeddata' event to ensure playback is ready`); + let promises = []; + promises.push(once(video, "loadeddata")); + if (_extraEvent != undefined) { + info( + `waiting '${_extraEvent}' event to ensure the probe has been recorded` + ); + promises.push( + new Promise(r => + video.addEventListener(_extraEvent, r, { once: true }) + ) + ); + } + await Promise.allSettled(promises); + } + ); } // Creates and configures a video element for EME playback in `tab`. Does not // start playback for the element. Returns a promise that will resolve once // the element is setup and ready for playback. -function loadEmeVideo(tab) { +function loadEmeVideo(tab, extraEvent = undefined) { const emeHelperUri = gTestPath.substr(0, gTestPath.lastIndexOf("/")) + "/eme_standalone.js"; return SpecialPowers.spawn( tab.linkedBrowser, - [emeHelperUri], - async _emeHelperUri => { + [emeHelperUri, extraEvent], + async (_emeHelperUri, _extraEvent) => { async function once(target, name) { return new Promise(r => target.addEventListener(name, r, { once: true }) @@ -113,7 +147,19 @@ function loadEmeVideo(tab) { await once(ms, "sourceended"); info(`waiting 'loadeddata' event to ensure playback is ready`); - await once(video, "loadeddata"); + let promises = []; + promises.push(once(video, "loadeddata")); + if (_extraEvent != undefined) { + info( + `waiting '${_extraEvent}' event to ensure the probe has been recorded` + ); + promises.push( + new Promise(r => + video.addEventListener(_extraEvent, r, { once: true }) + ) + ); + } + await Promise.allSettled(promises); } ); } |