зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1756269: Add nsIDOMWindowUtils.refreshDriverHasPendingTick API, for use in regression tests. r=smaug
This API essentially reports whether the refresh driver is actively consuming CPU. This is intended for use in regression tests for bugs about the refresh driver needlessly cycling. Differential Revision: https://phabricator.services.mozilla.com/D139218
This commit is contained in:
Родитель
207b1e1eae
Коммит
946ecff756
|
@ -4224,6 +4224,17 @@ nsDOMWindowUtils::GetFramesReflowed(uint64_t* aResult) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::GetRefreshDriverHasPendingTick(bool* aResult) {
|
||||
nsPresContext* presContext = GetPresContext();
|
||||
if (!presContext) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
*aResult = presContext->RefreshDriver()->HasPendingTick();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::EnterChaosMode() {
|
||||
ChaosMode::enterChaosMode();
|
||||
|
|
|
@ -1987,6 +1987,14 @@ interface nsIDOMWindowUtils : nsISupports {
|
|||
*/
|
||||
readonly attribute unsigned long long framesReflowed;
|
||||
|
||||
/**
|
||||
* Indicates whether the current frame's refresh driver has a pending tick,
|
||||
* as reported by nsRefreshDriver::HasPendingTick.
|
||||
*
|
||||
* May throw NS_ERROR_NOT_AVAILABLE.
|
||||
*/
|
||||
readonly attribute bool refreshDriverHasPendingTick;
|
||||
|
||||
/**
|
||||
* Controls the amount of chrome that should be visible on each side of
|
||||
* the window. Works like the chromemargin xul:window attribute.
|
||||
|
|
|
@ -163,6 +163,7 @@ skip-if = toolkit == 'android' # android: Requires plugin support
|
|||
support-files = preserve3d_sorting_hit_testing_iframe.html
|
||||
[test_preserve3d_sorting_hit_testing2.html]
|
||||
support-files = preserve3d_sorting_hit_testing2_iframe.html
|
||||
[test_refreshDriver_hasPendingTick.html]
|
||||
[test_reftests_with_caret.html]
|
||||
skip-if =
|
||||
tsan # Bug 1612707
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1756269
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 1756269: the nsIDOMWindowUtils.refreshDriverHasPendingTick API</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<style>
|
||||
@keyframes growWidth {
|
||||
from { width: 20px; }
|
||||
to { width: 30px; }
|
||||
}
|
||||
.animating {
|
||||
animation: 1s growWidth infinite alternate;
|
||||
}
|
||||
#sometimesAnimated {
|
||||
background: blue;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body onload="run()">
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1756269">Mozilla Bug 1756269</a>
|
||||
<div id="display">
|
||||
<div id="sometimesAnimated"></div>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script>
|
||||
"use strict";
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.requestFlakyTimeout("need to allow time to pass so that we can " +
|
||||
"detect unwanted extra refresh driver ticks");
|
||||
const gUtils = SpecialPowers.getDOMWindowUtils(window);
|
||||
|
||||
async function startAnimAndExpectTick() {
|
||||
// Start an animation:
|
||||
sometimesAnimated.classList.add("animating");
|
||||
|
||||
// double-rAF to flush pending paints:
|
||||
await new Promise(r => requestAnimationFrame(r));
|
||||
await new Promise(r => requestAnimationFrame(r));
|
||||
|
||||
ok(gUtils.refreshDriverHasPendingTick,
|
||||
"Expecting refresh driver to be ticking when animated content is present");
|
||||
|
||||
// clean up, i.e. remove animation:
|
||||
sometimesAnimated.classList.remove("animating");
|
||||
|
||||
// double-rAF to flush pending paints:
|
||||
await new Promise(r => requestAnimationFrame(r));
|
||||
await new Promise(r => requestAnimationFrame(r));
|
||||
}
|
||||
|
||||
async function expectTicksToStop() {
|
||||
let didStopTicking = false;
|
||||
// Note: The maximum loop count here is an arbitrary large value, just to let
|
||||
// us gracefully handle edge cases where multiple setTimeouts resolve before
|
||||
// a pending refresh driver tick. Really, we just want to be sure the refresh
|
||||
// driver *eventually* stops ticking, and we can do so gracefully by polling
|
||||
// with some generous-but-finite number of checks here.
|
||||
for (var i = 0; i < 100; i++) {
|
||||
await new Promise(r => setTimeout(r, 8));
|
||||
if(!gUtils.refreshDriverHasPendingTick) {
|
||||
didStopTicking = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ok(didStopTicking, "refresh driver should have eventually stopped ticking");
|
||||
}
|
||||
|
||||
async function run() {
|
||||
// By default, the refresh driver ticks on its own for some period of time
|
||||
// after pageload. Turn that off so we don't have to wait it out:
|
||||
await SpecialPowers.pushPrefEnv({'set':
|
||||
[['layout.keep_ticking_after_load_ms', 0]]});
|
||||
|
||||
// Start out with a double-rAF, to flush paints from pageload:
|
||||
await new Promise(r => requestAnimationFrame(r));
|
||||
await new Promise(r => requestAnimationFrame(r));
|
||||
|
||||
await startAnimAndExpectTick();
|
||||
await expectTicksToStop();
|
||||
await startAnimAndExpectTick();
|
||||
await expectTicksToStop();
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче