blob: cc8553662e791244941502374dd6c60479f83140 [file] [log] [blame]
[email protected]98998cd2009-01-15 01:29:371<html xmlns="http://www.w3.org/1999/xhtml">
2<head>
[email protected]efb086342013-11-05 00:56:213<script src="../resources/js-test.js"></script>
[email protected]98998cd2009-01-15 01:29:374</head>
5<body>
6<div id="description"></div>
7<div id="console"></div>
8
9<script>
10
11description("This test exercises the CSSMatrix interface");
12
13debug("");
14debug("CSSMatrix constructors");
15
[email protected]98998cd2009-01-15 01:29:3716
[email protected]779c0642011-01-11 21:03:4417var m = new WebKitCSSMatrix();
18shouldBeNonNull('m');
19shouldBeNonNull('new WebKitCSSMatrix()');
20shouldBeNonNull('new WebKitCSSMatrix(m)');
21shouldBeNonNull('new WebKitCSSMatrix("matrix(1, 0, 0, 1, 0, 0)")');
22shouldBeNonNull('new WebKitCSSMatrix("")');
23shouldBeNonNull('new WebKitCSSMatrix("none")');
24shouldBeNonNull('new WebKitCSSMatrix(" none ")');
[email protected]98998cd2009-01-15 01:29:3725
26debug("");
[email protected]953a9e42009-02-10 05:22:0827debug("Test toString");
28var m = new WebKitCSSMatrix("matrix(1, 0, 0, 1, 0, 0)");
29var s = m.toString();
30var a = s.split('(');
31shouldBe('a[0]', '"matrix"');
32var a2 = a[1].split(',');
33shouldBe('parseFloat(a2[0])', '1');
34shouldBe('parseFloat(a2[1])', '0');
35shouldBe('parseFloat(a2[2])', '0');
36shouldBe('parseFloat(a2[3])', '1');
37shouldBe('parseFloat(a2[4])', '0');
38var a3 = a2[5].split(")");
39shouldBe('parseFloat(a3[0])', '0');
40shouldBe('a3[1]', '""');
41
42debug("");
[email protected]98998cd2009-01-15 01:29:3743debug("Test bad input to string constructor");
44shouldThrow('new WebKitCSSMatrix("banana")');
45
46debug("");
47debug("Test attributes on default matrix");
48m = new WebKitCSSMatrix();
49shouldBe('m.a', '1');
50shouldBe('m.b', '0');
51shouldBe('m.c', '0');
52shouldBe('m.d', '1');
53shouldBe('m.e', '0');
54shouldBe('m.f', '0');
55
56debug("");
57debug("Test attributes on custom matrix");
58m = new WebKitCSSMatrix("matrix(11, 12, 21, 22, 41, 42)");
59shouldBe('m.a', '11');
60shouldBe('m.b', '12');
61shouldBe('m.c', '21');
62shouldBe('m.d', '22');
63shouldBe('m.e', '41');
64shouldBe('m.f', '42');
65
66debug("");
67debug("Test setMatrixValue - set to matrix()");
68m = new WebKitCSSMatrix();
69m.setMatrixValue("matrix(11, 12, 21, 22, 41, 42)");
70shouldBe('m.a', '11');
71shouldBe('m.b', '12');
72shouldBe('m.c', '21');
73shouldBe('m.d', '22');
74shouldBe('m.e', '41');
75shouldBe('m.f', '42');
76
77debug("");
78debug("Test setMatrixValue - set to translate(10px, 20px) scale(2, 3)");
79m = new WebKitCSSMatrix();
80m.setMatrixValue("translate(10px, 20px) scale(2, 3)");
81shouldBe('m.a', '2');
82shouldBe('m.b', '0');
83shouldBe('m.c', '0');
84shouldBe('m.d', '3');
85shouldBe('m.e', '10');
86shouldBe('m.f', '20');
87
88debug("");
89debug("Test throwing exception from setMatrixValue");
90shouldThrow('m.setMatrixValue("banana")');
91shouldThrow('m.setMatrixValue("translate(10em, 20%)")');
92shouldThrow('m.setMatrixValue("translate(10px, 20px) scale()")');
93
94debug("");
[email protected]8857e5e62010-04-30 17:23:2495debug("Test attributes on translate() and accumulation");
96m = new WebKitCSSMatrix();
97var m2 = m.translate(50,0);
98m2 = m2.translate(50,50);
99shouldBe('m2.a', '1');
100shouldBe('m2.b', '0');
101shouldBe('m2.c', '0');
102shouldBe('m2.d', '1');
103shouldBe('m2.e', '100');
104shouldBe('m2.f', '50');
105
106debug("");
107debug("Test immutability of translate");
108shouldBe('parseFloat(m.a)', '1');
109shouldBe('parseFloat(m.b)', '0');
110shouldBe('parseFloat(m.c)', '0');
111shouldBe('parseFloat(m.d)', '1');
112shouldBe('parseFloat(m.e)', '0');
113shouldBe('parseFloat(m.f)', '0');
114
115debug("");
116debug("Test attributes on scale()");
117var m3 = m2.scale(5);
118shouldBe('m3.a', '5');
119shouldBe('m3.b', '0');
120shouldBe('m3.c', '0');
121shouldBe('m3.d', '5');
122shouldBe('m3.e', '100');
123shouldBe('m3.f', '50');
124
125debug("");
126debug("Test immutability of scale()");
127shouldBe('parseFloat(m2.a)', '1');
128shouldBe('parseFloat(m2.b)', '0');
129shouldBe('parseFloat(m2.c)', '0');
130shouldBe('parseFloat(m2.d)', '1');
131shouldBe('parseFloat(m2.e)', '100');
132shouldBe('parseFloat(m2.f)', '50');
133
134debug("");
135debug("Test attributes on non-uniform scale()");
136var m4 = m3.scale(2,1);
137shouldBe('m4.a', '10');
138shouldBe('m4.b', '0');
139shouldBe('m4.c', '0');
140shouldBe('m4.d', '5');
141shouldBe('m4.e', '100');
142shouldBe('m4.f', '50');
143
144debug("");
145debug("Test immutability of non-uniform scale()");
146shouldBe('parseFloat(m3.a)', '5');
147shouldBe('parseFloat(m3.b)', '0');
148shouldBe('parseFloat(m3.c)', '0');
149shouldBe('parseFloat(m3.d)', '5');
150shouldBe('parseFloat(m3.e)', '100');
151shouldBe('parseFloat(m3.f)', '50');
152
153debug("");
154debug("Test rotate");
155m = new WebKitCSSMatrix();
156m2 = m.rotate(10);
157shouldBe('parseFloat(m2.a.toPrecision(6))', '0.984808');
158shouldBe('parseFloat(m2.b.toPrecision(6))', '0.173648');
159shouldBe('parseFloat(m2.c.toPrecision(6))', '-0.173648');
160shouldBe('parseFloat(m2.d.toPrecision(6))', '0.984808');
161shouldBe('m.e', '0');
162shouldBe('m.f', '0');
163
164debug("");
165debug("Test immutability of rotate");
166shouldBe('parseFloat(m.a)', '1');
167shouldBe('parseFloat(m.b)', '0');
168shouldBe('parseFloat(m.c)', '0');
169shouldBe('parseFloat(m.d)', '1');
170shouldBe('parseFloat(m.e)', '0');
171shouldBe('parseFloat(m.f)', '0');
172
173debug("");
[email protected]62eac4c2010-12-23 06:55:52174debug("Test skew in horizontal direction");
175m = new WebKitCSSMatrix();
176m2 = m.skewX(10);
177shouldBe('parseFloat(m2.a)', '1');
178shouldBe('parseFloat(m2.b)', '0');
179shouldBe('parseFloat(m2.c.toPrecision(6))', '0.176327');
180shouldBe('parseFloat(m2.d)', '1');
181shouldBe('parseFloat(m2.e)', '0');
182shouldBe('parseFloat(m2.f)', '0');
183
184debug("");
185debug("Test immutability of horizontal skew");
186shouldBe('parseFloat(m.a)', '1');
187shouldBe('parseFloat(m.b)', '0');
188shouldBe('parseFloat(m.c)', '0');
189shouldBe('parseFloat(m.d)', '1');
190shouldBe('parseFloat(m.e)', '0');
191shouldBe('parseFloat(m.f)', '0');
192
193debug("");
194debug("Test skew in vertical direction");
195m = new WebKitCSSMatrix();
196m2 = m.skewY(35);
197shouldBe('parseFloat(m2.a)', '1');
198shouldBe('parseFloat(m2.b.toPrecision(6))', '0.700208');
199shouldBe('parseFloat(m2.c)', '0');
200shouldBe('parseFloat(m2.d)', '1');
201shouldBe('parseFloat(m2.e)', '0');
202shouldBe('parseFloat(m2.f)', '0');
203
204debug("");
205debug("Test immutability of vertical skew");
206shouldBe('parseFloat(m.a)', '1');
207shouldBe('parseFloat(m.b)', '0');
208shouldBe('parseFloat(m.c)', '0');
209shouldBe('parseFloat(m.d)', '1');
210shouldBe('parseFloat(m.e)', '0');
211shouldBe('parseFloat(m.f)', '0');
212
213debug("");
[email protected]98998cd2009-01-15 01:29:37214debug("Test multiply");
215m = new WebKitCSSMatrix("matrix(1, 2, 3, 4, 5, 6)");
216m2 = new WebKitCSSMatrix("matrix(7, 8, 9, 10, 11, 12)");
217var m3 = m.multiply(m2);
[email protected]8857e5e62010-04-30 17:23:24218shouldBe('parseFloat(m3.a)', '31');
219shouldBe('parseFloat(m3.b)', '46');
220shouldBe('parseFloat(m3.c)', '39');
221shouldBe('parseFloat(m3.d)', '58');
222shouldBe('parseFloat(m3.e)', '52');
223shouldBe('parseFloat(m3.f)', '76');
224
225debug("");
226debug("Test that multiply works in the right direction");
227var tx = new WebKitCSSMatrix();
228var sx = new WebKitCSSMatrix();
229tx = tx.translate(100,0);
230sx = sx.scale(2,1);
231m = tx.multiply(sx);
232shouldBe('m.a', '2');
233shouldBe('m.b', '0');
234shouldBe('m.c', '0');
235shouldBe('m.d', '1');
236shouldBe('m.e', '100');
237shouldBe('m.f', '0');
238
239debug("")
240debug("Test immutability of multiply");
241shouldBe('tx.a', '1');
242shouldBe('tx.b', '0');
243shouldBe('tx.c', '0');
244shouldBe('tx.d', '1');
245shouldBe('tx.e', '100');
246shouldBe('tx.f', '0');
247shouldBe('sx.a', '2');
248shouldBe('sx.b', '0');
249shouldBe('sx.c', '0');
250shouldBe('sx.d', '1');
251shouldBe('sx.e', '0');
252shouldBe('sx.f', '0');
[email protected]98998cd2009-01-15 01:29:37253
254debug("");
[email protected]953a9e42009-02-10 05:22:08255debug("Test multiply with missing argument");
256m = new WebKitCSSMatrix("matrix(1, 2, 3, 4, 5, 6)");
257m2 = m.multiply();
258shouldBe('m2', 'null');
259
260debug("");
[email protected]98998cd2009-01-15 01:29:37261debug("Test inverse");
262m = new WebKitCSSMatrix("matrix(2, 0, 0, 2, 10, 20)");
263m2 = m.inverse();
264
265shouldBe('parseFloat(m2.a)', '0.5');
266shouldBe('parseFloat(m2.b)', '0');
267shouldBe('parseFloat(m2.c)', '0');
268shouldBe('parseFloat(m2.d)', '0.5');
269shouldBe('parseFloat(m2.e)', '-5');
270shouldBe('parseFloat(m2.f)', '-10');
271
272debug("");
[email protected]953a9e42009-02-10 05:22:08273debug("Test immutability of inverse");
274shouldBe('parseFloat(m.a)', '2');
275shouldBe('parseFloat(m.b)', '0');
276shouldBe('parseFloat(m.c)', '0');
277shouldBe('parseFloat(m.d)', '2');
278shouldBe('parseFloat(m.e)', '10');
279shouldBe('parseFloat(m.f)', '20');
280
281debug("");
[email protected]98998cd2009-01-15 01:29:37282debug("Test throwing exception from inverse");
283m = new WebKitCSSMatrix("matrix(0, 0, 0, 0, 0, 0)"); // not invertible
284shouldThrow('m.inverse()');
285
286debug("");
[email protected]98998cd2009-01-15 01:29:37287
288</script>
[email protected]98998cd2009-01-15 01:29:37289
290<script>
291</script>
292
293</body>
294</html>