Commit 56457d4e authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

[Code health] Remove usage of setTimeout in animation layout tests

Bug: 625562
Change-Id: I77bc4e7761e81254f73971f026d5e74a0a2d2d8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2394755
Commit-Queue: Xida Chen <xidachen@chromium.org>
Reviewed-by: default avatarKevin Ellis <kevers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805381}
parent 8e411d07
...@@ -52,8 +52,8 @@ ...@@ -52,8 +52,8 @@
function animationEnded(event) { function animationEnded(event) {
if (++animsFinished == numAnims) { if (++animsFinished == numAnims) {
setTimeout(endTest, 0); // This call to setTimeout should be ok in the test environment // Give the animation a chance to be 1 frame into the after phase.
// since we're just giving style a chance to resolve. requestAnimationFrame(endTest);
} }
}; };
......
...@@ -88,9 +88,8 @@ async_test(t => { ...@@ -88,9 +88,8 @@ async_test(t => {
} }
document.addEventListener("animationend", t.step_func(() => { document.addEventListener("animationend", t.step_func(() => {
if (++animsFinished == numAnims) { if (++animsFinished == numAnims) {
// This call to setTimeout() should be OK in the test environment // Give the animation a chance to be 1 frame into the after phase.
// since we're just giving style a chance to resolve. requestAnimationFrame(endTest);
t.step_timeout(endTest, 0);
} }
})); }));
})); }));
......
...@@ -32,7 +32,7 @@ window.onload = function() { ...@@ -32,7 +32,7 @@ window.onload = function() {
function onStart() { function onStart() {
target.removeEventListener('animationstart', onStart); target.removeEventListener('animationstart', onStart);
setTimeout(setDisplayNone, 300); requestAnimationFrame(setDisplayNone);
} }
function setDisplayNone() { function setDisplayNone() {
...@@ -53,7 +53,7 @@ function setDisplayBlock() { ...@@ -53,7 +53,7 @@ function setDisplayBlock() {
} }
function onRestart(e) { function onRestart(e) {
setTimeout(asyncHandle.step_func_done(measureProgress), 100); requestAnimationFrame(asyncHandle.step_func_done(measureProgress));
} }
function measureProgress() { function measureProgress() {
......
...@@ -27,7 +27,7 @@ async_test(function(t) { ...@@ -27,7 +27,7 @@ async_test(function(t) {
document.body.offsetTop; document.body.offsetTop;
var animation = document.body.getAnimations()[0]; var animation = document.body.getAnimations()[0];
setTimeout(function() { requestAnimationFrame(function() {
if (animation.playState === 'pending') { if (animation.playState === 'pending') {
var passed = false; var passed = false;
document.body.addEventListener('animationstart', function() { document.body.addEventListener('animationstart', function() {
...@@ -47,7 +47,7 @@ async_test(function(t) { ...@@ -47,7 +47,7 @@ async_test(function(t) {
// pass even if the implementation is incorrect. // pass even if the implementation is incorrect.
t.done(); t.done();
} }
}, 0); });
}); });
}); });
</script> </script>
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
var t = async_test('An animation which is initially paused produces the correct output when first created, and can be unpaused.'); var t = async_test('An animation which is initially paused produces the correct output when first created, and can be unpaused.');
setTimeout(t.step_func(() => { // this set timeout should be ok in the test environment requestAnimationFrame(t.step_func(() => {
assert_equals(getComputedStyle(animation1).left, '570px'); assert_equals(getComputedStyle(animation1).left, '570px');
assert_equals(getComputedStyle(animation2).left, '100px'); assert_equals(getComputedStyle(animation2).left, '100px');
assert_equals(getComputedStyle(animation3).left, '0px'); assert_equals(getComputedStyle(animation3).left, '0px');
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
assert_equals(getComputedStyle(animation1).left, '570px'); assert_equals(getComputedStyle(animation1).left, '570px');
assert_equals(getComputedStyle(animation2).left, '100px'); assert_equals(getComputedStyle(animation2).left, '100px');
assert_equals(getComputedStyle(animation3).left, '0px'); assert_equals(getComputedStyle(animation3).left, '0px');
}), 102); // arbitrary }));
function finished() { function finished() {
var left1 = parseFloat(getComputedStyle(animation1).left); var left1 = parseFloat(getComputedStyle(animation1).left);
......
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div id="target"></div>
<script>
var asyncHandle = async_test('Delayed animations are unaffected by on demand timeline updates.');
target.animate(null, {delay: 100}).onfinish = () => asyncHandle.done();
requestAnimationFrame(() => {
requestAnimationFrame(() => {
setTimeout(() => {
// Force layout tree update which forces an on demand timing update.
target.offsetTop;
}, 0);
});
});
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment