1 <html xmlns="http://www.w3.org/1999/xhtml">
3 <script>window.enablePixelTesting = true;</script>
4 <script src="../../fast/js/resources/js-test-pre.js"></script>
7 <svg id="svg" xmlns="http://www.w3.org/2000/svg" width="200" height="200">
8 <text id="text1" x="500 1000 1500" y="50"> ABC </text>
9 <text id="text2" x="500 100 50 150" y="75"> ABC </text>
10 <text id="text3" x="50 50 100 100 150" y="100"> ABC</text>
11 <text id="text4" x="100 50 150 150" y="125"> ABC</text>
12 <text id="reference" x="50 100 150" y="150">ABC </text>
15 <p id="description"></p>
16 <div id="console"></div>
17 <script type="text/javascript">
19 description("This is a test of the SVGLengthList::replaceItem() API.");
21 var svg = document.getElementById("svg");
22 var text1 = document.getElementById("text1");
23 var text2 = document.getElementById("text2");
24 var text3 = document.getElementById("text3");
25 var text4 = document.getElementById("text4");
28 debug("Create three SVGLength objects, with values=50,100,150");
29 var newLength1 = svg.createSVGLength();
30 newLength1.value = 50;
31 shouldBe("newLength1.value", "50");
33 var newLength2 = svg.createSVGLength();
34 newLength2.value = 100;
35 shouldBe("newLength2.value", "100");
37 var newLength3 = svg.createSVGLength();
38 newLength3.value = 150;
39 shouldBe("newLength3.value", "150");
42 debug("Check initial list state of text1");
43 shouldBe("text1.x.baseVal.numberOfItems", "3");
44 shouldBe("text1.x.baseVal.getItem(0).value", "500");
45 shouldBe("text1.x.baseVal.getItem(1).value", "1000");
46 shouldBe("text1.x.baseVal.getItem(2).value", "1500");
47 shouldThrow("text1.x.baseVal.getItem(3)");
50 debug("Replace the first three values in text1 x list with 'newLength1/2/3'");
51 shouldBe("text1.x.baseVal.replaceItem(newLength1, 0)", "newLength1");
52 shouldBe("text1.x.baseVal.replaceItem(newLength2, 1)", "newLength2");
53 shouldBe("text1.x.baseVal.replaceItem(newLength3, 2)", "newLength3");
54 shouldThrow("text1.x.baseVal.replaceItem(newLength3, -100)");
55 shouldThrow("text1.x.baseVal.replaceItem(newLength3, -1)");
56 shouldThrow("text1.x.baseVal.replaceItem(newLength3, 3)");
57 shouldThrow("text1.x.baseVal.replaceItem(newLength3, 100)");
60 debug("Verify that the text1 x value list is correct");
61 shouldBe("text1.x.baseVal.numberOfItems", "3");
62 shouldBe("text1.x.baseVal.getItem(0).value", "50");
63 shouldBe("text1.x.baseVal.getItem(1).value", "100");
64 shouldBe("text1.x.baseVal.getItem(2).value", "150");
67 debug("Check initial list state of text2");
68 shouldBe("text2.x.baseVal.numberOfItems", "4");
69 shouldBe("text2.x.baseVal.getItem(0).value", "500");
70 shouldBe("text2.x.baseVal.getItem(1).value", "100");
71 shouldBe("text2.x.baseVal.getItem(2).value", "50");
72 shouldBe("text2.x.baseVal.getItem(3).value", "150");
73 shouldThrow("text2.x.baseVal.getItem(4)");
76 debug("Replace the first item in text2 x list with the third item in the list");
77 shouldBe("text2.x.baseVal.replaceItem(text2.x.baseVal.getItem(2), 0).value", "50");
78 shouldBe("text2.x.baseVal.numberOfItems", "3");
79 shouldBe("text2.x.baseVal.getItem(0).value", "50");
80 shouldBe("text2.x.baseVal.getItem(1).value", "100");
81 shouldBe("text2.x.baseVal.getItem(2).value", "150");
84 debug("Check initial list state of text3");
85 shouldBe("text3.x.baseVal.numberOfItems", "5");
86 shouldBe("text3.x.baseVal.getItem(0).value", "50");
87 shouldBe("text3.x.baseVal.getItem(1).value", "50");
88 shouldBe("text3.x.baseVal.getItem(2).value", "100");
89 shouldBe("text3.x.baseVal.getItem(3).value", "100");
90 shouldBe("text3.x.baseVal.getItem(4).value", "150");
91 shouldThrow("text3.x.baseVal.getItem(5)");
94 debug("Check initial list state of text4");
95 shouldBe("text4.x.baseVal.numberOfItems", "4");
96 shouldBe("text4.x.baseVal.getItem(0).value", "100");
97 shouldBe("text4.x.baseVal.getItem(1).value", "50");
98 shouldBe("text4.x.baseVal.getItem(2).value", "150");
99 shouldBe("text4.x.baseVal.getItem(3).value", "150");
100 shouldThrow("text4.x.baseVal.getItem(4)");
103 debug("Replace the first item in text4 x list with the second item in the text3 x list");
104 shouldBe("text4.x.baseVal.replaceItem(text3.x.baseVal.getItem(1), 0).value", "50");
105 shouldBe("text3.x.baseVal.numberOfItems", "4");
106 shouldBe("text3.x.baseVal.getItem(0).value", "50");
107 shouldBe("text3.x.baseVal.getItem(1).value", "100");
108 shouldBe("text3.x.baseVal.getItem(2).value", "100");
109 shouldBe("text3.x.baseVal.getItem(3).value", "150");
110 shouldThrow("text3.x.baseVal.getItem(4)");
111 shouldBe("text4.x.baseVal.numberOfItems", "4");
112 shouldBe("text4.x.baseVal.getItem(0).value", "50");
113 shouldBe("text4.x.baseVal.getItem(1).value", "50");
114 shouldBe("text4.x.baseVal.getItem(2).value", "150");
115 shouldBe("text4.x.baseVal.getItem(3).value", "150");
116 shouldThrow("text4.x.baseVal.getItem(4)");
119 debug("Replace the second item in text4 x list with the second item in the text4 x list");
120 shouldBe("text4.x.baseVal.replaceItem(text3.x.baseVal.getItem(2), 1).value", "100");
121 shouldBe("text4.x.baseVal.numberOfItems", "4");
122 shouldBe("text4.x.baseVal.getItem(0).value", "50");
123 shouldBe("text4.x.baseVal.getItem(1).value", "100");
124 shouldBe("text4.x.baseVal.getItem(2).value", "150");
125 shouldBe("text4.x.baseVal.getItem(3).value", "150");
126 shouldThrow("text4.x.baseVal.getItem(4)");
129 debug("Check final list state of text1");
130 shouldBe("text1.x.baseVal.numberOfItems", "3");
131 shouldBe("text1.x.baseVal.getItem(0).value", "50");
132 shouldBe("text1.x.baseVal.getItem(1).value", "100");
133 shouldBe("text1.x.baseVal.getItem(2).value", "150");
134 shouldThrow("text1.x.baseVal.getItem(3)");
137 debug("Check final list state of text2");
138 shouldBe("text2.x.baseVal.numberOfItems", "3");
139 shouldBe("text2.x.baseVal.getItem(0).value", "50");
140 shouldBe("text2.x.baseVal.getItem(1).value", "100");
141 shouldBe("text2.x.baseVal.getItem(2).value", "150");
142 shouldThrow("text2.x.baseVal.getItem(3)");
145 debug("Check final list state of text3");
146 shouldBe("text3.x.baseVal.numberOfItems", "3");
147 shouldBe("text3.x.baseVal.getItem(0).value", "50");
148 shouldBe("text3.x.baseVal.getItem(1).value", "100");
149 shouldBe("text3.x.baseVal.getItem(2).value", "150");
150 shouldThrow("text3.x.baseVal.getItem(3)");
153 debug("Check final list state of text4");
154 shouldBe("text4.x.baseVal.numberOfItems", "4");
155 shouldBe("text4.x.baseVal.getItem(0).value", "50");
156 shouldBe("text4.x.baseVal.getItem(1).value", "100");
157 shouldBe("text4.x.baseVal.getItem(2).value", "150");
158 shouldBe("text4.x.baseVal.getItem(3).value", "150");
159 shouldThrow("text4.x.baseVal.getItem(4)");
162 debug("The test passes if you only see 'PASS' messages, and all five text elements on top look the same");
167 <script src="../../fast/js/resources/js-test-post.js"></script>