summaryrefslogtreecommitdiffstats
path: root/dom/media/autoplay/test/mochitest/AutoplayTestUtils.js
blob: aa8990c9d9127f64de8b33b413408cf14e6baaf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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,
    },
  ]);
}