Skip to content

Commit

Permalink
Bug 1841896 - Port helper_fission_transforms to regular mochitests r=…
Browse files Browse the repository at this point in the history
…hiro

Also remove helper_fission_basic since all it was doing was exercising the old Fission test infrastructure.

Differential Revision: https://phabricator.services.mozilla.com/D215151
  • Loading branch information
denvercoder21 committed Jul 17, 2024
1 parent 9593510 commit f091335
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 99 deletions.
20 changes: 20 additions & 0 deletions gfx/layers/apz/test/mochitest/apz_test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1320,3 +1320,23 @@ function compareVisualViewport(
);
}
}

// Loads a URL in an iframe and waits until APZ is stable
async function setupIframe(aIFrame, aURL) {
const iframeLoadPromise = promiseOneEvent(aIFrame, "load", null);
aIFrame.src = aURL;
await iframeLoadPromise;

await SpecialPowers.spawn(aIFrame, [], async () => {
await content.wrappedJSObject.waitUntilApzStable();
await SpecialPowers.contentTransformsReceived(content);
});
}

// Loads a URL in an iframe and replaces its origin to
// create an out-of-process iframe
async function setupCrossOriginIFrame(aIFrame, aUrl) {
let iframeURL = SimpleTest.getTestFileURL(aUrl);
iframeURL = iframeURL.replace(window.location.origin, "https://example.com");
await setupIframe(aIFrame, iframeURL);
}
2 changes: 0 additions & 2 deletions gfx/layers/apz/test/mochitest/browser_test_group_fission.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ add_task(async function test_main() {
// setup (optional): function that takes the top-level fission window and is
// run once after the subtest is loaded but before it is started.
var subtests = [
{ file: "helper_fission_basic.html" },
{ file: "helper_fission_transforms.html" },
{ file: "helper_fission_scroll_oopif.html" },
{
file: "helper_fission_event_region_override.html",
Expand Down
40 changes: 0 additions & 40 deletions gfx/layers/apz/test/mochitest/helper_fission_basic.html

This file was deleted.

12 changes: 12 additions & 0 deletions gfx/layers/apz/test/mochitest/helper_fission_plain.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html id="fission_empty_docelement">
<head>
<meta charset="utf-8">
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="apz_test_utils.js"></script>
</head>
<body>
</body>
</html>
128 changes: 71 additions & 57 deletions gfx/layers/apz/test/mochitest/helper_fission_transforms.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,80 +10,94 @@
<script src="apz_test_native_event_utils.js"></script>
<script>

fission_subtest_init();
async function test() {
const iframe = document.querySelector("iframe");
await setupCrossOriginIFrame(iframe, "helper_fission_plain.html");

FissionTestHelper.startTestPromise
.then(waitUntilApzStable)
.then(loadOOPIFrame("testframe", "helper_fission_empty.html"))
.then(waitUntilApzStable)
.then(test)
.then(FissionTestHelper.subtestDone, FissionTestHelper.subtestFailed);
let readyPromise = new Promise(resolve => {
window.addEventListener("message", event => {
if (event.data === "listenerready") {
resolve();
}
});
}, { once: true });

let result = await SpecialPowers.spawn(iframe, [], async () => {
content.document.addEventListener("click", (e) => {
let data = JSON.stringify({
type: "clicked",
coords: {
offsetX: e.clientX,
offsetY: e.clientY
}
});
content.window.parent.postMessage(data, "*");
});

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);
}, {once: true});
dump("OOPIF registered click listener\n");
return true;
};
content.window.parent.postMessage("listenerready", "*");

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});
}
return true;
});
ok(result, "Successfully installed event listener in OOP iframe");

async function test() {
let iframeElement = document.getElementById("testframe");
await readyPromise;

let iframeResponse = await FissionTestHelper.sendToOopif(iframeElement, `(${code_for_oopif_to_run})()`);
dump("OOPIF response: " + JSON.stringify(iframeResponse) + "\n");
ok(iframeResponse, "code_for_oopif_to_run successfully installed");
let childMessagePromise = new Promise(resolve => {
window.addEventListener("message", event => {

iframePromise = promiseOneEvent(window, "OOPIF:ClickData", null);
await synthesizeNativeMouseEventWithAPZ(
{ type: "click", target: document.body, offsetX: 400, offsetY: 400 },
() => dump("Finished synthesizing click, waiting for OOPIF message...\n")
);
iframeResponse = await iframePromise;
dump("OOPIF response: " + JSON.stringify(iframeResponse.data) + "\n");
let data = JSON.parse(event.data);
if ("type" in data && data.type == "clicked") {
let coordinates = {
offsetX: data.coords.offsetX,
offsetY: data.coords.offsetY
};
resolve(coordinates);
}
});
});

let expected_coord = 200 / Math.sqrt(2); // because the iframe is rotated 45 deg
ok(Math.abs(iframeResponse.data.x - expected_coord) < 3,
`x-coord ${iframeResponse.data.x} landed near expected value ${expected_coord}`);
ok(Math.abs(iframeResponse.data.y - expected_coord) < 3,
`y-coord ${iframeResponse.data.y} landed near expected value ${expected_coord}`);
}
await synthesizeNativeMouseEventWithAPZ(
{ type: "click", target: document.body, offsetX: 400, offsetY: 400 },
() => dump("Finished synthesizing click, waiting for OOPIF message...\n")
);

let clickCoordsInChild = await childMessagePromise;

let expected_coord = 200 / Math.sqrt(2); // because the iframe is rotated 45 deg
ok(Math.abs(clickCoordsInChild.offsetX - expected_coord) < 3,
`x-coord ${clickCoordsInChild.offsetX} landed near expected value ${expected_coord}`);
ok(Math.abs(clickCoordsInChild.offsetY - expected_coord) < 3,
`y-coord ${clickCoordsInChild.offsetY} landed near expected value ${expected_coord}`);
}

waitUntilApzStable()
.then(test)
.then(subtestDone, subtestFailed);

</script>
<style>
body, html {
margin: 0;
body,
html {
margin: 0;
}

div {
transform-origin: top left;
transform: translateX(400px) scale(2) rotate(45deg) translate(-50px, -50px);
width: 500px;
transform-origin: top left;
transform: translateX(400px) scale(2) rotate(45deg) translate(-50px, -50px);
width: 500px;
}

iframe {
width: 400px;
height: 300px;
position: absolute;
top: 50px;
left: 50px;
border: solid 1px black;
width: 400px;
height: 300px;
position: absolute;
top: 50px;
left: 50px;
border: solid 1px black;
}
</style>
</head>
<body onload="failsafe()">
<div><iframe id="testframe"></iframe></div>
<body>
<div><iframe id="testframe"></iframe></div>
</body>
</html>
2 changes: 2 additions & 0 deletions gfx/layers/apz/test/mochitest/mochitest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ run-if = [ # FIXME: enable on more desktop platforms (see bug 1608506 comment 4)
"os == 'mac'",
]

["test_group_fission.html"]

["test_group_fullscreen.html"]
run-if = ["os == 'android'"]

Expand Down
32 changes: 32 additions & 0 deletions gfx/layers/apz/test/mochitest/test_group_fission.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Various tests that spawn in out-of-process iframes.</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="apz_test_utils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="application/javascript">

var prefs = [
];

var subtests = [
{ "file": "helper_fission_transforms.html", "prefs": prefs },
];

if (isApzEnabled()) {
// This has a lot of subtests, and Android emulators are slow.
SimpleTest.requestLongerTimeout(2);
SimpleTest.waitForExplicitFinish();
window.onload = function () {
runSubtestsSeriallyInFreshWindows(subtests)
.then(SimpleTest.finish, SimpleTest.finishWithFailure);
};
}

</script>
</head>
<body>
</body>
</html>

0 comments on commit f091335

Please sign in to comment.