Bug 1418268 - Add a function to check whether there is a micro task checkpoint between animation tick and requestAnimationFrame callbacks. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 07 Dec 2017 08:43:59 +0900
changeset 708763 3c33dc8ddc1460691409d4350727d8d5bdf2073b
parent 708762 e72e0dafad843d62ea881d1734d0860a96e0021f
child 708764 4923922a51d44704b9fad2eab7f0f364ba43b559
push id92440
push userhikezoe@mozilla.com
push dateThu, 07 Dec 2017 03:58:44 +0000
reviewersbirtles
bugs1418268
milestone59.0a1
Bug 1418268 - Add a function to check whether there is a micro task checkpoint between animation tick and requestAnimationFrame callbacks. r?birtles MozReview-Commit-ID: 6C9Fbg7SKWU
dom/animation/test/mozilla/file_restyles.html
--- a/dom/animation/test/mozilla/file_restyles.html
+++ b/dom/animation/test/mozilla/file_restyles.html
@@ -90,28 +90,61 @@ function waitForWheelEvent(aTarget) {
 }
 
 var omtaEnabled = isOMTAEnabled();
 
 var isAndroid = !!navigator.userAgent.includes("Android");
 var isServo = isStyledByServo();
 var offscreenThrottlingEnabled =
   SpecialPowers.getBoolPref('dom.animations.offscreen-throttling');
+var hasMicroTaskCheckpointForAnimation;
 
 function add_task_if_omta_enabled(test) {
   if (!omtaEnabled) {
     info(test.name + " is skipped because OMTA is disabled");
     return;
   }
   add_task(test);
 }
 
 // We need to wait for all paints before running tests to avoid contaminations
 // from styling of this document itself.
 waitForAllPaints(() => {
+  // Drop this once we have the micro task checkpoint for animations
+  // (bug 1416966).
+  add_task(async function check_micro_task_checkpoint_for_animations() {
+    const div = addDiv(null);
+
+    async function checkMicroTaskCheckpoint() {
+      return new Promise(resolve => {
+        let didRequestAnimationFrame = false;
+
+        requestAnimationFrame(() => {
+          const animation = div.animate({ }, 100 * MS_PER_SEC);
+
+          requestAnimationFrame(() => {
+            didRequestAnimationFrame = true;
+          });
+
+          animation.ready.then(() => {
+            // If the animation.ready.then callback is called before the next
+            // requestAnimationFrame callback, that means that there is a
+            // micro task checkpoint between animation tick and
+            // requestAnimationFrame callbacks.
+            resolve(!didRequestAnimationFrame);
+          });
+        });
+      });
+    }
+
+    hasMicroTaskCheckpointForAnimation = await checkMicroTaskCheckpoint();
+
+    await ensureElementRemoval(div);
+  });
+
   add_task(async function restyling_for_main_thread_animations() {
     var div = addDiv(null, { style: 'animation: background-color 100s' });
     var animation = div.getAnimations()[0];
 
     await animation.ready;
     ok(!SpecialPowers.wrap(animation).isRunningOnCompositor);
 
     var markers = await observeStyling(5);