blob: b140f118d0886cb75802fa1540ca5f8576ac6a01 [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.canvasCollection.addEventListener(WI.Collection.Event.ItemAdded, (event) => {
InspectorTest.assert(event.data.item.contextType === WI.Canvas.ContextType.WebGPU);
created = true;
});
await InspectorTest.evaluateInPage(`createAttachedCanvas("gpu")`)
WI.canvasManager.canvasCollection.removeEventListener(WI.Collection.Event.ItemAdded, 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.canvasCollection.addEventListener(WI.Collection.Event.ItemAdded, (event) => {
InspectorTest.assert(event.data.item.contextType === WI.Canvas.ContextType.WebGPU);
created = true;
});
await InspectorTest.evaluateInPage(`createDetachedCanvas("gpu")`)
WI.canvasManager.canvasCollection.removeEventListener(WI.Collection.Event.ItemAdded, 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.canvasCollection.addEventListener(WI.Collection.Event.ItemAdded, (event) => {
InspectorTest.assert(event.data.item.contextType === WI.Canvas.ContextType.WebGPU);
created = true;
});
await InspectorTest.evaluateInPage(`createCSSCanvas("gpu", "css-canvas")`)
WI.canvasManager.canvasCollection.removeEventListener(WI.Collection.Event.ItemAdded, 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>