OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> |
| 3 <title>Tests for animation types</title> |
| 4 <link rel="help" href="https://w3c.github.io/web-animations/#animation-types"> |
| 5 <script src="/resources/testharness.js"></script> |
| 6 <script src="/resources/testharnessreport.js"></script> |
| 7 <script src="../../testcommon.js"></script> |
| 8 <style> |
| 9 html { |
| 10 font-size: 10px; |
| 11 } |
| 12 </style> |
| 13 <body> |
| 14 <div id="log"></div> |
| 15 <script> |
| 16 "use strict"; |
| 17 |
| 18 var gCSSProperties = { |
| 19 "align-content": { |
| 20 // https://drafts.csswg.org/css-align/#propdef-align-content |
| 21 tests: [ |
| 22 discrete("flex-start", "flex-end") |
| 23 ] |
| 24 }, |
| 25 "align-items": { |
| 26 // https://drafts.csswg.org/css-align/#propdef-align-items |
| 27 tests: [ |
| 28 discrete("flex-start", "flex-end") |
| 29 ] |
| 30 }, |
| 31 "align-self": { |
| 32 // https://drafts.csswg.org/css-align/#propdef-align-self |
| 33 tests: [ |
| 34 discrete("flex-start", "flex-end") |
| 35 ] |
| 36 }, |
| 37 "clip-rule": { |
| 38 // https://drafts.fxtf.org/css-masking-1/#propdef-clip-rule |
| 39 tests: [ |
| 40 discrete("evenodd", "nonzero") |
| 41 ] |
| 42 }, |
| 43 "color-interpolation": { |
| 44 // https://svgwg.org/svg2-draft/painting.html#ColorInterpolationProperty |
| 45 tests: [ |
| 46 discrete("linearRGB", "auto") |
| 47 ] |
| 48 }, |
| 49 "color-interpolation-filters": { |
| 50 // https://drafts.fxtf.org/filters-1/#propdef-color-interpolation-filters |
| 51 tests: [ |
| 52 discrete("sRGB", "linearRGB") |
| 53 ] |
| 54 }, |
| 55 "dominant-baseline": { |
| 56 // https://drafts.csswg.org/css-inline/#propdef-dominant-baseline |
| 57 tests: [ |
| 58 discrete("ideographic", "alphabetic") |
| 59 ] |
| 60 }, |
| 61 "fill-rule": { |
| 62 // https://svgwg.org/svg2-draft/painting.html#FillRuleProperty |
| 63 tests: [ |
| 64 discrete("evenodd", "nonzero") |
| 65 ] |
| 66 }, |
| 67 "flex-basis": { |
| 68 // https://drafts.csswg.org/css-flexbox/#propdef-flex-basis |
| 69 tests: [ |
| 70 lengthPercentageOrCalc(), |
| 71 discrete("auto", "10px") |
| 72 ] |
| 73 }, |
| 74 "flex-direction": { |
| 75 // https://drafts.csswg.org/css-flexbox/#propdef-flex-direction |
| 76 tests: [ |
| 77 discrete("row", "row-reverse") |
| 78 ] |
| 79 }, |
| 80 "flex-grow": { |
| 81 // https://drafts.csswg.org/css-flexbox/#flex-grow-property |
| 82 tests: [ |
| 83 positiveNumber() |
| 84 ] |
| 85 }, |
| 86 "flex-shrink": { |
| 87 // https://drafts.csswg.org/css-flexbox/#propdef-flex-shrink |
| 88 tests: [ |
| 89 positiveNumber() |
| 90 ] |
| 91 }, |
| 92 "flex-wrap": { |
| 93 // https://drafts.csswg.org/css-flexbox/#propdef-flex-wrap |
| 94 tests: [ |
| 95 discrete("nowrap", "wrap") |
| 96 ] |
| 97 }, |
| 98 "font-style": { |
| 99 // https://drafts.csswg.org/css-fonts/#propdef-font-style |
| 100 tests: [ |
| 101 discrete("italic", "oblique") |
| 102 ] |
| 103 }, |
| 104 "image-rendering": { |
| 105 // https://drafts.csswg.org/css-images/#propdef-image-rendering |
| 106 tests: [ |
| 107 discrete("optimizeQuality", "pixelated") |
| 108 ] |
| 109 }, |
| 110 "justify-content": { |
| 111 // https://drafts.csswg.org/css-align/#propdef-justify-content |
| 112 tests: [ |
| 113 discrete("baseline", "last-baseline") |
| 114 ] |
| 115 }, |
| 116 "justify-items": { |
| 117 // https://drafts.csswg.org/css-align/#propdef-justify-items |
| 118 tests: [ |
| 119 discrete("baseline", "last-baseline") |
| 120 ] |
| 121 }, |
| 122 "justify-self": { |
| 123 // https://drafts.csswg.org/css-align/#propdef-justify-self |
| 124 tests: [ |
| 125 discrete("baseline", "last-baseline") |
| 126 ] |
| 127 }, |
| 128 "mask-type": { |
| 129 // https://drafts.fxtf.org/css-masking-1/#propdef-mask-type |
| 130 tests: [ |
| 131 discrete("alpha", "luminance") |
| 132 ] |
| 133 }, |
| 134 "order": { |
| 135 // https://drafts.csswg.org/css-flexbox/#propdef-order |
| 136 tests: [ |
| 137 integer() |
| 138 ] |
| 139 }, |
| 140 "pointer-events": { |
| 141 // https://svgwg.org/svg2-draft/interact.html#PointerEventsProperty |
| 142 tests: [ |
| 143 discrete("fill", "none") |
| 144 ] |
| 145 }, |
| 146 "ruby-align": { |
| 147 // https://drafts.csswg.org/css-ruby-1/#propdef-ruby-align |
| 148 tests: [ |
| 149 discrete("start", "center") |
| 150 ] |
| 151 }, |
| 152 "ruby-position": { |
| 153 // https://drafts.csswg.org/css-ruby-1/#propdef-ruby-position |
| 154 tests: [ |
| 155 discrete("under", "over") |
| 156 ], |
| 157 tagName: "ruby" |
| 158 }, |
| 159 "shape-rendering": { |
| 160 // https://svgwg.org/svg2-draft/painting.html#ShapeRenderingProperty |
| 161 tests: [ |
| 162 discrete("optimizeSpeed", "crispEdges") |
| 163 ] |
| 164 }, |
| 165 "stroke-linecap": { |
| 166 // https://svgwg.org/svg2-draft/painting.html#StrokeLinecapProperty |
| 167 tests: [ |
| 168 discrete("round", "square") |
| 169 ] |
| 170 }, |
| 171 "stroke-linejoin": { |
| 172 // https://svgwg.org/svg2-draft/painting.html#StrokeLinejoinProperty |
| 173 tests: [ |
| 174 discrete("round", "miter") |
| 175 ], |
| 176 tagName: "rect" |
| 177 }, |
| 178 "text-anchor": { |
| 179 // https://svgwg.org/svg2-draft/text.html#TextAnchorProperty |
| 180 tests: [ |
| 181 discrete("middle", "end") |
| 182 ] |
| 183 }, |
| 184 "text-combine-upright": { |
| 185 // https://drafts.csswg.org/css-writing-modes-3/#propdef-text-combine-uprigh
t |
| 186 tests: [ |
| 187 discrete("all", "digits") |
| 188 ] |
| 189 }, |
| 190 "text-decoration-line": { |
| 191 // https://drafts.csswg.org/css-text-decor-3/#propdef-text-decoration-line |
| 192 tests: [ |
| 193 discrete("underline", "overline") |
| 194 ] |
| 195 }, |
| 196 "text-orientation": { |
| 197 // https://drafts.csswg.org/css-writing-modes-3/#propdef-text-orientation |
| 198 tests: [ |
| 199 discrete("upright", "sideways") |
| 200 ] |
| 201 }, |
| 202 "text-rendering": { |
| 203 // https://svgwg.org/svg2-draft/painting.html#TextRenderingProperty |
| 204 tests: [ |
| 205 discrete("optimizeSpeed", "optimizeLegibility") |
| 206 ] |
| 207 }, |
| 208 "vector-effect": { |
| 209 // https://svgwg.org/svg2-draft/coords.html#VectorEffectProperty |
| 210 tests: [ |
| 211 discrete("none", "non-scaling-stroke") |
| 212 ] |
| 213 }, |
| 214 "visibility": { |
| 215 // https://drafts.csswg.org/css2/visufx.html#propdef-visibility |
| 216 tests: [ |
| 217 visibility() |
| 218 ] |
| 219 }, |
| 220 "word-break": { |
| 221 // https://drafts.csswg.org/css-text-3/#propdef-word-break |
| 222 tests: [ |
| 223 discrete("keep-all", "break-all") |
| 224 ] |
| 225 }, |
| 226 "writing-mode": { |
| 227 // https://drafts.csswg.org/css-writing-modes-3/#propdef-writing-mode |
| 228 tests: [ |
| 229 discrete("vertical-rl", "sideways-rl") |
| 230 ] |
| 231 }, |
| 232 } |
| 233 |
| 234 for (var property in gCSSProperties) { |
| 235 if (!isSupported(property)) { |
| 236 continue; |
| 237 } |
| 238 var testData = gCSSProperties[property]; |
| 239 testData.tests.forEach(function(testFunction) { |
| 240 testFunction(property, testData); |
| 241 }); |
| 242 } |
| 243 |
| 244 function discrete(from, to) { |
| 245 return function(property, options) { |
| 246 test(function(t) { |
| 247 var idlName = propertyToIDL(property); |
| 248 var keyframes = {}; |
| 249 keyframes[idlName] = [from, to]; |
| 250 var target = createElement(t, options.tagName); |
| 251 var animation = target.animate(keyframes, |
| 252 { duration: 1000, fill: "both" }); |
| 253 testAnimationSamples(animation, idlName, |
| 254 [{ time: 0, expected: from.toLowerCase() }, |
| 255 { time: 499, expected: from.toLowerCase() }, |
| 256 { time: 500, expected: to.toLowerCase() }, |
| 257 { time: 1000, expected: to.toLowerCase() }]); |
| 258 }, property + " uses discrete animation when animating between '" |
| 259 + from + "' and '" + to + "' with linear easing"); |
| 260 |
| 261 test(function(t) { |
| 262 // Easing: http://cubic-bezier.com/#.68,0,1,.01 |
| 263 // With this curve, we don't reach the 50% point until about 95% of |
| 264 // the time has expired. |
| 265 var idlName = propertyToIDL(property); |
| 266 var keyframes = {}; |
| 267 keyframes[idlName] = [from, to]; |
| 268 var target = createElement(t, options.tagName); |
| 269 var animation = target.animate(keyframes, |
| 270 { duration: 1000, fill: "both", |
| 271 easing: "cubic-bezier(0.68,0,1,0.01)" }); |
| 272 testAnimationSamples(animation, idlName, |
| 273 [{ time: 0, expected: from.toLowerCase() }, |
| 274 { time: 940, expected: from.toLowerCase() }, |
| 275 { time: 960, expected: to.toLowerCase() }]); |
| 276 }, property + " uses discrete animation when animating between '" |
| 277 + from + "' and '" + to + "' with effect easing"); |
| 278 |
| 279 test(function(t) { |
| 280 // Easing: http://cubic-bezier.com/#.68,0,1,.01 |
| 281 // With this curve, we don't reach the 50% point until about 95% of |
| 282 // the time has expired. |
| 283 var idlName = propertyToIDL(property); |
| 284 var keyframes = {}; |
| 285 keyframes[idlName] = [from, to]; |
| 286 keyframes.easing = "cubic-bezier(0.68,0,1,0.01)"; |
| 287 var target = createElement(t, options.tagName); |
| 288 var animation = target.animate(keyframes, |
| 289 { duration: 1000, fill: "both" }); |
| 290 testAnimationSamples(animation, idlName, |
| 291 [{ time: 0, expected: from.toLowerCase() }, |
| 292 { time: 940, expected: from.toLowerCase() }, |
| 293 { time: 960, expected: to.toLowerCase() }]); |
| 294 }, property + " uses discrete animation when animating between '" |
| 295 + from + "' and '" + to + "' with keyframe easing"); |
| 296 } |
| 297 } |
| 298 |
| 299 function length() { |
| 300 return function(property, options) { |
| 301 test(function(t) { |
| 302 var idlName = propertyToIDL(property); |
| 303 var keyframes = {}; |
| 304 keyframes[idlName] = ["10px", "50px"]; |
| 305 var target = createElement(t, options.tagName); |
| 306 var animation = target.animate(keyframes, |
| 307 { duration: 1000, fill: "both" }); |
| 308 testAnimationSamples(animation, idlName, |
| 309 [{ time: 0, expected: "10px" }, |
| 310 { time: 500, expected: "30px" }, |
| 311 { time: 1000, expected: "50px" }]); |
| 312 }, property + " supports animating as a length"); |
| 313 |
| 314 test(function(t) { |
| 315 var idlName = propertyToIDL(property); |
| 316 var keyframes = {}; |
| 317 keyframes[idlName] = ["1rem", "5rem"]; |
| 318 var target = createElement(t, options.tagName); |
| 319 var animation = target.animate(keyframes, |
| 320 { duration: 1000, fill: "both" }); |
| 321 testAnimationSamples(animation, idlName, |
| 322 [{ time: 0, expected: "10px" }, |
| 323 { time: 500, expected: "30px" }, |
| 324 { time: 1000, expected: "50px" }]); |
| 325 }, property + " supports animating as a length of rem"); |
| 326 } |
| 327 } |
| 328 |
| 329 function percentage() { |
| 330 return function(property, options) { |
| 331 test(function(t) { |
| 332 var idlName = propertyToIDL(property); |
| 333 var keyframes = {}; |
| 334 keyframes[idlName] = ["10%", "50%"]; |
| 335 var target = createElement(t, options.tagName); |
| 336 var animation = target.animate(keyframes, |
| 337 { duration: 1000, fill: "both" }); |
| 338 testAnimationSamples(animation, idlName, |
| 339 [{ time: 0, expected: "10%" }, |
| 340 { time: 500, expected: "30%" }, |
| 341 { time: 1000, expected: "50%" }]); |
| 342 }, property + " supports animating as a percentage"); |
| 343 } |
| 344 } |
| 345 |
| 346 function integer() { |
| 347 return function(property, options) { |
| 348 test(function(t) { |
| 349 var idlName = propertyToIDL(property); |
| 350 var keyframes = {}; |
| 351 keyframes[idlName] = [-2, 2]; |
| 352 var target = createElement(t, options.tagName); |
| 353 var animation = target.animate(keyframes, |
| 354 { duration: 1000, fill: "both" }); |
| 355 testAnimationSamples(animation, idlName, |
| 356 [{ time: 0, expected: "-2" }, |
| 357 { time: 500, expected: "0" }, |
| 358 { time: 1000, expected: "2" }]); |
| 359 }, property + " supports animating as an integer"); |
| 360 } |
| 361 } |
| 362 |
| 363 function positiveNumber() { |
| 364 return function(property, options) { |
| 365 test(function(t) { |
| 366 var idlName = propertyToIDL(property); |
| 367 var keyframes = {}; |
| 368 keyframes[idlName] = [1.1, 1.5]; |
| 369 var target = createElement(t, options.tagName); |
| 370 var animation = target.animate(keyframes, |
| 371 { duration: 1000, fill: "both" }); |
| 372 testAnimationSamples(animation, idlName, |
| 373 [{ time: 0, expected: "1.1" }, |
| 374 { time: 500, expected: "1.3" }, |
| 375 { time: 1000, expected: "1.5" }]); |
| 376 }, property + " supports animating as a positive number"); |
| 377 } |
| 378 } |
| 379 |
| 380 function lengthPercentageOrCalc() { |
| 381 return function(property, options) { |
| 382 length()(property, options); |
| 383 percentage()(property, options); |
| 384 |
| 385 test(function(t) { |
| 386 var idlName = propertyToIDL(property); |
| 387 var keyframes = {}; |
| 388 keyframes[idlName] = ["10px", "20%"]; |
| 389 var target = createElement(t, options.tagName); |
| 390 var animation = target.animate(keyframes, |
| 391 { duration: 1000, fill: "both" }); |
| 392 testAnimationSamples(animation, idlName, |
| 393 [{ time: 0, expected: "10px" }, |
| 394 { time: 500, expected: "calc(5px + 10%)" }, |
| 395 { time: 1000, expected: "20%" }]); |
| 396 }, property + " supports animating as combination units 'px' and '%'"); |
| 397 |
| 398 test(function(t) { |
| 399 var idlName = propertyToIDL(property); |
| 400 var keyframes = {}; |
| 401 keyframes[idlName] = ["10%", "2em"]; |
| 402 var target = createElement(t, options.tagName); |
| 403 var animation = target.animate(keyframes, |
| 404 { duration: 1000, fill: "both" }); |
| 405 testAnimationSamples(animation, idlName, |
| 406 [{ time: 0, expected: "10%" }, |
| 407 { time: 500, expected: "calc(10px + 5%)" }, |
| 408 { time: 1000, expected: "20px" }]); |
| 409 }, property + " supports animating as combination units '%' and 'em'"); |
| 410 |
| 411 test(function(t) { |
| 412 var idlName = propertyToIDL(property); |
| 413 var keyframes = {}; |
| 414 keyframes[idlName] = ["1em", "2rem"]; |
| 415 var target = createElement(t, options.tagName); |
| 416 var animation = target.animate(keyframes, |
| 417 { duration: 1000, fill: "both" }); |
| 418 testAnimationSamples(animation, idlName, |
| 419 [{ time: 0, expected: "10px" }, |
| 420 { time: 500, expected: "15px" }, |
| 421 { time: 1000, expected: "20px" }]); |
| 422 }, property + " supports animating as combination units 'em' and 'rem'"); |
| 423 |
| 424 test(function(t) { |
| 425 var idlName = propertyToIDL(property); |
| 426 var keyframes = {}; |
| 427 keyframes[idlName] = ["10px", "calc(1em + 20%)"]; |
| 428 var target = createElement(t, options.tagName); |
| 429 var animation = target.animate(keyframes, |
| 430 { duration: 1000, fill: "both" }); |
| 431 testAnimationSamples(animation, idlName, |
| 432 [{ time: 0, expected: "10px" }, |
| 433 { time: 500, expected: "calc(10px + 10%)" }, |
| 434 { time: 1000, expected: "calc(10px + 20%)" }]); |
| 435 }, property + " supports animating as combination units 'px' and 'calc'"); |
| 436 |
| 437 test(function(t) { |
| 438 var idlName = propertyToIDL(property); |
| 439 var keyframes = {}; |
| 440 keyframes[idlName] = ["calc(10px + 10%)", "calc(1em + 1rem + 20%)"]; |
| 441 var target = createElement(t, options.tagName); |
| 442 var animation = target.animate(keyframes, |
| 443 { duration: 1000, fill: "both" }); |
| 444 testAnimationSamples(animation, idlName, |
| 445 [{ time: 0, |
| 446 expected: "calc(10px + 10%)" }, |
| 447 { time: 500, |
| 448 expected: "calc(15px + 15%)" }, |
| 449 { time: 1000, |
| 450 expected: "calc(20px + 20%)" }]); |
| 451 }, property + " supports animating as a calc"); |
| 452 } |
| 453 } |
| 454 |
| 455 function visibility() { |
| 456 return function(property, options) { |
| 457 test(function(t) { |
| 458 var idlName = propertyToIDL(property); |
| 459 var keyframes = {}; |
| 460 keyframes[idlName] = ["visible", "hidden"]; |
| 461 var target = createElement(t, options.tagName); |
| 462 var animation = target.animate(keyframes, |
| 463 { duration: 1000, fill: "both" }); |
| 464 testAnimationSamples(animation, idlName, |
| 465 [{ time: 0, expected: "visible" }, |
| 466 { time: 999, expected: "visible" }, |
| 467 { time: 1000, expected: "hidden" }]); |
| 468 }, property + " uses visibility animation when animating " |
| 469 + "from 'visible' to 'hidden'"); |
| 470 |
| 471 test(function(t) { |
| 472 var idlName = propertyToIDL(property); |
| 473 var keyframes = {}; |
| 474 keyframes[idlName] = ["hidden", "visible"]; |
| 475 var target = createElement(t, options.tagName); |
| 476 var animation = target.animate(keyframes, |
| 477 { duration: 1000, fill: "both" }); |
| 478 testAnimationSamples(animation, idlName, |
| 479 [{ time: 0, expected: "hidden" }, |
| 480 { time: 1, expected: "visible" }, |
| 481 { time: 1000, expected: "visible" }]); |
| 482 }, property + " uses visibility animation when animating " |
| 483 + "from 'hidden' to 'visible'"); |
| 484 |
| 485 test(function(t) { |
| 486 var idlName = propertyToIDL(property); |
| 487 var keyframes = {}; |
| 488 keyframes[idlName] = ["hidden", "collapse"]; |
| 489 var target = createElement(t, options.tagName); |
| 490 var animation = target.animate(keyframes, |
| 491 { duration: 1000, fill: "both" }); |
| 492 testAnimationSamples(animation, idlName, |
| 493 [{ time: 0, expected: "hidden" }, |
| 494 { time: 499, expected: "hidden" }, |
| 495 { time: 500, expected: "collapse" }, |
| 496 { time: 1000, expected: "collapse" }]); |
| 497 }, property + " uses visibility animation when animating " |
| 498 + "from 'hidden' to 'collapse'"); |
| 499 |
| 500 test(function(t) { |
| 501 // Easing: http://cubic-bezier.com/#.68,-.55,.26,1.55 |
| 502 // With this curve, the value is less than 0 till about 34% |
| 503 // also more than 1 since about 63% |
| 504 var idlName = propertyToIDL(property); |
| 505 var keyframes = {}; |
| 506 keyframes[idlName] = ["visible", "hidden"]; |
| 507 var target = createElement(t, options.tagName); |
| 508 var animation = |
| 509 target.animate(keyframes, |
| 510 { duration: 1000, fill: "both", |
| 511 easing: "cubic-bezier(0.68, -0.55, 0.26, 1.55)" }); |
| 512 testAnimationSamples(animation, idlName, |
| 513 [{ time: 0, expected: "visible" }, |
| 514 { time: 1, expected: "visible" }, |
| 515 { time: 330, expected: "visible" }, |
| 516 { time: 340, expected: "visible" }, |
| 517 { time: 620, expected: "visible" }, |
| 518 { time: 630, expected: "hidden" }, |
| 519 { time: 1000, expected: "hidden" }]); |
| 520 }, property + " uses visibility animation when animating " |
| 521 + "from 'visible' to 'hidden' with easeInOutBack easing"); |
| 522 } |
| 523 } |
| 524 |
| 525 function testAnimationSamples(animation, idlName, testSamples) { |
| 526 var target = animation.effect.target; |
| 527 testSamples.forEach(function(testSample) { |
| 528 animation.currentTime = testSample.time; |
| 529 assert_equals(getComputedStyle(target)[idlName], testSample.expected, |
| 530 "The value should be " + testSample.expected + |
| 531 " at " + testSample.time + "ms"); |
| 532 }); |
| 533 } |
| 534 |
| 535 function isSupported(property) { |
| 536 var testKeyframe = new TestKeyframe(propertyToIDL(property)); |
| 537 try { |
| 538 // Since TestKeyframe returns 'undefined' for |property|, |
| 539 // the KeyframeEffect constructor will throw |
| 540 // if the string "undefined" is not a valid value for the property. |
| 541 new KeyframeEffect(null, testKeyframe); |
| 542 } catch(e) {} |
| 543 return testKeyframe.propAccessCount !== 0; |
| 544 } |
| 545 |
| 546 function TestKeyframe(testProp) { |
| 547 var _propAccessCount = 0; |
| 548 |
| 549 Object.defineProperty(this, testProp, { |
| 550 get: function() { _propAccessCount++; }, |
| 551 enumerable: true |
| 552 }); |
| 553 |
| 554 Object.defineProperty(this, 'propAccessCount', { |
| 555 get: function() { return _propAccessCount; } |
| 556 }); |
| 557 } |
| 558 |
| 559 function propertyToIDL(property) { |
| 560 // https://w3c.github.io/web-animations/#animation-property-name-to-idl-attrib
ute-name |
| 561 if (property === "float") { |
| 562 return "cssFloat"; |
| 563 } |
| 564 return property.replace(/-[a-z]/gi, |
| 565 function (str) { |
| 566 return str.substr(1).toUpperCase(); }); |
| 567 } |
| 568 |
| 569 </script> |
OLD | NEW |