diff options
Diffstat (limited to 'testing/web-platform/tests/html/canvas/element/manual/transformations')
7 files changed, 162 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> diff --git a/testing/web-platform/tests/html/canvas/element/manual/transformations/canvas_transformations_reset_001-ref.html b/testing/web-platform/tests/html/canvas/element/manual/transformations/canvas_transformations_reset_001-ref.html new file mode 100644 index 0000000000..caeea04cef --- /dev/null +++ b/testing/web-platform/tests/html/canvas/element/manual/transformations/canvas_transformations_reset_001-ref.html @@ -0,0 +1,21 @@ +<!DOCTYPE html> +<html> +<body> +<style> + html, body, div { + margin: 0; + padding: 0; + } + div { + width: 75px; + height: 75px; + float: left; + } +</style> + +<div style="background-color:red"></div> +<div style="clear:left"></div> +<div style="background-color:blue"></div> + +</body> +</html> diff --git a/testing/web-platform/tests/html/canvas/element/manual/transformations/canvas_transformations_reset_001.html b/testing/web-platform/tests/html/canvas/element/manual/transformations/canvas_transformations_reset_001.html new file mode 100644 index 0000000000..c12acbf6f3 --- /dev/null +++ b/testing/web-platform/tests/html/canvas/element/manual/transformations/canvas_transformations_reset_001.html @@ -0,0 +1,22 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<link rel="match" href="canvas_transformations_reset_001-ref.html"> +<style> + html, body { + margin: 0; + padding: 0; + } +</style> +<canvas id="c" width="150" height="150"></canvas> +<script> +var c = document.getElementById("c"); +var ctx = c.getContext("2d"); + +ctx.translate(75, 75); +ctx.fillStyle = 'blue'; +ctx.fillRect(0, 0, 75, 75); + +ctx.resetTransform(); +ctx.fillStyle = 'red'; +ctx.fillRect(0, 0, 75, 75); +</script> diff --git a/testing/web-platform/tests/html/canvas/element/manual/transformations/canvas_transformations_scale_001-ref.htm b/testing/web-platform/tests/html/canvas/element/manual/transformations/canvas_transformations_scale_001-ref.htm new file mode 100644 index 0000000000..1201bcca9f --- /dev/null +++ b/testing/web-platform/tests/html/canvas/element/manual/transformations/canvas_transformations_scale_001-ref.htm @@ -0,0 +1,11 @@ +<!doctype HTML> +<html> + <head> + <title>HTML5 Canvas Test: scale() transformation</title> + <link rel="author" title="Microsoft" href="http://www.microsoft.com" /> + </head> + <body> + <p>Description: The scale(x, y) method must add the scaling transformation described by the arguments to the transformation matrix.</p> + <div><img alt='black rectangle' src="/images/black-rectangle.png"></div> + </body> +</html> diff --git a/testing/web-platform/tests/html/canvas/element/manual/transformations/canvas_transformations_scale_001.htm b/testing/web-platform/tests/html/canvas/element/manual/transformations/canvas_transformations_scale_001.htm new file mode 100644 index 0000000000..73f71351ea --- /dev/null +++ b/testing/web-platform/tests/html/canvas/element/manual/transformations/canvas_transformations_scale_001.htm @@ -0,0 +1,31 @@ +<!doctype HTML> + +<html> + <head> + <title>HTML5 Canvas Test: scale() transformation</title> + <link rel="match" href="canvas_transformations_scale_001-ref.htm"> + <link rel="author" title="Microsoft" href="http://www.microsoft.com" /> + <link rel="help" href="http://www.w3.org/TR/2dcontext/#dom-context-2d-scale" /> + <meta name="assert" content="The scale(x, y) method must add the scaling transformation described by the arguments to the transformation matrix." /> + <script type="text/javascript"> + function runTest() + { + var canvas = document.getElementById("canvas1"); + var ctx = canvas.getContext("2d"); + + // Draw a red rectangle. + ctx.fillStyle = "rgba(255, 0, 0, 1.0)"; + ctx.fillRect(0, 0, 100, 50); + + // Draw a black rectangle with scaling. + ctx.fillStyle = "rgba(0, 0, 0, 1.0)"; + ctx.scale(2, 2); + ctx.fillRect(0, 0, 50, 25); + } + </script> + </head> + <body onload="runTest()"> + <p>Description: The scale(x, y) method must add the scaling transformation described by the arguments to the transformation matrix.</p> + <canvas id="canvas1" width="300" height="150">Browser does not support HTML5 Canvas.</canvas> + </body> +</html> diff --git a/testing/web-platform/tests/html/canvas/element/manual/transformations/transform_a.html b/testing/web-platform/tests/html/canvas/element/manual/transformations/transform_a.html new file mode 100644 index 0000000000..8c1f59efda --- /dev/null +++ b/testing/web-platform/tests/html/canvas/element/manual/transformations/transform_a.html @@ -0,0 +1,22 @@ +<!doctype html> +<meta charset=utf-8> +<link rel=match href=transform_ref.html> +<style> +html, body { + margin: 0; +} +</style> +<canvas id=c width=400 height=300></canvas> +<script> +var canvas = document.getElementById('c'); +var ctx = canvas.getContext('2d'); +ctx.scale(3, 3); +ctx.fillStyle = 'rgb(255, 0, 0)'; +ctx.beginPath(); +ctx.moveTo(10, 10); +ctx.bezierCurveTo(10, 10, 20, 10, 20, 10); +ctx.bezierCurveTo(20, 10, 20, 20, 20, 20); +ctx.bezierCurveTo(20, 20, 10, 20, 10, 20); +ctx.closePath(); +ctx.fill(); +</script> diff --git a/testing/web-platform/tests/html/canvas/element/manual/transformations/transform_ref.html b/testing/web-platform/tests/html/canvas/element/manual/transformations/transform_ref.html new file mode 100644 index 0000000000..2a166c36ce --- /dev/null +++ b/testing/web-platform/tests/html/canvas/element/manual/transformations/transform_ref.html @@ -0,0 +1,16 @@ +<!doctype html> +<meta charset=utf-8> +<style> +html, body { + margin: 0; +} +section { + position: absolute; + background: rgb(255, 0, 0); + width: 30px; + height: 30px; + top: 30px; + left: 30px; +} +</style> +<section></section> |