Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <html xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 2 | <head> |
michael@0 | 3 | <title>Test for SMIL when things change after an animation is frozen</title> |
michael@0 | 4 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 5 | <script type="text/javascript" src="smilTestUtils.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 7 | </head> |
michael@0 | 8 | <body> |
michael@0 | 9 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=533291">Mozilla Bug 533291</a> |
michael@0 | 10 | <p id="display"></p> |
michael@0 | 11 | <!-- Bug 628848: The following should be display: none but we currently don't |
michael@0 | 12 | handle percentage lengths properly when the whole fragment is display: none |
michael@0 | 13 | --> |
michael@0 | 14 | <div id="content" style="visibility: hidden"> |
michael@0 | 15 | <svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px" |
michael@0 | 16 | onload="this.pauseAnimations()"> |
michael@0 | 17 | <g id="circleParent"> |
michael@0 | 18 | <circle cx="0" cy="20" r="15" fill="blue" id="circle"/> |
michael@0 | 19 | </g> |
michael@0 | 20 | </svg> |
michael@0 | 21 | </div> |
michael@0 | 22 | <pre id="test"> |
michael@0 | 23 | <script class="testbody" type="text/javascript"> |
michael@0 | 24 | <![CDATA[ |
michael@0 | 25 | /** Test for SMIL values that are context-sensitive **/ |
michael@0 | 26 | |
michael@0 | 27 | /* See bugs 533291 and 562815. |
michael@0 | 28 | |
michael@0 | 29 | The format of each test is basically: |
michael@0 | 30 | 1) create some animated and frozen state |
michael@0 | 31 | 2) test the animated values |
michael@0 | 32 | 3) change the context |
michael@0 | 33 | 4) test that context-sensitive animation values have changed |
michael@0 | 34 | |
michael@0 | 35 | Ideally, after changing the context (3), the animated state would instantly |
michael@0 | 36 | update. However, this is not currently the case for many situations. |
michael@0 | 37 | |
michael@0 | 38 | For CSS properties we have bug 545282 - In animations involving 'inherit' |
michael@0 | 39 | / 'currentColor', changes to inherited value / 'color' don't show up in |
michael@0 | 40 | animated value immediately |
michael@0 | 41 | |
michael@0 | 42 | For SVG lengths we have bug 508206 - Relative units used in |
michael@0 | 43 | animation don't update immediately |
michael@0 | 44 | |
michael@0 | 45 | (There are a few of todo_is's in the following tests so that if those bugs |
michael@0 | 46 | are ever resolved we'll know to update this test case accordingly.) |
michael@0 | 47 | |
michael@0 | 48 | So in between (3) and (4) we force a sample. This is currently done by |
michael@0 | 49 | calling SVGSVGElement.setCurrentTime with the same current time which has the |
michael@0 | 50 | side effect of forcing a sample. |
michael@0 | 51 | |
michael@0 | 52 | What we *are* testing is that we're not too zealous with caching animation |
michael@0 | 53 | values whilst in the frozen state. Normally we'd say, "Hey, we're frozen, |
michael@0 | 54 | let's just use the same animation result as last time" but for some |
michael@0 | 55 | context-sensitive animation values that doesn't work. |
michael@0 | 56 | */ |
michael@0 | 57 | |
michael@0 | 58 | /* Global Variables */ |
michael@0 | 59 | const SVGNS = "http://www.w3.org/2000/svg"; |
michael@0 | 60 | |
michael@0 | 61 | // Animation parameters -- not used for <set> animation |
michael@0 | 62 | const ANIM_DUR = "4s"; |
michael@0 | 63 | const TIME_ANIM_END = "4"; |
michael@0 | 64 | const TIME_AFTER_ANIM_END = "5"; |
michael@0 | 65 | |
michael@0 | 66 | const gSvg = document.getElementById("svg"); |
michael@0 | 67 | const gCircle = document.getElementById("circle"); |
michael@0 | 68 | const gCircleParent = document.getElementById("circleParent"); |
michael@0 | 69 | |
michael@0 | 70 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 71 | |
michael@0 | 72 | // MAIN FUNCTION |
michael@0 | 73 | // ------------- |
michael@0 | 74 | |
michael@0 | 75 | function main() |
michael@0 | 76 | { |
michael@0 | 77 | ok(gSvg.animationsPaused(), "should be paused by <svg> load handler"); |
michael@0 | 78 | is(gSvg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); |
michael@0 | 79 | |
michael@0 | 80 | const tests = |
michael@0 | 81 | [ testBaseValueChange, |
michael@0 | 82 | testCurrentColorChange, |
michael@0 | 83 | testCurrentColorChangeUsingStyle, |
michael@0 | 84 | testCurrentColorChangeOnFallback, |
michael@0 | 85 | testInheritChange, |
michael@0 | 86 | testInheritChangeUsingStyle, |
michael@0 | 87 | testEmUnitChangeOnProp, |
michael@0 | 88 | testEmUnitChangeOnPropBase, |
michael@0 | 89 | testEmUnitChangeOnLength, |
michael@0 | 90 | testPercentUnitChangeOnProp, |
michael@0 | 91 | testPercentUnitChangeOnLength, |
michael@0 | 92 | testRelativeFontSize, |
michael@0 | 93 | testRelativeFontWeight, |
michael@0 | 94 | testRelativeFont, |
michael@0 | 95 | testCalcFontSize, |
michael@0 | 96 | testDashArray, |
michael@0 | 97 | testClip |
michael@0 | 98 | ]; |
michael@0 | 99 | |
michael@0 | 100 | while (tests.length) { |
michael@0 | 101 | tests.shift()(); |
michael@0 | 102 | } |
michael@0 | 103 | SimpleTest.finish(); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | // HELPER FUNCTIONS |
michael@0 | 107 | // ---------------- |
michael@0 | 108 | function createAnimSetTo(attrName, toVal) |
michael@0 | 109 | { |
michael@0 | 110 | var anim = document.createElementNS(SVGNS,"set"); |
michael@0 | 111 | anim.setAttribute("attributeName", attrName); |
michael@0 | 112 | anim.setAttribute("to", toVal); |
michael@0 | 113 | return gCircle.appendChild(anim); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | function createAnimBy(attrName, byVal) |
michael@0 | 117 | { |
michael@0 | 118 | var anim = document.createElementNS(SVGNS,"animate"); |
michael@0 | 119 | anim.setAttribute("attributeName", attrName); |
michael@0 | 120 | anim.setAttribute("dur", ANIM_DUR); |
michael@0 | 121 | anim.setAttribute("begin","0s"); |
michael@0 | 122 | anim.setAttribute("by", byVal); |
michael@0 | 123 | anim.setAttribute("fill", "freeze"); |
michael@0 | 124 | return gCircle.appendChild(anim); |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | function createAnimFromTo(attrName, fromVal, toVal) |
michael@0 | 128 | { |
michael@0 | 129 | var anim = document.createElementNS(SVGNS,"animate"); |
michael@0 | 130 | anim.setAttribute("attributeName", attrName); |
michael@0 | 131 | anim.setAttribute("dur", ANIM_DUR); |
michael@0 | 132 | anim.setAttribute("begin","0s"); |
michael@0 | 133 | anim.setAttribute("from", fromVal); |
michael@0 | 134 | anim.setAttribute("to", toVal); |
michael@0 | 135 | anim.setAttribute("fill", "freeze"); |
michael@0 | 136 | return gCircle.appendChild(anim); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | // Common setup code for each test function: seek to 0, and make sure |
michael@0 | 140 | // the previous test cleaned up its animations. |
michael@0 | 141 | function setupTest() { |
michael@0 | 142 | gSvg.setCurrentTime(0); |
michael@0 | 143 | if (gCircle.firstChild) { |
michael@0 | 144 | ok(false, "Previous test didn't clean up after itself."); |
michael@0 | 145 | } |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | // THE TESTS |
michael@0 | 149 | // --------- |
michael@0 | 150 | |
michael@0 | 151 | function testBaseValueChange() |
michael@0 | 152 | { |
michael@0 | 153 | setupTest(); |
michael@0 | 154 | var anim = createAnimBy("cx", "50"); |
michael@0 | 155 | gSvg.setCurrentTime(TIME_ANIM_END); |
michael@0 | 156 | is(gCircle.cx.animVal.value, 50, |
michael@0 | 157 | "Checking animated cx as anim ends"); |
michael@0 | 158 | |
michael@0 | 159 | gSvg.setCurrentTime(TIME_AFTER_ANIM_END); |
michael@0 | 160 | is(gCircle.cx.animVal.value, 50, |
michael@0 | 161 | "Checking animated cx after anim ends"); |
michael@0 | 162 | |
michael@0 | 163 | gCircle.setAttribute("cx", 20); |
michael@0 | 164 | is(gCircle.cx.animVal.value, 70, |
michael@0 | 165 | "Checking animated cx after anim ends & after changing base val"); |
michael@0 | 166 | |
michael@0 | 167 | anim.parentNode.removeChild(anim); // clean up |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | function testCurrentColorChange() |
michael@0 | 171 | { |
michael@0 | 172 | gCircle.setAttribute("color", "red"); // At first: currentColor=red |
michael@0 | 173 | var anim = createAnimSetTo("fill", "currentColor"); |
michael@0 | 174 | |
michael@0 | 175 | gSvg.setCurrentTime(0); // trigger synchronous sample |
michael@0 | 176 | is(SMILUtil.getComputedStyleSimple(gCircle, "fill"), "rgb(255, 0, 0)", |
michael@0 | 177 | "Checking animated fill=currentColor after animating"); |
michael@0 | 178 | |
michael@0 | 179 | gCircle.setAttribute("color", "lime"); // Change: currentColor=lime |
michael@0 | 180 | // Bug 545282: We should really detect this change and update immediately but |
michael@0 | 181 | // currently we don't until we get sampled again |
michael@0 | 182 | todo_is(SMILUtil.getComputedStyleSimple(gCircle, "fill"), "rgb(0, 255, 0)", |
michael@0 | 183 | "Checking animated fill=currentColor after updating context but before " + |
michael@0 | 184 | "sampling"); |
michael@0 | 185 | gSvg.setCurrentTime(0); |
michael@0 | 186 | is(SMILUtil.getComputedStyleSimple(gCircle, "fill"), "rgb(0, 255, 0)", |
michael@0 | 187 | "Checking animated fill=currentColor after updating context"); |
michael@0 | 188 | |
michael@0 | 189 | // Clean up |
michael@0 | 190 | gCircle.removeAttribute("color"); |
michael@0 | 191 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | function testCurrentColorChangeUsingStyle() |
michael@0 | 195 | { |
michael@0 | 196 | setupTest(); |
michael@0 | 197 | gCircle.setAttribute("style", "color: red"); // At first: currentColor=red |
michael@0 | 198 | var anim = createAnimSetTo("fill", "currentColor"); |
michael@0 | 199 | |
michael@0 | 200 | gSvg.setCurrentTime(0); |
michael@0 | 201 | is(SMILUtil.getComputedStyleSimple(gCircle, "fill"), "rgb(255, 0, 0)", |
michael@0 | 202 | "Checking animated fill=currentColor after animating (using style attr)"); |
michael@0 | 203 | |
michael@0 | 204 | gCircle.setAttribute("style", "color: lime"); // Change: currentColor=lime |
michael@0 | 205 | gSvg.setCurrentTime(0); |
michael@0 | 206 | is(SMILUtil.getComputedStyleSimple(gCircle, "fill"), "rgb(0, 255, 0)", |
michael@0 | 207 | "Checking animated fill=currentColor after updating context " |
michael@0 | 208 | + "(using style attr)"); |
michael@0 | 209 | |
michael@0 | 210 | // Clean up |
michael@0 | 211 | gCircle.removeAttribute("style"); |
michael@0 | 212 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | function getFallbackColor(pServerStr) |
michael@0 | 216 | { |
michael@0 | 217 | return pServerStr.substr(pServerStr.indexOf(" ")+1); |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | function testCurrentColorChangeOnFallback() |
michael@0 | 221 | { |
michael@0 | 222 | setupTest(); |
michael@0 | 223 | gCircle.setAttribute("color", "red"); // At first: currentColor=red |
michael@0 | 224 | var anim = createAnimSetTo("fill", "url(#missingGrad) currentColor"); |
michael@0 | 225 | |
michael@0 | 226 | gSvg.setCurrentTime(0); |
michael@0 | 227 | var fallback = |
michael@0 | 228 | getFallbackColor(SMILUtil.getComputedStyleSimple(gCircle, "fill")); |
michael@0 | 229 | is(fallback, "rgb(255, 0, 0)", |
michael@0 | 230 | "Checking animated fallback fill=currentColor after animating"); |
michael@0 | 231 | |
michael@0 | 232 | gCircle.setAttribute("color", "lime"); // Change: currentColor=lime |
michael@0 | 233 | gSvg.setCurrentTime(0); |
michael@0 | 234 | fallback = getFallbackColor(SMILUtil.getComputedStyleSimple(gCircle, "fill")); |
michael@0 | 235 | is(fallback, "rgb(0, 255, 0)", |
michael@0 | 236 | "Checking animated fallback fill=currentColor after updating context"); |
michael@0 | 237 | |
michael@0 | 238 | gCircle.removeAttribute("style"); |
michael@0 | 239 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | function testInheritChange() |
michael@0 | 243 | { |
michael@0 | 244 | setupTest(); |
michael@0 | 245 | gCircleParent.setAttribute("fill", "red"); // At first: inherit=red |
michael@0 | 246 | var anim = createAnimSetTo("fill", "inherit"); |
michael@0 | 247 | |
michael@0 | 248 | gSvg.setCurrentTime(0); |
michael@0 | 249 | is(SMILUtil.getComputedStyleSimple(gCircle, "fill"), "rgb(255, 0, 0)", |
michael@0 | 250 | "Checking animated fill=inherit after animating"); |
michael@0 | 251 | |
michael@0 | 252 | gCircleParent.setAttribute("fill", "lime"); // Change: inherit=lime |
michael@0 | 253 | gSvg.setCurrentTime(0); |
michael@0 | 254 | is(SMILUtil.getComputedStyleSimple(gCircle, "fill"), "rgb(0, 255, 0)", |
michael@0 | 255 | "Checking animated fill=inherit after updating context"); |
michael@0 | 256 | |
michael@0 | 257 | gCircleParent.removeAttribute("fill"); |
michael@0 | 258 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 259 | } |
michael@0 | 260 | |
michael@0 | 261 | function testInheritChangeUsingStyle() |
michael@0 | 262 | { |
michael@0 | 263 | setupTest(); |
michael@0 | 264 | gCircleParent.setAttribute("style", "fill: red"); // At first: inherit=red |
michael@0 | 265 | var anim = createAnimSetTo("fill", "inherit"); |
michael@0 | 266 | |
michael@0 | 267 | gSvg.setCurrentTime(0); |
michael@0 | 268 | is(SMILUtil.getComputedStyleSimple(gCircle, "fill"), "rgb(255, 0, 0)", |
michael@0 | 269 | "Checking animated fill=inherit after animating (using style attr)"); |
michael@0 | 270 | |
michael@0 | 271 | gCircleParent.setAttribute("style", "fill: lime"); // Change: inherit=lime |
michael@0 | 272 | gSvg.setCurrentTime(0); |
michael@0 | 273 | is(SMILUtil.getComputedStyleSimple(gCircle, "fill"), "rgb(0, 255, 0)", |
michael@0 | 274 | "Checking animated fill=inherit after updating context " |
michael@0 | 275 | + "(using style attr)"); |
michael@0 | 276 | |
michael@0 | 277 | gCircleParent.removeAttribute("style"); |
michael@0 | 278 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 279 | } |
michael@0 | 280 | |
michael@0 | 281 | function testEmUnitChangeOnProp() |
michael@0 | 282 | { |
michael@0 | 283 | setupTest(); |
michael@0 | 284 | gCircleParent.setAttribute("font-size", "10px"); // At first: font-size: 10px |
michael@0 | 285 | var anim = createAnimSetTo("font-size", "2em"); |
michael@0 | 286 | |
michael@0 | 287 | gSvg.setCurrentTime(0); |
michael@0 | 288 | is(SMILUtil.getComputedStyleSimple(gCircle, "font-size"), "20px", |
michael@0 | 289 | "Checking animated font-size=2em after animating ends"); |
michael@0 | 290 | |
michael@0 | 291 | gCircleParent.setAttribute("font-size", "20px"); // Change: font-size: 20px |
michael@0 | 292 | gSvg.setCurrentTime(0); |
michael@0 | 293 | is(SMILUtil.getComputedStyleSimple(gCircle, "font-size"), "40px", |
michael@0 | 294 | "Checking animated font-size=2em after updating context"); |
michael@0 | 295 | |
michael@0 | 296 | gCircleParent.removeAttribute("font-size"); |
michael@0 | 297 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 298 | } |
michael@0 | 299 | |
michael@0 | 300 | function testEmUnitChangeOnPropBase() |
michael@0 | 301 | { |
michael@0 | 302 | // Test the case where the base value for our animation sandwich is |
michael@0 | 303 | // context-sensitive. |
michael@0 | 304 | // Currently, this is taken care of by the compositor which keeps a cached |
michael@0 | 305 | // base value and compares it with the current base value. This test then just |
michael@0 | 306 | // serves as a regression test in case the compositor's behaviour changes. |
michael@0 | 307 | setupTest(); |
michael@0 | 308 | gSvg.setAttribute("font-size", "10px"); // At first: font-size: 10px |
michael@0 | 309 | gCircleParent.setAttribute("font-size", "1em"); // Base: 10px |
michael@0 | 310 | var anim = createAnimBy("font-size", "10px"); |
michael@0 | 311 | |
michael@0 | 312 | gSvg.setCurrentTime(TIME_AFTER_ANIM_END); |
michael@0 | 313 | is(SMILUtil.getComputedStyleSimple(gCircle, "font-size"), "20px", |
michael@0 | 314 | "Checking animated font-size=20px after anim ends"); |
michael@0 | 315 | |
michael@0 | 316 | gSvg.setAttribute("font-size", "20px"); // Change: font-size: 20px |
michael@0 | 317 | gSvg.setCurrentTime(TIME_AFTER_ANIM_END); |
michael@0 | 318 | is(SMILUtil.getComputedStyleSimple(gCircle, "font-size"), "30px", |
michael@0 | 319 | "Checking animated font-size=30px after updating context"); |
michael@0 | 320 | |
michael@0 | 321 | gCircleParent.removeAttribute("font-size"); |
michael@0 | 322 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 323 | } |
michael@0 | 324 | |
michael@0 | 325 | function testEmUnitChangeOnLength() |
michael@0 | 326 | { |
michael@0 | 327 | setupTest(); |
michael@0 | 328 | gCircleParent.setAttribute("font-size", "10px"); // At first: font-size: 10px |
michael@0 | 329 | var anim = createAnimSetTo("cx", "2em"); |
michael@0 | 330 | |
michael@0 | 331 | gSvg.setCurrentTime(0); |
michael@0 | 332 | is(gCircle.cx.animVal.value, 20, |
michael@0 | 333 | "Checking animated length=2em after animating"); |
michael@0 | 334 | |
michael@0 | 335 | gCircleParent.setAttribute("font-size", "20px"); // Change: font-size: 20px |
michael@0 | 336 | // Bug 508206: We should really detect this change and update immediately but |
michael@0 | 337 | // currently we don't until we get sampled again |
michael@0 | 338 | todo_is(gCircle.cx.animVal.value, 40, |
michael@0 | 339 | "Checking animated length=2em after updating context but before sampling"); |
michael@0 | 340 | |
michael@0 | 341 | gSvg.setCurrentTime(0); |
michael@0 | 342 | is(gCircle.cx.animVal.value, 40, |
michael@0 | 343 | "Checking animated length=2em after updating context and after " + |
michael@0 | 344 | "resampling"); |
michael@0 | 345 | |
michael@0 | 346 | gCircleParent.removeAttribute("font-size"); |
michael@0 | 347 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 348 | } |
michael@0 | 349 | |
michael@0 | 350 | function testPercentUnitChangeOnProp() |
michael@0 | 351 | { |
michael@0 | 352 | setupTest(); |
michael@0 | 353 | gCircleParent.setAttribute("font-size", "10px"); // At first: font-size: 10px |
michael@0 | 354 | var anim = createAnimSetTo("font-size", "150%"); |
michael@0 | 355 | |
michael@0 | 356 | gSvg.setCurrentTime(0); |
michael@0 | 357 | is(SMILUtil.getComputedStyleSimple(gCircle, "font-size"), "15px", |
michael@0 | 358 | "Checking animated font-size=150% after animating"); |
michael@0 | 359 | |
michael@0 | 360 | gCircleParent.setAttribute("font-size", "20px"); // Change: font-size: 20px |
michael@0 | 361 | gSvg.setCurrentTime(0); |
michael@0 | 362 | is(SMILUtil.getComputedStyleSimple(gCircle, "font-size"), "30px", |
michael@0 | 363 | "Checking animated font-size=150% after updating context"); |
michael@0 | 364 | |
michael@0 | 365 | gCircleParent.removeAttribute("font-size"); |
michael@0 | 366 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 367 | } |
michael@0 | 368 | |
michael@0 | 369 | function testPercentUnitChangeOnLength() |
michael@0 | 370 | { |
michael@0 | 371 | setupTest(); |
michael@0 | 372 | var oldHeight = gSvg.getAttribute("height"); |
michael@0 | 373 | gSvg.setAttribute("height", "100px"); // At first: viewport height: 100px |
michael@0 | 374 | var anim = createAnimSetTo("cy", "100%"); |
michael@0 | 375 | |
michael@0 | 376 | gSvg.setCurrentTime(0); // Force synchronous sample so animation takes effect |
michael@0 | 377 | // Due to bug 627594 (SVGLength.value for percent value lengths doesn't |
michael@0 | 378 | // reflect updated viewport until reflow) the following will fail. |
michael@0 | 379 | // Check that it does indeed fail so that when that bug is fixed this test |
michael@0 | 380 | // can be updated. |
michael@0 | 381 | todo_is(gCircle.cy.animVal.value, 100, |
michael@0 | 382 | "Checking animated length=100% after animating but before reflow"); |
michael@0 | 383 | gSvg.forceRedraw(); |
michael@0 | 384 | // Even after doing a reflow though we'll still fail due to bug 508206 |
michael@0 | 385 | // (Relative units used in animation don't update immediately) |
michael@0 | 386 | todo_is(gCircle.cy.animVal.value, 100, |
michael@0 | 387 | "Checking animated length=100% after animating but before resampling"); |
michael@0 | 388 | gSvg.setCurrentTime(0); |
michael@0 | 389 | // Now we should be up to date |
michael@0 | 390 | is(gCircle.cy.animVal.value, 100, |
michael@0 | 391 | "Checking animated length=100% after animating"); |
michael@0 | 392 | |
michael@0 | 393 | gSvg.setAttribute("height", "50px"); // Change: height: 50px |
michael@0 | 394 | gSvg.forceRedraw(); // Bug 627594 |
michael@0 | 395 | gSvg.setCurrentTime(0); // Bug 508206 |
michael@0 | 396 | is(gCircle.cy.animVal.value, 50, |
michael@0 | 397 | "Checking animated length=100% after updating context"); |
michael@0 | 398 | |
michael@0 | 399 | gSvg.setAttribute("height", oldHeight); |
michael@0 | 400 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 401 | } |
michael@0 | 402 | |
michael@0 | 403 | function testRelativeFontSize() |
michael@0 | 404 | { |
michael@0 | 405 | setupTest(); |
michael@0 | 406 | gCircleParent.setAttribute("font-size", "10px"); // At first: font-size: 10px |
michael@0 | 407 | var anim = createAnimSetTo("font-size", "larger"); |
michael@0 | 408 | |
michael@0 | 409 | gSvg.setCurrentTime(0); |
michael@0 | 410 | var fsize = parseInt(SMILUtil.getComputedStyleSimple(gCircle, "font-size")); |
michael@0 | 411 | // CSS 2 suggests a scaling factor of 1.2 so we should be looking at something |
michael@0 | 412 | // around about 12 or so |
michael@0 | 413 | ok(fsize > 10 && fsize < 20, |
michael@0 | 414 | "Checking animated font-size > 10px after animating"); |
michael@0 | 415 | |
michael@0 | 416 | gCircleParent.setAttribute("font-size", "20px"); // Change: font-size: 20px |
michael@0 | 417 | gSvg.setCurrentTime(0); |
michael@0 | 418 | fsize = parseInt(SMILUtil.getComputedStyleSimple(gCircle, "font-size")); |
michael@0 | 419 | ok(fsize > 20, "Checking animated font-size > 20px after updating context"); |
michael@0 | 420 | |
michael@0 | 421 | gCircleParent.removeAttribute("font-size"); |
michael@0 | 422 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 423 | } |
michael@0 | 424 | |
michael@0 | 425 | function testRelativeFontWeight() |
michael@0 | 426 | { |
michael@0 | 427 | setupTest(); |
michael@0 | 428 | gCircleParent.setAttribute("font-weight", "100"); // At first: font-weight 100 |
michael@0 | 429 | var anim = createAnimSetTo("font-weight", "bolder"); |
michael@0 | 430 | // CSS 2: 'bolder': Specifies the next weight that is assigned to a font |
michael@0 | 431 | // that is darker than the inherited one. If there is no such weight, it |
michael@0 | 432 | // simply results in the next darker numerical value (and the font remains |
michael@0 | 433 | // unchanged), unless the inherited value was '900', in which case the |
michael@0 | 434 | // resulting weight is also '900'. |
michael@0 | 435 | |
michael@0 | 436 | gSvg.setCurrentTime(0); |
michael@0 | 437 | var weight = |
michael@0 | 438 | parseInt(SMILUtil.getComputedStyleSimple(gCircle, "font-weight")); |
michael@0 | 439 | ok(weight > 100, "Checking animated font-weight > 100 after animating"); |
michael@0 | 440 | |
michael@0 | 441 | gCircleParent.setAttribute("font-weight", "800"); // Change: font-weight 800 |
michael@0 | 442 | gSvg.setCurrentTime(0); |
michael@0 | 443 | weight = parseInt(SMILUtil.getComputedStyleSimple(gCircle, "font-weight")); |
michael@0 | 444 | is(weight, 900, |
michael@0 | 445 | "Checking animated font-weight = 900 after updating context"); |
michael@0 | 446 | |
michael@0 | 447 | gCircleParent.removeAttribute("font-weight"); |
michael@0 | 448 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 449 | } |
michael@0 | 450 | |
michael@0 | 451 | function testRelativeFont() |
michael@0 | 452 | { |
michael@0 | 453 | // Test a relative font-size as part of a 'font' spec since the code path |
michael@0 | 454 | // is different in this case |
michael@0 | 455 | // It turns out that, due to the way we store shorthand font properties, we |
michael@0 | 456 | // don't need to worry about marking such values as context-sensitive since we |
michael@0 | 457 | // seem to store them in their relative form. If, however, we change the way |
michael@0 | 458 | // we store shorthand font properties in the future, this will serve as |
michael@0 | 459 | // a useful regression test. |
michael@0 | 460 | setupTest(); |
michael@0 | 461 | gCircleParent.setAttribute("font-size", "10px"); // At first: font-size: 10px |
michael@0 | 462 | // We must be sure to set every part of the shorthand property to some |
michael@0 | 463 | // non-context sensitive value because we want to test that even if only the |
michael@0 | 464 | // font-size is relative we will update it appropriately. |
michael@0 | 465 | var anim = |
michael@0 | 466 | createAnimSetTo("font", "normal normal bold larger/normal sans-serif"); |
michael@0 | 467 | |
michael@0 | 468 | gSvg.setCurrentTime(0); |
michael@0 | 469 | var fsize = parseInt(SMILUtil.getComputedStyleSimple(gCircle, "font-size")); |
michael@0 | 470 | ok(fsize > 10 && fsize < 20, |
michael@0 | 471 | "Checking size of shorthand 'font' > 10px after animating"); |
michael@0 | 472 | |
michael@0 | 473 | gCircleParent.setAttribute("font-size", "20px"); // Change: font-size: 20px |
michael@0 | 474 | gSvg.setCurrentTime(0); |
michael@0 | 475 | fsize = parseInt(SMILUtil.getComputedStyleSimple(gCircle, "font-size")); |
michael@0 | 476 | ok(fsize > 20, |
michael@0 | 477 | "Checking size of shorthand 'font' > 20px after updating context"); |
michael@0 | 478 | |
michael@0 | 479 | gCircleParent.removeAttribute("font-size"); |
michael@0 | 480 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 481 | } |
michael@0 | 482 | |
michael@0 | 483 | function testCalcFontSize() |
michael@0 | 484 | { |
michael@0 | 485 | setupTest(); |
michael@0 | 486 | gCircleParent.setAttribute("font-size", "10px"); // At first: font-size: 10px |
michael@0 | 487 | var anim = createAnimSetTo("font-size", "-moz-calc(110% + 0.1em)"); |
michael@0 | 488 | |
michael@0 | 489 | gSvg.setCurrentTime(0); |
michael@0 | 490 | var fsize = parseInt(SMILUtil.getComputedStyleSimple(gCircle, "font-size")); |
michael@0 | 491 | // Font size should be 1.1 * 10px + 0.1 * 10px = 12 |
michael@0 | 492 | is(fsize, 12, "Checking animated calc font-size == 12px after animating"); |
michael@0 | 493 | |
michael@0 | 494 | gCircleParent.setAttribute("font-size", "20px"); // Change: font-size: 20px |
michael@0 | 495 | gSvg.setCurrentTime(0); |
michael@0 | 496 | fsize = parseInt(SMILUtil.getComputedStyleSimple(gCircle, "font-size")); |
michael@0 | 497 | is(fsize, 24, "Checking animated calc font-size == 24px after updating " + |
michael@0 | 498 | "context"); |
michael@0 | 499 | |
michael@0 | 500 | gCircleParent.removeAttribute("font-size"); |
michael@0 | 501 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 502 | } |
michael@0 | 503 | |
michael@0 | 504 | function testDashArray() |
michael@0 | 505 | { |
michael@0 | 506 | // stroke dasharrays don't currently convert units--but if someone ever fixes |
michael@0 | 507 | // that, hopefully this test will fail and remind us not to cache percentage |
michael@0 | 508 | // values in that case |
michael@0 | 509 | setupTest(); |
michael@0 | 510 | var oldHeight = gSvg.getAttribute("height"); |
michael@0 | 511 | var oldWidth = gSvg.getAttribute("width"); |
michael@0 | 512 | gSvg.setAttribute("height", "100px"); // At first: viewport: 100x100px |
michael@0 | 513 | gSvg.setAttribute("width", "100px"); |
michael@0 | 514 | var anim = createAnimFromTo("stroke-dasharray", "0 5", "0 50%"); |
michael@0 | 515 | |
michael@0 | 516 | gSvg.setCurrentTime(TIME_AFTER_ANIM_END); |
michael@0 | 517 | |
michael@0 | 518 | // Now we should be up to date |
michael@0 | 519 | is(SMILUtil.getComputedStyleSimple(gCircle, "stroke-dasharray"), "0, 50%", |
michael@0 | 520 | "Checking animated stroke-dasharray after animating"); |
michael@0 | 521 | |
michael@0 | 522 | gSvg.setAttribute("height", "50px"); // Change viewport: 50x50px |
michael@0 | 523 | gSvg.setAttribute("width", "50px"); |
michael@0 | 524 | gSvg.setCurrentTime(TIME_AFTER_ANIM_END); |
michael@0 | 525 | is(SMILUtil.getComputedStyleSimple(gCircle, "stroke-dasharray"), "0, 50%", |
michael@0 | 526 | "Checking animated stroke-dasharray after updating context"); |
michael@0 | 527 | |
michael@0 | 528 | gSvg.setAttribute("height", oldHeight); |
michael@0 | 529 | gSvg.setAttribute("width", oldWidth); |
michael@0 | 530 | gCircle.removeChild(gCircle.firstChild); |
michael@0 | 531 | } |
michael@0 | 532 | |
michael@0 | 533 | function testClip() |
michael@0 | 534 | { |
michael@0 | 535 | setupTest(); |
michael@0 | 536 | gCircleParent.setAttribute("font-size", "20px"); // At first: font-size: 20px |
michael@0 | 537 | |
michael@0 | 538 | // The clip property only applies to elements that establish a new |
michael@0 | 539 | // viewport so we need to create a nested svg and add animation to that |
michael@0 | 540 | var nestedSVG = document.createElementNS(SVGNS, "svg"); |
michael@0 | 541 | nestedSVG.setAttribute("clip", "rect(0px 0px 0px 0px)"); |
michael@0 | 542 | gCircleParent.appendChild(nestedSVG); |
michael@0 | 543 | |
michael@0 | 544 | var anim = createAnimSetTo("clip", "rect(1em 1em 1em 1em)"); |
michael@0 | 545 | // createAnimSetTo will make the animation a child of gCircle so we need to |
michael@0 | 546 | // move it so it targets nestedSVG instead |
michael@0 | 547 | nestedSVG.appendChild(anim); |
michael@0 | 548 | |
michael@0 | 549 | gSvg.setCurrentTime(TIME_AFTER_ANIM_END); |
michael@0 | 550 | is(SMILUtil.getComputedStyleSimple(nestedSVG, "clip"), |
michael@0 | 551 | "rect(20px, 20px, 20px, 20px)", |
michael@0 | 552 | "Checking animated clip rect after animating"); |
michael@0 | 553 | |
michael@0 | 554 | gCircleParent.setAttribute("font-size", "10px"); // Change: font-size: 10px |
michael@0 | 555 | gSvg.setCurrentTime(TIME_AFTER_ANIM_END); |
michael@0 | 556 | is(SMILUtil.getComputedStyleSimple(nestedSVG, "clip"), |
michael@0 | 557 | "rect(10px, 10px, 10px, 10px)", |
michael@0 | 558 | "Checking animated clip rect after updating context"); |
michael@0 | 559 | |
michael@0 | 560 | gCircleParent.removeAttribute("font-size"); |
michael@0 | 561 | gCircleParent.removeChild(nestedSVG); |
michael@0 | 562 | } |
michael@0 | 563 | |
michael@0 | 564 | window.addEventListener("load", main, false); |
michael@0 | 565 | ]]> |
michael@0 | 566 | </script> |
michael@0 | 567 | </pre> |
michael@0 | 568 | </body> |
michael@0 | 569 | </html> |