Bug 1443358 - Introduce a new function that is able to count restyle in a given window. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Mon, 02 Apr 2018 13:27:59 +0900
changeset 775974 28bb6a2438aeb88b387f10aace4870ef179dd78c
parent 775890 ef717c03ff54d10b2e30df7e63fc11172c69db44
child 775975 9c4659b0db34cd8bc5cffefbf9828b641dc1ac35
push id104775
push userhikezoe@mozilla.com
push dateMon, 02 Apr 2018 07:32:20 +0000
reviewersbirtles
bugs1443358
milestone61.0a1
Bug 1443358 - Introduce a new function that is able to count restyle in a given window. r?birtles This function will be used for checking restyle counts in an iframe in the next patch. MozReview-Commit-ID: 2PPjJTzXMXH
dom/animation/test/mozilla/file_restyles.html
--- a/dom/animation/test/mozilla/file_restyles.html
+++ b/dom/animation/test/mozilla/file_restyles.html
@@ -47,40 +47,46 @@ div {
   background-color: white;
 }
 </style>
 </head>
 <body>
 <script>
 'use strict';
 
-function getDocShellForObservingRestyles() {
+function getDocShellForObservingRestylesForWindow(aWindow) {
   const docShell =
-    SpecialPowers.wrap(window)
+    SpecialPowers.wrap(aWindow)
                  .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
                  .getInterface(SpecialPowers.Ci.nsIWebNavigation)
                  .QueryInterface(SpecialPowers.Ci.nsIDocShell);
 
   docShell.recordProfileTimelineMarkers = true;
   docShell.popProfileTimelineMarkers();
 
   return docShell;
 }
 
 // Returns the animation restyle markers observed during |frameCount| refresh
-// driver ticks.  This function is typically used to count the number of
-// restyles that take place as part of the style update that happens on each
-// refresh driver tick, as opposed to synchronous restyles triggered by script.
+// driver ticks in this `window`.  This function is typically used to count the
+// number of restyles that take place as part of the style update that happens
+// on each refresh driver tick, as opposed to synchronous restyles triggered by
+// script.
 //
 // For the latter observeAnimSyncStyling (below) should be used.
 function observeStyling(frameCount, onFrame) {
-  let docShell = getDocShellForObservingRestyles();
+  return observeStylingInTargetWindow(window, frameCount, onFrame);
+}
+
+// As with observeStyling but applied to target window |aWindow|.
+function observeStylingInTargetWindow(aWindow, aFrameCount, aOnFrame) {
+  let docShell = getDocShellForObservingRestylesForWindow(aWindow);
 
   return new Promise(resolve => {
-    return waitForAnimationFrames(frameCount, onFrame).then(() => {
+    return waitForAnimationFrames(aFrameCount, aOnFrame).then(() => {
       var markers = docShell.popProfileTimelineMarkers();
       docShell.recordProfileTimelineMarkers = false;
       var stylingMarkers = markers.filter((marker, index) => {
         return marker.name == 'Styles' && marker.isAnimationOnly;
       });
       resolve(stylingMarkers);
     });
   });
@@ -88,17 +94,17 @@ function observeStyling(frameCount, onFr
 
 // Returns observed animation restyle markers when |funcToMakeRestyleHappen|
 // is called.
 // NOTE: This function is synchronous version of the above observeStyling().
 // Unlike the above observeStyling, this function takes a callback function,
 // |funcToMakeRestyleHappen|, which may be expected to trigger a synchronous
 // restyles, and returns any restyle markers produced by calling that function.
 function observeAnimSyncStyling(funcToMakeRestyleHappen) {
-  let docShell = getDocShellForObservingRestyles();
+  let docShell = getDocShellForObservingRestylesForWindow(window);
 
   funcToMakeRestyleHappen();
 
   let markers = docShell.popProfileTimelineMarkers();
   docShell.recordProfileTimelineMarkers = false;
   return markers.filter((marker, index) => {
     return marker.name == 'Styles' && marker.isAnimationOnly;
   });