2d.layer.malformed-operations.html (3446B)
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>Canvas 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 <link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css"> 9 10 <h1>2d.layer.malformed-operations</h1> 11 12 <script> 13 14 test(t => { 15 const canvas = document.createElement('canvas'); 16 canvas.width = 200; 17 canvas.height = 200; 18 const ctx = canvas.getContext('2d'); 19 20 // Shouldn't throw on its own. 21 ctx.createPattern(canvas, 'repeat'); 22 // Make sure the exception isn't caused by calling the function twice. 23 ctx.createPattern(canvas, 'repeat'); 24 // Calling again inside a layer should throw. 25 ctx.beginLayer(); 26 assert_throws_dom("InvalidStateError", 27 () => ctx.createPattern(canvas, 'repeat')); 28 }, "Throws if createPattern is called while layers are open."); 29 30 test(t => { 31 const canvas = document.createElement('canvas'); 32 canvas.width = 200; 33 canvas.height = 200; 34 const ctx = canvas.getContext('2d'); 35 36 const canvas2 = new OffscreenCanvas(200, 200); 37 const ctx2 = canvas2.getContext('2d'); 38 // Shouldn't throw on its own. 39 ctx2.drawImage(canvas, 0, 0); 40 // Make sure the exception isn't caused by calling the function twice. 41 ctx2.drawImage(canvas, 0, 0); 42 // Calling again inside a layer should throw. 43 ctx.beginLayer(); 44 assert_throws_dom("InvalidStateError", 45 () => ctx2.drawImage(canvas, 0, 0)); 46 }, "Throws if drawImage is called while layers are open."); 47 48 test(t => { 49 const canvas = document.createElement('canvas'); 50 canvas.width = 200; 51 canvas.height = 200; 52 const ctx = canvas.getContext('2d'); 53 54 // Shouldn't throw on its own. 55 ctx.getImageData(0, 0, 200, 200); 56 // Make sure the exception isn't caused by calling the function twice. 57 ctx.getImageData(0, 0, 200, 200); 58 // Calling again inside a layer should throw. 59 ctx.beginLayer(); 60 assert_throws_dom("InvalidStateError", 61 () => ctx.getImageData(0, 0, 200, 200)); 62 }, "Throws if getImageData is called while layers are open."); 63 64 test(t => { 65 const canvas = document.createElement('canvas'); 66 canvas.width = 200; 67 canvas.height = 200; 68 const ctx = canvas.getContext('2d'); 69 70 const canvas2 = new OffscreenCanvas(200, 200); 71 const ctx2 = canvas2.getContext('2d') 72 const data = ctx2.getImageData(0, 0, 1, 1); 73 // Shouldn't throw on its own. 74 ctx.putImageData(data, 0, 0); 75 // Make sure the exception isn't caused by calling the function twice. 76 ctx.putImageData(data, 0, 0); 77 // Calling again inside a layer should throw. 78 ctx.beginLayer(); 79 assert_throws_dom("InvalidStateError", 80 () => ctx.putImageData(data, 0, 0)); 81 }, "Throws if putImageData is called while layers are open."); 82 83 test(t => { 84 const canvas = document.createElement('canvas'); 85 canvas.width = 200; 86 canvas.height = 200; 87 const ctx = canvas.getContext('2d'); 88 89 // Shouldn't throw on its own. 90 canvas.toDataURL(); 91 // Make sure the exception isn't caused by calling the function twice. 92 canvas.toDataURL(); 93 // Calling again inside a layer should throw. 94 ctx.beginLayer(); 95 assert_throws_dom("InvalidStateError", 96 () => canvas.toDataURL()); 97 }, "Throws if toDataURL is called while layers are open."); 98 99 </script>