forked from mirrors/gecko-dev
The test fixes all fell into the follow categories: A) The test uses requestAnimationFrame to wait one frame and expects scrolling to be complete. With the desktop zooming scrollbars in order for the scrolling to show up on the main thread we need to send the scroll request to the compositor and then hear back from it via an apz repaint request (apz callback helper). Waiting on requestAnimationFrame will complete the first part, but not necessarily the second part. The fix is to wait for a scroll event. B) Switching tests to wait for scroll events exposes another problem: the test can do things that cause a scroll in order to setup the test (and that may not be obvious that it causes a scroll) before actually proceeding to do the test and do something that causes a scroll and then checks for the scroll change of the second thing. Waiting for a requestAnimationFrame would include both those scrolls without desktop zooming scrollbars, but if we wait for a scroll event we will get the scroll event for the first thing which we are not interested in. So we need to make sure scroll events are cleared out before waiting for any scroll events. We do this by waiting two requestAnimationFrame's and waiting for apz to be flushed. We also use this when a test does something and it wants to test that scrolling is not performed. The main thing that causes scrolling that may not be obvious: calling node.focus(). With stacks like: from test_scroll_per_page.html ``` #01: mozilla::ScrollFrameHelper::CompleteAsyncScroll(nsRect const&, mozilla::ScrollOrigin) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x47d6cc0] #02: mozilla::ScrollFrameHelper::ScrollToWithOrigin(nsPoint, mozilla::ScrollMode, mozilla::ScrollOrigin, nsRect const*, nsIScrollbarMediator::ScrollSnapMode) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x47d7732] #03: mozilla::layout::ScrollAnchorContainer::ApplyAdjustments() [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x4742913] #04: mozilla::PresShell::FlushPendingScrollAnchorAdjustments() [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x4650069] #05: mozilla::PresShell::ProcessReflowCommands(bool) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x465742b] #06: mozilla::PresShell::DoFlushPendingNotifications(mozilla::ChangesToFlush) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x4656af8] #07: mozilla::dom::Document::FlushPendingNotifications(mozilla::ChangesToFlush) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x1a87d3c] #08: mozilla::PresShell::ScrollContentIntoView(nsIContent*, mozilla::ScrollAxis, mozilla::ScrollAxis, mozilla::ScrollFlags) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x4652b96] #09: nsFocusManager::ScrollIntoView(mozilla::PresShell*, nsIContent*, unsigned int) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x1bedd1c] #10: nsFocusManager::Focus(nsPIDOMWindowOuter*, mozilla::dom::Element*, unsigned int, bool, bool, bool, bool, bool, nsIContent*) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x1be6be0] #11: nsFocusManager::SetFocusInner(mozilla::dom::Element*, int, bool, bool) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x1be212f] #12: nsFocusManager::SetFocus(mozilla::dom::Element*, unsigned int) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x1be32ba] #13: mozilla::dom::Element::Focus(mozilla::dom::FocusOptions const&, mozilla::dom::CallerType, mozilla::ErrorResult&) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x1aaf283] #14: mozilla::dom::HTMLElement_Binding::focus(JSContext*, JS::Handle<JSObject*>, void*, JSJitMethodCallArgs const&) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x2d65f3b] ``` from editor/libeditor/tests/test_bug549262.html ``` #01: mozilla::ScrollFrameHelper::CompleteAsyncScroll(nsRect const&, mozilla::ScrollOrigin) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x47d6cc0] #02: mozilla::ScrollFrameHelper::ScrollToWithOrigin(nsPoint, mozilla::ScrollMode, mozilla::ScrollOrigin, nsRect const*, nsIScrollbarMediator::ScrollSnapMode) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x47d7732] #03: mozilla::PresShell::ScrollFrameRectIntoView(nsIFrame*, nsRect const&, mozilla::ScrollAxis, mozilla::ScrollAxis, mozilla::ScrollFlags) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x46541bc] #04: mozilla::PresShell::DoScrollContentIntoView() [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x4653776] #05: mozilla::PresShell::DoFlushPendingNotifications(mozilla::ChangesToFlush) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x4656b11] #06: mozilla::dom::Document::FlushPendingNotifications(mozilla::ChangesToFlush) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x1a87d3c] #07: mozilla::PresShell::ScrollContentIntoView(nsIContent*, mozilla::ScrollAxis, mozilla::ScrollAxis, mozilla::ScrollFlags) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x4652b96] #08: nsFocusManager::ScrollIntoView(mozilla::PresShell*, nsIContent*, unsigned int) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x1bedd1c] #09: nsFocusManager::Focus(nsPIDOMWindowOuter*, mozilla::dom::Element*, unsigned int, bool, bool, bool, bool, bool, nsIContent*) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x1be6be0] #10: nsFocusManager::SetFocusInner(mozilla::dom::Element*, int, bool, bool) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x1be212f] #11: nsFocusManager::SetFocus(mozilla::dom::Element*, unsigned int) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x1be32ba] #12: mozilla::dom::Element::Focus(mozilla::dom::FocusOptions const&, mozilla::dom::CallerType, mozilla::ErrorResult&) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x1aaf283] #13: mozilla::dom::HTMLElement_Binding::focus(JSContext*, JS::Handle<JSObject*>, void*, JSJitMethodCallArgs const&) [/Users/tim/ffopt2/src/obj-x86_64-apple-darwin19.6.0/toolkit/library/build/XUL + 0x2d65f3b] ``` C) Several tests use nsIDOMWindowUtils advanceTimeAndRefresh/restoreNormalRefresh and expect scrolling to be done after a call to advanceTimeAndRefresh. This is basically A), advanceTimeAndRefresh does a refresh driver tick but doesn't allow a repaint request to come back to the main thread. Differential Revision: https://phabricator.services.mozilla.com/D89403
128 lines
4.7 KiB
HTML
128 lines
4.7 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no" />
|
|
<title>Scrolling by pages with fixed-pos headers and footers</title>
|
|
<style>
|
|
.fp { position:fixed; left:0; width:100%; }
|
|
.fp2 { position:fixed; left:0; width:100%; }
|
|
</style>
|
|
</head>
|
|
<body onscroll="didScroll()" onload="test()">
|
|
<div class="fp" id="top" style="top:0; height:10px; background:yellow;"></div>
|
|
<div class="fp2" id="top2" style="top:10px; height:11px; background:blue;"></div>
|
|
<div class="fp" style="top:50%; height:7px; background:cyan;"></div>
|
|
<div class="fp2" id="bottom2" style="bottom:9px; height:12px; background:red;"></div>
|
|
<div class="fp" id="bottom" style="bottom:0; height:13px; background:yellow;"></div>
|
|
<p id="target">Something to click on to get focus
|
|
<div style="height:3000px;"></div>
|
|
<pre id="test">
|
|
<script class="testbody">
|
|
var SimpleTest = window.opener.SimpleTest;
|
|
var SpecialPowers = window.opener.SpecialPowers;
|
|
var is = window.opener.is;
|
|
|
|
function showElements(show, classname) {
|
|
var elements = document.getElementsByClassName(classname);
|
|
for (var i = 0; i < elements.length; ++i) {
|
|
elements[i].style.display = show ? '' : 'none';
|
|
}
|
|
document.documentElement.getBoundingClientRect();
|
|
}
|
|
function showFixedPosElements(show) {
|
|
showElements(show, "fp");
|
|
}
|
|
function showFixedPosElements2(show) {
|
|
showElements(show, "fp2");
|
|
}
|
|
|
|
var nextCont;
|
|
function didScroll() {
|
|
var c = nextCont;
|
|
nextCont = null;
|
|
if (c) {
|
|
c();
|
|
}
|
|
}
|
|
|
|
function resetScrollAndScrollDownOnePageWithContinuation(cont) {
|
|
if (document.documentElement.scrollTop != 0) {
|
|
document.documentElement.scrollTop = 0;
|
|
nextCont = function() {
|
|
setTimeout(function() { scrollDownOnePageWithContinuation(cont) }, 0);
|
|
};
|
|
} else {
|
|
scrollDownOnePageWithContinuation(cont);
|
|
}
|
|
}
|
|
|
|
function scrollDownOnePageWithContinuation(cont) {
|
|
nextCont = cont;
|
|
window.scrollByPages(1);
|
|
}
|
|
|
|
function test() {
|
|
var smoothScrollPref = "general.smoothScroll";
|
|
SpecialPowers.pushPrefEnv({"set":[[smoothScrollPref, false]]}, runTest);
|
|
}
|
|
|
|
function runTest() {
|
|
showFixedPosElements(false);
|
|
showFixedPosElements2(false);
|
|
resetScrollAndScrollDownOnePageWithContinuation(function() {
|
|
var fullPageScrollDown = document.documentElement.scrollTop;
|
|
|
|
showFixedPosElements(true);
|
|
resetScrollAndScrollDownOnePageWithContinuation(function() {
|
|
var fullPageScrollDownWithHeaderAndFooter = document.documentElement.scrollTop;
|
|
is(fullPageScrollDownWithHeaderAndFooter, fullPageScrollDown - (10 + 13),
|
|
"Reduce scroll distance by size of small header and footer");
|
|
|
|
document.getElementById("bottom").style.height = (window.innerHeight - 20) + "px";
|
|
resetScrollAndScrollDownOnePageWithContinuation(function() {
|
|
is(document.documentElement.scrollTop, fullPageScrollDown - 10,
|
|
"Ignore really big elements when reducing scroll size");
|
|
document.getElementById("bottom").style.height = "13px";
|
|
|
|
document.getElementById("top").style.width = "100px";
|
|
resetScrollAndScrollDownOnePageWithContinuation(function() {
|
|
is(document.documentElement.scrollTop, fullPageScrollDown - 13,
|
|
"Ignore elements that don't span the entire viewport side");
|
|
document.getElementById("top").style.width = "100%";
|
|
|
|
showFixedPosElements2(true);
|
|
resetScrollAndScrollDownOnePageWithContinuation(function() {
|
|
is(document.documentElement.scrollTop, fullPageScrollDown - (10 + 11 + 9 + 12),
|
|
"Combine multiple overlapping elements");
|
|
showFixedPosElements2(false);
|
|
|
|
document.getElementById("top").style.width = "400px";
|
|
resetScrollAndScrollDownOnePageWithContinuation(function() {
|
|
is(document.documentElement.scrollTop, fullPageScrollDown - (10 + 13),
|
|
"Don't ignore elements that span more than half the viewport side");
|
|
document.getElementById("top").style.width = "100%";
|
|
|
|
document.getElementById("top").style.top = "-40px";
|
|
document.getElementById("top").style.transform = "translateY(38px)";
|
|
resetScrollAndScrollDownOnePageWithContinuation(function() {
|
|
is(document.documentElement.scrollTop,
|
|
fullPageScrollDown - (10 + 13 - 40 + 38),
|
|
"Account for offset and transform");
|
|
document.getElementById("top").style.width = "100%";
|
|
|
|
// Scroll back up so test results are visible
|
|
document.documentElement.scrollTop = 0;
|
|
SimpleTest.finish();
|
|
window.close();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|