blob: 0ee338062584798495828b4c6e3b465083f6b461 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/comparisons.js"></script>
<script>
var EPSILON = 10e-6; // Float epsilon
var testParams = [
{
input: new DOMMatrixReadOnly([0, 0, 0, 0, 0, 0]),
is2D: true,
cssText: "matrix(0, 0, 0, 0, 0, 0)"
},
{
input: new DOMMatrixReadOnly([2, 4, 6, 8, 10, 12]),
is2D: true,
cssText: "matrix(2, 4, 6, 8, 10, 12)"
},
{
input: new DOMMatrixReadOnly([-2, -4, -6, -8, -10, -12]),
is2D: true,
cssText: "matrix(-2, -4, -6, -8, -10, -12)"
},
{
input: new DOMMatrixReadOnly([1.1, -2.2, 3.3, -4.4, 5.5, 0.6]),
is2D: true,
cssText: "matrix(1.1, -2.2, 3.3, -4.4, 5.5, 0.6)"
},
{
input: new DOMMatrixReadOnly(
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
is2D: false,
cssText: "matrix3d(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)"
},
{
input: new DOMMatrixReadOnly(
[11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44]),
is2D: false,
cssText: "matrix3d(11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44)"
},
{
input: new DOMMatrixReadOnly(
[1.1, 1.2, -13, -1.4, 2, 0, -2, 4, 3.1, 3, 3, 3.4, -4.1, 42, 43, 4.4]),
is2D: false,
cssText: "matrix3d(1.1, 1.2, -13, -1.4, 2, 0, -2, 4, 3.1, 3, 3, 3.4, -4.1, 42, 43, 4.4)"
},
// Set is2D to true with options, while also passing a 3D matrix. Should be
// truncated for cssText.
{
input: new DOMMatrixReadOnly(
[11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44]),
is2D: true,
cssText: "matrix(11, 12, 21, 22, 41, 42)"
}
];
for (let params of testParams) {
let matrixComponent = new CSSMatrixComponent(params.input, {is2D: params.is2D});
test(() => {
assert_matrix_approx_equals(matrixComponent.matrix, params.input, EPSILON);
}, "matrix getter returns same matrix as the input for " + params.cssText);
test(() => {
assert_equals(matrixComponent.is2D, params.is2D);
}, "is2D value is correct for " + params.cssText);
}
test(() => {
assert_throws(new TypeError(), () => { new CSSMatrixComponent(); });
assert_throws(new TypeError(), () => { new CSSMatrixComponent(0); });
assert_throws(new TypeError(), () => { new CSSMatrixComponent("string") });
assert_throws(new TypeError(), () => { new CSSMatrixComponent(null); });
assert_throws(new TypeError(), () => { new CSSMatrixComponent(undefined); });
}, "invalid number of arguments to the constructor throws");
</script>