2d.layer.malformed-operations.html (3192B)
1 <!DOCTYPE html> 2 <!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. --> 3 <meta charset="UTF-8"> 4 <title>OffscreenCanvas test: 2d.layer.malformed-operations</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/html/canvas/resources/canvas-tests.js"></script> 8 9 <h1>2d.layer.malformed-operations</h1> 10 11 <script> 12 13 test(t => { 14 const canvas = new OffscreenCanvas(200, 200); 15 const ctx = canvas.getContext('2d'); 16 17 // Shouldn't throw on its own. 18 ctx.createPattern(canvas, 'repeat'); 19 // Make sure the exception isn't caused by calling the function twice. 20 ctx.createPattern(canvas, 'repeat'); 21 // Calling again inside a layer should throw. 22 ctx.beginLayer(); 23 assert_throws_dom("InvalidStateError", 24 () => ctx.createPattern(canvas, 'repeat')); 25 }, "Throws if createPattern is called while layers are open."); 26 27 test(t => { 28 const canvas = new OffscreenCanvas(200, 200); 29 const ctx = canvas.getContext('2d'); 30 31 const canvas2 = new OffscreenCanvas(200, 200); 32 const ctx2 = canvas2.getContext('2d'); 33 // Shouldn't throw on its own. 34 ctx2.drawImage(canvas, 0, 0); 35 // Make sure the exception isn't caused by calling the function twice. 36 ctx2.drawImage(canvas, 0, 0); 37 // Calling again inside a layer should throw. 38 ctx.beginLayer(); 39 assert_throws_dom("InvalidStateError", 40 () => ctx2.drawImage(canvas, 0, 0)); 41 }, "Throws if drawImage is called while layers are open."); 42 43 test(t => { 44 const canvas = new OffscreenCanvas(200, 200); 45 const ctx = canvas.getContext('2d'); 46 47 // Shouldn't throw on its own. 48 ctx.getImageData(0, 0, 200, 200); 49 // Make sure the exception isn't caused by calling the function twice. 50 ctx.getImageData(0, 0, 200, 200); 51 // Calling again inside a layer should throw. 52 ctx.beginLayer(); 53 assert_throws_dom("InvalidStateError", 54 () => ctx.getImageData(0, 0, 200, 200)); 55 }, "Throws if getImageData is called while layers are open."); 56 57 test(t => { 58 const canvas = new OffscreenCanvas(200, 200); 59 const ctx = canvas.getContext('2d'); 60 61 const canvas2 = new OffscreenCanvas(200, 200); 62 const ctx2 = canvas2.getContext('2d') 63 const data = ctx2.getImageData(0, 0, 1, 1); 64 // Shouldn't throw on its own. 65 ctx.putImageData(data, 0, 0); 66 // Make sure the exception isn't caused by calling the function twice. 67 ctx.putImageData(data, 0, 0); 68 // Calling again inside a layer should throw. 69 ctx.beginLayer(); 70 assert_throws_dom("InvalidStateError", 71 () => ctx.putImageData(data, 0, 0)); 72 }, "Throws if putImageData is called while layers are open."); 73 74 test(t => { 75 const canvas = new OffscreenCanvas(200, 200); 76 const ctx = canvas.getContext('2d'); 77 78 // Shouldn't throw on its own. 79 canvas.transferToImageBitmap(); 80 // Make sure the exception isn't caused by calling the function twice. 81 canvas.transferToImageBitmap(); 82 // Calling again inside a layer should throw. 83 ctx.beginLayer(); 84 assert_throws_dom("InvalidStateError", 85 () => canvas.transferToImageBitmap()); 86 }, "Throws if transferToImageBitmap is called while layers are open."); 87 88 </script>