1 <html xmlns=
"http://www.w3.org/1999/xhtml">
3 <script src=
"../resources/js-test.js"></script>
6 <div id=
"description"></div>
7 <div id=
"console"></div>
11 description("This test exercises the CSSMatrix interface");
14 debug("CSSMatrix constructors");
17 var m
= new WebKitCSSMatrix();
19 shouldBeNonNull('new WebKitCSSMatrix()');
20 shouldBeNonNull('new WebKitCSSMatrix(m)');
21 shouldBeNonNull('new WebKitCSSMatrix("matrix(1, 0, 0, 1, 0, 0)")');
22 shouldBeNonNull('new WebKitCSSMatrix("")');
23 shouldBeNonNull('new WebKitCSSMatrix("none")');
24 shouldBeNonNull('new WebKitCSSMatrix(" none ")');
27 debug("Test toString");
28 var m
= new WebKitCSSMatrix("matrix(1, 0, 0, 1, 0, 0)");
31 shouldBe('a[0]', '"matrix"');
32 var a2
= a
[1].split(',');
33 shouldBe('parseFloat(a2[0])', '1');
34 shouldBe('parseFloat(a2[1])', '0');
35 shouldBe('parseFloat(a2[2])', '0');
36 shouldBe('parseFloat(a2[3])', '1');
37 shouldBe('parseFloat(a2[4])', '0');
38 var a3
= a2
[5].split(")");
39 shouldBe('parseFloat(a3[0])', '0');
40 shouldBe('a3[1]', '""');
43 debug("Test bad input to string constructor");
44 shouldThrow('new WebKitCSSMatrix("banana")');
47 debug("Test attributes on default matrix");
48 m
= new WebKitCSSMatrix();
57 debug("Test attributes on custom matrix");
58 m
= new WebKitCSSMatrix("matrix(11, 12, 21, 22, 41, 42)");
59 shouldBe('m.a', '11');
60 shouldBe('m.b', '12');
61 shouldBe('m.c', '21');
62 shouldBe('m.d', '22');
63 shouldBe('m.e', '41');
64 shouldBe('m.f', '42');
67 debug("Test setMatrixValue - set to matrix()");
68 m
= new WebKitCSSMatrix();
69 m
.setMatrixValue("matrix(11, 12, 21, 22, 41, 42)");
70 shouldBe('m.a', '11');
71 shouldBe('m.b', '12');
72 shouldBe('m.c', '21');
73 shouldBe('m.d', '22');
74 shouldBe('m.e', '41');
75 shouldBe('m.f', '42');
78 debug("Test setMatrixValue - set to translate(10px, 20px) scale(2, 3)");
79 m
= new WebKitCSSMatrix();
80 m
.setMatrixValue("translate(10px, 20px) scale(2, 3)");
85 shouldBe('m.e', '10');
86 shouldBe('m.f', '20');
89 debug("Test throwing exception from setMatrixValue");
90 shouldThrow('m.setMatrixValue("banana")');
91 shouldThrow('m.setMatrixValue("translate(10em, 20%)")');
92 shouldThrow('m.setMatrixValue("translate(10px, 20px) scale()")');
95 debug("Test attributes on translate() and accumulation");
96 m
= new WebKitCSSMatrix();
97 var m2
= m
.translate(50,0);
98 m2
= m2
.translate(50,50);
99 shouldBe('m2.a', '1');
100 shouldBe('m2.b', '0');
101 shouldBe('m2.c', '0');
102 shouldBe('m2.d', '1');
103 shouldBe('m2.e', '100');
104 shouldBe('m2.f', '50');
107 debug("Test immutability of translate");
108 shouldBe('parseFloat(m.a)', '1');
109 shouldBe('parseFloat(m.b)', '0');
110 shouldBe('parseFloat(m.c)', '0');
111 shouldBe('parseFloat(m.d)', '1');
112 shouldBe('parseFloat(m.e)', '0');
113 shouldBe('parseFloat(m.f)', '0');
116 debug("Test attributes on scale()");
117 var m3
= m2
.scale(5);
118 shouldBe('m3.a', '5');
119 shouldBe('m3.b', '0');
120 shouldBe('m3.c', '0');
121 shouldBe('m3.d', '5');
122 shouldBe('m3.e', '100');
123 shouldBe('m3.f', '50');
126 debug("Test immutability of scale()");
127 shouldBe('parseFloat(m2.a)', '1');
128 shouldBe('parseFloat(m2.b)', '0');
129 shouldBe('parseFloat(m2.c)', '0');
130 shouldBe('parseFloat(m2.d)', '1');
131 shouldBe('parseFloat(m2.e)', '100');
132 shouldBe('parseFloat(m2.f)', '50');
135 debug("Test attributes on non-uniform scale()");
136 var m4
= m3
.scale(2,1);
137 shouldBe('m4.a', '10');
138 shouldBe('m4.b', '0');
139 shouldBe('m4.c', '0');
140 shouldBe('m4.d', '5');
141 shouldBe('m4.e', '100');
142 shouldBe('m4.f', '50');
145 debug("Test immutability of non-uniform scale()");
146 shouldBe('parseFloat(m3.a)', '5');
147 shouldBe('parseFloat(m3.b)', '0');
148 shouldBe('parseFloat(m3.c)', '0');
149 shouldBe('parseFloat(m3.d)', '5');
150 shouldBe('parseFloat(m3.e)', '100');
151 shouldBe('parseFloat(m3.f)', '50');
154 debug("Test rotate");
155 m
= new WebKitCSSMatrix();
157 shouldBe('parseFloat(m2.a.toPrecision(6))', '0.984808');
158 shouldBe('parseFloat(m2.b.toPrecision(6))', '0.173648');
159 shouldBe('parseFloat(m2.c.toPrecision(6))', '-0.173648');
160 shouldBe('parseFloat(m2.d.toPrecision(6))', '0.984808');
161 shouldBe('m.e', '0');
162 shouldBe('m.f', '0');
165 debug("Test immutability of rotate");
166 shouldBe('parseFloat(m.a)', '1');
167 shouldBe('parseFloat(m.b)', '0');
168 shouldBe('parseFloat(m.c)', '0');
169 shouldBe('parseFloat(m.d)', '1');
170 shouldBe('parseFloat(m.e)', '0');
171 shouldBe('parseFloat(m.f)', '0');
174 debug("Test skew in horizontal direction");
175 m
= new WebKitCSSMatrix();
177 shouldBe('parseFloat(m2.a)', '1');
178 shouldBe('parseFloat(m2.b)', '0');
179 shouldBe('parseFloat(m2.c.toPrecision(6))', '0.176327');
180 shouldBe('parseFloat(m2.d)', '1');
181 shouldBe('parseFloat(m2.e)', '0');
182 shouldBe('parseFloat(m2.f)', '0');
185 debug("Test immutability of horizontal skew");
186 shouldBe('parseFloat(m.a)', '1');
187 shouldBe('parseFloat(m.b)', '0');
188 shouldBe('parseFloat(m.c)', '0');
189 shouldBe('parseFloat(m.d)', '1');
190 shouldBe('parseFloat(m.e)', '0');
191 shouldBe('parseFloat(m.f)', '0');
194 debug("Test skew in vertical direction");
195 m
= new WebKitCSSMatrix();
197 shouldBe('parseFloat(m2.a)', '1');
198 shouldBe('parseFloat(m2.b.toPrecision(6))', '0.700208');
199 shouldBe('parseFloat(m2.c)', '0');
200 shouldBe('parseFloat(m2.d)', '1');
201 shouldBe('parseFloat(m2.e)', '0');
202 shouldBe('parseFloat(m2.f)', '0');
205 debug("Test immutability of vertical skew");
206 shouldBe('parseFloat(m.a)', '1');
207 shouldBe('parseFloat(m.b)', '0');
208 shouldBe('parseFloat(m.c)', '0');
209 shouldBe('parseFloat(m.d)', '1');
210 shouldBe('parseFloat(m.e)', '0');
211 shouldBe('parseFloat(m.f)', '0');
214 debug("Test multiply");
215 m
= new WebKitCSSMatrix("matrix(1, 2, 3, 4, 5, 6)");
216 m2
= new WebKitCSSMatrix("matrix(7, 8, 9, 10, 11, 12)");
217 var m3
= m
.multiply(m2
);
218 shouldBe('parseFloat(m3.a)', '31');
219 shouldBe('parseFloat(m3.b)', '46');
220 shouldBe('parseFloat(m3.c)', '39');
221 shouldBe('parseFloat(m3.d)', '58');
222 shouldBe('parseFloat(m3.e)', '52');
223 shouldBe('parseFloat(m3.f)', '76');
226 debug("Test that multiply works in the right direction");
227 var tx
= new WebKitCSSMatrix();
228 var sx
= new WebKitCSSMatrix();
229 tx
= tx
.translate(100,0);
232 shouldBe('m.a', '2');
233 shouldBe('m.b', '0');
234 shouldBe('m.c', '0');
235 shouldBe('m.d', '1');
236 shouldBe('m.e', '100');
237 shouldBe('m.f', '0');
240 debug("Test immutability of multiply");
241 shouldBe('tx.a', '1');
242 shouldBe('tx.b', '0');
243 shouldBe('tx.c', '0');
244 shouldBe('tx.d', '1');
245 shouldBe('tx.e', '100');
246 shouldBe('tx.f', '0');
247 shouldBe('sx.a', '2');
248 shouldBe('sx.b', '0');
249 shouldBe('sx.c', '0');
250 shouldBe('sx.d', '1');
251 shouldBe('sx.e', '0');
252 shouldBe('sx.f', '0');
255 debug("Test multiply with missing argument");
256 m
= new WebKitCSSMatrix("matrix(1, 2, 3, 4, 5, 6)");
258 shouldBe('m2', 'null');
261 debug("Test inverse");
262 m
= new WebKitCSSMatrix("matrix(2, 0, 0, 2, 10, 20)");
265 shouldBe('parseFloat(m2.a)', '0.5');
266 shouldBe('parseFloat(m2.b)', '0');
267 shouldBe('parseFloat(m2.c)', '0');
268 shouldBe('parseFloat(m2.d)', '0.5');
269 shouldBe('parseFloat(m2.e)', '-5');
270 shouldBe('parseFloat(m2.f)', '-10');
273 debug("Test immutability of inverse");
274 shouldBe('parseFloat(m.a)', '2');
275 shouldBe('parseFloat(m.b)', '0');
276 shouldBe('parseFloat(m.c)', '0');
277 shouldBe('parseFloat(m.d)', '2');
278 shouldBe('parseFloat(m.e)', '10');
279 shouldBe('parseFloat(m.f)', '20');
282 debug("Test throwing exception from inverse");
283 m
= new WebKitCSSMatrix("matrix(0, 0, 0, 0, 0, 0)"); // not invertible
284 shouldThrow('m.inverse()');