test_dataTypes.html (18864B)
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=437448 5 --> 6 <head> 7 <title>Test for Bug 437448</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=437448">Mozilla Bug 437448</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"></div> 15 16 <iframe id="svg" src="dataTypes-helper.svg"></iframe> 17 18 <pre id="test"> 19 <script class="testbody" type="application/javascript"> 20 SimpleTest.waitForExplicitFinish(); 21 22 function runTests() { 23 var doc = $("svg").contentWindow.document; 24 var filter = doc.getElementById("filter"); 25 var convolve = doc.getElementById("convolve"); 26 var blur = doc.getElementById("blur"); 27 var marker = doc.getElementById("marker"); 28 29 // class attribute 30 filter.setAttribute("class", "foo"); 31 is(filter.getAttribute("class"), "foo", "class attribute"); 32 is(filter.className.baseVal, "foo", "className baseVal"); 33 is(filter.className.animVal, "foo", "className animVal"); 34 filter.className.baseVal = "bar"; 35 is(filter.getAttribute("class"), "bar", "class attribute"); 36 is(filter.className.baseVal, "bar", "className baseVal"); 37 is(filter.className.animVal, "bar", "className animVal"); 38 filter.removeAttribute("class"); 39 is(filter.hasAttribute("class"), false, "class attribute"); 40 ok(filter.getAttribute("class") === null, "removed class attribute"); 41 is(filter.className.baseVal, "", "className baseVal"); 42 is(filter.className.animVal, "", "className animVal"); 43 filter.setAttribute("class", ""); 44 ok(filter.getAttribute("class") === "", "empty class attribute"); 45 46 // length attribute 47 48 marker.setAttribute("markerWidth", "12.5"); 49 is(marker.markerWidth.baseVal.value, 12.5, "length baseVal"); 50 is(marker.markerWidth.animVal.value, 12.5, "length animVal"); 51 52 var baseMarkerWidth = marker.markerWidth.baseVal; 53 var animMarkerWidth = marker.markerWidth.animVal; 54 marker.setAttribute("markerWidth", "15.5"); 55 is(baseMarkerWidth.value, 15.5, "length baseVal"); 56 is(animMarkerWidth.value, 15.5, "length animVal"); 57 58 marker.markerWidth.baseVal.value = 7.5; 59 is(marker.markerWidth.animVal.value, 7.5, "length animVal"); 60 is(marker.getAttribute("markerWidth"), "7.5", "length attribute"); 61 62 marker.setAttribute("markerWidth", ""); 63 ok(marker.getAttribute("markerWidth") === "", "empty length attribute"); 64 marker.removeAttribute("markerWidth"); 65 ok(marker.getAttribute("markerWidth") === null, "removed length attribute"); 66 67 // number attribute 68 69 convolve.setAttribute("divisor", "12.5"); 70 is(convolve.divisor.baseVal, 12.5, "number baseVal"); 71 is(convolve.divisor.animVal, 12.5, "number animVal"); 72 73 convolve.divisor.baseVal = 7.5; 74 is(convolve.divisor.animVal, 7.5, "number animVal"); 75 is(convolve.getAttribute("divisor"), "7.5", "number attribute"); 76 77 convolve.setAttribute("divisor", ""); 78 ok(convolve.getAttribute("divisor") === "", "empty number attribute"); 79 convolve.removeAttribute("divisor"); 80 ok(convolve.getAttribute("divisor") === null, "removed number attribute"); 81 82 // number-optional-number attribute 83 84 blur.setAttribute("stdDeviation", "20.5"); 85 is(blur.stdDeviationX.baseVal, 20.5, "number-optional-number first baseVal"); 86 is(blur.stdDeviationX.animVal, 20.5, "number-optional-number first animVal"); 87 is(blur.stdDeviationY.baseVal, 20.5, "number-optional-number second baseVal"); 88 is(blur.stdDeviationY.animVal, 20.5, "number-optional-number second animVal"); 89 90 blur.stdDeviationX.baseVal = 8.5; 91 is(blur.stdDeviationX.animVal, 8.5, "number-optional-number first animVal"); 92 is(blur.stdDeviationY.animVal, 20.5, "number-optional-number second animVal"); 93 is(blur.getAttribute("stdDeviation"), "8.5, 20.5", "number-optional-number attribute"); 94 95 blur.stdDeviationY.baseVal = 8.5; 96 is(blur.getAttribute("stdDeviation"), "8.5", "number-optional-number attribute"); 97 98 blur.setStdDeviation(24.5, 0.5); 99 is(blur.stdDeviationX.baseVal, 24.5, "number-optional-number first baseVal"); 100 is(blur.stdDeviationX.animVal, 24.5, "number-optional-number first animVal"); 101 is(blur.stdDeviationY.baseVal, 0.5, "number-optional-number second baseVal"); 102 is(blur.stdDeviationY.animVal, 0.5, "number-optional-number second animVal"); 103 104 blur.setAttribute("stdDeviation", ""); 105 ok(blur.getAttribute("stdDeviation") === "", 106 "empty number-optional-number attribute"); 107 blur.removeAttribute("stdDeviation"); 108 ok(blur.getAttribute("stdDeviation") === null, 109 "removed number-optional-number attribute"); 110 111 // integer attribute 112 113 convolve.setAttribute("targetX", "12"); 114 is(convolve.targetX.baseVal, 12, "integer baseVal"); 115 is(convolve.targetX.animVal, 12, "integer animVal"); 116 convolve.targetX.baseVal = 7; 117 is(convolve.targetX.animVal, 7, "integer animVal"); 118 is(convolve.getAttribute("targetX"), "7", "integer attribute"); 119 convolve.setAttribute("targetX", ""); 120 ok(convolve.getAttribute("targetX") === "", "empty integer attribute"); 121 convolve.removeAttribute("targetX"); 122 ok(convolve.getAttribute("targetX") === null, "removed integer attribute"); 123 124 // integer-optional-integer attribute 125 126 convolve.setAttribute("order", "5"); 127 is(convolve.orderX.baseVal, 5, "integer-optional-integer first baseVal"); 128 is(convolve.orderX.animVal, 5, "integer-optional-integer first animVal"); 129 is(convolve.orderY.baseVal, 5, "integer-optional-integer second baseVal"); 130 is(convolve.orderY.animVal, 5, "integer-optional-integer second animVal"); 131 132 convolve.orderX.baseVal = 7; 133 is(convolve.orderX.animVal, 7, "integer-optional-integer first animVal"); 134 is(convolve.orderY.animVal, 5, "integer-optional-integer second animVal"); 135 is(convolve.getAttribute("order"), "7, 5", "integer-optional-integer attribute"); 136 137 convolve.orderY.baseVal = 7; 138 is(convolve.getAttribute("order"), "7", "integer-optional-integer attribute"); 139 140 convolve.setAttribute("order", "11, 13"); 141 is(convolve.orderX.baseVal, 11, "integer-optional-integer first baseVal"); 142 is(convolve.orderX.animVal, 11, "integer-optional-integer first animVal"); 143 is(convolve.orderY.baseVal, 13, "integer-optional-integer second baseVal"); 144 is(convolve.orderY.animVal, 13, "integer-optional-integer second animVal"); 145 146 // 32 bit integer range 147 convolve.setAttribute("order", "-2147483648, 2147483647"); 148 is(convolve.orderX.baseVal, -2147483648, "integer-optional-integer first baseVal"); 149 is(convolve.orderX.animVal, -2147483648, "integer-optional-integer first animVal"); 150 is(convolve.orderY.baseVal, 2147483647, "integer-optional-integer second baseVal"); 151 is(convolve.orderY.animVal, 2147483647, "integer-optional-integer second animVal"); 152 153 // too big, clamp 154 convolve.setAttribute("order", "-2147483649, 2147483648"); 155 is(convolve.orderX.baseVal, -2147483648, "integer-optional-integer first baseVal"); 156 is(convolve.orderX.animVal, -2147483648, "integer-optional-integer first animVal"); 157 is(convolve.orderY.baseVal, 2147483647, "integer-optional-integer second baseVal"); 158 is(convolve.orderY.animVal, 2147483647, "integer-optional-integer second animVal"); 159 160 // invalid 161 convolve.setAttribute("order", "-00000000000invalid, 214748364720invalid"); 162 is(convolve.orderX.baseVal, 3, "integer-optional-integer first baseVal"); 163 is(convolve.orderX.animVal, 3, "integer-optional-integer first animVal"); 164 is(convolve.orderY.baseVal, 3, "integer-optional-integer second baseVal"); 165 is(convolve.orderY.animVal, 3, "integer-optional-integer second animVal"); 166 167 convolve.setAttribute("order", ""); 168 ok(convolve.getAttribute("order") === "", 169 "empty integer-optional-integer attribute"); 170 convolve.removeAttribute("order"); 171 ok(convolve.getAttribute("order") === null, 172 "removed integer-optional-integer attribute"); 173 174 // angle attribute 175 176 marker.setAttribute("orient", "90deg"); 177 is(marker.orientAngle.baseVal.value, 90, "angle baseVal"); 178 is(marker.orientAngle.animVal.value, 90, "angle animVal"); 179 180 var baseAngle = marker.orientAngle.baseVal; 181 var animAngle = marker.orientAngle.animVal; 182 marker.setAttribute("orient", "45deg"); 183 is(baseAngle.value, 45, "angle baseVal"); 184 is(animAngle.value, 45, "angle animVal"); 185 186 marker.orientAngle.baseVal.value = 30; 187 is(marker.orientAngle.animVal.value, 30, "angle animVal"); 188 is(marker.getAttribute("orient"), "30deg", "angle attribute"); 189 190 marker.setAttribute("orient", "auto"); 191 is(marker.getAttribute("orient"), "auto", "checking 'auto' string preserved"); 192 is(marker.orientType.baseVal, SVGMarkerElement.SVG_MARKER_ORIENT_AUTO, "type baseVal"); 193 is(marker.orientType.animVal, SVGMarkerElement.SVG_MARKER_ORIENT_AUTO, "type animVal"); 194 195 marker.setAttribute("orient", "auto-start-reverse"); 196 is(marker.getAttribute("orient"), "auto-start-reverse", "checking 'auto-start-reverse' string preserved"); 197 is(marker.orientType.baseVal, SVGMarkerElement.SVG_MARKER_ORIENT_AUTO_START_REVERSE, "type baseVal"); 198 is(marker.orientType.animVal, SVGMarkerElement.SVG_MARKER_ORIENT_AUTO_START_REVERSE, "type animVal"); 199 200 marker.setAttribute("orient", ""); 201 ok(marker.getAttribute("orient") === "", "empty angle attribute"); 202 marker.removeAttribute("orient"); 203 ok(marker.getAttribute("orient") === null, "removed angle attribute"); 204 205 // boolean attribute 206 207 convolve.setAttribute("preserveAlpha", "false"); 208 is(convolve.preserveAlpha.baseVal, false, "boolean baseVal"); 209 is(convolve.preserveAlpha.animVal, false, "boolean animVal"); 210 convolve.preserveAlpha.baseVal = true; 211 is(convolve.preserveAlpha.animVal, true, "boolean animVal"); 212 is(convolve.getAttribute("preserveAlpha"), "true", "boolean attribute"); 213 convolve.setAttribute("preserveAlpha", ""); 214 ok(convolve.getAttribute("preserveAlpha") === "", "empty boolean attribute"); 215 convolve.removeAttribute("preserveAlpha"); 216 ok(convolve.getAttribute("preserveAlpha") === null, 217 "removed boolean attribute"); 218 219 // enum attribute 220 221 is(1, SVGFEConvolveMatrixElement.SVG_EDGEMODE_DUPLICATE, "SVG_EDGEMODE_DUPLICATE value"); 222 is(2, SVGFEConvolveMatrixElement.SVG_EDGEMODE_WRAP, "SVG_EDGEMODE_WRAP value"); 223 224 convolve.setAttribute("edgeMode", "wrap"); 225 is(convolve.edgeMode.baseVal, SVGFEConvolveMatrixElement.SVG_EDGEMODE_WRAP, "enum baseVal"); 226 is(convolve.edgeMode.animVal, SVGFEConvolveMatrixElement.SVG_EDGEMODE_WRAP, "enum animVal"); 227 convolve.edgeMode.baseVal = SVGFEConvolveMatrixElement.SVG_EDGEMODE_DUPLICATE; 228 is(convolve.edgeMode.animVal, SVGFEConvolveMatrixElement.SVG_EDGEMODE_DUPLICATE, "enum animVal"); 229 is(convolve.getAttribute("edgeMode"), "duplicate", "enum attribute"); 230 convolve.setAttribute("edgeMode", ""); 231 ok(convolve.getAttribute("edgeMode") === "", "empty enum attribute"); 232 convolve.removeAttribute("edgeMode"); 233 ok(convolve.getAttribute("edgeMode") === null, "removed enum attribute"); 234 235 // string attribute 236 237 convolve.setAttribute("result", "foo"); 238 is(convolve.result.baseVal, "foo", "string baseVal"); 239 is(convolve.result.animVal, "foo", "string animVal"); 240 convolve.result.baseVal = "bar"; 241 is(convolve.result.animVal, "bar", "string animVal"); 242 is(convolve.getAttribute("result"), "bar", "string attribute"); 243 convolve.setAttribute("result", ""); 244 ok(convolve.getAttribute("result") === "", "empty string attribute"); 245 convolve.removeAttribute("result"); 246 ok(convolve.getAttribute("result") === null, "removed string attribute"); 247 248 // preserveAspectRatio attribute 249 250 is(0, SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_UNKNOWN, "SVG_PRESERVEASPECTRATIO_UNKNOWN value"); 251 is(1, SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_NONE, "SVG_PRESERVEASPECTRATIO_NONE value"); 252 is(3, SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMIN, "SVG_PRESERVEASPECTRATIO_XMIDYMIN value"); 253 is(5, SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMID, "SVG_PRESERVEASPECTRATIO_XMINYMID value"); 254 is(7, SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMID, "SVG_PRESERVEASPECTRATIO_XMAXYMID value"); 255 is(10, SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMAX, "SVG_PRESERVEASPECTRATIO_XMAXYMAX value"); 256 257 is(0, SVGPreserveAspectRatio.SVG_MEETORSLICE_UNKNOWN, "SVG_MEETORSLICE_UNKNOWN value"); 258 is(1, SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET, "SVG_MEETORSLICE_MEET value"); 259 is(2, SVGPreserveAspectRatio.SVG_MEETORSLICE_SLICE, "SVG_MEETORSLICE_SLICE value"); 260 261 marker.setAttribute("preserveAspectRatio", "xMinYMid slice"); 262 is(marker.preserveAspectRatio.baseVal.align, 263 SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMID, "preserveAspectRatio.align baseVal"); 264 is(marker.preserveAspectRatio.animVal.align, 265 SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMID, "preserveAspectRatio.align animVal"); 266 is(marker.preserveAspectRatio.baseVal.meetOrSlice, 267 SVGPreserveAspectRatio.SVG_MEETORSLICE_SLICE, "preserveAspectRatio.meetOrSlice baseVal"); 268 is(marker.preserveAspectRatio.animVal.meetOrSlice, 269 SVGPreserveAspectRatio.SVG_MEETORSLICE_SLICE, "preserveAspectRatio.meetOrSlice animVal"); 270 marker.preserveAspectRatio.baseVal.align = 271 SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMIN; 272 is(marker.preserveAspectRatio.animVal.align, 273 SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMIN, "preserveAspectRatio animVal"); 274 is(marker.preserveAspectRatio.animVal.meetOrSlice, 275 SVGPreserveAspectRatio.SVG_MEETORSLICE_SLICE, "preserveAspectRatio.meetOrSlice animVal"); 276 marker.preserveAspectRatio.baseVal.meetOrSlice = SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET; 277 is(marker.preserveAspectRatio.animVal.align, 278 SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMIN, "preserveAspectRatio animVal"); 279 is(marker.preserveAspectRatio.animVal.meetOrSlice, 280 SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET, "preserveAspectRatio.meetOrSlice animVal"); 281 is(marker.getAttribute("preserveAspectRatio"), "xMidYMin meet", "preserveAspectRatio attribute"); 282 283 var basePreserveAspectRatio = marker.preserveAspectRatio.baseVal; 284 var animPreserveAspectRatio = marker.preserveAspectRatio.animVal; 285 marker.setAttribute("preserveAspectRatio", "xMaxYMid slice"); 286 is(basePreserveAspectRatio.align, 287 SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMID, "preserveAspectRatio.align baseVal"); 288 is(animPreserveAspectRatio.align, 289 SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMID, "preserveAspectRatio.align animVal"); 290 is(basePreserveAspectRatio.meetOrSlice, 291 SVGPreserveAspectRatio.SVG_MEETORSLICE_SLICE, "preserveAspectRatio.meetOrSlice baseVal"); 292 is(animPreserveAspectRatio.meetOrSlice, 293 SVGPreserveAspectRatio.SVG_MEETORSLICE_SLICE, "preserveAspectRatio.meetOrSlice animVal"); 294 295 marker.setAttribute("preserveAspectRatio", " none"); // invalid, space at beginning 296 is(basePreserveAspectRatio.align, SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMID, 297 "default preserveAspectRatio attribute"); 298 299 marker.setAttribute("preserveAspectRatio", "none "); // invalid, space at end 300 is(basePreserveAspectRatio.align, SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMID, 301 "default preserveAspectRatio attribute"); 302 303 marker.setAttribute("preserveAspectRatio", ""); 304 ok(marker.getAttribute("preserveAspectRatio") === "", 305 "empty preserveAspectRatio attribute"); 306 marker.removeAttribute("preserveAspectRatio"); 307 ok(marker.getAttribute("preserveAspectRatio") === null, 308 "removed preserveAspectRatio attribute"); 309 310 // viewBox attribute 311 var baseViewBox = marker.viewBox.baseVal; 312 var animViewBox = marker.viewBox.animVal; 313 is(baseViewBox, null, "viewBox baseVal"); 314 is(animViewBox, null, "viewBox animVal"); 315 316 marker.setAttribute("viewBox", "1 2 3 4"); 317 is(marker.viewBox.baseVal.x, 1, "viewBox.x baseVal"); 318 is(marker.viewBox.animVal.x, 1, "viewBox.x animVal"); 319 is(marker.viewBox.baseVal.y, 2, "viewbox.y baseVal"); 320 is(marker.viewBox.animVal.y, 2, "viewbox.y animVal"); 321 is(marker.viewBox.baseVal.width, 3, "viewbox.width baseVal"); 322 is(marker.viewBox.animVal.width, 3, "viewbox.width animVal"); 323 is(marker.viewBox.baseVal.height, 4, "viewbox.height baseVal"); 324 is(marker.viewBox.animVal.height, 4, "viewbox.height animVal"); 325 marker.viewBox.baseVal.x = 5; 326 is(marker.viewBox.animVal.x, 5, "viewBox.x animVal"); 327 marker.viewBox.baseVal.y = 6; 328 is(marker.viewBox.animVal.y, 6, "viewBox.y animVal"); 329 marker.viewBox.baseVal.width = 7; 330 is(marker.viewBox.animVal.width, 7, "viewBox.width animVal"); 331 marker.viewBox.baseVal.height = 8; 332 is(marker.viewBox.animVal.height, 8, "viewBox.height animVal"); 333 is(marker.getAttribute("viewBox"), "5 6 7 8", "viewBox attribute"); 334 var storedViewBox = marker.viewBox.baseVal; 335 marker.removeAttribute("viewBox"); 336 is(marker.hasAttribute("viewBox"), false, "viewBox hasAttribute"); 337 ok(marker.getAttribute("viewBox") === null, "removed viewBox attribute"); 338 is(marker.viewBox.baseVal, null, "viewBox baseVal"); 339 is(marker.viewBox.animVal, null, "viewBox animVal"); 340 341 is(storedViewBox.width, 7, "Should not lose values"); 342 storedViewBox.width = 200; 343 is(storedViewBox.width, 200, "Should be able to change detached viewBox rect"); 344 is(marker.hasAttribute("viewBox"), false, "viewBox hasAttribute should still be false"); 345 ok(marker.getAttribute("viewBox") === null, "viewBox attribute should still be null"); 346 is(marker.viewBox.baseVal, null, "viewBox baseVal"); 347 is(marker.viewBox.animVal, null, "viewBox animVal"); 348 349 marker.setAttribute("viewBox", "none"); 350 is(marker.hasAttribute("viewBox"), true, "viewBox hasAttribute"); 351 is(marker.viewBox.baseVal, null, "viewBox baseVal"); 352 is(marker.viewBox.animVal, null, "viewBox animVal"); 353 354 marker.setAttribute("viewBox", ""); 355 is(marker.hasAttribute("viewBox"), true, "viewBox hasAttribute"); 356 ok(marker.getAttribute("viewBox") === "", "empty viewBox attribute"); 357 358 marker.setAttribute("viewBox", "9 10 11 12"); 359 marker.removeAttribute("viewBox"); 360 marker.setAttribute("viewBox", "9 10 11 12"); 361 is(marker.viewBox.baseVal.x, 9, "viewBox.x baseVal after re-setting attribute to same rect value"); 362 is(marker.viewBox.baseVal.y, 10, "viewBox.y baseVal after re-setting attribute to same rect value"); 363 is(marker.viewBox.baseVal.width, 11, "viewBox.width baseVal after re-setting attribute to same rect value"); 364 is(marker.viewBox.baseVal.height, 12, "viewBox.height baseVal after re-setting attribute to same rect value"); 365 is(marker.viewBox.animVal.x, 9, "viewBox.x animVal after re-setting attribute to same rect value"); 366 is(marker.viewBox.animVal.y, 10, "viewBox.y animVal after re-setting attribute to same rect value"); 367 is(marker.viewBox.animVal.width, 11, "viewBox.width animVal after re-setting attribute to same rect value"); 368 is(marker.viewBox.animVal.height, 12, "viewBox.height animVal after re-setting attribute to same rect value"); 369 370 SimpleTest.finish(); 371 } 372 373 window.addEventListener("load", runTests); 374 </script> 375 </pre> 376 </body> 377 </html>