gecko-dev/dom/canvas/test/test_offscreencanvas_sharedworker.html

62 lines
1.6 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML>
<html>
<head>
<title>WebGL in OffscreenCanvas</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
</head>
<body>
<script>
SimpleTest.waitForExplicitFinish();
function createCanvas() {
var htmlCanvas = document.createElement('canvas');
ok(htmlCanvas, "Should have HTML canvas element");
ok(htmlCanvas.transferControlToOffscreen,
"HTMLCanvasElement has transferControlToOffscreen function");
htmlCanvas.width = 64;
htmlCanvas.height = 64;
document.body.appendChild(htmlCanvas);
return htmlCanvas;
}
function transferCtrlToOffscreen(canvas) {
var offscreencanvas = canvas.transferControlToOffscreen();
ok(offscreencanvas, "Expected transferControlToOffscreen to succeed");
return offscreencanvas;
}
function testShareWorker(worker, canvasType) {
var offscreenCanvas = transferCtrlToOffscreen(createCanvas());
// We don't support transferring OffscreenCanvas via shared worker.
SimpleTest.doesThrow(
function() {
worker.port.postMessage({canvasType: canvasType, testType: 'basic',
canvas: offscreenCanvas}, [offscreenCanvas]);
},
"OffscreenCanvas cannot transfer to shared worker"
);
}
function runTest() {
var worker = new SharedWorker("offscreencanvas.js");
ok(worker, "Web worker successfully created");
worker.port.start();
testShareWorker(worker, '2d');
testShareWorker(worker, 'webgl');
SimpleTest.finish();
}
SpecialPowers.pushPrefEnv({'set': [
['gfx.offscreencanvas.enabled', true],
['webgl.force-enabled', true],
]}, runTest);
</script>
</body>
</html>