blob: bc181f62f2d4f43eb4a1abf1d9f836fce3d2bb5f [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="resources/create-context-utilities.css">
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script src="resources/create-context-utilities.js"></script>
<script>
if (window.internals)
window.internals.settings.setWebGPUEnabled(true);
function createDevice() {
function receivedDevice(device) {
window.contexts.push(device);
}
function receivedAdapter(adapter) {
adapter.requestDevice().then(receivedDevice);
}
navigator.gpu.requestAdapter().then(receivedAdapter);
}
function test() {
let suite = InspectorTest.CreateContextUtilities.initializeTestSuite("Canvas.CreateContextWebGPU");
InspectorTest.CreateContextUtilities.addSimpleTestCase({
name: "Device",
expression: `createDevice()`,
contextType: WI.Canvas.ContextType.WebGPU,
});
suite.addTestCase({
name: "Canvas.CreateContextWebGPU.Canvas.Attached",
description: "Ensure that attached GPUCanvasContext aren't tracked as a canvas, instead of the WebGPUDevice.",
async test() {
let created = false;
let listener = WI.canvasManager.addEventListener(WI.CanvasManager.Event.CanvasAdded, (event) => {
InspectorTest.assert(event.target.contextType === WI.Canvas.ContextType.WebGPU);
created = true;
});
await InspectorTest.evaluateInPage(`createAttachedCanvas("gpu")`)
WI.canvasManager.removeEventListener(WI.CanvasManager.Event.CanvasAdded, listener);
InspectorTest.expectFalse(created, "Inspector canvas should not be created for attached GPUCanvasContext without connected WebGPUDevice.");
},
});
suite.addTestCase({
name: "Canvas.CreateContextWebGPU.Canvas.Detached",
description: "Ensure that detached GPUCanvasContext aren't tracked as a canvas, instead of the WebGPUDevice.",
async test() {
let created = false;
let listener = WI.canvasManager.addEventListener(WI.CanvasManager.Event.CanvasAdded, (event) => {
InspectorTest.assert(event.target.contextType === WI.Canvas.ContextType.WebGPU);
created = true;
});
await InspectorTest.evaluateInPage(`createDetachedCanvas("gpu")`)
WI.canvasManager.removeEventListener(WI.CanvasManager.Event.CanvasAdded, listener);
InspectorTest.expectFalse(created, "Inspector canvas should not be created for detached GPUCanvasContext without connected WebGPUDevice.");
},
});
suite.addTestCase({
name: "Canvas.CreateContextWebGPU.Canvas.CSS",
description: "Ensure that CSS GPUCanvasContext aren't tracked as a canvas, instead of the WebGPUDevice.",
async test() {
let created = false;
let listener = WI.canvasManager.addEventListener(WI.CanvasManager.Event.CanvasAdded, (event) => {
InspectorTest.assert(event.target.contextType === WI.Canvas.ContextType.WebGPU);
created = true;
});
await InspectorTest.evaluateInPage(`createCSSCanvas("gpu", "css-canvas")`)
WI.canvasManager.removeEventListener(WI.CanvasManager.Event.CanvasAdded, listener);
InspectorTest.expectFalse(created, "Inspector canvas should not be created for CSS GPUCanvasContext without connected WebGPUDevice.");
},
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Test that CanvasManager tracks creation and destruction of WebGPU canvases.</p>
</body>
</html>