Debian Codegraph @

test_non_regression/fail/na/script/struct-dom-15-f.svg

raw
1 <svg id="svg-root" width="100%" height="100%"
2 viewBox="0 0 480 360" xmlns="http://www.w3.org/2000/svg"
3 xmlns:xlink="http://www.w3.org/1999/xlink" onload="runTest()">
4 <!--======================================================================-->
5 <!--= Copyright 2008 World Wide Web Consortium, (Massachusetts =-->
6 <!--= Institute of Technology, European Research Consortium for =-->
7 <!--= Informatics and Mathematics (ERCIM), Keio University). =-->
8 <!--= All Rights Reserved. =-->
9 <!--= See http://www.w3.org/Consortium/Legal/. =-->
10 <!--======================================================================-->
11 <d:SVGTestCase xmlns:d="http://www.w3.org/2000/02/svg/testsuite/description/"
12 template-version="1.4" reviewer="SVGWG" author="ED" status="accepted"
13 version="$Revision: 1.3 $" testname="$RCSfile: struct-dom-15-f.svg,v $">
14 <d:testDescription xmlns="http://www.w3.org/1999/xhtml" href="http://www.w3.org/TR/SVG11/struct.html#InterfaceSVGElementInstance">
15 <p>
16 Test SVGElementInstance and EventTarget.dispatchEvent.
17 </p>
18 </d:testDescription>
19 <d:operatorScript xmlns="http://www.w3.org/1999/xhtml">
20 <p>
21 Run the test. No interaction required.
22 </p>
23 </d:operatorScript>
24 <d:passCriteria xmlns="http://www.w3.org/1999/xhtml">
25 <p>
26 The test is passed if there are three green circles visible, and no red.
27 </p>
28 </d:passCriteria>
29 </d:SVGTestCase>
30 <title id="test-title">$RCSfile: struct-dom-15-f.svg,v $</title>
31 <defs>
32 <font-face
33 font-family="SVGFreeSansASCII"
34 unicode-range="U+0-7F">
35 <font-face-src>
36 <font-face-uri xlink:href="../resources/SVGFreeSans.svg#ascii"/>
37 </font-face-src>
38 </font-face>
39 </defs>
40 <g id="test-body-content" font-family="SVGFreeSansASCII,sans-serif" font-size="18">
41
42 <defs>
43 <circle id="defscircle1" cx="240" cy="180" r="25" onclick="verifyDefs1(evt)" fill="red"/>
44 <circle id="defscircle2" cx="240" cy="180" r="25" onclick="verifyDefs2(evt)" fill="red"/>
45
46 <script><![CDATA[
47 function verifyDefs1(e)
48 {
49 var dc = document.getElementById("defscircle1");
50 if (e.target === e.currentTarget && // Assertion: the target and currentTarget are the same
51 e.target === dc) // Assertion: the target is the 'circle' element since we dispatched the event directly to it, not to an SVGElementInstance
52 {
53 dc.setAttribute("fill", "lime");
54 }
55 }
56
57 // checks that event.target and event.currentTarget point to an SVGElementInstance (the instanceRoot)
58 function verifyDefs2(e)
59 {
60 var instance = document.getElementById("use2").instanceRoot;
61 if (e.target === e.currentTarget && // Assertion: the target and currentTarget are the same
62 e.target === instance) // Assertion: the target is SVGElementInstance corresponding to the 'circle' element with id="defscircle2", since we dispatched the event to that instance
63 {
64 instance.correspondingElement.setAttribute("fill", "lime");
65 }
66 }
67
68 function verify(e)
69 {
70 var c = document.getElementById("circle");
71 if (e.target === e.currentTarget && // Assertion: the target and currentTarget are the same
72 e.target === c) // Assertion: the target is the 'circle' element since we dispatched the event directly to it
73 {
74 c.setAttribute("fill", "lime");
75 }
76 }
77
78 function dispatchMouseClick(target)
79 {
80 var mouseevent = document.createEvent("MouseEvents");
81 mouseevent.initMouseEvent("click",
82 true, // canbubble
83 true, // cancellable
84 document.defaultView, // the AbstractView
85 1, // mouseclick count
86 0, // screen x coordinate
87 0, // screen y coordinate
88 0, // client x coordinate
89 0, // client y coordinate
90 false, // ctrlKey
91 false, // altKey
92 false, // shiftKey
93 false, // metaKey
94 0, // mousebutton
95 null); // related target
96 target.dispatchEvent(mouseevent);
97 }
98
99 function runTest()
100 {
101 // test simple circle inside <defs>
102 try {
103 var defsCircle = document.getElementById("defscircle1");
104 dispatchMouseClick(defsCircle);
105 } catch(e) {}
106
107 // test SVGElementInstance
108 try {
109 var elementInstance2 = document.getElementById("use2").instanceRoot;
110 dispatchMouseClick(elementInstance2);
111 } catch(e) {}
112
113 // test simple circle outside of <defs>
114 try {
115 var circle = document.getElementById("circle");
116 dispatchMouseClick(circle);
117 } catch(e) {}
118 }
119 ]]></script>
120 </defs>
121
122 <circle id="circle" cx="240" cy="180" r="25" onclick="verify(evt)" fill="red"/>
123
124 <use id="use1" xlink:href="#defscircle1" transform="translate(80,0)"/>
125 <use id="use2" xlink:href="#defscircle2" transform="translate(-80,0)"/>
126 <use id="use3" xlink:href="#defsg1"/>
127 </g>
128 <g font-family="SVGFreeSansASCII,sans-serif" font-size="32">
129 <text id="revision" x="10" y="340" stroke="none"
130 fill="black">$Revision: 1.3 $</text>
131 </g>
132 <rect id="test-frame" x="1" y="1" width="478" height="358" fill="none" stroke="#000"/>
133 <!-- comment out this watermark once the test is approved -->
134 <!--<g id="draft-watermark">
135 <rect x="1" y="1" width="478" height="20" fill="red" stroke="black" stroke-width="1"/>
136 <text font-family="SVGFreeSansASCII,sans-serif" font-weight="bold" font-size="20" x="240"
137 text-anchor="middle" y="18" stroke-width="0.5" stroke="black" fill="white">DRAFT</text>
138 </g>-->
139 </svg>