OLD | NEW |
1 /* This is the helper function to run animation tests: | 1 /* This is the helper function to run animation tests: |
2 | 2 |
3 Test page requirements: | 3 Test page requirements: |
4 - The body must contain an empty div with id "result" | 4 - The body must contain an empty div with id "result" |
5 - Call this function directly from the <script> inside the test page | 5 - Call this function directly from the <script> inside the test page |
6 | 6 |
7 Function parameters: | 7 Function parameters: |
8 expected [required]: an array of arrays defining a set of CSS properties tha
t must have given values at specific times (see below) | 8 expected [required]: an array of arrays defining a set of CSS properties tha
t must have given values at specific times (see below) |
9 callback [optional]: a function to be executed just before the test starts (
none by default) | 9 callback [optional]: a function to be executed just before the test starts (
none by default) |
10 event [optional]: which DOM event to wait for before starting the test ("web
kitAnimationStart" by default) | 10 event [optional]: which DOM event to wait for before starting the test ("web
kitAnimationStart" by default) |
11 | 11 |
12 Each sub-array must contain these items in this order: | 12 Each sub-array must contain these items in this order: |
13 - the name of the CSS animation (may be null) [1] | 13 FIXME: Remove the name element as it is no longer required. |
| 14 - deprecated: the name of the CSS animation (may be null) |
14 - the time in seconds at which to snapshot the CSS property | 15 - the time in seconds at which to snapshot the CSS property |
15 - the id of the element on which to get the CSS property value [2] | 16 - the id of the element on which to get the CSS property value [1] |
16 - the name of the CSS property to get [3] | 17 - the name of the CSS property to get [2] |
17 - the expected value for the CSS property | 18 - the expected value for the CSS property |
18 - the tolerance to use when comparing the effective CSS property value with
its expected value | 19 - the tolerance to use when comparing the effective CSS property value with
its expected value |
19 | 20 |
20 [1] If null is passed, a regular setTimeout() will be used instead to snapsh
ot the animated property in the future, | 21 [1] If a single string is passed, it is the id of the element to test. If an
array with 2 elements is passed they |
21 instead of fast forwarding using the pauseAnimationAtTimeOnElement() JS API
from Internals. | |
22 | |
23 [2] If a single string is passed, it is the id of the element to test. If an
array with 2 elements is passed they | |
24 are the ids of 2 elements, whose values are compared for equality. In this c
ase the expected value is ignored | 22 are the ids of 2 elements, whose values are compared for equality. In this c
ase the expected value is ignored |
25 but the tolerance is used in the comparison. If the second element is prefix
ed with "static:", no animation on that | 23 but the tolerance is used in the comparison. If the second element is prefix
ed with "static:", no animation on that |
26 element is required, allowing comparison with an unanimated "expected value"
element. | 24 element is required, allowing comparison with an unanimated "expected value"
element. |
27 | 25 |
28 If a string with a '.' is passed, this is an element in an iframe. The strin
g before the dot is the iframe id | 26 If a string with a '.' is passed, this is an element in an iframe. The strin
g before the dot is the iframe id |
29 and the string after the dot is the element name in that iframe. | 27 and the string after the dot is the element name in that iframe. |
30 | 28 |
31 [3] If the CSS property name is "webkitTransform", expected value must be an
array of 1 or more numbers corresponding to the matrix elements, | 29 [2] If the CSS property name is "webkitTransform", expected value must be an
array of 1 or more numbers corresponding to the matrix elements, |
32 or a string which will be compared directly (useful if the expected value is
"none") | 30 or a string which will be compared directly (useful if the expected value is
"none") |
33 If the CSS property name is "webkitTransform.N", expected value must be a nu
mber corresponding to the Nth element of the matrix | 31 If the CSS property name is "webkitTransform.N", expected value must be a nu
mber corresponding to the Nth element of the matrix |
34 | 32 |
35 */ | 33 */ |
36 | 34 |
37 function isCloseEnough(actual, desired, tolerance) | 35 function isCloseEnough(actual, desired, tolerance) |
38 { | 36 { |
39 var diff = Math.abs(actual - desired); | 37 var diff = Math.abs(actual - desired); |
40 return diff <= tolerance; | 38 return diff <= tolerance; |
41 } | 39 } |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // Check for a dot separated string | 231 // Check for a dot separated string |
234 var iframeId; | 232 var iframeId; |
235 if (!compareElements) { | 233 if (!compareElements) { |
236 var array = elementId.split('.'); | 234 var array = elementId.split('.'); |
237 if (array.length == 2) { | 235 if (array.length == 2) { |
238 iframeId = array[0]; | 236 iframeId = array[0]; |
239 elementId = array[1]; | 237 elementId = array[1]; |
240 } | 238 } |
241 } | 239 } |
242 | 240 |
243 if (animationName && hasPauseAnimationAPI && !internals.pauseAnimationAtTime
OnElement(animationName, time, document.getElementById(elementId))) { | 241 if (animationName && hasPauseAnimationAPI) |
244 result += "FAIL - animation \"" + animationName + "\" is not running" +
"<br>"; | 242 internals.pauseAnimations(time); |
245 return; | |
246 } | |
247 | |
248 if (compareElements && !element2Static && animationName && hasPauseAnimation
API && !internals.pauseAnimationAtTimeOnElement(animationName, time, document.ge
tElementById(elementId2))) { | |
249 result += "FAIL - animation \"" + animationName + "\" is not running" +
"<br>"; | |
250 return; | |
251 } | |
252 | 243 |
253 var computedValue, computedValue2; | 244 var computedValue, computedValue2; |
254 if (compareElements) { | 245 if (compareElements) { |
255 computedValue = getPropertyValue(property, elementId, iframeId); | 246 computedValue = getPropertyValue(property, elementId, iframeId); |
256 computedValue2 = getPropertyValue(property, elementId2, iframeId); | 247 computedValue2 = getPropertyValue(property, elementId2, iframeId); |
257 | 248 |
258 if (comparePropertyValue(property, computedValue, computedValue2, tolera
nce)) | 249 if (comparePropertyValue(property, computedValue, computedValue2, tolera
nce)) |
259 result += "PASS - \"" + property + "\" property for \"" + elementId
+ "\" and \"" + elementId2 + | 250 result += "PASS - \"" + property + "\" property for \"" + elementId
+ "\" and \"" + elementId2 + |
260 "\" elements at " + time + "s are close enough to ea
ch other" + "<br>"; | 251 "\" elements at " + time + "s are close enough to ea
ch other" + "<br>"; |
261 else | 252 else |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 { | 370 { |
380 if (testStarted) return; | 371 if (testStarted) return; |
381 testStarted = true; | 372 testStarted = true; |
382 | 373 |
383 if (callback) | 374 if (callback) |
384 callback(); | 375 callback(); |
385 | 376 |
386 var maxTime = 0; | 377 var maxTime = 0; |
387 | 378 |
388 for (var i = 0; i < expected.length; ++i) { | 379 for (var i = 0; i < expected.length; ++i) { |
389 var animationName = expected[i][0]; | |
390 var time = expected[i][1]; | 380 var time = expected[i][1]; |
391 | 381 |
392 // We can only use the animation fast-forward mechanism if there's an an
imation name | 382 if (hasPauseAnimationAPI) |
393 // and Internals implements pauseAnimationAtTimeOnElement() | |
394 if (animationName && hasPauseAnimationAPI) | |
395 checkExpectedValue(expected, i); | 383 checkExpectedValue(expected, i); |
396 else { | 384 else { |
397 if (time > maxTime) | 385 if (time > maxTime) |
398 maxTime = time; | 386 maxTime = time; |
399 | 387 |
400 window.setTimeout(checkExpectedValueCallback(expected, i), time * 10
00); | 388 window.setTimeout(checkExpectedValueCallback(expected, i), time * 10
00); |
401 } | 389 } |
402 } | 390 } |
403 | 391 |
404 if (maxTime > 0) | 392 if (maxTime > 0) |
(...skipping 28 matching lines...) Expand all Loading... |
433 startTest(expected, callback); | 421 startTest(expected, callback); |
434 }, false); | 422 }, false); |
435 } | 423 } |
436 | 424 |
437 function waitForAnimationToStart(element, callback) | 425 function waitForAnimationToStart(element, callback) |
438 { | 426 { |
439 element.addEventListener('webkitAnimationStart', function() { | 427 element.addEventListener('webkitAnimationStart', function() { |
440 window.setTimeout(callback, 0); // delay to give hardware animations a c
hance to start | 428 window.setTimeout(callback, 0); // delay to give hardware animations a c
hance to start |
441 }, false); | 429 }, false); |
442 } | 430 } |
OLD | NEW |