OLD | NEW |
---|---|
1 (function(){ | 1 (function(){ |
2 'use strict' | 2 'use strict' |
3 | 3 |
4 function createElement() { | 4 function createElement() { |
5 var element = document.createElement('div'); | 5 var element = document.createElement('div'); |
6 document.documentElement.appendChild(element); | 6 document.documentElement.appendChild(element); |
7 return element; | 7 return element; |
8 } | 8 } |
9 | 9 |
10 function heldTiming(iterationStart) { | 10 function heldTiming(progress) { |
11 return { | 11 return { |
12 duration: 1000, | 12 duration: 1000, |
13 playbackRate: 0, | |
14 fill: 'forwards', | 13 fill: 'forwards', |
15 iterationStart: iterationStart, | 14 delay: -progress * 1000, |
16 }; | 15 }; |
17 } | 16 } |
18 | 17 |
19 function assertAnimationStyles(keyframes, expectations) { | 18 function assertAnimationStyles(keyframes, expectations, description) { |
20 for (var progress in expectations) { | 19 for (var progress in expectations) { |
21 var element = createElement(); | 20 var element = createElement(); |
22 element.animate(keyframes, heldTiming(progress)); | 21 element.animate(keyframes, heldTiming(progress)); |
23 var computedStyle = getComputedStyle(element); | 22 var computedStyle = getComputedStyle(element); |
24 for (var property in expectations[progress]) { | 23 for (var property in expectations[progress]) { |
25 assert_equals(computedStyle[property], expectations[progress][property], | 24 assert_equals(computedStyle[property], expectations[progress][property], |
26 property + ' at ' + (progress * 100) + '%'); | 25 property + ' at ' + (progress * 100) + '%' + (description ? ' ' + desc ription : '')); |
27 } | 26 } |
28 } | 27 } |
29 } | 28 } |
30 | 29 |
30 // Currently our animation timeline is not stable during page load script execut ion. | |
31 // By deferring the tests to requestAnimationFrame() we can get a stable timelin e and | |
32 // avoid flaky test results. | |
shans
2014/04/30 11:46:27
Considering that we want these to be w3c tests eve
alancutter (OOO until 2018)
2014/05/01 00:05:13
It's not clear how soon the unstable animation tim
| |
33 function testInRAF(testFunction, description, properties) { | |
34 async_test(function(testHandle) { | |
35 requestAnimationFrame(function() { | |
36 testHandle.step(testFunction); | |
37 testHandle.done(); | |
38 }) | |
39 }, description, properties); | |
40 } | |
41 | |
31 window.assertAnimationStyles = assertAnimationStyles; | 42 window.assertAnimationStyles = assertAnimationStyles; |
43 window.testInRAF = testInRAF; | |
32 })(); | 44 })(); |
OLD | NEW |