Bug 1395971 - Wait for animation being ready to restyle. r=birtles, a=test-only
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Fri, 01 Jun 2018 07:35:52 +0900
changeset 473684 89660f6b902f36002aa206ad734aa3b36c1d40b9
parent 473683 6036d334f8c91565da5ce962073ed566af117c81
child 473685 e881e8e454ebfb00e0ecf4ddf98818e7212dc318
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles, test-only
bugs1395971
milestone61.0
Bug 1395971 - Wait for animation being ready to restyle. r=birtles, a=test-only MozReview-Commit-ID: LqZGaxs4UIB
dom/animation/test/mozilla/file_deferred_start.html
dom/animation/test/mozilla/file_restyles.html
dom/animation/test/testcommon.js
--- a/dom/animation/test/mozilla/file_deferred_start.html
+++ b/dom/animation/test/mozilla/file_deferred_start.html
@@ -92,19 +92,22 @@ promise_test(async t => {
 
   const div = addDiv(t, { class: 'target' });
 
   // As with the above test, any stray paints can cause this test to produce
   // a false negative (that is, pass when it should fail). To avoid this we
   // wait for paints and only then do we commence the test.
   await waitForPaints();
 
-  div.animate({ transform: [ 'translate(0px)', 'translate(100px)' ] },
-              { duration: 400 * MS_PER_SEC,
-                delay: -200 * MS_PER_SEC });
+  const animation =
+    div.animate({ transform: [ 'translate(0px)', 'translate(100px)' ] },
+                { duration: 400 * MS_PER_SEC,
+                  delay: -200 * MS_PER_SEC });
+
+  await waitForAnimationReadyToRestyle(animation);
 
   await waitForPaints();
 
   const transformStr =
     SpecialPowers.DOMWindowUtils.getOMTAStyle(div, 'transform');
   const translateX = getTranslateXFromTransform(transformStr);
 
   // If the delay has been applied we should be about half-way through
--- a/dom/animation/test/mozilla/file_restyles.html
+++ b/dom/animation/test/mozilla/file_restyles.html
@@ -127,28 +127,16 @@ function waitForWheelEvent(aTarget) {
 
     sendWheelAndPaintNoFlush(aTarget, centerX, centerY,
                              { deltaMode: WheelEvent.DOM_DELTA_PIXEL,
                                deltaY: targetRect.height },
                              resolve);
   });
 }
 
-async function waitForAnimationReadyToRestyle(aAnimation) {
-  await aAnimation.ready;
-  // If |aAnimation| begins at the current timeline time, we will not process
-  // restyling in the initial frame because of aligning with the refresh driver,
-  // the animation frame in which the ready promise is resolved happens to
-  // coincide perfectly with the start time of the animation.  In this case no
-  // restyling is needed in the frame so we have to wait one more frame.
-  if (animationStartsRightNow(aAnimation)) {
-    await waitForNextFrame();
-  }
-}
-
 var omtaEnabled = isOMTAEnabled();
 
 var isAndroid = !!navigator.userAgent.includes("Android");
 const isWebRender =
   SpecialPowers.DOMWindowUtils.layerManagerType == 'WebRender';
 
 function add_task_if_omta_enabled(test) {
   if (!omtaEnabled) {
--- a/dom/animation/test/testcommon.js
+++ b/dom/animation/test/testcommon.js
@@ -418,8 +418,20 @@ function waitForPaints() {
 // asynchronously (e.g. using play()) and then ended up running the next frame
 // at precisely the time the animation started (due to aligning with vsync
 // refresh rate) then we won't end up restyling in that frame.
 function animationStartsRightNow(aAnimation) {
   return aAnimation.startTime === aAnimation.timeline.currentTime &&
          aAnimation.currentTime === 0;
 }
 
+// Waits for a given animation being ready to restyle.
+async function waitForAnimationReadyToRestyle(aAnimation) {
+  await aAnimation.ready;
+  // If |aAnimation| begins at the current timeline time, we will not process
+  // restyling in the initial frame because of aligning with the refresh driver,
+  // the animation frame in which the ready promise is resolved happens to
+  // coincide perfectly with the start time of the animation.  In this case no
+  // restyling is needed in the frame so we have to wait one more frame.
+  if (animationStartsRightNow(aAnimation)) {
+    await waitForNextFrame();
+  }
+}