diff options
Diffstat (limited to 'testing/web-platform/tests/html/canvas/element/manual/transformations/2d.transformation.getTransform.html')
-rw-r--r-- | testing/web-platform/tests/html/canvas/element/manual/transformations/2d.transformation.getTransform.html | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/canvas/element/manual/transformations/2d.transformation.getTransform.html b/testing/web-platform/tests/html/canvas/element/manual/transformations/2d.transformation.getTransform.html new file mode 100644 index 0000000000..664efd50e6 --- /dev/null +++ b/testing/web-platform/tests/html/canvas/element/manual/transformations/2d.transformation.getTransform.html @@ -0,0 +1,39 @@ +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<script> +// Ensure that context2d.getTransform works +const epsilon = 1e-5; +const canvas = document.createElement('canvas'); +const ctx = canvas.getContext('2d'); + +test(function(t) { + assert_array_equals(ctx.getTransform().toFloat32Array(), + [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], + "Assert that an untransformed matrix is identity"); + + ctx.scale(2, 3); + transform = ctx.getTransform(); + assert_array_equals(ctx.getTransform().toFloat32Array(), + [2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], + "Assert that context2d scaling works"); + + ctx.rotate(Math.PI/2); + transform = ctx.getTransform(); + assert_array_approx_equals(ctx.getTransform().toFloat32Array(), + [0, 3, 0, 0, -2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], epsilon, + "Assert that context2d rotate works"); + + ctx.translate(1, -1); + transform = ctx.getTransform(); + assert_array_approx_equals(ctx.getTransform().toFloat32Array(), + [0, 3, 0, 0, -2, 0, 0, 0, 0, 0, 1, 0, 2, 3, 0, 1], epsilon, + "Assert context2d translate works."); + + ctx.resetTransform(); + assert_array_equals(ctx.getTransform().toFloat32Array(), + [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], + "Assert that a reset matrix is identity"); +}, 'This test ensures that getTransform works correctly.'); +</script> +</body> |