tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

videoFrame-serialization.crossAgentCluster.https.html (2198B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <script src='/resources/testharness.js'></script>
      5  <script src='/resources/testharnessreport.js'></script>
      6  <script src='/common/get-host-info.sub.js'></script>
      7  <script src='/webcodecs/utils.js'></script>
      8 </head>
      9 <body>
     10 <script>
     11 const HELPER = '/webcodecs/videoFrame-serialization.crossAgentCluster.helper.html';
     12 const CROSSORIGIN_BASE = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
     13 const CROSSORIGIN_HELPER = CROSSORIGIN_BASE + HELPER;
     14 
     15 promise_test(async (t) => {
     16  const target = (await appendIframe(CROSSORIGIN_HELPER)).contentWindow;
     17  let frame = createVideoFrame(t, 20);
     18  assert_false(await canSerializeVideoFrame(target, frame));
     19 }, 'Verify frames cannot be passed accross the different agent clusters');
     20 
     21 promise_test(async (t) => {
     22  const target = (await appendIframe(CROSSORIGIN_HELPER)).contentWindow;
     23  let frame = createVideoFrame(t, 80);
     24  assert_false(await canTransferVideoFrame(target, frame));
     25 }, 'Verify frames cannot be transferred accross the different agent clusters');
     26 
     27 function appendIframe(src) {
     28  const frame = document.createElement('iframe');
     29  document.body.appendChild(frame);
     30  frame.src = src;
     31  return new Promise(resolve => frame.onload = () => resolve(frame));
     32 };
     33 
     34 function createVideoFrame(test, timestamp) {
     35  let data = new Uint8Array([
     36    1, 2, 3, 4, 5, 6, 7, 8,
     37    9, 10, 11, 12, 13, 14, 15, 16,
     38  ]);
     39  const frame = new VideoFrame(data, {
     40    timestamp,
     41    codedWidth: 2,
     42    codedHeight: 2,
     43    format: 'RGBA',
     44  });
     45  test.add_cleanup(() => frame.close());
     46  return frame;
     47 }
     48 
     49 function canSerializeVideoFrame(target, vf) {
     50  return canPostVideoFrame(target, vf, false);
     51 };
     52 
     53 function canTransferVideoFrame(target, vf) {
     54  return canPostVideoFrame(target, vf, true);
     55 };
     56 
     57 function canPostVideoFrame(target, vf, transfer) {
     58  if (transfer) {
     59    target.postMessage(vf, '*', [vf]);
     60    assert_true(isFrameClosed(vf));
     61  } else {
     62    target.postMessage(vf, '*');
     63  }
     64  // vf.timestamp doesn't change after vf is closed, so it's fine to use it.
     65  target.postMessage({'id': vf.timestamp}, '*');
     66  return new Promise(resolve => window.onmessage = e => {
     67    resolve(e.data == 'RECEIVED');
     68  });
     69 };
     70 </script>
     71 </body>
     72 </html>