OLD | NEW |
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <script src="../../resources/testharness.js"></script> |
2 <html> | 2 <script src="../../resources/testharnessreport.js"></script> |
3 <head> | |
4 <script src="../../resources/js-test.js"></script> | |
5 </head> | |
6 <body> | 3 <body> |
7 <script src="script-tests/canvas-resetTransform.js"></script> | 4 <script> |
| 5 test(function(t) { |
| 6 |
| 7 var canvas = document.createElement('canvas'); |
| 8 document.body.appendChild(canvas); |
| 9 canvas.setAttribute('width', '100'); |
| 10 canvas.setAttribute('height', '100'); |
| 11 var ctx = canvas.getContext('2d'); |
| 12 |
| 13 ctx.save(); |
| 14 ctx.scale(0.5, 0.5); |
| 15 ctx.resetTransform(); |
| 16 ctx.fillStyle = 'green'; |
| 17 ctx.fillRect(0, 0, 100, 100); |
| 18 ctx.restore(); |
| 19 |
| 20 var imageData = ctx.getImageData(98, 98, 1, 1).data; |
| 21 assert_array_equals(imageData.slice(0, 3), [0, 128, 0]); |
| 22 |
| 23 ctx.save(); |
| 24 ctx.scale(0.5, 0.5); |
| 25 ctx.save(); |
| 26 ctx.resetTransform(); |
| 27 ctx.fillStyle = 'green'; |
| 28 ctx.fillRect(0, 0, 100, 100); |
| 29 ctx.restore(); |
| 30 ctx.fillStyle = 'red'; |
| 31 ctx.fillRect(0, 0, 100, 100); |
| 32 ctx.restore(); |
| 33 |
| 34 imageData = ctx.getImageData(98, 98, 1, 1).data; |
| 35 assert_array_equals(imageData.slice(0, 3), [0, 128, 0]); |
| 36 |
| 37 imageData = ctx.getImageData(48, 48, 1, 1).data; |
| 38 assert_array_equals(imageData.slice(0, 3), [255, 0, 0]); |
| 39 |
| 40 /* This should draw a green rectangle on on top of a red one. The red should
not be visible. */ |
| 41 ctx.save(); |
| 42 ctx.beginPath(); |
| 43 ctx.moveTo(0, 0); |
| 44 ctx.lineTo(100, 0); |
| 45 ctx.lineTo(100, 100); |
| 46 ctx.lineTo(0, 100); |
| 47 ctx.fillStyle = 'red'; |
| 48 ctx.fill(); |
| 49 ctx.translate(200, 0); |
| 50 ctx.resetTransform(); |
| 51 ctx.fillStyle = 'green'; |
| 52 ctx.fill(); |
| 53 ctx.restore(); |
| 54 |
| 55 imageData = ctx.getImageData(50, 50, 1, 1).data; |
| 56 assert_array_equals(imageData.slice(0, 3), [0, 128, 0]); |
| 57 |
| 58 ctx.save(); |
| 59 ctx.fillStyle = 'red'; |
| 60 ctx.fillRect(0, 0, 100, 100); |
| 61 ctx.beginPath(); |
| 62 ctx.moveTo(0, 0); |
| 63 ctx.lineTo(100, 0); |
| 64 ctx.lineTo(100, 100); |
| 65 ctx.lineTo(0, 100); |
| 66 ctx.scale(0, 0); |
| 67 ctx.resetTransform(); |
| 68 ctx.fillStyle = 'green'; |
| 69 ctx.fill(); |
| 70 ctx.restore(); |
| 71 |
| 72 imageData = ctx.getImageData(98, 98, 1, 1).data; |
| 73 assert_array_equals(imageData.slice(0, 3), [0, 128, 0]); |
| 74 |
| 75 ctx.save(); |
| 76 ctx.fillStyle = 'red'; |
| 77 ctx.fillRect(0, 0, 100, 100); |
| 78 ctx.beginPath(); |
| 79 ctx.moveTo(0, 0); |
| 80 ctx.lineTo(100, 0); |
| 81 ctx.lineTo(100, 50); |
| 82 ctx.scale(0, 0); |
| 83 ctx.lineTo(100, 100); |
| 84 ctx.resetTransform(); |
| 85 ctx.lineTo(0, 100); |
| 86 ctx.fillStyle = 'green'; |
| 87 ctx.fill(); |
| 88 ctx.restore(); |
| 89 |
| 90 imageData = ctx.getImageData(98, 98, 1, 1).data; |
| 91 assert_array_equals(imageData.slice(0, 3), [255, 0, 0]); |
| 92 |
| 93 imageData = ctx.getImageData(98, 48, 1, 1).data; |
| 94 assert_array_equals(imageData.slice(0, 3), [0, 128, 0]); |
| 95 }, "This test checks resetTransform in canvas v5"); |
| 96 </script> |
8 </body> | 97 </body> |
9 </html> | |
OLD | NEW |