var gScrollable128 = document.getElementById("Scrollable128"); var gScrollable96 = document.getElementById("Scrollable96"); var gScrollable64 = document.getElementById("Scrollable64"); var gScrollable32 = document.getElementById("Scrollable32"); var gRoot = document.documentElement;
// TODO(emilio): page scrolling seems to interact weirdly with
// Android (probably due to the visual viewport? but I can't repro
// on the emulator). It's probably not a big deal though since you
// can't usually do page scrolling on Android, and chances are
// actual behavior is correct and we just need to tweak the test.
const kIsAndroid = navigator.userAgent.includes("Android");
function* prepareScrollUnits()
{ var result = -1;
function handler(aEvent)
{
result = aEvent.detail;
aEvent.preventDefault();
setTimeout(runTest, 0);
}
window.addEventListener("MozMousePixelScroll", handler, { capture: true, passive: false });
{
const kAllScrollables = [gRoot, gScrollable128, gScrollable96, gScrollable64, gScrollable32];
function resetAllScrollables() {
for (let scrollable of kAllScrollables) {
scrollable.style.overflow = "";
scrollable.scrollLeft = 0;
scrollable.scrollTop = 0;
}
}
function closestScrollable(s) {
if (s == gScrollable32 || s == gRoot) {
return gRoot;
}
let closest = kAllScrollables[kAllScrollables.indexOf(s) - 1];
ok(closest, `Should find a closest scrollable for ${s.id}`);
return closest;
}
for (let deltaMode of [WheelEvent.DOM_DELTA_LINE, WheelEvent.DOM_DELTA_PAGE]) {
if (deltaMode == WheelEvent.DOM_DELTA_PAGE && kIsAndroid) {
// See comment around kIsAndroid.
continue;
}
for (let scrollable of kAllScrollables) {
for (let { x, y, direction } of kAllScrollDirections) {
tests.push({
description: `Should be computed from nearest scrollable element (${scrollable.id}, ${deltaMode}, ${direction})`,
target: scrollable,
event: {
deltaMode,
deltaX: x,
deltaY: y,
lineOrPageDeltaX: x,
lineOrPageDeltaY: y,
},
prepare () {
resetAllScrollables();
},
cleanup () {
},
expected: {
x: x ? scrollable : null,
y: y ? scrollable : null,
}
});
tests.push({
description: `Should be computed from actual scroll target or root if not scrollable in the direction (${scrollable.id}, ${deltaMode}, ${direction})`,
target: scrollable,
event: {
deltaMode,
deltaX: -x,
deltaY: -y,
lineOrPageDeltaX: -x,
lineOrPageDeltaY: -y
},
prepare () {
resetAllScrollables();
},
cleanup () {
},
expected: {
x: x ? gRoot : null,
y: y ? gRoot : null,
}
});
// Root's page delta depends on whether there's an horizontal scrollbar
// or not, so this test on the root would be off by a few pixels.
if (scrollable != gRoot || deltaMode != WheelEvent.DOM_DELTA_PAGE) {
tests.push({
description: `Should be computed from actual scroll target or root if scrollable in the direction but overflow: hidden (${scrollable.id}, ${deltaMode}, ${direction})`,
target: scrollable,
event: {
deltaMode,
deltaX: x,
deltaY: y,
lineOrPageDeltaX: x,
lineOrPageDeltaY: y,
},
prepare () {
resetAllScrollables();
scrollable.style.overflow = "hidden";
},
cleanup () {
scrollable.style.overflow = "";
},
expected: {
x: x ? closestScrollable(scrollable) : null,
y: y ? closestScrollable(scrollable) : null,
}
});
}
}
}
}
}
var currentTest, description, firedX, firedY; var expectedHandlerCalls;
function handler(aEvent)
{
aEvent.preventDefault();
if (aEvent.axis != MouseScrollEvent.HORIZONTAL_AXIS &&
aEvent.axis != MouseScrollEvent.VERTICAL_AXIS) {
ok(false,
description + "The event had invalid axis (" + aEvent.axis + ")");
if (--expectedHandlerCalls == 0) {
setTimeout(runTest, 0);
}
return;
}
function runTest()
{
if (!gTestContinuation) {
gTestContinuation = testBody();
} var ret = gTestContinuation.next();
if (ret.done) {
SimpleTest.finish();
}
}
function startTest() {
SpecialPowers.pushPrefEnv({"set": [["mousewheel.default.delta_multiplier_x", 100],
["mousewheel.default.delta_multiplier_y", 100],
["mousewheel.default.delta_multiplier_z", 100],
["mousewheel.with_alt.delta_multiplier_x", 100],
["mousewheel.with_alt.delta_multiplier_y", 100],
["mousewheel.with_alt.delta_multiplier_z", 100],
["mousewheel.with_control.delta_multiplier_x", 100],
["mousewheel.with_control.delta_multiplier_y", 100],
["mousewheel.with_control.delta_multiplier_z", 100],
["mousewheel.with_meta.delta_multiplier_x", 100],
["mousewheel.with_meta.delta_multiplier_y", 100],
["mousewheel.with_meta.delta_multiplier_z", 100],
["mousewheel.with_shift.delta_multiplier_x", 100],
["mousewheel.with_shift.delta_multiplier_y", 100],
["mousewheel.with_shift.delta_multiplier_z", 100],
// If APZ is enabled we should ensure the preventDefault calls work even
// if the test is running slowly.
["apz.content_response_timeout", 2000],
]}, runTest);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.