blob: a0663983319c5b07da0014bc425b53ecf5857c33 [file] [log] [blame]
commit-queue@webkit.org7ab490e2010-11-22 12:32:31 +00001<html xmlns="http://www.w3.org/1999/xhtml">
2<head>
commit-queue@webkit.org7ab490e2010-11-22 12:32:31 +00003<script>window.enablePixelTesting = true;</script>
mark.lam@apple.com1ca737d2013-09-08 05:29:22 +00004<script src="../../resources/js-test-pre.js"></script>
commit-queue@webkit.org7ab490e2010-11-22 12:32:31 +00005</head>
6<body>
7<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="200" height="200">
8 <polyline id="poly1" stroke="green" points="0 0 100 0 100 100 0 100"/>
9</svg>
10
11<p id="description"></p>
12<div id="console"></div>
13<script type="text/javascript">
14<![CDATA[
15 description("This is a test of the simple SVGPointList API parts.");
16
fmalita@chromium.orga54f0f22013-02-13 17:49:47 +000017 if (window.testRunner)
18 testRunner.dumpAsText();
19
commit-queue@webkit.org7ab490e2010-11-22 12:32:31 +000020 // Extend String prototype, to offer a function, that formats the points attribute in the same way across browsers
21 String.prototype.formatPointsAttribute = function() {
22 return this.replace(/,/g, " "); // Remove Firefox commas
23 }
24
25 function dumpPoint(point) {
26 return "x=" + point.x.toFixed(0) + " y=" + point.y.toFixed(0);
27 }
28
29 var svg = document.getElementById("svg");
30 var poly1 = document.getElementById("poly1");
31 shouldBe("poly1.points.numberOfItems", "4");
32 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
33 shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
34 shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
35 shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
36 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
37
38 var point;
39 debug("");
40 debug("Creating point x=200 y=100");
41 shouldBeEqualToString("(point = svg.createSVGPoint()).toString()", "[object SVGPoint]");
42 shouldBe("point.x = 200", "200");
43 shouldBe("point.y = 100", "100");
44
45 debug("");
46 debug("Test uncommon arguments for initialize()");
47 shouldBe("poly1.points.initialize(point)", "point");
48 shouldBe("poly1.points.numberOfItems", "1");
49 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=200 y=100");
50 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "200 100");
51 shouldThrow("poly1.points.initialize(poly1)");
52 shouldThrow("poly1.points.initialize(0)");
53 shouldThrow("poly1.points.initialize('aString')");
54
55 debug("");
56 debug("Reset points attribute to 0 0 100 0 100 100 0 100");
57 shouldBeUndefined("poly1.setAttribute('points', '0 0 100 0 100 100 0 100')");
58 shouldBe("poly1.points.numberOfItems", "4");
59 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
60 shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
61 shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
62 shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
63 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
64
65 debug("");
66 debug("Test uncommon arguments for getItem()");
67 shouldThrow("poly1.points.getItem(30)");
68 shouldBe("poly1.points.getItem('aString')", "poly1.points.getItem(0)");
69 shouldBe("poly1.points.getItem(poly1)", "poly1.points.getItem(0)");
70 shouldBe("poly1.points.getItem(null)", "poly1.points.getItem(0)");
71
72 debug("");
73 debug("Test uncommon arguments for insertItemBefore()");
74 shouldThrow("poly1.points.insertItemBefore(30)");
75 shouldThrow("poly1.points.insertItemBefore('aString')");
76 shouldThrow("poly1.points.insertItemBefore(poly1)");
77 shouldThrow("poly1.points.insertItemBefore(null)");
78
79 shouldBeEqualToString("dumpPoint(poly1.points.insertItemBefore(poly1.points.getItem(1), 'aString'))", "x=100 y=0");
80 shouldBe("poly1.points.numberOfItems", "4");
81 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=100 y=0");
82 shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=0 y=0");
83 shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
84 shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
85 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "100 0 0 0 100 100 0 100");
86
87 shouldBeEqualToString("dumpPoint(poly1.points.insertItemBefore(poly1.points.getItem(1), poly1))", "x=0 y=0");
88 shouldBe("poly1.points.numberOfItems", "4");
89 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
90 shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
91 shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
92 shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
93 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
94
95 shouldBeEqualToString("dumpPoint(poly1.points.insertItemBefore(poly1.points.getItem(1), null))", "x=100 y=0");
96 shouldBe("poly1.points.numberOfItems", "4");
97 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=100 y=0");
98 shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=0 y=0");
99 shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
100 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "100 0 0 0 100 100 0 100");
101
102 shouldBeEqualToString("dumpPoint(poly1.points.insertItemBefore(poly1.points.getItem(1), 0))", "x=0 y=0");
103 shouldBe("poly1.points.numberOfItems", "4");
104 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
105 shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
106 shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
107 shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
108 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
109
110 shouldThrow("poly1.points.insertItemBefore(30, 0)");
111 shouldThrow("poly1.points.insertItemBefore('aString', 0)");
112 shouldThrow("poly1.points.insertItemBefore(poly1, 0)");
113 shouldThrow("poly1.points.insertItemBefore(null, 0)");
114
115 debug("");
116 debug("Test uncommon arguments for replaceItem()");
117 shouldThrow("poly1.points.replaceItem(30)");
118 shouldThrow("poly1.points.replaceItem('aString')");
119 shouldThrow("poly1.points.replaceItem(poly1)");
120 shouldThrow("poly1.points.replaceItem(null, 0)");
121 shouldThrow("poly1.points.replaceItem('aString', 0)");
122 shouldThrow("poly1.points.replaceItem(poly1, 0)");
123 shouldThrow("poly1.points.replaceItem(1, 0)");
124
125 debug("");
126 debug("Test uncommon arguments for replaceItem() and xml-dom synchronization");
127 shouldBe("poly1.points.numberOfItems", "4");
128 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
129 shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
130 shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
131 shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
132 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
133
134 shouldBeEqualToString("dumpPoint(poly1.points.replaceItem(poly1.points.getItem(0), 0))", "x=0 y=0");
fmalita@chromium.orga54f0f22013-02-13 17:49:47 +0000135 shouldBe("poly1.points.numberOfItems", "4");
commit-queue@webkit.org7ab490e2010-11-22 12:32:31 +0000136 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
fmalita@chromium.orga54f0f22013-02-13 17:49:47 +0000137 shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
138 shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
139 shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
140 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
commit-queue@webkit.org7ab490e2010-11-22 12:32:31 +0000141
142 shouldBeEqualToString("dumpPoint(poly1.points.replaceItem(poly1.points.getItem(0), 'aString'))", "x=0 y=0");
fmalita@chromium.orga54f0f22013-02-13 17:49:47 +0000143 shouldBe("poly1.points.numberOfItems", "4");
commit-queue@webkit.org7ab490e2010-11-22 12:32:31 +0000144 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
fmalita@chromium.orga54f0f22013-02-13 17:49:47 +0000145 shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
146 shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
147 shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
148 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
commit-queue@webkit.org7ab490e2010-11-22 12:32:31 +0000149
150 shouldBeEqualToString("dumpPoint(poly1.points.replaceItem(poly1.points.getItem(0), poly1))", "x=0 y=0");
fmalita@chromium.orga54f0f22013-02-13 17:49:47 +0000151 shouldBe("poly1.points.numberOfItems", "4");
commit-queue@webkit.org7ab490e2010-11-22 12:32:31 +0000152 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=0");
fmalita@chromium.orga54f0f22013-02-13 17:49:47 +0000153 shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=0");
154 shouldBeEqualToString("dumpPoint(poly1.points.getItem(2))", "x=100 y=100");
155 shouldBeEqualToString("dumpPoint(poly1.points.getItem(3))", "x=0 y=100");
156 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 0 100 0 100 100 0 100");
commit-queue@webkit.org7ab490e2010-11-22 12:32:31 +0000157
fmalita@chromium.orga54f0f22013-02-13 17:49:47 +0000158 shouldBeEqualToString("dumpPoint(poly1.points.replaceItem(poly1.points.getItem(0), null))", "x=0 y=0");
159 shouldBe("poly1.points.numberOfItems", "4");
160 shouldBeEqualToString("poly1.getAttribute('points')", "0 0 100 0 100 100 0 100");
commit-queue@webkit.org7ab490e2010-11-22 12:32:31 +0000161
162 debug("");
163 debug("Reset points attribute to 0 0 100 0 100 100 0 100");
164 shouldBeUndefined("poly1.setAttribute('points', '0 0 100 0 100 100 0 100')");
165
166 debug("");
167 debug("Test uncommon arguments for removeItem()");
168 shouldThrow("poly1.points.removeItem(30)");
169
170 shouldBeEqualToString("dumpPoint(poly1.points.removeItem('aString'))", "x=0 y=0");
171 shouldBe("poly1.points.numberOfItems", "3");
172 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=100 y=0");
173 shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=100 y=100");
174 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=100 y=0");
175 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "100 0 100 100 0 100");
176
177 shouldBeEqualToString("dumpPoint(poly1.points.removeItem(poly1))", "x=100 y=0");
178 shouldBe("poly1.points.numberOfItems", "2");
179 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=100 y=100");
180 shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=0 y=100");
181 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "100 100 0 100");
182
183 shouldBeEqualToString("dumpPoint(poly1.points.removeItem(null))", "x=100 y=100");
184 shouldBe("poly1.points.numberOfItems", "1");
185 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=100");
186 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 100");
187
188 debug("");
189 debug("Test uncommon arguments for appendItem()");
190 shouldThrow("poly1.points.appendItem(30)");
191 shouldThrow("poly1.points.appendItem('aString')");
192 shouldThrow("poly1.points.appendItem(poly1)");
193 shouldThrow("poly1.points.appendItem(null)");
194
195 shouldBeEqualToString("dumpPoint(poly1.points.appendItem(point))", "x=200 y=100");
196 shouldBe("poly1.points.numberOfItems", "2");
197 shouldBeEqualToString("dumpPoint(poly1.points.getItem(0))", "x=0 y=100");
198 shouldBeEqualToString("dumpPoint(poly1.points.getItem(1))", "x=200 y=100");
199 shouldBeEqualToString("poly1.getAttribute('points').formatPointsAttribute()", "0 100 200 100");
200
commit-queue@webkit.org7ab490e2010-11-22 12:32:31 +0000201]]>
202</script>
mark.lam@apple.com1ca737d2013-09-08 05:29:22 +0000203<script src="../../resources/js-test-post.js"></script>
commit-queue@webkit.org7ab490e2010-11-22 12:32:31 +0000204</body>
205</html>