| OLD | NEW |
| (Empty) |
| 1 description("This test checks the SVGAngle API"); | |
| 2 | |
| 3 var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg"); | |
| 4 var angle = svgElement.createSVGAngle(); | |
| 5 | |
| 6 debug(""); | |
| 7 debug("Check initial angle values"); | |
| 8 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 9 shouldBeEqualToString("angle.valueAsString", "0"); | |
| 10 shouldBe("angle.value", "0"); | |
| 11 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 12 | |
| 13 // Spec: Raised if unitType is SVG_ANGLETYPE_UNKNOWN or not a valid unit type co
nstant (one of the other SVG_ANGLETYPE_* constants defined on this interface). | |
| 14 debug(""); | |
| 15 debug("Check invalid arguments for 'convertToSpecifiedUnits'"); | |
| 16 shouldThrow("angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_UNKNOWN)"); | |
| 17 shouldThrow("angle.convertToSpecifiedUnits(-1)"); | |
| 18 shouldThrow("angle.convertToSpecifiedUnits(5)"); | |
| 19 // 'aString' converts to short 0 (through NaN) according to ECMA-262, ToUint16. | |
| 20 // Therefore this throws NOT_SUPPORTED_ERR. | |
| 21 shouldThrow("angle.convertToSpecifiedUnits('aString')"); | |
| 22 // Same here, via ToString conversion of object. | |
| 23 shouldThrow("angle.convertToSpecifiedUnits(angle)"); | |
| 24 // Same here, via ToString conversion of object. | |
| 25 shouldThrow("angle.convertToSpecifiedUnits(svgElement)"); | |
| 26 shouldThrow("angle.convertToSpecifiedUnits()"); | |
| 27 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 28 | |
| 29 debug(""); | |
| 30 debug("Check valid arguments for 'convertToSpecifiedUnits', that should only mod
ify the 'valueAsString'"); | |
| 31 shouldBeUndefined("angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_RAD)"); | |
| 32 shouldBeEqualToString("angle.valueAsString", "0rad"); | |
| 33 shouldBe("angle.value", "0"); | |
| 34 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 35 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_RAD"); | |
| 36 | |
| 37 shouldBeUndefined("angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_GRAD)"); | |
| 38 shouldBeEqualToString("angle.valueAsString", "0grad"); | |
| 39 shouldBe("angle.value", "0"); | |
| 40 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 41 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_GRAD"); | |
| 42 | |
| 43 shouldBeUndefined("angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG)"); | |
| 44 shouldBeEqualToString("angle.valueAsString", "0deg"); | |
| 45 shouldBe("angle.value", "0"); | |
| 46 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 47 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_DEG"); | |
| 48 | |
| 49 shouldBeUndefined("angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_UNSPECIF
IED)"); | |
| 50 shouldBeEqualToString("angle.valueAsString", "0"); | |
| 51 shouldBe("angle.value", "0"); | |
| 52 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 53 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 54 | |
| 55 // Spec: Raised if unitType is SVG_ANGLETYPE_UNKNOWN or not a valid unit type co
nstant (one of the other SVG_ANGLETYPE_* constants defined on this interface). | |
| 56 debug(""); | |
| 57 debug("Check invalid arguments for 'newValueSpecifiedUnits'"); | |
| 58 shouldThrow("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_UNKNOWN, 50)"); | |
| 59 shouldThrow("angle.newValueSpecifiedUnits(-1, 50)"); | |
| 60 shouldThrow("angle.newValueSpecifiedUnits(5, 50)"); | |
| 61 shouldThrow("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG)"); | |
| 62 shouldThrow("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, 'aString')
"); | |
| 63 shouldBe("angle.value", "0"); | |
| 64 shouldBeUndefined("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, 0)")
; | |
| 65 shouldThrow("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, angle)"); | |
| 66 shouldBe("angle.value", "0"); | |
| 67 shouldThrow("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, svgElement
)"); | |
| 68 shouldBe("angle.value", "0"); | |
| 69 shouldThrow("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, NaN)"); | |
| 70 shouldBe("angle.value", "0"); | |
| 71 shouldThrow("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, Infinity)"
); | |
| 72 shouldBe("angle.value", "0"); | |
| 73 shouldThrow("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG)"); | |
| 74 // All of the following unitType arguments convert to 0 (SVG_ANGLETYPE_UNKNOWN). | |
| 75 shouldThrow("angle.newValueSpecifiedUnits('aString', 4)"); | |
| 76 shouldThrow("angle.newValueSpecifiedUnits(angle, 4)"); | |
| 77 shouldThrow("angle.newValueSpecifiedUnits(svgElement, 4)"); | |
| 78 shouldThrow("angle.newValueSpecifiedUnits('aString', 'aString')"); | |
| 79 shouldThrow("angle.newValueSpecifiedUnits(angle, angle)"); | |
| 80 shouldThrow("angle.newValueSpecifiedUnits(svgElement, svgElement)"); | |
| 81 shouldThrow("angle.newValueSpecifiedUnits()"); | |
| 82 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_DEG"); | |
| 83 | |
| 84 debug(""); | |
| 85 debug("Check valid arguments for 'newValueSpecifiedUnits', that should only modi
fy the 'valueAsString'"); | |
| 86 shouldBeUndefined("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_RAD, pars
eFloat(Math.PI.toFixed(5)))"); | |
| 87 shouldBeEqualToString("angle.valueAsString", Math.PI.toFixed(5) + "rad"); | |
| 88 shouldBeEqualToString("angle.value.toFixed(1)", "180.0"); | |
| 89 shouldBe("angle.valueInSpecifiedUnits.toFixed(5)", "Math.PI.toFixed(5)"); | |
| 90 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_RAD"); | |
| 91 | |
| 92 shouldBeUndefined("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_GRAD, 400
)"); | |
| 93 shouldBeEqualToString("angle.valueAsString", "400grad"); | |
| 94 shouldBeEqualToString("angle.value.toFixed(1)", "360.0"); | |
| 95 shouldBe("angle.valueInSpecifiedUnits", "400"); | |
| 96 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_GRAD"); | |
| 97 | |
| 98 shouldBeUndefined("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, 360)
"); | |
| 99 shouldBeEqualToString("angle.valueAsString", "360deg"); | |
| 100 shouldBe("angle.value", "360"); | |
| 101 shouldBe("angle.valueInSpecifiedUnits", "360"); | |
| 102 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_DEG"); | |
| 103 | |
| 104 shouldBeUndefined("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_UNSPECIFI
ED, 180)"); | |
| 105 shouldBeEqualToString("angle.valueAsString", "180"); | |
| 106 shouldBe("angle.value", "180"); | |
| 107 shouldBe("angle.valueInSpecifiedUnits", "180"); | |
| 108 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 109 | |
| 110 debug(""); | |
| 111 debug("Reset to initial angle state"); | |
| 112 shouldBeUndefined("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_UNSPECIFI
ED, 0)"); | |
| 113 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 114 | |
| 115 // Spec: Raised if the assigned string cannot be parsed as a valid <angle>. | |
| 116 debug(""); | |
| 117 debug("Check setting invalid 'valueAsString' arguments"); | |
| 118 shouldThrow("angle.valueAsString = '10px'"); | |
| 119 shouldBeEqualToString("angle.valueAsString", "0"); | |
| 120 shouldBe("angle.value", "0"); | |
| 121 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 122 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 123 | |
| 124 shouldThrow("angle.valueAsString = '10x'"); | |
| 125 shouldBeEqualToString("angle.valueAsString", "0"); | |
| 126 shouldBe("angle.value", "0"); | |
| 127 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 128 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 129 | |
| 130 shouldThrow("angle.valueAsString = '5graD'"); | |
| 131 shouldBeEqualToString("angle.valueAsString", "0"); | |
| 132 shouldBe("angle.value", "0"); | |
| 133 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 134 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 135 | |
| 136 shouldThrow("angle.valueAsString = '5Rad'"); | |
| 137 shouldBeEqualToString("angle.valueAsString", "0"); | |
| 138 shouldBe("angle.value", "0"); | |
| 139 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 140 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 141 | |
| 142 shouldThrow("angle.valueAsString = ',5 rad'"); | |
| 143 shouldBeEqualToString("angle.valueAsString", "0"); | |
| 144 shouldBe("angle.value", "0"); | |
| 145 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 146 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 147 | |
| 148 shouldThrow("angle.valueAsString = null"); | |
| 149 shouldBeEqualToString("angle.valueAsString", "0"); | |
| 150 shouldBe("angle.value", "0"); | |
| 151 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 152 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 153 | |
| 154 debug(""); | |
| 155 debug("Check setting invalid 'valueInSpecifiedUnits' arguments"); | |
| 156 shouldThrow("angle.valueInSpecifiedUnits = 'test'"); | |
| 157 shouldBe("angle.value", "0"); | |
| 158 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 159 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 160 shouldBe("angle.valueInSpecifiedUnits = 0", "0"); | |
| 161 | |
| 162 shouldThrow("angle.valueInSpecifiedUnits = angle"); | |
| 163 shouldBe("angle.value", "0"); | |
| 164 shouldThrow("angle.valueInSpecifiedUnits = NaN"); | |
| 165 shouldBe("angle.value", "0"); | |
| 166 shouldThrow("angle.valueInSpecifiedUnits = Infinity"); | |
| 167 shouldBe("angle.value", "0"); | |
| 168 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 169 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 170 | |
| 171 debug(""); | |
| 172 debug("Check setting invalid 'value' arguments"); | |
| 173 shouldBe("angle.value = 0", "0"); | |
| 174 shouldThrow("angle.value = 'test'"); | |
| 175 shouldBe("angle.value", "0"); | |
| 176 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 177 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 178 | |
| 179 shouldBe("angle.value = 0", "0"); | |
| 180 shouldThrow("angle.value = angle"); | |
| 181 shouldBe("angle.value", "0"); | |
| 182 shouldThrow("angle.value = NaN"); | |
| 183 shouldBe("angle.value", "0"); | |
| 184 shouldThrow("angle.value = Infinity"); | |
| 185 shouldBe("angle.value", "0"); | |
| 186 shouldBe("angle.valueInSpecifiedUnits", "0"); | |
| 187 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_UNSPECIFIED"); | |
| 188 | |
| 189 debug(""); | |
| 190 debug("Reset to angle in degree units"); | |
| 191 shouldBeUndefined("angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, 0)")
; | |
| 192 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_DEG"); | |
| 193 | |
| 194 debug(""); | |
| 195 debug("Check setting valid 'value' arguments, assure that 'valueInSpecifiedUnits
' and 'valueAsString' are synchronized"); | |
| 196 shouldBe("angle.value = 50", "50"); | |
| 197 shouldBe("angle.valueInSpecifiedUnits", "50"); | |
| 198 shouldBeEqualToString("angle.valueAsString", "50deg"); | |
| 199 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_DEG"); | |
| 200 | |
| 201 debug(""); | |
| 202 debug("Try modifiying the readonly 'unitType', needs to fail"); | |
| 203 shouldBeUndefined("angle.unitType = SVGAngle.SVG_ANGLETTYE_RAD"); | |
| 204 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_DEG"); | |
| 205 | |
| 206 debug(""); | |
| 207 debug("Check setting valid 'valueInSpecifiedUnits' arguments, assure that 'value
' and 'valueAsString' are synchronized"); | |
| 208 shouldBe("angle.valueInSpecifiedUnits = 100", "100"); | |
| 209 shouldBe("angle.value", "100"); | |
| 210 shouldBeEqualToString("angle.valueAsString", "100deg"); | |
| 211 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_DEG"); | |
| 212 | |
| 213 debug(""); | |
| 214 debug("Check setting valid 'valueAsString' arguments, assure that 'value' and 'v
alueInSpecifiedUnits' are synchronized"); | |
| 215 shouldBeEqualToString("angle.valueAsString = '200grad'", "200grad"); | |
| 216 shouldBe("angle.valueInSpecifiedUnits", "200"); | |
| 217 shouldBeEqualToString("angle.value.toFixed(1)", "180.0"); | |
| 218 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_GRAD"); | |
| 219 | |
| 220 debug(""); | |
| 221 debug("Now convert the GRAD value into a RAD value, and assure that all properti
es have been synchronized"); | |
| 222 shouldBeUndefined("angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_RAD)"); | |
| 223 shouldBeEqualToString("angle.value.toFixed(1)", "180.0"); | |
| 224 shouldBeEqualToString("angle.valueInSpecifiedUnits.toFixed(5)", Math.PI.toFixed(
5)); | |
| 225 shouldBeEqualToString("angle.valueAsString", Math.PI.toFixed(5) + "rad"); | |
| 226 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_RAD"); | |
| 227 | |
| 228 debug(""); | |
| 229 debug("Now try converting the RAD value into an unknown value, that should fail
and throw"); | |
| 230 shouldThrow("angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_UNKNOWN)"); | |
| 231 shouldBeEqualToString("angle.value.toFixed(1)", "180.0"); | |
| 232 shouldBeEqualToString("angle.valueInSpecifiedUnits.toFixed(5)", Math.PI.toFixed(
5)); | |
| 233 shouldBeEqualToString("angle.valueAsString", Math.PI.toFixed(5) + "rad"); | |
| 234 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_RAD"); | |
| 235 | |
| 236 debug(""); | |
| 237 debug("Now convert the RAD value into a DEG value, and assure that all propertie
s have been synchronized"); | |
| 238 shouldBeUndefined("angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG)"); | |
| 239 shouldBeEqualToString("angle.value.toFixed(1)", "180.0"); | |
| 240 shouldBeEqualToString("angle.valueInSpecifiedUnits.toFixed(1)", "180.0"); | |
| 241 shouldBeEqualToString("angle.valueAsString", "180deg"); | |
| 242 shouldBe("angle.unitType", "SVGAngle.SVG_ANGLETYPE_DEG"); | |
| 243 | |
| 244 successfullyParsed = true; | |
| OLD | NEW |