WEFT_OS/tests/frame/confinement/index.html

115 lines
4 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>confinement</title>
<style>
@import url('@HTTP@style.css');
@font-face { font-family: probe; src: url('@HTTP@font.woff'); }
html, body { margin: 0; height: 100%; }
body { display: flex; flex-direction: column; font-family: probe; }
div { flex: 1; background: #808080; }
iframe { position: absolute; width: 1px; height: 1px; border: 0; }
</style>
<script>
// A srcdoc frame holds this page's content and must not reach the engine's
// privileged navigator.servo interface; it reports what it sees.
var srcdocReport = null;
addEventListener('message', function (event) {
if (typeof event.data === 'string' && event.data.indexOf('servo:') === 0) {
srcdocReport = event.data;
}
});
</script>
</head>
<body>
<div id="own-image"></div>
<div id="bridge"></div>
<div id="outside-image"></div>
<div id="other-image"></div>
<div id="linked-image"></div>
<div id="http-image"></div>
<div id="http-fetch"></div>
<div id="websocket"></div>
<div id="worker-fetch"></div>
<div id="srcdoc-internals"></div>
<span>probe</span>
<script type="text/plain" id="worker-source">
// Reports whether a fetch to the URL it is sent leaves the worker.
onmessage = function (event) {
fetch(event.data, { mode: 'no-cors' }).then(
function () { postMessage('fetched'); },
function () { postMessage('refused'); });
};
</script>
<iframe srcdoc="<img src='@HTTP@srcdoc.png'><script>parent.postMessage('servo:' + typeof navigator.servo, '*');</script>"></iframe>
<script>
// One band per probe: green when the outcome matches the policy, red when it
// does not. Every refused probe would succeed without the policy: the images
// are valid PNG files, the fetches use no-cors, so an opaque response would
// resolve them, and the WebSocket listener completes the handshake. The
// stylesheet import, the font, the frame's image and the beacon have no band;
// the harness requires that none of them reaches its server. The harness
// substitutes the server URLs and the path of a file outside the package.
var HTTP = '@HTTP@';
var WS = '@WS@';
var OTHER = '@OTHER_URL@';
var WORKER = document.getElementById('worker-source').textContent;
function mark(id, ok) {
document.getElementById(id).style.background = ok ? '#00c000' : '#e00000';
}
function image(id, src, shouldLoad) {
var img = new Image();
img.onload = function () { mark(id, shouldLoad); };
img.onerror = function () { mark(id, !shouldLoad); };
img.src = src;
}
image('own-image', 'own.png', true);
image('outside-image', '../outside.png', false);
image('other-image', OTHER, false);
image('linked-image', 'linked/other.png', false);
image('http-image', HTTP + 'image.png', false);
fetch(HTTP + 'probe', { mode: 'no-cors' }).then(
function () { mark('http-fetch', false); },
function () { mark('http-fetch', true); });
try {
var ws = new WebSocket(WS);
ws.onopen = function () { mark('websocket', false); };
ws.onerror = function () { mark('websocket', true); };
} catch (e) {
mark('websocket', true);
}
try {
// A worker must never fetch past the policy. Servo currently refuses
// worker scripts for file: pages, blob: ones included, so the worker does
// not start; that also keeps it from fetching.
var worker = new Worker(URL.createObjectURL(new Blob([WORKER], { type: 'text/javascript' })));
worker.onmessage = function (event) { mark('worker-fetch', event.data === 'refused'); };
worker.onerror = function () { mark('worker-fetch', true); };
worker.postMessage(HTTP + 'worker');
} catch (e) {
mark('worker-fetch', true);
}
(function srcdoc() {
if (srcdocReport === null) { setTimeout(srcdoc, 50); return; }
mark('srcdoc-internals', srcdocReport === 'servo:undefined');
})();
try { navigator.sendBeacon(HTTP + 'beacon', 'probe'); } catch (e) {}
(function bridge() {
if (!window.weftIpc) { setTimeout(bridge, 50); return; }
window.weftIpc.onmessage = function (raw) {
try { mark('bridge', typeof JSON.parse(raw).count === 'number'); } catch (_) {}
};
window.weftIpc.send('get');
})();
</script>
</body>
</html>