| 1 |
<svg version="1.1" baseProfile="basic" onload="domTest(evt)" id="svg-root" |
| 2 |
width="100%" height="100%" viewBox="0 0 480 360" |
| 3 |
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> |
| 4 |
<!--======================================================================--> |
| 5 |
<!--= SVG 1.1 2nd Edition Test Case =--> |
| 6 |
<!--======================================================================--> |
| 7 |
<!--= Copyright 2009 World Wide Web Consortium, (Massachusetts =--> |
| 8 |
<!--= Institute of Technology, European Research Consortium for =--> |
| 9 |
<!--= Informatics and Mathematics (ERCIM), Keio University). =--> |
| 10 |
<!--= All Rights Reserved. =--> |
| 11 |
<!--= See http://www.w3.org/Consortium/Legal/. =--> |
| 12 |
<!--======================================================================--> |
| 13 |
<d:SVGTestCase xmlns:d="http://www.w3.org/2000/02/svg/testsuite/description/" |
| 14 |
template-version="1.4" reviewer="SVGWG" author="VH" status="accepted" |
| 15 |
version="$Revision: 1.8 $" testname="$RCSfile: struct-dom-01-b.svg,v $"> |
| 16 |
<d:testDescription xmlns="http://www.w3.org/1999/xhtml" href="http://www.w3.org/TR/SVG11/struct.html#DOMInterfaces"> |
| 17 |
<p> |
| 18 |
Verify the basic capability to handle the SVG DOM API. |
| 19 |
</p> |
| 20 |
<p> |
| 21 |
The test is composed of a top |
| 22 |
level svg element with an 'onload' event handler and a rect element. Both |
| 23 |
the svg and the rect elements have an identifier. The 'onload' handler |
| 24 |
invokes SVG-specific DOM API methods which use these identifiers. |
| 25 |
</p> |
| 26 |
<p> |
| 27 |
First, the handler gets the SVG element owner of the rect element and checks it has |
| 28 |
the expected identifier. Then, the handler accesses the coordinates of the rect element |
| 29 |
and uses them to build a 'shadow' rectangle under the existing one. Finally, the 'shadow' |
| 30 |
rectangle is created using the SVGSVGElement's createSVGRect method. |
| 31 |
</p> |
| 32 |
</d:testDescription> |
| 33 |
<d:operatorScript xmlns="http://www.w3.org/1999/xhtml"> |
| 34 |
<p> |
| 35 |
Run the test. No interaction required. |
| 36 |
</p> |
| 37 |
</d:operatorScript> |
| 38 |
<d:passCriteria xmlns="http://www.w3.org/1999/xhtml"> |
| 39 |
<p>The test passes if:</p> |
| 40 |
<ul> |
| 41 |
<li>The text "This document's root identifier is: svg-root" is shown.</li> |
| 42 |
<li>A green rectangle with a black shadow is shown.</li> |
| 43 |
</ul> |
| 44 |
</d:passCriteria> |
| 45 |
</d:SVGTestCase> |
| 46 |
<title id="test-title">$RCSfile: struct-dom-01-b.svg,v $</title> |
| 47 |
<defs> |
| 48 |
<font-face font-family="SVGFreeSansASCII" unicode-range="U+0-7F"> |
| 49 |
<font-face-src> |
| 50 |
<font-face-uri xlink:href="../resources/SVGFreeSans.svg#ascii"/> |
| 51 |
</font-face-src> |
| 52 |
</font-face> |
| 53 |
</defs> |
| 54 |
<g id="test-body-content" font-family="SVGFreeSansASCII,sans-serif" font-size="18"> |
| 55 |
<script type="text/ecmascript" xlink:href="../resources/testharness.js"></script> |
| 56 |
<script type="text/ecmascript"><![CDATA[ |
| 57 |
function domTest(evt) { |
| 58 |
|
| 59 |
var svg_ns = "http://www.w3.org/2000/svg"; |
| 60 |
|
| 61 |
// Get Document |
| 62 |
var target = evt.target; |
| 63 |
var doc = target.ownerDocument; |
| 64 |
|
| 65 |
// |
| 66 |
// Test that our rectangle is an SVGElement instance |
| 67 |
// |
| 68 |
var rect = doc.getElementById("rectId"); |
| 69 |
var rootSVG = rect.ownerSVGElement; |
| 70 |
var rootId = rootSVG.getAttribute( "id" ); |
| 71 |
|
| 72 |
// Insert a new text element to the DOM tree using the id |
| 73 |
var newText = doc.createElementNS(svg_ns, 'text'); |
| 74 |
newText.setAttribute('x', '50'); |
| 75 |
newText.setAttribute('y', '100'); |
| 76 |
var message = "This document's root identifier is: " + rootId; |
| 77 |
var textContent = doc.createTextNode(message); |
| 78 |
newText.appendChild(textContent); |
| 79 |
rect.parentNode.appendChild(newText); |
| 80 |
|
| 81 |
// |
| 82 |
// Now, check that our rectangle is an instance of SVGRect by accessing |
| 83 |
// specific methods in order to get its x, y, width and height attributes. |
| 84 |
// |
| 85 |
var x = rect.x.baseVal.value; // SVGRect -> SVGAnimatedLenght -> SVGLength -> long |
| 86 |
var y = rect.y.baseVal.value; |
| 87 |
var width = rect.width.baseVal.value; |
| 88 |
var height = rect.height.baseVal.value; |
| 89 |
|
| 90 |
// |
| 91 |
// Now, build a new SVGRect through the SVGSVGElement interface. |
| 92 |
// |
| 93 |
var newRect = doc.createElementNS(svg_ns, 'rect'); |
| 94 |
|
| 95 |
// |
| 96 |
// Set the x, y, width and height of this element |
| 97 |
// |
| 98 |
newRect.x.baseVal.value = x + 10; |
| 99 |
newRect.y.baseVal.value = y + 10; |
| 100 |
newRect.setAttribute("width", width); |
| 101 |
newRect.setAttribute("height", height); |
| 102 |
|
| 103 |
// |
| 104 |
// Insert new element in DOM tree |
| 105 |
// |
| 106 |
rect.parentNode.insertBefore(newRect, rect); |
| 107 |
|
| 108 |
// |
| 109 |
// Check the pass criteria using the JS framework |
| 110 |
// |
| 111 |
test(function() {assert_equals(rootId, "svg-root")}, "Assert that the document's root identifier is 'svg-root'."); |
| 112 |
test(function() { |
| 113 |
assert_true(newRect instanceof SVGRectElement); |
| 114 |
assert_equals(newRect.getAttribute('x'), String(x+10)); |
| 115 |
assert_equals(newRect.getAttribute('y'), String(y+10)); |
| 116 |
assert_equals(newRect.getAttribute('width'), String(width)); |
| 117 |
assert_equals(newRect.getAttribute('height'), String(height)); |
| 118 |
}, "Assert that 'newRect' is replica (ignoring fill) of 'rect' with different x and y."); |
| 119 |
} |
| 120 |
|
| 121 |
]]></script> |
| 122 |
<!--======================================================================--> |
| 123 |
<!-- Since this test is examining the SVG DOM, it could use any language --> |
| 124 |
<!-- binding. Here is the equivalent code for the Java binding --> |
| 125 |
<!-- |
| 126 |
|
| 127 |
// |
| 128 |
// Test that our rectangle is an SVGElement instance |
| 129 |
// |
| 130 |
SVGRectElement rect = (SVGRectElement) doc.getElementById("rectId"); |
| 131 |
SVGElement rootSVG = rect.getOwnerSVGElement(); |
| 132 |
String rootId = rootSVG.getId(); |
| 133 |
|
| 134 |
// Insert a new text element to the DOM tree using the id |
| 135 |
Element newText = doc.createElement("text"); |
| 136 |
newText.setAttribute("x", "50"); |
| 137 |
newText.setAttribute("y", "100"); |
| 138 |
String message = "This document's root identifier is=" " + rootId" |
| 139 |
Text textContent = doc.createTextNode(message); |
| 140 |
newText.appendChild(textContent); |
| 141 |
rect.getParentNode().appendChild(newText); |
| 142 |
|
| 143 |
// |
| 144 |
// Now, check that our rectangle is an instance of SVGRect by accessing |
| 145 |
// specific methods in order to get its x, y, width and height attributes. |
| 146 |
// |
| 147 |
float x = rect.getX().getBaseVal().getValue(); |
| 148 |
float y = rect.getY().getBaseVal().getValue(); |
| 149 |
float width = rect.getWidth().getBaseVal().getValue(); |
| 150 |
float height = rect.getHeight().getBaseVal().getValue(); |
| 151 |
|
| 152 |
// |
| 153 |
// Now, build a new SVGRect through the SVGSVGElement interface. |
| 154 |
// |
| 155 |
SVGRectElement newRect = (SVGRectElement) doc.createElement("rect"); |
| 156 |
|
| 157 |
// |
| 158 |
// Set the x, y, width and height of this element |
| 159 |
// |
| 160 |
newRect.getX().getBaseVal().setValue(x + 10); |
| 161 |
newRect.getY().getBaseVal().setValue(y + 10); |
| 162 |
newRect.getWidth().getBaseVal().setValue(width); |
| 163 |
newRect.getHeight().getBaseVal().setValue(height); |
| 164 |
|
| 165 |
// |
| 166 |
// Insert new element in DOM tree |
| 167 |
// |
| 168 |
alert(newRect) |
| 169 |
rect.getParentNode().insertBefore(newRect, rect); |
| 170 |
|
| 171 |
--> |
| 172 |
<!-- ===================================================================== --> |
| 173 |
<!-- The following rectangle's is accessed in the 'domTest' ECMA Script --> |
| 174 |
<!-- handler. --> |
| 175 |
<!-- ===================================================================== --> |
| 176 |
<rect id="rectId" x="40" y="150" width="50" height="50" fill="green"/> |
| 177 |
</g> |
| 178 |
<g font-family="SVGFreeSansASCII,sans-serif" font-size="32"> |
| 179 |
<text id="revision" x="10" y="340" stroke="none" fill="black">$Revision: 1.8 $</text> |
| 180 |
</g> |
| 181 |
<rect id="test-frame" x="1" y="1" width="478" height="358" fill="none" stroke="#000000"/> |
| 182 |
<!-- comment out this watermark once the test is approved --> |
| 183 |
<!--<g id="draft-watermark"> |
| 184 |
<rect x="1" y="1" width="478" height="20" fill="red" stroke="black" stroke-width="1"/> |
| 185 |
<text font-family="SVGFreeSansASCII,sans-serif" font-weight="bold" font-size="20" x="240" |
| 186 |
text-anchor="middle" y="18" stroke-width="0.5" stroke="black" fill="white">DRAFT</text> |
| 187 |
</g>--> |
| 188 |
</svg> |