Bug 1574061 - Use the target window object for waitForAnimationFrames in observeStylingInTargetWindow. r=boris
authorHiroyuki Ikezoe <hikezoe.birchill@mozilla.com>
Thu, 15 Aug 2019 21:20:45 +0000
changeset 488356 4473a7402f25c2f632ce4aa06dee18328c96d59b
parent 488355 62785507e4cf2c2ac8c19fa930b890ff562f1e5c
child 488357 db9aaec44445e5ccfef53a25cd6812107c3df802
push id113906
push userncsoregi@mozilla.com
push dateFri, 16 Aug 2019 04:07:24 +0000
treeherdermozilla-inbound@d887276421d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersboris
bugs1574061
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1574061 - Use the target window object for waitForAnimationFrames in observeStylingInTargetWindow. r=boris Also waitForAnimationReadyToRestyle should use owner window object instead of global `window`. Differential Revision: https://phabricator.services.mozilla.com/D42078
dom/animation/test/mozilla/file_restyles.html
dom/animation/test/testcommon.js
--- a/dom/animation/test/mozilla/file_restyles.html
+++ b/dom/animation/test/mozilla/file_restyles.html
@@ -79,17 +79,17 @@ function observeStyling(frameCount, onFr
   return observeStylingInTargetWindow(window, frameCount, onFrame);
 }
 
 // As with observeStyling but applied to target window |aWindow|.
 function observeStylingInTargetWindow(aWindow, aFrameCount, aOnFrame) {
   const docShell = getDocShellForObservingRestylesForWindow(aWindow);
 
   return new Promise(resolve => {
-    return waitForAnimationFrames(aFrameCount, aOnFrame).then(() => {
+    return waitForAnimationFrames(aFrameCount, aOnFrame, aWindow).then(() => {
       const markers = docShell.popProfileTimelineMarkers();
       docShell.recordProfileTimelineMarkers = false;
       const stylingMarkers = markers.filter((marker, index) => {
         return marker.name == 'Styles' && marker.isAnimationOnly;
       });
       resolve(stylingMarkers);
     });
   });
--- a/dom/animation/test/testcommon.js
+++ b/dom/animation/test/testcommon.js
@@ -252,50 +252,54 @@ function waitForFrame() {
 }
 
 /**
  * Waits for a requestAnimationFrame callback in the next refresh driver tick.
  * Note that the 'dom.animations-api.core.enabled' and
  * 'dom.animations-api.timelines.enabled' prefs should be true to use this
  * function.
  */
-function waitForNextFrame() {
-  const timeAtStart = document.timeline.currentTime;
+function waitForNextFrame(aWindow = window) {
+  const timeAtStart = aWindow.document.timeline.currentTime;
   return new Promise(resolve => {
-    window.requestAnimationFrame(() => {
-      if (timeAtStart === document.timeline.currentTime) {
-        window.requestAnimationFrame(resolve);
+    aWindow.requestAnimationFrame(() => {
+      if (timeAtStart === aWindow.document.timeline.currentTime) {
+        aWindow.requestAnimationFrame(resolve);
       } else {
         resolve();
       }
     });
   });
 }
 
 /**
  * Returns a Promise that is resolved after the given number of consecutive
  * animation frames have occured (using requestAnimationFrame callbacks).
  *
- * @param frameCount  The number of animation frames.
- * @param onFrame  An optional function to be processed in each animation frame.
+ * @param aFrameCount  The number of animation frames.
+ * @param aOnFrame  An optional function to be processed in each animation frame.
+ * @param aWindow  An optional window object to be used for requestAnimationFrame.
  */
-function waitForAnimationFrames(frameCount, onFrame) {
-  const timeAtStart = document.timeline.currentTime;
+function waitForAnimationFrames(aFrameCount, aOnFrame, aWindow = window) {
+  const timeAtStart = aWindow.document.timeline.currentTime;
   return new Promise(function(resolve, reject) {
     function handleFrame() {
-      if (onFrame && typeof onFrame === "function") {
-        onFrame();
+      if (aOnFrame && typeof aOnFrame === "function") {
+        aOnFrame();
       }
-      if (timeAtStart != document.timeline.currentTime && --frameCount <= 0) {
+      if (
+        timeAtStart != aWindow.document.timeline.currentTime &&
+        --aFrameCount <= 0
+      ) {
         resolve();
       } else {
-        window.requestAnimationFrame(handleFrame); // wait another frame
+        aWindow.requestAnimationFrame(handleFrame); // wait another frame
       }
     }
-    window.requestAnimationFrame(handleFrame);
+    aWindow.requestAnimationFrame(handleFrame);
   });
 }
 
 /**
  * Promise wrapper for requestIdleCallback.
  */
 function waitForIdle() {
   return new Promise(resolve => {
@@ -480,11 +484,11 @@ function animationStartsRightNow(aAnimat
 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();
+    await waitForNextFrame(aAnimation.ownerGlobal);
   }
 }