Bug 979161 part 4 - Add a non-flushing version of waitForAllPaints to paint_listener.js; r=mattwoodrow

This patch adds waitForAllPaints which does *not* call getBoundingClientRect
since that can cause a flush. Sometimes this flush is undesirable since it can
mask bugs in the code under test which should be performing this flush itself.
This commit is contained in:
Brian Birtles 2014-03-10 13:47:12 +09:00
parent 80173f8459
commit 730325e4c1

View File

@ -2,6 +2,10 @@
var accumulatedRect = null;
var onpaint = function() {};
var debug = false;
const FlushModes = {
FLUSH: 0,
NOFLUSH: 1
};
function paintListener(event) {
if (event.target != window)
@ -24,10 +28,15 @@
}
window.addEventListener("MozAfterPaint", paintListener, false);
function waitForAllPaintsFlushed(callback, subdoc) {
document.documentElement.getBoundingClientRect();
if (subdoc) {
subdoc.documentElement.getBoundingClientRect();
function waitForPaints(callback, subdoc, flushMode) {
// The call to getBoundingClientRect will flush pending layout
// notifications. Sometimes, however, this is undesirable since it can mask
// bugs where the code under test should be performing the flush.
if (flushMode === FlushModes.FLUSH) {
document.documentElement.getBoundingClientRect();
if (subdoc) {
subdoc.documentElement.getBoundingClientRect();
}
}
var utils = SpecialPowers.getDOMWindowUtils(window);
if (!utils.isMozAfterPaintPending) {
@ -43,7 +52,14 @@
if (debug) {
dump("waiting for paint...\n");
}
onpaint = function() { waitForAllPaintsFlushed(callback, subdoc); };
onpaint = function() { waitForPaints(callback, subdoc, flushMode); };
}
window.waitForAllPaintsFlushed = waitForAllPaintsFlushed;
window.waitForAllPaintsFlushed = function(callback, subdoc) {
waitForPaints(callback, subdoc, FlushModes.FLUSH);
};
window.waitForAllPaints = function(callback) {
waitForPaints(callback, null, FlushModes.NOFLUSH);
};
})();