Commit 4343b675 authored by Chun-Min Chang's avatar Chun-Min Chang
Browse files

Bug 1774302 - Add a wpt posting VideoFrame across agent cluster boundaries r=padenot,smaug

Depends on D153686

Differential Revision: https://phabricator.services.mozilla.com/D159546
parent f9bcc8c6
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
[videoFrame-serialization.crossAgentCluster.html]
  prefs: [dom.media.webcodecs.enabled:true]
  expected:
    if (os == "android") and fission: [OK, TIMEOUT]
+23 −0
Original line number Diff line number Diff line
<!DOCTYPE html>
<html>
<body>
<p id='location'></p>
<div id='log'></div>
<script>
  document.querySelector('#location').innerHTML = window.origin;
  let received = new Map();
  window.onmessage = (e) => {
    let msg = e.data + ' (from ' + e.origin + ')';
    document.querySelector('#log').innerHTML += '<p>' + msg + '<p>';
    if (e.data.hasOwnProperty('id')) {
      e.source.postMessage(
        received.get(e.data.id) ? 'RECEIVED' : 'NOT_RECEIVED', '*');
      return;
    }
    if (e.data.toString() == '[object VideoFrame]') {
      received.set(e.data.timestamp, e.data);
    }
  };
</script>
</body>
</html>
+57 −0
Original line number Diff line number Diff line
<!DOCTYPE html>
<html>
<head>
  <script src='/resources/testharness.js'></script>
  <script src='/resources/testharnessreport.js'></script>
  <script src='/common/get-host-info.sub.js'></script>
</head>
<body>
<script>
const HELPER = '/webcodecs/videoFrame-serialization.crossAgentCluster.helper.html';
const SAMEORIGIN_BASE = get_host_info().HTTP_ORIGIN;
const CROSSORIGIN_BASE = get_host_info().HTTP_NOTSAMESITE_ORIGIN;
const SAMEORIGIN_HELPER = SAMEORIGIN_BASE + HELPER;
const CROSSORIGIN_HELPER = CROSSORIGIN_BASE + HELPER;

promise_test(async () => {
  const target = (await appendIframe(SAMEORIGIN_HELPER)).contentWindow;
  let frame = createVideoFrame(10);
  assert_true(await canSendVideoFrame(target, frame));
}, 'Verify frames can be passed within the same agent clusters');

promise_test(async () => {
  const target = (await appendIframe(CROSSORIGIN_HELPER)).contentWindow;
  let frame = createVideoFrame(20);
  assert_false(await canSendVideoFrame(target, frame));
}, 'Verify frames cannot be passed accross the different agent clusters');

function appendIframe(src) {
  const frame = document.createElement('iframe');
  document.body.appendChild(frame);
  frame.src = src;
  return new Promise(resolve => frame.onload = () => resolve(frame));
};

function createVideoFrame(ts) {
  let data = new Uint8Array([
    1, 2, 3, 4, 5, 6, 7, 8,
    9, 10, 11, 12, 13, 14, 15, 16,
  ]);
  return new VideoFrame(data, {
    timestamp: ts,
    codedWidth: 2,
    codedHeight: 2,
    format: 'RGBA',
  });
}

function canSendVideoFrame(target, vf) {
  target.postMessage(vf, '*');
  target.postMessage({'id': vf.timestamp}, '*');
  return new Promise(resolve => window.onmessage = e => {
    resolve(e.data == 'RECEIVED');
  });
};
</script>
</body>
</html>