| 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="[reviewer]" author="ED" status="created" |
| 13 |
version="$Revision: 1.2 $" testname="$RCSfile: struct-dom-20-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 two green circles visible, and no red. |
| 27 |
</p> |
| 28 |
</d:passCriteria> |
| 29 |
</d:SVGTestCase> |
| 30 |
<title id="test-title">$RCSfile: struct-dom-20-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 |
<g id="defsg1" onclick="verifyDefs3(evt)"> |
| 44 |
<circle id="defscircle3" cx="80" cy="180" r="25" fill="red"/> |
| 45 |
<use id="defsuse1" xlink:href="#defscircle4" transform="translate(-600, 0)" onclick="verifyDefs4(evt)"/> |
| 46 |
</g> |
| 47 |
<circle id="defscircle4" cx="1000" cy="180" r="25" fill="red"/> |
| 48 |
|
| 49 |
<script><![CDATA[ |
| 50 |
function verifyDefs3(e) |
| 51 |
{ |
| 52 |
var instance = document.getElementById("use3").instanceRoot; |
| 53 |
var dc3instance = instance.firstChild.nextSibling; |
| 54 |
if (e.target != e.currentTarget && // Assertion: the target and currentTarget are different since the event bubbled |
| 55 |
e.target === dc3instance && // Assertion: the event was dispatched to the correct EventTarget |
| 56 |
e.currentTarget === instance) // Assertion: the event bubbled up to the SVGElementInstance corresponding to the element with id="defsg1" |
| 57 |
{ |
| 58 |
dc3instance.correspondingElement.setAttribute("fill", "lime"); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
function verifyDefs4(e) |
| 63 |
{ |
| 64 |
var useElement = document.getElementById("use3"); |
| 65 |
var nestedUseInstance = useElement.instanceRoot.childNodes.item(3); |
| 66 |
var instanceNestedCircle = nestedUseInstance.childNodes.item(0); |
| 67 |
if (e.target != e.currentTarget && // Assertion: the target and currentTarget are different since the event bubbled |
| 68 |
e.target === instanceNestedCircle && // Assertion: the event was dispatched to the correct EventTarget |
| 69 |
e.currentTarget === nestedUseInstance && // Assertion: the event bubbled up to the SVGElementInstance corresponding to the element with id="defsuse1" |
| 70 |
instanceNestedCircle.parentNode === nestedUseInstance && // Assertion: the parentNode is the SVGElementInstance of the 'use' that referenced the circle |
| 71 |
instanceNestedCircle.correspondingUseElement === useElement) // Assertion: When 'use' elements are nested then the correspondingUseElement is the outermost 'use' |
| 72 |
{ |
| 73 |
document.getElementById("defscircle4").setAttribute("fill", "lime"); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
function verify(e) |
| 78 |
{ |
| 79 |
var c = document.getElementById("circle"); |
| 80 |
if (e.target === e.currentTarget && // Assertion: the target and currentTarget are the same |
| 81 |
e.target === c) // Assertion: the target is the 'circle' element since we dispatched the event directly to it |
| 82 |
{ |
| 83 |
c.setAttribute("fill", "lime"); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
function dispatchMouseClick(target) |
| 88 |
{ |
| 89 |
var mouseevent = document.createEvent("MouseEvents"); |
| 90 |
mouseevent.initMouseEvent("click", |
| 91 |
true, // canbubble |
| 92 |
true, // cancellable |
| 93 |
document.defaultView, // the AbstractView |
| 94 |
1, // mouseclick count |
| 95 |
0, // screen x coordinate |
| 96 |
0, // screen y coordinate |
| 97 |
0, // client x coordinate |
| 98 |
0, // client y coordinate |
| 99 |
false, // ctrlKey |
| 100 |
false, // altKey |
| 101 |
false, // shiftKey |
| 102 |
false, // metaKey |
| 103 |
0, // mousebutton |
| 104 |
null); // related target |
| 105 |
target.dispatchEvent(mouseevent); |
| 106 |
} |
| 107 |
|
| 108 |
function runTest() |
| 109 |
{ |
| 110 |
// test bubbling click |
| 111 |
try { |
| 112 |
var instanceCircle = document.getElementById("use3").instanceRoot.firstChild.nextSibling; |
| 113 |
dispatchMouseClick(instanceCircle); |
| 114 |
} catch(e) {} |
| 115 |
|
| 116 |
// test nested use with bubbling click |
| 117 |
try { |
| 118 |
var nestedUseInstance = document.getElementById("use3").instanceRoot.childNodes.item(3); |
| 119 |
var instanceNestedCircle = nestedUseInstance.childNodes.item(0); |
| 120 |
dispatchMouseClick(instanceNestedCircle); |
| 121 |
} catch(e) {} |
| 122 |
} |
| 123 |
]]></script> |
| 124 |
</defs> |
| 125 |
|
| 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.2 $</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> |