blob: 5f04ba4e7d3b642a4e1f2b84bbcd508c2968311a [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<script>
description("The test to ensure that calling setTransform with a DOMMatrix works as expected.");
function shouldHaveMatrixEquality(matrixName, expected) {
shouldEvaluateTo(matrixName + ".a", expected[0]);
shouldEvaluateTo(matrixName + ".b", expected[1]);
shouldEvaluateTo(matrixName + ".c", expected[2]);
shouldEvaluateTo(matrixName + ".d", expected[3]);
shouldEvaluateTo(matrixName + ".e", expected[4]);
shouldEvaluateTo(matrixName + ".f", expected[5]);
}
var ctx = document.createElement("canvas").getContext("2d");
var originalTransform = ctx.getTransform();
shouldHaveMatrixEquality("originalTransform", [1, 0, 0, 1, 0, 0]);
ctx.resetTransform();
ctx.setTransform(new DOMMatrix([1, 2, 3, 4, 5, 6]));
var newTransformFromDOMMatrix = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromDOMMatrix", [1, 2, 3, 4, 5, 6]);
ctx.setTransform(1, 2, 3, 4, 5, 6);
ctx.setTransform(new DOMMatrix);
var newTransformFromEmptyDOMMatrix = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromEmptyDOMMatrix", [1, 0, 0, 1, 0, 0]);
ctx.resetTransform();
ctx.setTransform(new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]));
var newTransformFrom3dDOMMatrix = ctx.getTransform();
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m11", 1);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m12", 2);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m13", 0);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m14", 0);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m21", 5);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m22", 6);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m23", 0);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m24", 0);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m31", 0);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m32", 0);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m33", 1);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m34", 0);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m41", 13);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m42", 14);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m43", 0);
shouldEvaluateTo("newTransformFrom3dDOMMatrix.m44", 1);
ctx.setTransform(1, 2, 3, 4, 5, 6);
ctx.setTransform({});
var newTransformFromEmptyObject = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromEmptyObject", [1, 0, 0, 1, 0, 0]);
ctx.resetTransform();
ctx.setTransform({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6});
var newTransformFromObject = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromObject", [1, 2, 3, 4, 5, 6]);
ctx.setTransform(1, 2, 3, 4, 5, 6);
shouldThrowErrorName(function() {
ctx.setTransform({a: 1, m11: 11, b: 2, m12: 12, c: 3, m21: 21, d: 4, m22: 22, e: 5, m41: 41, f: 6, m42: 42});
}, "TypeError");
var newTransformFromInvalidMatrixObject = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromInvalidMatrixObject", [1, 2, 3, 4, 5, 6]);
ctx.setTransform(1, 2, 3, 4, 5, 6);
shouldThrowErrorName(function() {
ctx.setTransform(1);
}, "TypeError");
var newTransformFromNonObjectNumber = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromNonObjectNumber", [1, 2, 3, 4, 5, 6]);
ctx.setTransform(1, 2, 3, 4, 5, 6);
shouldThrowErrorName(function() {
ctx.setTransform("test");
}, "TypeError");
var newTransformFromNonObjectString = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromNonObjectString", [1, 2, 3, 4, 5, 6]);
ctx.setTransform(1, 2, 3, 4, 5, 6);
shouldThrowErrorName(function() {
ctx.setTransform(true);
}, "TypeError");
var newTransformFromNonObjectBoolean = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromNonObjectBoolean", [1, 2, 3, 4, 5, 6]);
ctx.setTransform(1, 2, 3, 4, 5, 6);
ctx.setTransform({a: {}});
var newTransformFromInvalidValueObject = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromInvalidValueObject", [1, 2, 3, 4, 5, 6]);
ctx.setTransform(1, 2, 3, 4, 5, 6);
ctx.setTransform({test: 1});
var newTransformFromInvalidKeyObject = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromInvalidKeyObject", [1, 0, 0, 1, 0, 0]);
ctx.setTransform(1, 2, 3, 4, 5, 6);
ctx.setTransform(null);
var newTransformFromNull = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromNull", [1, 0, 0, 1, 0, 0]);
ctx.setTransform(1, 2, 3, 4, 5, 6);
ctx.setTransform([]);
var newTransformFromEmptyArray = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromEmptyArray", [1, 0, 0, 1, 0, 0]);
ctx.setTransform(1, 2, 3, 4, 5, 6);
ctx.setTransform([1, 2, 3, 4, 5, 6]);
var newTransformFromArray = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromArray", [1, 0, 0, 1, 0, 0]);
ctx.setTransform(1, 2, 3, 4, 5, 6);
ctx.setTransform(["test"]);
var newTransformFromInvalidArray = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromInvalidArray", [1, 0, 0, 1, 0, 0]);
ctx.setTransform(1, 2, 3, 4, 5, 6);
ctx.setTransform();
var newTransformFromNoArgument = ctx.getTransform();
shouldHaveMatrixEquality("newTransformFromNoArgument", [1, 0, 0, 1, 0, 0]);
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>