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
--- 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;
});