Remove some support for < iOS 13
[WebKit-https.git] / LayoutTests / inspector / canvas / shaderProgram-add-remove-webgpu.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
5 <script src="resources/shaderProgram-utilities-webgpu.js"></script>
6 <script>
7 window.beforeTest = async function() {
8     await Promise.all([
9         createComputePipeline("INVALID"),
10         createRenderPipeline("INVALID", "INVALID"),
11     ]);
12 };
13
14 function test() {
15     let suite = InspectorTest.createAsyncSuite(`Canvas.ShaderProgram.WebGPU`);
16
17     let canvas = WI.canvasManager.canvases[0];
18     InspectorTest.assert(canvas, "There should be a canvas.");
19     InspectorTest.assert(WI.canvasManager.canvases.length === 1, "There should only be one canvas.");
20     InspectorTest.assert(canvas.contextType === WI.Canvas.ContextType.WebGPU, "Canvas should be WebGPU.");
21
22     async function awaitProgramAdded(programType) {
23         return new Promise((resolve, reject) => {
24             let listenerItemAdded = canvas.shaderProgramCollection.addEventListener(WI.Collection.Event.ItemAdded, (event) => {
25                 let program = event.data.item;
26                 if (program.programType !== programType)
27                     return;
28
29                 InspectorTest.expectThat(program instanceof WI.ShaderProgram, `Added "${programType}" ShaderProgram.`);
30                 InspectorTest.assert(program.canvas === canvas, "ShaderProgram should be for the known Canvas.");
31
32                 resolve(program);
33             });
34         });
35     }
36
37     suite.addTestCase({
38         name: "Canvas.ShaderProgram.WebGPU.Existing",
39         description: "Check that ShaderProgramAdded is sent for a program created before CanvasAgent is enabled.",
40         async test() {
41             async function checkExists(programType) {
42                 if (InspectorTest.ShaderProgram.programForType(programType)) {
43                     InspectorTest.pass(`Added "${programType}" ShaderProgram.`);
44                     return;
45                 }
46
47                 await awaitProgramAdded(programType);
48             }
49
50             await Promise.all([
51                 checkExists(WI.ShaderProgram.ProgramType.Compute),
52                 checkExists(WI.ShaderProgram.ProgramType.Render),
53             ]);
54
55             InspectorTest.expectEqual(canvas.shaderProgramCollection.size, 2, "There should be two ShaderProgram.");
56         }
57     });
58
59     suite.addTestCase({
60         name: "Canvas.ShaderProgram.WebGPU.Added.Compute.Valid",
61         description: "Check that added/removed events are sent.",
62         async test() {
63             await Promise.all([
64                 awaitProgramAdded(WI.ShaderProgram.ProgramType.Compute),
65                 InspectorTest.evaluateInPage(`createComputePipeline()`),
66             ]);
67         }
68     });
69
70     suite.addTestCase({
71         name: "Canvas.ShaderProgram.WebGPU.Added.Compute.Invalid",
72         description: "Check that added/removed events are sent.",
73         async test() {
74             let shaderProgramAdded = false;
75
76             let listener = canvas.shaderProgramCollection.singleFireEventListener(WI.Collection.Event.ItemAdded, (event) => {
77                 shaderProgramAdded = true;
78             });
79
80             await InspectorTest.evaluateInPage(`createComputePipeline("INVALID")`);
81
82             canvas.shaderProgramCollection.removeEventListener(WI.Collection.Event.ItemAdded, listener);
83             InspectorTest.expectFalse(shaderProgramAdded, "Should not create a ShaderProgram for an invalid descriptor.");
84         }
85     });
86
87     suite.addTestCase({
88         name: "Canvas.ShaderProgram.WebGPU.Added.Render.Valid",
89         description: "Check that added/removed events are sent.",
90         async test() {
91             await Promise.all([
92                 awaitProgramAdded(WI.ShaderProgram.ProgramType.Render),
93                 InspectorTest.evaluateInPage(`createRenderPipeline()`),
94             ]);
95         }
96     });
97
98     suite.addTestCase({
99         name: "Canvas.ShaderProgram.WebGPU.Added.Render.Invalid",
100         description: "Check that added/removed events are sent.",
101         async test() {
102             let shaderProgramAdded = false;
103
104             let listener = canvas.shaderProgramCollection.singleFireEventListener(WI.Collection.Event.ItemAdded, (event) => {
105                 shaderProgramAdded = true;
106             });
107
108             await InspectorTest.evaluateInPage(`createRenderPipeline("INVALID", "INVALID")`);
109
110             canvas.shaderProgramCollection.removeEventListener(WI.Collection.Event.ItemAdded, listener);
111             InspectorTest.expectFalse(shaderProgramAdded, "Should not create a ShaderProgram for an invalid descriptor.");
112         }
113     });
114
115     suite.addTestCase({
116         name: "Canvas.ShaderProgram.WebGPU.ParentDeviceRemoved",
117         description: "Check that the ShaderProgram is removed before it's parent Canvas.",
118         test(resolve, reject) {
119             let canvasRemoved = false;
120
121             WI.canvasManager.singleFireEventListener(WI.CanvasManager.Event.CanvasRemoved, (event) => {
122                 canvasRemoved = true;
123             });
124
125             let shaderProgramCount = canvas.shaderProgramCollection.size;
126             let listenerItemRemoved = canvas.shaderProgramCollection.addEventListener(WI.Collection.Event.ItemRemoved, (event) => {
127                 if (--shaderProgramCount)
128                     return;
129
130                 canvas.shaderProgramCollection.removeEventListener(WI.Collection.Event.ItemRemoved, listenerItemRemoved);
131                 InspectorTest.expectFalse(canvasRemoved, "Removed ShaderProgram before Canvas.");
132                 resolve();
133             });
134
135             InspectorTest.evaluateInPage(`deleteDevice()`);
136         }
137     });
138
139     suite.runTestCasesAndFinish();
140 }
141 </script>
142 </head>
143 <body onload="load()">
144     <p>Test that CanvasManager tracks creation and destruction of WebGPU shader programs.</p>
145 </body>
146 </html>