Bug 1591968 - Put window.mozPaintCount behind a default-off pref. r=bzbarsky

It's not the kind of thing we want people to allow observing, generally, and
even less so the kind of thing that we may want people to rely on.

Move internal callers (all of them tests) to a new DOMWindowUtils.paintCount
method.

Differential Revision: https://phabricator.services.mozilla.com/D50817

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-10-29 10:25:53 +00:00
parent abe6482b65
commit cc80d088a2
14 changed files with 50 additions and 27 deletions

View File

@ -4150,3 +4150,10 @@ nsDOMWindowUtils::GetUsesOverlayScrollbars(bool* aResult) {
*aResult = Document::UseOverlayScrollbars(GetDocument()); *aResult = Document::UseOverlayScrollbars(GetDocument());
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsDOMWindowUtils::GetPaintCount(uint64_t* aPaintCount) {
auto* presShell = GetPresShell();
*aPaintCount = presShell ? presShell->GetPaintCount() : 0;
return NS_OK;
}

View File

@ -1935,6 +1935,13 @@ interface nsIDOMWindowUtils : nsISupports {
*/ */
attribute ACString systemFont; attribute ACString systemFont;
/**
* Returns the number of times this document for this window has
* been painted to the screen.
*
* Use this instead of window.mozPaintCount
*/
readonly attribute unsigned long long paintCount;
/** /**
* Simulate the system setting corresponding to 'prefers-reduced-motion' * Simulate the system setting corresponding to 'prefers-reduced-motion'

View File

@ -21,14 +21,12 @@ function deltaInBounds(dx,dy, dw,dh) {
200 <= b && b <= 220); 200 <= b && b <= 220);
} }
var initialFrame;
function start() { function start() {
window.removeEventListener("MozReftestInvalidate", start); window.removeEventListener("MozReftestInvalidate", start);
window.addEventListener("MozAfterPaint", step); window.addEventListener("MozAfterPaint", step);
window.addEventListener("MozPaintWaitFinished", step); window.addEventListener("MozPaintWaitFinished", step);
initialFrame = window.mozPaintCount;
plugin = document.getElementById("plugin"); plugin = document.getElementById("plugin");
movePluginTo(0,0, 200,200); movePluginTo(0,0, 200,200);

View File

@ -22,5 +22,5 @@ random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) fails-if(!haveTestPlugin) f
random-if(!haveTestPlugin) HTTP == plugin-transform-1.html plugin-transform-1-ref.html random-if(!haveTestPlugin) HTTP == plugin-transform-1.html plugin-transform-1-ref.html
fails-if(!haveTestPlugin) HTTP == plugin-transform-2.html plugin-transform-2-ref.html fails-if(!haveTestPlugin) HTTP == plugin-transform-2.html plugin-transform-2-ref.html
skip-if(!haveTestPlugin) HTTP == shrink-1.html shrink-1-ref.html skip-if(!haveTestPlugin) HTTP == shrink-1.html shrink-1-ref.html
skip-if(!haveTestPlugin) HTTP == update-1.html update-1-ref.html pref(dom.mozPaintCount.enabled,true) skip-if(!haveTestPlugin) HTTP == update-1.html update-1-ref.html
skip-if(!haveTestPlugin) HTTP == windowless-layers.html windowless-layers-ref.html skip-if(!haveTestPlugin) HTTP == windowless-layers.html windowless-layers-ref.html

View File

@ -15,6 +15,9 @@ function start()
var last_paint_count = 0; var last_paint_count = 0;
// Enough paints to test reusing a surface after it has been // Enough paints to test reusing a surface after it has been
// moved from front to back buffer. // moved from front to back buffer.
// FIXME: Stop using mozPaintCount for this test.
// Can't make it a chrome:// url because it needs http, thus no
// SpecialPowers :/
var final_paint_count = window.mozPaintCount + 10; var final_paint_count = window.mozPaintCount + 10;
var final_color = "FFFF0000"; var final_color = "FFFF0000";

View File

@ -303,8 +303,10 @@ partial interface Window {
/** /**
* Returns the number of times this document for this window has * Returns the number of times this document for this window has
* been painted to the screen. * been painted to the screen.
*
* If you need this for tests use nsIDOMWindowUtils.paintCount instead.
*/ */
[Throws] readonly attribute unsigned long long mozPaintCount; [Throws, Pref="dom.mozPaintCount.enabled"] readonly attribute unsigned long long mozPaintCount;
attribute EventHandler ondevicemotion; attribute EventHandler ondevicemotion;
attribute EventHandler ondeviceorientation; attribute EventHandler ondeviceorientation;

View File

@ -31,17 +31,17 @@
} }
function doTest(evt) { function doTest(evt) {
var initialCount = win.mozPaintCount; var initialCount = win.windowUtils.paintCount;
function nextStep() { function nextStep() {
if (win.mozPaintCount == initialCount || win.isMozAfterPaintPending) { if (win.windowUtils.paintCount == initialCount || win.isMozAfterPaintPending) {
SimpleTest.info("Waiting for mozPaintCount (= " + initialCount + ") to increase" + testInfo()); SimpleTest.info("Waiting for mozPaintCount (= " + initialCount + ") to increase" + testInfo());
// Do not use SimpleTest.executeSoon() here: give a little more time. // Do not use SimpleTest.executeSoon() here: give a little more time.
setTimeout(nextStep, 100); setTimeout(nextStep, 100);
return; return;
} }
isnot(win.mozPaintCount, initialCount, "mozPaintCount has increased" + testInfo()); isnot(win.windowUtils.paintCount, initialCount, "mozPaintCount has increased" + testInfo());
function testLeafLayersPartitionWindow() { function testLeafLayersPartitionWindow() {
var success = win.windowUtils var success = win.windowUtils
@ -67,7 +67,7 @@
function resizeListener() { function resizeListener() {
win.removeEventListener("resize", resizeListener, true); win.removeEventListener("resize", resizeListener, true);
// We want a paint after resize. // We want a paint after resize.
initialCount = win.mozPaintCount; initialCount = win.windowUtils.paintCount;
SimpleTest.executeSoon(nextStep); SimpleTest.executeSoon(nextStep);
} }
win.addEventListener("resize", resizeListener, true); win.addEventListener("resize", resizeListener, true);

View File

@ -33,7 +33,7 @@ function onAfterPaint () {
function startTest() { function startTest() {
setTimeout(function () { setTimeout(function () {
afterPaintCount = 0; afterPaintCount = 0;
initialPaintCount = window.mozPaintCount; initialPaintCount = SpecialPowers.DOMWindowUtils.paintCount;
window.addEventListener("MozAfterPaint", onAfterPaint, true); window.addEventListener("MozAfterPaint", onAfterPaint, true);
doBackgroundFlicker(); doBackgroundFlicker();
}, 500); }, 500);
@ -49,7 +49,7 @@ const minimumAfterPaintsToPass = 10;
function doPluginFlicker() { function doPluginFlicker() {
ok(true, "Plugin color iteration " + color + ok(true, "Plugin color iteration " + color +
", afterpaint count: " + afterPaintCount + ", afterpaint count: " + afterPaintCount +
", mozpaint count: " + window.mozPaintCount); ", mozpaint count: " + SpecialPowers.DOMWindowUtils.paintCount);
if (afterPaintCount >= minimumAfterPaintsToPass) { if (afterPaintCount >= minimumAfterPaintsToPass) {
ok(true, "afterPaintCount incremented enough from plugin color changes."); ok(true, "afterPaintCount incremented enough from plugin color changes.");
SimpleTest.finish(); SimpleTest.finish();
@ -69,11 +69,11 @@ function doPluginFlicker() {
function doBackgroundFlicker() { function doBackgroundFlicker() {
ok(true, "Background color iteration " + color + ok(true, "Background color iteration " + color +
", afterpaint count: " + afterPaintCount + ", afterpaint count: " + afterPaintCount +
", mozpaint count: " + window.mozPaintCount); ", mozpaint count: " + SpecialPowers.DOMWindowUtils.paintCount);
if (afterPaintCount >= minimumAfterPaintsToPass) { if (afterPaintCount >= minimumAfterPaintsToPass) {
ok(true, "afterPaintCount incremented enough from background color changes."); ok(true, "afterPaintCount incremented enough from background color changes.");
afterPaintCount = 0; afterPaintCount = 0;
initialPaintCount = window.mozPaintCount; initialPaintCount = SpecialPowers.DOMWindowUtils.paintCount;
doPluginFlicker(); doPluginFlicker();
return; return;
} }

View File

@ -21,6 +21,7 @@ var iterations = 0;
var plugin = document.getElementById("plugin"); var plugin = document.getElementById("plugin");
var lastPaintCount; var lastPaintCount;
var expectedWidth; var expectedWidth;
var utils = SpecialPowers.DOMWindowUtils;
var toggle = true; var toggle = true;
function invalidationLoop() { function invalidationLoop() {
@ -32,7 +33,7 @@ function invalidationLoop() {
invalidationLoop(); invalidationLoop();
function doIteration() { function doIteration() {
lastPaintCount = window.mozPaintCount; lastPaintCount = utils.paintCount;
ok(true, "Beginning iteration " + iterations + ", last paint count: " + lastPaintCount); ok(true, "Beginning iteration " + iterations + ", last paint count: " + lastPaintCount);
expectedWidth = 201 + iterations; expectedWidth = 201 + iterations;
@ -41,13 +42,12 @@ function doIteration() {
} }
function checkDone() { function checkDone() {
ok(true, "Check to see if we're done: " + window.mozPaintCount); ok(true, "Check to see if we're done: " + utils.paintCount);
if (window.mozPaintCount == lastPaintCount) { if (utils.paintCount == lastPaintCount) {
setTimeout(checkDone, 30); setTimeout(checkDone, 30);
return; return;
} }
var utils = SpecialPowers.getDOMWindowUtils(window);
is(plugin.getWidthAtLastPaint(), utils.screenPixelsPerCSSPixel*expectedWidth, is(plugin.getWidthAtLastPaint(), utils.screenPixelsPerCSSPixel*expectedWidth,
"Check that we set width before painting"); "Check that we set width before painting");

View File

@ -1,7 +1,7 @@
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html>
<head> <head>
<title>Tests for mozPaintCount</title> <title>Tests for DOMWindowUtils.paintCount</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script> <script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="plugin-utils.js"></script> <script type="application/javascript" src="plugin-utils.js"></script>
<script type="application/javascript"> <script type="application/javascript">
@ -22,13 +22,13 @@
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
var startPaintCount = window.mozPaintCount; var startPaintCount = SpecialPowers.DOMWindowUtils.paintCount;
ok(true, "Got to initial paint count: " + startPaintCount); ok(true, "Got to initial paint count: " + startPaintCount);
var color = 0; var color = 0;
function doPluginFlicker() { function doPluginFlicker() {
ok(true, "Plugin color iteration " + color + ", paint count: " + window.mozPaintCount); ok(true, "Plugin color iteration " + color + ", paint count: " + SpecialPowers.DOMWindowUtils.paintCount);
if (window.mozPaintCount - startPaintCount > 20) { if (SpecialPowers.DOMWindowUtils.paintCount - startPaintCount > 20) {
ok(true, "Got enough paints from plugin color changes"); ok(true, "Got enough paints from plugin color changes");
SimpleTest.finish(); SimpleTest.finish();
return; return;
@ -45,10 +45,10 @@ function doPluginFlicker() {
} }
function doBackgroundFlicker() { function doBackgroundFlicker() {
ok(true, "Background color iteration " + color + ", paint count: " + window.mozPaintCount); ok(true, "Background color iteration " + color + ", paint count: " + SpecialPowers.DOMWindowUtils.paintCount);
if (window.mozPaintCount - startPaintCount > 20) { if (SpecialPowers.DOMWindowUtils.paintCount - startPaintCount > 20) {
ok(true, "Got enough paints from background color changes"); ok(true, "Got enough paints from background color changes");
startPaintCount = window.mozPaintCount; startPaintCount = SpecialPowers.DOMWindowUtils.paintCount;
doPluginFlicker(); doPluginFlicker();
return; return;
} }

View File

@ -4,7 +4,7 @@
<script> <script>
var startPaintCount = 0; var startPaintCount = 0;
function doTest() { function doTest() {
startPaintCount = window.mozPaintCount; startPaintCount = window.windowUtils.paintCount;
document.querySelector('#src').style.visibility='visible'; document.querySelector('#src').style.visibility='visible';
document.querySelector('#dest').style.visibility='visible'; document.querySelector('#dest').style.visibility='visible';
setTimeout(check, 200); setTimeout(check, 200);
@ -12,7 +12,7 @@ function doTest() {
var calls = 0; var calls = 0;
function check() { function check() {
calls++; calls++;
if ((window.mozPaintCount - startPaintCount) > 3) { if ((window.windowUtils.paintCount - startPaintCount) > 3) {
finishSuccess(); finishSuccess();
return; return;
} }

View File

@ -1872,7 +1872,7 @@ fuzzy-if(webrender,63-64,407-845) == 1081185-1.html 1081185-1-ref.html
== 1105137-1.html 1105137-1-ref.html == 1105137-1.html 1105137-1-ref.html
fuzzy-if(d2d,0-36,0-304) fuzzy-if(/^Windows\x20NT\x2010\.0/.test(http.oscpu)&&d2d,0-139,0-701) == 1116480-1-fakeitalic-overflow.html 1116480-1-fakeitalic-overflow-ref.html fuzzy-if(d2d,0-36,0-304) fuzzy-if(/^Windows\x20NT\x2010\.0/.test(http.oscpu)&&d2d,0-139,0-701) == 1116480-1-fakeitalic-overflow.html 1116480-1-fakeitalic-overflow-ref.html
== 1111753-1.html about:blank == 1111753-1.html about:blank
== 1114526-1.html 1114526-1-ref.html == chrome://reftest/content/bugs/1114526-1.html 1114526-1-ref.html
fuzzy-if(skiaContent,0-1,0-800000) == 1119117-1a.html 1119117-1-ref.html fuzzy-if(skiaContent,0-1,0-800000) == 1119117-1a.html 1119117-1-ref.html
fuzzy-if(skiaContent,0-1,0-800000) == 1119117-1b.html 1119117-1-ref.html fuzzy-if(skiaContent,0-1,0-800000) == 1119117-1b.html 1119117-1-ref.html
== 1120431-1.html 1120431-1-ref.html == 1120431-1.html 1120431-1-ref.html

View File

@ -1238,6 +1238,12 @@
# Prefs starting with "dom." # Prefs starting with "dom."
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# Whether window.mozPaintCount is exposed to the web.
- name: dom.mozPaintCount.enabled
type: bool
value: false
mirror: always
# Allow cut/copy # Allow cut/copy
- name: dom.allow_cut_copy - name: dom.allow_cut_copy
type: bool type: bool

View File

@ -19,7 +19,7 @@
"about:blank", "about:blank",
null, null,
"chrome,dialog=no,outerHeight=170,outerWidth=200"); "chrome,dialog=no,outerHeight=170,outerWidth=200");
waitForSuccess(function() { return win.mozPaintCount }, waitForSuccess(function() { return SpecialPowers.DOMWindowUtils.paintCount },
"No paint received", checkInitialSize); "No paint received", checkInitialSize);
} }