Bug 1548687 - Add mochitest to exercise scrolling an oopif's ancestor. r=botond

This scrolls the document containing the OOPIF and ensures that
hit-testing still works. Some of the fission hit-testing machinery is
still WR-only, so we have to restrict the subtest to only run when WR
is enabled.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kartikaya Gupta 2019-06-19 19:23:54 +00:00
Родитель 3a0462de3c
Коммит 1f1cd321aa
3 изменённых файлов: 101 добавлений и 0 удалений

Просмотреть файл

@ -399,6 +399,15 @@ function moveMouseAndScrollWheelOver(target, dx, dy, testDriver, waitForScroll =
});
}
// Same as moveMouseAndScrollWheelOver, but returns a promise instead of taking
// a callback function. Eventually we should convert all these callback-taking
// functions into promise-producing functions but for now this is a stopgap.
function promiseMoveMouseAndScrollWheelOver(target, dx, dy, waitForScroll = true) {
return new Promise(resolve => {
moveMouseAndScrollWheelOver(target, dx, dy, resolve, waitForScroll);
});
}
// Synthesizes events to drag |element|'s vertical scrollbar by the distance
// specified, synthesizing a mousemove for each increment as specified.
// Returns false if the element doesn't have a vertical scrollbar. Otherwise,

Просмотреть файл

@ -16,6 +16,7 @@ add_task(async function test_main() {
if (isWebRender) {
test_urls = test_urls.concat([
httpURL("helper_fission_transforms.html"),
httpURL("helper_fission_scroll_oopif.html"),
// add additional WebRender-specific tests here
]);
}

Просмотреть файл

@ -0,0 +1,91 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for async-scrolling an OOPIF and ensuring hit-testing still works</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<script src="helper_fission_utils.js"></script>
<script src="apz_test_utils.js"></script>
<script src="apz_test_native_event_utils.js"></script>
<script>
fission_subtest_init();
FissionTestHelper.startTestPromise
.then(waitUntilApzStable)
.then(loadOOPIFrame("testframe", "helper_fission_empty.html"))
.then(waitUntilApzStable)
.then(runAsyncContinuation(test))
.then(FissionTestHelper.subtestDone, FissionTestHelper.subtestDone);
let code_for_oopif_to_run = function() {
document.addEventListener("click", function(e) {
dump(`OOPIF got click at ${e.clientX},${e.clientY}\n`);
let result = { x: e.clientX, y: e.clientY };
FissionTestHelper.fireEventInEmbedder("OOPIF:ClickData", result);
});
dump("OOPIF registered click listener\n");
return true;
};
async function clickOnIframe(x, y) {
let iframePromise = promiseOneEvent("OOPIF:ClickData", null);
synthesizeNativeClick(document.body, x, y, function() {
dump("Finished synthesizing click, waiting for OOPIF message...\n");
});
let iframeResponse = await iframePromise;
dump("OOPIF response: " + JSON.stringify(iframeResponse.data) + "\n");
return iframeResponse.data;
}
function failsafe() {
// Catch and fail faster on the case where the click ends up not going to
// the iframe like it should. Otherwise the test hangs until timeout which
// is more painful.
document.addEventListener("click", function(e) {
dump(`${location.href} got click at ${e.clientX},${e.clientY}\n`);
ok(false, "The OOPIF hosting page should not have gotten the click");
setTimeout(FissionTestHelper.subtestDone, 0);
}, {once: true});
}
// The actual test
async function* test() {
ok(SpecialPowers.getBoolPref("apz.paint_skipping.enabled"),
"paint-skipping is expected to be enabled for this test to be meaningful");
let iframeElement = document.getElementById("testframe");
let iframeResponse = await FissionTestHelper.sendToOopif(iframeElement, code_for_oopif_to_run.toSource() + "()");
dump("OOPIF response: " + JSON.stringify(iframeResponse) + "\n");
ok(iframeResponse, "code_for_oopif_to_run successfully installed");
// hit-test into the iframe before scrolling
let oldClickPoint = await clickOnIframe(50, 250);
// do an APZ scroll and wait for the main-thread to get the repaint request,
// and queue up a paint-skip scroll notification back to APZ.
await promiseMoveMouseAndScrollWheelOver(document.body, 10, 10);
await promiseAllPaintsDone();
is(window.scrollY, 10, "window has scrolled by 10 pixels");
// hit-test into the iframe after scrolling. The coordinates here are the
// same relative to the body as before, but get computed to be different
// relative to the window/screen.
let newClickPoint = await clickOnIframe(50, 250);
is(newClickPoint.x, oldClickPoint.x, "x-coord of old and new match");
is(newClickPoint.y, oldClickPoint.y, "y-coord of old and new match");
}
</script>
</head>
<body onload="failsafe()">
<iframe style="margin-top: 200px" id="testframe"></iframe>
<div style="height: 5000px">tall div to make the page scrollable</div>
</body>
</html>