OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../../resources/testharness.js"></script> | 2 <script src="../../resources/testharness.js"></script> |
3 <script src="../../resources/testharnessreport.js"></script> | 3 <script src="../../resources/testharnessreport.js"></script> |
4 <script src="./resources/geometry-interfaces-test-helpers.js"></script> | 4 <script src="./resources/geometry-interfaces-test-helpers.js"></script> |
5 <script> | 5 <script> |
6 test(() => { | 6 test(() => { |
7 var matrix = new DOMMatrix(); | 7 var matrix = new DOMMatrix(); |
8 assert_identity_2d_matrix(matrix); | 8 assert_identity_2d_matrix(matrix); |
9 }, "DOMMatrix() constructor"); | 9 }, "DOMMatrix() constructor"); |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 }, "DOMMatrix fromFloat32Array - 3D matrix"); | 28 }, "DOMMatrix fromFloat32Array - 3D matrix"); |
29 | 29 |
30 test(() => { | 30 test(() => { |
31 // 10.1 and 16.6 are not representable as a 32-bit float | 31 // 10.1 and 16.6 are not representable as a 32-bit float |
32 var float64Array = new Float64Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 12,
13, 14, 15, 16.6]); | 32 var float64Array = new Float64Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 12,
13, 14, 15, 16.6]); |
33 var matrix3d = DOMMatrix.fromFloat64Array(float64Array); | 33 var matrix3d = DOMMatrix.fromFloat64Array(float64Array); |
34 assert_3d_matrix_equals(matrix3d, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 12, 13
, 14, 15, 16.6]); | 34 assert_3d_matrix_equals(matrix3d, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10.1, 11, 12, 13
, 14, 15, 16.6]); |
35 }, "DOMMatrix fromFloat64Array - 3D matrix"); | 35 }, "DOMMatrix fromFloat64Array - 3D matrix"); |
36 | 36 |
37 test(() => { | 37 test(() => { |
| 38 var matrix = new DOMMatrix(""); |
| 39 assert_identity_2d_matrix(matrix); |
| 40 }, "DOMMatrix(transformList) - emptyString"); |
| 41 |
| 42 test(() => { |
| 43 var matrix = new DOMMatrix("matrix(1.0, 2.0, 3.0, 4.0, 5.0, 6.0) translate(44p
x, 55px) skewX(30deg)"); |
| 44 var expectedMatrix = new DOMMatrix(); |
| 45 expectedMatrix.multiplySelf(new DOMMatrix([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])) |
| 46 expectedMatrix.translateSelf(44, 55) |
| 47 expectedMatrix.skewXSelf(30); |
| 48 assert_matrix_almost_equals(matrix, expectedMatrix); |
| 49 }, "DOMMatrix(transformList) - transformList"); |
| 50 |
| 51 test(() => { |
38 var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6]); | 52 var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6]); |
39 assert_2d_matrix_equals(matrix, [1, 2, 3, 4, 5, 6]); | 53 assert_2d_matrix_equals(matrix, [1, 2, 3, 4, 5, 6]); |
40 }, "DOMMatrix(numberSequence) constructor"); | 54 }, "DOMMatrix(numberSequence) constructor"); |
41 | 55 |
42 test(() => { | 56 test(() => { |
43 var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16]); | 57 var matrix = new DOMMatrix([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16]); |
44 assert_3d_matrix_equals(matrix, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
, 15, 16]); | 58 assert_3d_matrix_equals(matrix, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
, 15, 16]); |
45 }, "DOMMatrix(numberSequence) constructor"); | 59 }, "DOMMatrix(numberSequence) constructor"); |
46 | 60 |
47 test(() => { | 61 test(() => { |
(...skipping 12 matching lines...) Expand all Loading... |
60 assert_true(matrix.is2D); | 74 assert_true(matrix.is2D); |
61 assert_true(matrix.isIdentity); | 75 assert_true(matrix.isIdentity); |
62 matrix.m31 = 1; | 76 matrix.m31 = 1; |
63 matrix.m33 = 0; | 77 matrix.m33 = 0; |
64 assert_false(matrix.is2D); | 78 assert_false(matrix.is2D); |
65 assert_false(matrix.isIdentity); | 79 assert_false(matrix.isIdentity); |
66 matrix.m31 = 0; | 80 matrix.m31 = 0; |
67 matrix.m33 = 1; | 81 matrix.m33 = 1; |
68 assert_false(matrix.is2D); | 82 assert_false(matrix.is2D); |
69 assert_true(matrix.isIdentity); | 83 assert_true(matrix.isIdentity); |
70 }, "DOMMatrix.is2D can never be set to 'true' when it was set to 'false' before
calling setMatrixValue()."); | 84 }, "DOMMatrix.is2D can never be set to 'true' when it was set to 'false' before
calling setMatrixValue()"); |
71 | 85 |
72 test(() => { | 86 test(() => { |
73 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray([1, 2, 3, 4, 5])); }, | 87 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray([1, 2, 3, 4, 5])); }, |
74 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
."); | 88 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
"); |
75 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray([1, 2, 3, 4, 5])); }, | 89 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray([1, 2, 3, 4, 5])); }, |
76 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
."); | 90 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
"); |
77 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray([1, 2, 3, 4, 5, 6 ,7])); }, | 91 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray([1, 2, 3, 4, 5, 6 ,7])); }, |
78 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
."); | 92 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
"); |
79 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray([1, 2, 3, 4, 5, 6 ,7])); }, | 93 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray([1, 2, 3, 4, 5, 6 ,7])); }, |
80 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
."); | 94 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
"); |
81 }, "DOMMatrix fromFloat*Array - invalid array size of nearby 6"); | 95 }, "DOMMatrix fromFloat*Array - invalid array size of nearby 6"); |
82 | 96 |
83 test(() => { | 97 test(() => { |
84 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray([1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11, 12, 13, 14, 15])); }, | 98 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray([1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11, 12, 13, 14, 15])); }, |
85 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
."); | 99 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
"); |
86 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray([1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11, 12, 13, 14, 15])); }, | 100 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray([1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11, 12, 13, 14, 15])); }, |
87 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
."); | 101 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
"); |
88 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray([1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])); }, | 102 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray([1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])); }, |
89 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
."); | 103 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
"); |
90 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray([1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])); }, | 104 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray([1, 2, 3, 4, 5, 6 ,7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])); }, |
91 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
."); | 105 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
"); |
92 }, "DOMMatrix fromFloat*Array - invalid array size of nearby 16"); | 106 }, "DOMMatrix fromFloat*Array - invalid array size of nearby 16"); |
93 | 107 |
94 test(() => { | 108 test(() => { |
95 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray([])); }, | 109 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray([])); }, |
96 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
."); | 110 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
"); |
97 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray([])); }, | 111 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray([])); }, |
98 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
."); | 112 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
"); |
99 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray([1])); }, | 113 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray([1])); }, |
100 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
."); | 114 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
"); |
101 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray([1])); }, | 115 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray([1])); }, |
102 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
."); | 116 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
"); |
103 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray(65536)); }, | 117 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat32Array(new Float32A
rray(65536)); }, |
104 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
."); | 118 "fromFloat32Array function only accepts 1 Float32Array with 6 or 16 elements
"); |
105 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray(65536)); }, | 119 assert_throws(new TypeError(), () => { DOMMatrix.fromFloat64Array(new Float64A
rray(65536)); }, |
106 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
."); | 120 "fromFloat64Array function only accepts 1 Float64Array with 6 or 16 elements
"); |
107 }, "DOMMatrix fromFloat*Array - invalid array size"); | 121 }, "DOMMatrix fromFloat*Array - invalid array size"); |
108 | 122 |
109 test(() => { | 123 test(() => { |
110 assert_identity_2d_matrix(DOMMatrix.fromMatrix()); | 124 assert_identity_2d_matrix(DOMMatrix.fromMatrix()); |
111 }, "DOMMatrix.fromMatrix() with no parameter."); | 125 }, "DOMMatrix.fromMatrix() with no parameter"); |
112 | 126 |
113 test(() => { | 127 test(() => { |
114 assert_identity_2d_matrix(DOMMatrix.fromMatrix(null)); | 128 assert_identity_2d_matrix(DOMMatrix.fromMatrix(null)); |
115 }, "DOMMatrix.fromMatrix() with null."); | 129 }, "DOMMatrix.fromMatrix() with null"); |
116 | 130 |
117 test(() => { | 131 test(() => { |
118 assert_identity_2d_matrix(DOMMatrix.fromMatrix(undefined)); | 132 assert_identity_2d_matrix(DOMMatrix.fromMatrix(undefined)); |
119 }, "DOMMatrix.fromMatrix() with undefined."); | 133 }, "DOMMatrix.fromMatrix() with undefined"); |
120 | 134 |
121 test(() => { | 135 test(() => { |
122 assert_identity_2d_matrix(DOMMatrix.fromMatrix({})); | 136 assert_identity_2d_matrix(DOMMatrix.fromMatrix({})); |
123 }, "DOMMatrix.fromMatrix() with empty object."); | 137 }, "DOMMatrix.fromMatrix() with empty object"); |
124 | 138 |
125 test(() => { | 139 test(() => { |
126 var matrix = DOMMatrix.fromMatrix({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}); | 140 var matrix = DOMMatrix.fromMatrix({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}); |
127 assert_2d_matrix_equals(matrix, [1, 2, 3, 4, 5, 6]); | 141 assert_2d_matrix_equals(matrix, [1, 2, 3, 4, 5, 6]); |
128 }, "DOMMatrix.fromMatrix({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}) should create a 2
D DOMMatrix."); | 142 }, "DOMMatrix.fromMatrix({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}) should create a 2
D DOMMatrix"); |
129 | 143 |
130 test(() => { | 144 test(() => { |
131 var matrix = DOMMatrix.fromMatrix({m11: 1, m22: 2, m33: 3, m44: 4, m23: 5, m43
: 6}); | 145 var matrix = DOMMatrix.fromMatrix({m11: 1, m22: 2, m33: 3, m44: 4, m23: 5, m43
: 6}); |
132 assert_3d_matrix_equals(matrix, [1, 0, 0, 0, 0, 2, 5, 0, 0, 0, 3, 0, 0, 0, 6,
4]); | 146 assert_3d_matrix_equals(matrix, [1, 0, 0, 0, 0, 2, 5, 0, 0, 0, 3, 0, 0, 0, 6,
4]); |
133 }, "DOMMatrix.fromMatrix({m11: 1, m22: 2, m33: 3, m44: 4, m23: 5, m43: 6}) shoul
d create a 3D DOMMatrix."); | 147 }, "DOMMatrix.fromMatrix({m11: 1, m22: 2, m33: 3, m44: 4, m23: 5, m43: 6}) shoul
d create a 3D DOMMatrix"); |
134 | 148 |
135 test(() => { | 149 test(() => { |
136 var matrix = DOMMatrix.fromMatrix({a: 7, c: 9}); | 150 var matrix = DOMMatrix.fromMatrix({a: 7, c: 9}); |
137 assert_2d_matrix_equals(matrix, [7, 0, 9, 1, 0, 0]); | 151 assert_2d_matrix_equals(matrix, [7, 0, 9, 1, 0, 0]); |
138 }, "If 2d related properties don't be set, should set to fallback."); | 152 }, "If 2d related properties don't be set, should set to fallback"); |
139 | 153 |
140 test(() => { | 154 test(() => { |
141 var matrix = DOMMatrix.fromMatrix({ | 155 var matrix = DOMMatrix.fromMatrix({ |
142 m11: NaN, m12: NaN, m13: NaN, m14: NaN, | 156 m11: NaN, m12: NaN, m13: NaN, m14: NaN, |
143 m21: NaN, m22: NaN, m23: NaN, m24: NaN, | 157 m21: NaN, m22: NaN, m23: NaN, m24: NaN, |
144 m31: NaN, m32: NaN, m33: NaN, m34: NaN, | 158 m31: NaN, m32: NaN, m33: NaN, m34: NaN, |
145 m41: NaN, m42: NaN, m43: NaN, m44: NaN, | 159 m41: NaN, m42: NaN, m43: NaN, m44: NaN, |
146 is2D: false | 160 is2D: false |
147 }); | 161 }); |
148 assert_3d_matrix_equals(matrix, [NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN, NaN, NaN, NaN]); | 162 assert_3d_matrix_equals(matrix, [NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN, NaN, NaN, NaN]); |
(...skipping 29 matching lines...) Expand all Loading... |
178 assert_object_equals(matrix3d.toJSON(), | 192 assert_object_equals(matrix3d.toJSON(), |
179 { a : 1, b : 2, c : 5, d : 6, e : 13, f : 14, | 193 { a : 1, b : 2, c : 5, d : 6, e : 13, f : 14, |
180 is2D : false, isIdentity : false, | 194 is2D : false, isIdentity : false, |
181 m11 : 1, m12 : 2, m13 : 3, m14 : 4, | 195 m11 : 1, m12 : 2, m13 : 3, m14 : 4, |
182 m21 : 5, m22 : 6, m23 : 7, m24 : 8, | 196 m21 : 5, m22 : 6, m23 : 7, m24 : 8, |
183 m31 : 9, m32 : 10.1, m33 : 11, m34 : 12, | 197 m31 : 9, m32 : 10.1, m33 : 11, m34 : 12, |
184 m41 : 13, m42 : 14, m43 : 15, m44 : 16.6}); | 198 m41 : 13, m42 : 14, m43 : 15, m44 : 16.6}); |
185 }, "DOMMatrix toJSON() - 3D matrix"); | 199 }, "DOMMatrix toJSON() - 3D matrix"); |
186 | 200 |
187 test(() => { | 201 test(() => { |
| 202 assert_throws(new SyntaxError(), () => { new DOMMatrix(1, 2, 3, 4, 5, 6); }, |
| 203 "DOMMatrix(transformList) can't parse unknown keyword - DOMMatrixReadOnly(1,
2, 3, 4, 5, 6) is same with DOMMatrixReadOnly('1')"); |
| 204 assert_throws(new SyntaxError(), () => { new DOMMatrix("myString"); }, |
| 205 "DOMMatrix(transformList) can't parse unknown keyword"); |
| 206 assert_throws(new SyntaxError(), () => { new DOMMatrix("initial");}, |
| 207 "CSS-wide keywords are disallowed"); |
| 208 assert_throws(new SyntaxError(), () => { new DOMMatrix("notExistFunction()");
}, |
| 209 "can't parse not exist function"); |
| 210 assert_throws(new SyntaxError(), () => { new DOMMatrix("translateY(50%)"); }, |
| 211 "using relative units should throw a SyntaxError"); |
| 212 assert_throws(new SyntaxError(), () => { new DOMMatrix("translateX(1.2em)"); }
, |
| 213 "using relative units should throw a SyntaxError"); |
| 214 assert_throws(new SyntaxError(), () => { new DOMMatrix("translateX(10ex)"); }, |
| 215 "using relative units should throw a SyntaxError"); |
| 216 assert_throws(new SyntaxError(), () => { new DOMMatrix("translateX(10ch)"); }, |
| 217 "using relative units should throw a SyntaxError"); |
| 218 assert_throws(new SyntaxError(), () => { new DOMMatrix("translateX(10rem)"); }
, |
| 219 "using relative units should throw a SyntaxError"); |
| 220 assert_throws(new SyntaxError(), () => { new DOMMatrix("translateX(10vw)"); }, |
| 221 "using relative units should throw a SyntaxError"); |
| 222 assert_throws(new SyntaxError(), () => { new DOMMatrix("translateX(10vh)"); }, |
| 223 "using relative units should throw a SyntaxError"); |
| 224 assert_throws(new SyntaxError(), () => { new DOMMatrix("translateX(10vmin)");
}, |
| 225 "using relative units should throw a SyntaxError"); |
| 226 assert_throws(new SyntaxError(), () => { new DOMMatrix("translateX(10vmax)");
}, |
| 227 "using relative units should throw a SyntaxError"); |
| 228 assert_throws(new SyntaxError(), () => { new DOMMatrix("translateX(calc(10px +
1em))"); }, |
| 229 "using relative units should throw a SyntaxError"); |
188 assert_throws(new TypeError(), () => { | 230 assert_throws(new TypeError(), () => { |
189 var matrix = DOMMatrix.fromMatrix({a: 1, b: 2, m33: 3, m44: 4, is2D: true}); | 231 var matrix = DOMMatrix.fromMatrix({a: 1, b: 2, m33: 3, m44: 4, is2D: true}); |
190 }, "The 'is2D' property is set to true but the input matrix is 3d matrix."); | 232 }, "The 'is2D' property is set to true but the input matrix is 3d matrix"); |
191 assert_throws(new TypeError(), () => { | 233 assert_throws(new TypeError(), () => { |
192 var matrix = DOMMatrix.fromMatrix({a: 1, b: 2, m11: 3}); | 234 var matrix = DOMMatrix.fromMatrix({a: 1, b: 2, m11: 3}); |
193 }, "The 'a' property should equal the 'm11' property."); | 235 }, "The 'a' property should equal the 'm11' property"); |
194 }, "DOMMatrix.fromMatrix(): Exception test."); | 236 }, "DOMMatrix.fromMatrix(): Exception test"); |
| 237 |
195 </script> | 238 </script> |
OLD | NEW |