| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <body> |
| <script> |
| var ctx = document.createElement('canvas').getContext('2d'); |
| |
| function checkPixel(x, y, rgb) { |
| assert_array_equals(ctx.getImageData(x, y, 1, 1).data.slice(0,3), rgb); |
| } |
| |
| test(function(t) { |
| |
| ctx.beginPath(); |
| ctx.scale(0.5, 0.5); |
| ctx.setTransform(1, 0, 0, 1, 0, 0); |
| ctx.fillStyle = 'green'; |
| ctx.fillRect(0, 0, 100, 100); |
| checkPixel(2, 1, [0, 128, 0]); |
| |
| ctx.beginPath(); |
| ctx.rect(0, 0, 100, 100); |
| ctx.save(); |
| ctx.setTransform(0.5, 0, 0, 0.5, 10, 10); |
| ctx.fillStyle = 'red'; |
| ctx.fillRect(0, 0, 100, 100); |
| ctx.restore(); |
| ctx.fillStyle = 'green'; |
| ctx.fillRect(0, 0, 100, 100); |
| checkPixel(2, 1, [0, 128, 0]); |
| |
| ctx.beginPath(); |
| ctx.fillStyle = 'green'; |
| ctx.save(); |
| ctx.setTransform(0.5, 0, 0, 0.5, 0, 0); |
| ctx.fillStyle = 'red'; |
| ctx.fillRect(0, 0, 100, 100); |
| ctx.restore(); |
| ctx.fillRect(0, 0, 100, 100); |
| checkPixel(2, 1, [0, 128, 0]); |
| |
| ctx.beginPath(); |
| ctx.fillStyle = 'green'; |
| ctx.fillRect(0, 0, 100, 100); |
| ctx.setTransform(0, 0, 0, 0, 0, 0); |
| ctx.fillStyle = 'red'; |
| ctx.fillRect(0, 0, 100, 100); |
| checkPixel(2, 1, [0, 128, 0]); |
| |
| ctx.beginPath(); |
| ctx.resetTransform(); |
| ctx.save(); |
| ctx.setTransform(0, 0, 0, 0, 0, 0); |
| ctx.fillStyle = 'red'; |
| ctx.fillRect(0, 0, 100, 100); |
| ctx.restore(); |
| ctx.fillStyle = 'blue'; |
| ctx.fillRect(0, 0, 100, 100); |
| checkPixel(2, 1, [0, 0, 255]); |
| |
| ctx.beginPath(); |
| ctx.fillStyle = 'red'; |
| ctx.fillRect(0, 0, 100, 100); |
| ctx.setTransform(0, 0, 0, 0, 0, 0); |
| ctx.fillStyle = 'green'; |
| ctx.fillRect(0, 0, 100, 100); |
| ctx.setTransform(1, 0, 0, 1, 0, 0); |
| ctx.fillStyle = 'blue'; |
| ctx.fillRect(0, 0, 100, 100); |
| checkPixel(2, 1, [0, 0, 255]); |
| |
| }, "Series of tests to ensure correct behaviour of canvas.setTransform()"); |
| </script> |
| </body> |