test_SVGLengthList.xhtml (6222B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <!-- 3 https://bugzilla.mozilla.org/show_bug.cgi?id=515116 4 --> 5 <head> 6 <title>Tests specific to SVGLengthList</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=515116">Mozilla Bug 515116</a> 12 <p id="display"></p> 13 <div id="content" style="display:none;"> 14 <svg id="svg" xmlns="http://www.w3.org/2000/svg" width="100" height="100"> 15 <text id="text" x="10cm 20cm 30mc"/> 16 <rect id="rect" x="40" y="50"/> 17 <text id="text2" x="60"/> 18 </svg> 19 </div> 20 <pre id="test"> 21 <script class="testbody" type="text/javascript"> 22 <![CDATA[ 23 24 SimpleTest.waitForExplicitFinish(); 25 26 /* 27 This file runs a series of SVGLengthList specific tests. Generic SVGXxxList 28 tests can be found in test_SVGxxxList.xhtml. Anything that can be generalized 29 to other list types belongs there. 30 */ 31 32 function run_tests() { 33 document.getElementById("svg").pauseAnimations(); 34 35 var text = document.getElementById("text"); 36 var lengths = text.x.baseVal; 37 38 is(lengths.numberOfItems, 0, "Checking numberOfItems"); 39 40 // Test mutation events 41 // --- Initialization 42 text.textContent = "abc"; 43 text.setAttribute("x", "10 20 30"); 44 is(lengths.numberOfItems, 3, "Checking numberOfItems"); 45 // -- Actual changes 46 lengths[0].value = 8; 47 lengths[0].valueInSpecifiedUnits = 9; 48 lengths[0].valueAsString = "10"; 49 lengths[0].convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_CM); 50 lengths[0].newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_MM, 11); 51 try { 52 lengths[0].newValueSpecifiedUnits(100, 11); 53 } catch (e) { 54 is(e.code, DOMException.NOT_SUPPORTED_ERR, "should throw NotSupportedError"); 55 } 56 // -- Redundant changes 57 lengths[0].valueAsString = "10"; 58 lengths[0].value = 10; 59 lengths[0].valueInSpecifiedUnits = 10; 60 lengths[0].valueAsString = "10"; 61 lengths[0].convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_NUMBER); 62 lengths[0].newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_NUMBER, 10); 63 // -- Invalid attribute 64 text.setAttribute("x", ",20"); 65 is(lengths.numberOfItems, 0, "Checking that parsing stops at invalid token"); 66 // -- Attribute removal 67 text.removeAttribute("x"); 68 // -- Non-existent attribute removal 69 text.removeAttribute("x"); 70 text.removeAttributeNS(null, "x"); 71 72 // Test that the addition of an owned SVGLength to an SVGLengthList creates a 73 // copy of the SVGLength, and an unowned SVGLength does not make a copy 74 var text2 = document.getElementById("text2"); 75 var rect = document.getElementById("rect"); 76 var subtests = [ 77 function initialize(aItem) { 78 text.removeAttribute("x"); 79 return lengths.initialize(aItem); 80 }, 81 function insertItemBefore(aItem) { 82 text.removeAttribute("x"); 83 return lengths.insertItemBefore(aItem, 0); 84 }, 85 function replaceItem(aItem) { 86 text.setAttribute("x", "10"); 87 return lengths.replaceItem(aItem, 0); 88 }, 89 function appendItem(aItem) { 90 text.removeAttribute("x"); 91 return lengths.appendItem(aItem); 92 }, 93 ]; 94 subtests.forEach(function(aFunction) { 95 // -- Adding an unowned SVGLength 96 var name = aFunction.name; 97 var existingItem = document.getElementById("svg").createSVGLength(); 98 var newItem = aFunction(existingItem); 99 is(newItem, lengths.getItem(0), name + " return value is correct when passed an unowned object"); 100 is(newItem, existingItem, name + " did not make a copy when passed an unowned object"); 101 }); 102 subtests.forEach(function(aFunction) { 103 // -- Adding an SVGLength that is a baseVal 104 var name = aFunction.name; 105 var existingItem = rect.x.baseVal; 106 var newItem = aFunction(existingItem); 107 is(newItem, lengths.getItem(0), name + " return value is correct when passed a baseVal"); 108 isnot(newItem, existingItem, name + " made a copy when passed a baseVal"); 109 is(newItem.value, existingItem.value, name + " made a copy with the right values when passed a baseVal"); 110 is(rect.x.baseVal, existingItem, name + " left the original object alone when passed a baseVal"); 111 }); 112 subtests.forEach(function(aFunction) { 113 // -- Adding an SVGLength that is an animVal 114 var name = aFunction.name; 115 var existingItem = rect.x.animVal; 116 var newItem = aFunction(existingItem); 117 is(newItem, lengths.getItem(0), name + " return value is correct when passed an animVal"); 118 isnot(newItem, existingItem, name + " made a copy when passed an animVal"); 119 is(newItem.value, existingItem.value, name + " made a copy with the right values when passed an animVal"); 120 is(rect.x.animVal, existingItem, name + " left the original object alone when passed an animVal"); 121 }); 122 subtests.forEach(function(aFunction) { 123 // -- Adding an SVGLength that is in a baseVal list 124 var name = aFunction.name; 125 var existingItem = text2.x.baseVal.getItem(0); 126 var newItem = aFunction(existingItem); 127 is(newItem, lengths.getItem(0), name + " return value is correct when passed a baseVal list item"); 128 isnot(newItem, existingItem, name + " made a copy when passed a baseVal list item"); 129 is(newItem.value, existingItem.value, name + " made a copy with the right values when passed a baseVal list item"); 130 is(text2.x.baseVal.getItem(0), existingItem, name + " left the original object alone when passed a baseVal list item"); 131 }); 132 subtests.forEach(function(aFunction) { 133 // -- Adding an SVGLength that is in a animVal list 134 var name = aFunction.name; 135 var existingItem = text2.x.animVal.getItem(0); 136 var newItem = aFunction(existingItem); 137 is(newItem, lengths.getItem(0), name + " return value is correct when passed a animVal list item"); 138 isnot(newItem, existingItem, name + " made a copy when passed a animVal list item"); 139 is(newItem.value, existingItem.value, name + " made a copy with the right values when passed a animVal list item"); 140 is(text2.x.animVal.getItem(0), existingItem, name + " left the original object alone when passed a animVal list item"); 141 }); 142 143 SimpleTest.finish(); 144 } 145 146 window.addEventListener("load", 147 () => SimpleTest.executeSoon(run_tests) 148 ); 149 150 ]]> 151 </script> 152 </pre> 153 </body> 154 </html>