Debian Codegraph @

samples/tests/spec/scripting/getElementById.svg

raw
1 <?xml version="1.0" standalone="no"?>
2 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
3 "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
4
5 <!--
6
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
13
14 http://www.apache.org/licenses/LICENSE-2.0
15
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
21
22 -->
23 <!-- ====================================================================== -->
24 <!-- Test of the getElementById method -->
25 <!-- -->
26 <!-- @author [email protected] -->
27 <!-- @version $Id$ -->
28 <!-- ====================================================================== -->
29
30 <?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?>
31
32 <svg id="body" width="450" height="500" viewBox="0 0 450 500"
33 onload="doTest()"
34 xmlns="http://www.w3.org/2000/svg"
35 xmlns:xlink="http://www.w3.org/1999/xlink">
36
37 <title>Test of 'getElementById' method</title>
38
39 <text x="50%" y="45" class="title">Test of 'getElementById' method</text>
40
41 <script type="text/ecmascript">
42 var svgns = "http://www.w3.org/2000/svg";
43
44 function setText(id, text, color) {
45 var tspan = document.getElementById(id);
46 tspan.appendChild(document.createTextNode(text));
47 tspan.setAttribute("fill", color);
48 }
49 function checkTest(e, base, id, tId) {
50 if (e == base.getElementById(id))
51 setText(tId, "success", "green");
52 else
53 setText(tId, "failed", "red");
54 }
55 function doTest() {
56 var g = document.getElementById("group");
57 var id1 = g.firstChild;
58 var id2 = id1.nextSibling;
59 var id3 = id2.nextSibling;
60 var id4 = id3.nextSibling;
61 var svg1 = id4.nextSibling;
62 var id5 = svg1.firstChild;
63 var id6 = id5.nextSibling;
64 var id7 = svg1.nextSibling;
65
66 checkTest(id1, document, "id1", "t1");
67 checkTest(id2, document, "id2", "t2");
68 checkTest(null, document, "undefined", "t3");
69
70 checkTest(svg1, document, "svg1", "t4");
71 checkTest(svg1, svg1, "svg1", "t5");
72
73 checkTest(id5, document, "id5", "t6");
74 checkTest(id5, svg1, "id5", "t7");
75 checkTest(id6, svg1, "id6", "t8");
76 checkTest(id7, svg1, "id7", "t9");
77
78 id2.setAttribute("id", "d1");
79 checkTest(id2, document, "d1", "t10");
80
81 var attr = document.createAttribute("id");
82 attr.setValue("d2");
83 id3.setAttributeNode(attr);
84 checkTest(id3, document, "d2", "t11");
85 checkTest(null, document, "id3", "t12");
86 attr.setValue("d3");
87 checkTest(id3, document, "d3", "t13");
88
89 id4.removeAttribute("id");
90 checkTest(null, document, "id4", "t14");
91
92 svg1.parentNode.removeChild(svg1);
93 checkTest(null, document, "id5", "t15");
94 checkTest(id5, svg1, "id5", "t16");
95
96 var svg2 = document.createElementNS(svgns, "svg");
97 var id8 = document.createElementNS(svgns, "desc");
98 svg2.appendChild(id8);
99 id8.setAttribute("id", "id8");
100 checkTest(null, document, "id8", "t17");
101 checkTest(null, svg1, "id8", "t18");
102 checkTest(id8, svg2, "id8", "t19");
103
104 var id9 = document.createElementNS(svgns, "desc");
105 id9.setAttribute("id", "id9");
106 svg2.appendChild(id9);
107 checkTest(null, document, "id9", "t20");
108 checkTest(null, svg1, "id9", "t21");
109 checkTest(id9, svg2, "id9", "t22");
110
111 var id5_2 = id5.cloneNode(true);
112 g.appendChild(id5_2);
113 checkTest(id5_2, document, "id5", "t23");
114 }
115 </script>
116
117 <g id="group"><rect id="id1" x="10" y="60" width="50" height="50"
118 fill="gold" stroke="black"
119 /><rect id="id2" x="70" y="60" width="50" height="50"
120 fill="crimson" stroke="black"
121 /><rect id="id3" x="130" y="60" width="50" height="50"
122 fill="gold" stroke="black"
123 /><rect id="id4" x="190" y="60" width="50" height="50"
124 fill="crimson" stroke="black"
125 /><svg id="svg1" x="0" y="0" width="450" height="500"
126 ><rect id="id5" x="250" y="60" width="50" height="50"
127 fill="gold" stroke="black"
128 /><rect id="id6" x="310" y="60" width="50" height="50"
129 fill="crimson" stroke="black"
130 /></svg><rect id="id7" x="370" y="60" width="50" height="50"
131 fill="gold" stroke="black"/>
132
133 <text x="60" y="140" text-anchor="end"
134 >Test 1: <tspan id="t1" x="65" text-anchor="start"/></text>
135 <text x="60" y="160" text-anchor="end"
136 >Test 2: <tspan id="t2" x="65" text-anchor="start"/></text>
137 <text x="60" y="180" text-anchor="end"
138 >Test 3: <tspan id="t3" x="65" text-anchor="start"/></text>
139 <text x="60" y="200" text-anchor="end"
140 >Test 4: <tspan id="t4" x="65" text-anchor="start"/></text>
141 <text x="60" y="220" text-anchor="end"
142 >Test 5: <tspan id="t5" x="65" text-anchor="start"/></text>
143
144 <text x="60" y="240" text-anchor="end"
145 >Test 6: <tspan id="t6" x="65" text-anchor="start"/></text>
146 <text x="60" y="260" text-anchor="end"
147 >Test 7: <tspan id="t7" x="65" text-anchor="start"/></text>
148 <text x="60" y="280" text-anchor="end"
149 >Test 8: <tspan id="t8" x="65" text-anchor="start"/></text>
150 <text x="60" y="300" text-anchor="end"
151 >Test 9: <tspan id="t9" x="65" text-anchor="start"/></text>
152 <text x="60" y="320" text-anchor="end"
153 >Test 10: <tspan id="t10" x="65" text-anchor="start"/></text>
154
155 <text x="60" y="340" text-anchor="end"
156 >Test 11: <tspan id="t11" x="65" text-anchor="start"/></text>
157
158
159 <text x="220" y="140" text-anchor="end"
160 >Test 12: <tspan id="t12" x="225" text-anchor="start"/></text>
161 <text x="220" y="160" text-anchor="end"
162 >Test 13: <tspan id="t13" x="225" text-anchor="start"/></text>
163 <text x="220" y="180" text-anchor="end"
164 >Test 14: <tspan id="t14" x="225" text-anchor="start"/></text>
165 <text x="220" y="200" text-anchor="end"
166 >Test 15: <tspan id="t15" x="225" text-anchor="start"/></text>
167 <text x="220" y="220" text-anchor="end"
168 >Test 16: <tspan id="t16" x="225" text-anchor="start"/></text>
169 <text x="220" y="240" text-anchor="end"
170 >Test 17: <tspan id="t17" x="225" text-anchor="start"/></text>
171 <text x="220" y="260" text-anchor="end"
172 >Test 18: <tspan id="t18" x="225" text-anchor="start"/></text>
173 <text x="220" y="280" text-anchor="end"
174 >Test 19: <tspan id="t19" x="225" text-anchor="start"/></text>
175 <text x="220" y="300" text-anchor="end"
176 >Test 20: <tspan id="t20" x="225" text-anchor="start"/></text>
177 <text x="220" y="320" text-anchor="end"
178 >Test 21: <tspan id="t21" x="225" text-anchor="start"/></text>
179 <text x="220" y="340" text-anchor="end"
180 >Test 22: <tspan id="t22" x="225" text-anchor="start"/></text>
181 <text x="220" y="360" text-anchor="end"
182 >Test 23: <tspan id="t23" x="225" text-anchor="start"/></text>
183 </g>
184 </svg>