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 callbacks [optional]: a function to be executed immediately after animation
starts; | 9 callbacks [optional]: a function to be executed immediately after animation
starts; |
10 or, an object in the form {time: function} containing
functions to be | 10 or, an object in the form {time: function} containing
functions to be |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 } | 346 } |
347 } | 347 } |
348 } else { | 348 } else { |
349 result = isCloseEnough(computedValue, expectedValue, tolerance); | 349 result = isCloseEnough(computedValue, expectedValue, tolerance); |
350 } | 350 } |
351 return result; | 351 return result; |
352 } | 352 } |
353 | 353 |
354 function endTest() | 354 function endTest() |
355 { | 355 { |
356 document.getElementById('result').innerHTML = result; | 356 var resultElement = useResultElement ? document.getElementById('result') : d
ocument.documentElement; |
| 357 resultElement.innerHTML = result; |
357 | 358 |
358 if (window.testRunner) | 359 if (window.testRunner) |
359 testRunner.notifyDone(); | 360 testRunner.notifyDone(); |
360 } | 361 } |
361 | 362 |
362 function runChecksWithRAF(checks) | 363 function runChecksWithRAF(checks) |
363 { | 364 { |
364 var finished = true; | 365 var finished = true; |
365 var time = performance.now() - animStartTime; | 366 var time = performance.now() - animStartTime; |
366 | 367 |
(...skipping 23 matching lines...) Expand all Loading... |
390 } | 391 } |
391 | 392 |
392 function startTest(checks) | 393 function startTest(checks) |
393 { | 394 { |
394 if (hasPauseAnimationAPI) | 395 if (hasPauseAnimationAPI) |
395 runChecksWithPauseAPI(checks); | 396 runChecksWithPauseAPI(checks); |
396 else | 397 else |
397 runChecksWithRAF(checks); | 398 runChecksWithRAF(checks); |
398 } | 399 } |
399 | 400 |
| 401 var useResultElement = false; |
400 var result = ""; | 402 var result = ""; |
401 var hasPauseAnimationAPI; | 403 var hasPauseAnimationAPI; |
402 var animStartTime; | 404 var animStartTime; |
403 | 405 |
404 // FIXME: remove deprecatedEvent, disablePauseAnimationAPI and doPixelTest | 406 // FIXME: remove deprecatedEvent, disablePauseAnimationAPI and doPixelTest |
405 function runAnimationTest(expected, callbacks, deprecatedEvent, disablePauseAnim
ationAPI, doPixelTest) | 407 function runAnimationTest(expected, callbacks, deprecatedEvent, disablePauseAnim
ationAPI, doPixelTest) |
406 { | 408 { |
| 409 if (disablePauseAnimationAPI) |
| 410 result += 'Warning this test is running in real-time and may be flaky.<b
r>'; |
407 if (deprecatedEvent) | 411 if (deprecatedEvent) |
408 throw 'Event argument is deprecated!'; | 412 throw 'Event argument is deprecated!'; |
409 if (!expected) | 413 if (!expected) |
410 throw "Expected results are missing!"; | 414 throw "Expected results are missing!"; |
411 | 415 |
412 hasPauseAnimationAPI = 'internals' in window; | 416 hasPauseAnimationAPI = 'internals' in window; |
413 if (disablePauseAnimationAPI) | 417 if (disablePauseAnimationAPI) |
414 hasPauseAnimationAPI = false; | 418 hasPauseAnimationAPI = false; |
415 | 419 |
416 var checks = {}; | 420 var checks = {}; |
417 | 421 |
418 if (typeof callbacks == 'function') | 422 if (typeof callbacks == 'function') |
419 checks[0] = [callbacks]; | 423 checks[0] = [callbacks]; |
420 else for (var time in callbacks) { | 424 else for (var time in callbacks) { |
421 timeMs = Math.round(time * 1000); | 425 timeMs = Math.round(time * 1000); |
422 checks[timeMs] = [callbacks[time]]; | 426 checks[timeMs] = [callbacks[time]]; |
423 } | 427 } |
424 | 428 |
425 for (var i = 0; i < expected.length; i++) { | 429 for (var i = 0; i < expected.length; i++) { |
426 var expectation = expected[i]; | 430 var expectation = expected[i]; |
427 var timeMs = Math.round(expectation[1] * 1000); | 431 var timeMs = Math.round(expectation[1] * 1000); |
428 if (!checks[timeMs]) | 432 if (!checks[timeMs]) |
429 checks[timeMs] = []; | 433 checks[timeMs] = []; |
430 checks[timeMs].push(checkExpectedValue.bind(null, expected, i)); | 434 checks[timeMs].push(checkExpectedValue.bind(null, expected, i)); |
431 } | 435 } |
432 | 436 |
| 437 var doPixelTest = Boolean(doPixelTest); |
| 438 useResultElement = doPixelTest; |
| 439 |
433 if (window.testRunner) { | 440 if (window.testRunner) { |
434 if (!doPixelTest) | 441 testRunner.dumpAsText(doPixelTest); |
435 testRunner.dumpAsText(); | |
436 testRunner.waitUntilDone(); | 442 testRunner.waitUntilDone(); |
437 } | 443 } |
438 | 444 |
439 var started = false; | 445 var started = false; |
440 document.addEventListener('webkitAnimationStart', function() { | 446 document.addEventListener('webkitAnimationStart', function() { |
441 if (!started) { | 447 if (!started) { |
442 started = true; | 448 started = true; |
443 animStartTime = performance.now(); | 449 animStartTime = performance.now(); |
444 // delay to give hardware animations a chance to start | 450 // delay to give hardware animations a chance to start |
445 setTimeout(function() { | 451 setTimeout(function() { |
446 startTest(checks); | 452 startTest(checks); |
447 }, 0); | 453 }, 0); |
448 } | 454 } |
449 }, false); | 455 }, false); |
450 } | 456 } |
OLD | NEW |