test_context_configure.html (2365B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" href="/tests/SimpleTest/test.css" /> 7 </head> 8 <body> 9 <script> 10 ok( 11 SpecialPowers.getBoolPref("dom.webgpu.enabled"), 12 "Pref should be enabled." 13 ); 14 15 async function testBody() { 16 const canvas = document.createElement("canvas"); 17 const context = canvas.getContext("webgpu"); 18 19 // The first two tests here are redundant with the CTS test 20 // webgpu:web_platform,canvas,configure:device:*, but when 21 // they were added, that CTS test had additional checks that 22 // were still failing. 23 let expectedError; 24 try { 25 context.configure({}); 26 } catch (error) { 27 expectedError = error; 28 } 29 is( 30 expectedError?.name, 31 "TypeError", 32 "Canvas configure without a device should generate a TypeError." 33 ); 34 35 const adapter = await navigator.gpu.requestAdapter({}); 36 const device = await adapter.requestDevice({}); 37 const format = navigator.gpu.getPreferredCanvasFormat(adapter); 38 39 expectedError = undefined; 40 try { 41 context.getCurrentTexture(); 42 } catch (error) { 43 expectedError = error; 44 } 45 is( 46 expectedError?.name, 47 "InvalidStateError", 48 "getCurrentTexture on unconfigured canvas should generate an InvalidStateError." 49 ); 50 51 // Attempt to configure with a too-large canvas, which should 52 // fail due to device texture limits. 53 canvas.width = 1970696937; 54 expectedError = undefined; 55 try { 56 context.configure({ 57 device, 58 format, 59 }); 60 } catch (error) { 61 expectedError = error; 62 } 63 // Bug 1967833: This should become an "is". Or possibly it 64 // should expect a validation error (asynchronously) instead. 65 todo_is( 66 expectedError?.name, 67 "TypeError", 68 "Failed configure should generate a TypeError." 69 ); 70 } 71 72 SimpleTest.waitForExplicitFinish(); 73 testBody() 74 .catch(e => ok(false, "Unhandled exception " + e)) 75 .finally(() => SimpleTest.finish()); 76 </script> 77 </body> 78 </html>