test_SVGxxxListIndexing.xhtml (3313B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <!-- 3 https://bugzilla.mozilla.org/show_bug.cgi?id=631437 4 --> 5 <head> 6 <title>Tests the array indexing and .length on SVGXXXList objects</title> 7 <script src="/tests/SimpleTest/SimpleTest.js"></script> 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 9 </head> 10 <body> 11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=631437">Mozilla Bug 631437</a> 12 <svg xmlns="http://www.w3.org/2000/svg" id="svg"> 13 <text id="text" x="10 20 30" rotate="40 50 60">abcde</text> 14 <path id="path" d="M0,0 L100,100"/> 15 <polygon id="poly" points="50,50 70,70 90,50"/> 16 <g id="g" transform="translate(20 30) rotate(50 60 70) scale(2)" 17 requiredExtensions="foo bar baz"/> 18 </svg> 19 <script type="text/javascript"><![CDATA[ 20 21 var text = document.getElementById("text"), 22 path = document.getElementById("path"), 23 poly = document.getElementById("poly"), 24 g = document.getElementById("g"); 25 26 function CheckList(aListObject, aExpectedListLength, aListDescription) { 27 is(aListObject.numberOfItems, aExpectedListLength, aListDescription + ".numberOfItems"); 28 is(aListObject.length, aExpectedListLength, aListDescription + ".length"); 29 for (let i = 0; i < aListObject.length; i++) { 30 let item = aListObject.getItem(i); 31 ok(aListObject[i] === item, aListDescription + "[" + i + "]"); 32 } 33 is(typeof(aListObject[aListObject.length]), "undefined", aListDescription + "[outOfBounds]"); 34 } 35 36 var tests = [ 37 { element: text, 38 attribute: "x", 39 listProperty: "x.baseVal", 40 type: "SVGLengthList", 41 subtests: [ { values: null, length: 3 }, 42 { values: "40", length: 1 }, 43 { values: "1em 2em 3em 4em 5em", length: 5 } ] }, 44 { element: text, 45 attribute: "rotate", 46 listProperty: "rotate.baseVal", 47 type: "SVGNumberList", 48 subtests: [ { values: null, length: 3 }, 49 { values: "10", length: 1 }, 50 { values: "1 2 3 4 5", length: 5 } ] }, 51 { element: poly, 52 attribute: "points", 53 listProperty: "animatedPoints", 54 type: "SVGPointList", 55 subtests: [ { values: null, length: 3 }, 56 { values: "100,100", length: 1 }, 57 { values: "0,0 10,10 20,0 30,10 40,0", length: 5 } ] }, 58 { element: g, 59 attribute: "transform", 60 listProperty: "transform.baseVal", 61 type: "SVGTransformList", 62 subtests: [ { values: null, length: 3 }, 63 { values: "skewX(45)", length: 1 }, 64 { values: "translate(1 2) rotate(3) scale(4) skewY(5) skewX(6)", 65 length: 5 } ] }, 66 { element: g, 67 attribute: "requiredExtensions", 68 listProperty: "requiredExtensions", 69 type: "SVGStringList", 70 subtests: [ { values: null, length: 3 }, 71 { values: "foo", length: 1 }, 72 { values: "foo bar baz qux", length: 4 } ] }, 73 ]; 74 75 for (let test of tests) { 76 let list = test.element; 77 for (let property of test.listProperty.split(".")) { 78 list = list[property]; 79 } 80 81 for (let subtest of test.subtests) { 82 if (subtest.values) { 83 test.element.setAttribute(test.attribute, subtest.values); 84 } 85 86 CheckList(list, subtest.length, 87 test.type + ": " + test.element.localName + "." + 88 test.listProperty); 89 } 90 } 91 ]]></script> 92 </body> 93 </html>