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
This commit is contained in:
Chun-Min Chang 2022-10-26 16:41:54 +00:00
Родитель f9bcc8c6af
Коммит 4343b67583
3 изменённых файлов: 85 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,5 @@
[videoFrame-serialization.crossAgentCluster.html]
prefs: [dom.media.webcodecs.enabled:true]
expected:
if (os == "android") and fission: [OK, TIMEOUT]

Просмотреть файл

@ -0,0 +1,23 @@
<!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>

Просмотреть файл

@ -0,0 +1,57 @@
<!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>