summaryrefslogtreecommitdiffstats
path: root/dom/media/autoplay/test/mochitest/AutoplayTestUtils.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/media/autoplay/test/mochitest/AutoplayTestUtils.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/autoplay/test/mochitest/AutoplayTestUtils.js')
-rw-r--r--dom/media/autoplay/test/mochitest/AutoplayTestUtils.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/dom/media/autoplay/test/mochitest/AutoplayTestUtils.js b/dom/media/autoplay/test/mochitest/AutoplayTestUtils.js
new file mode 100644
index 0000000000..aa8990c9d9
--- /dev/null
+++ b/dom/media/autoplay/test/mochitest/AutoplayTestUtils.js
@@ -0,0 +1,46 @@
+/* import-globals-from ../../../test/manifest.js */
+
+function playAndPostResult(muted, parent_window) {
+ let element = document.createElement("video");
+ element.preload = "auto";
+ element.muted = muted;
+ element.src = "short.mp4";
+ element.id = "video";
+ document.body.appendChild(element);
+ element.play().then(
+ () => {
+ parent_window.postMessage(
+ { played: true, allowedToPlay: element.allowedToPlay },
+ "*"
+ );
+ },
+ () => {
+ parent_window.postMessage(
+ { played: false, allowedToPlay: element.allowedToPlay },
+ "*"
+ );
+ }
+ );
+}
+
+function nextWindowMessage() {
+ return nextEvent(window, "message");
+}
+
+function log(msg) {
+ var log_pane = document.body;
+ log_pane.appendChild(document.createTextNode(msg));
+ log_pane.appendChild(document.createElement("br"));
+}
+
+const autoplayPermission = "autoplay-media";
+
+async function pushAutoplayAllowedPermission() {
+ return SpecialPowers.pushPermissions([
+ {
+ type: autoplayPermission,
+ allow: true,
+ context: document,
+ },
+ ]);
+}