Truly independent web browser
<!DOCTYPE html>
<script src="../../include.js"></script>
<script src="frame-in-flight.js"></script>
<style>
body { margin: 0; }
#target { cursor: pointer; position: absolute; left: 150px; top: 0; width: 1000px; height: 100px; }
</style>
<div id="target"></div>
<script>
// The compositor runs a transform animation itself, which moves a box across the pointer at rest between the
// frames the main thread presents, and reports each frame of it that moves content under the pointer. The hover
// follows with the animation sampled at the frame's time, and shows the cursor of what is under the pointer then.
// The output is printed at the end, so that no text of it lies under the pointer meanwhile.
asyncTest(async done => {
await whileLaneHovers(async frameTime => {
internals.mouseMove(50, 50);
let time = frameTime;
const lines = [];
const events = [];
target.addEventListener("mouseover", () => events.push("mouseover"));
target.addEventListener("mouseout", () => events.push("mouseout"));
const state = what => `${what}: ${internals.currentCursor()}, :hover ${target.matches(":hover")}, events ${events.join(" ") || "none"}`;
const step = async change => {
change();
time += 16;
internals.injectRenderingOpportunity(time);
await untilLaneSettled();
await nextTask();
};
lines.push(state("at rest"));
// Moves 150px a second: under the pointer from 1s to 7s in.
let animation;
await step(() => animation = target.animate([{ transform: "translateX(0)" }, { transform: "translateX(-1500px)" }], { duration: 10000 }));
while (animation.pending)
await step(() => {});
lines.push(state("as the animation started"));
const frame = async (at, what) => {
internals.noteAnimatedContentMovedUnderPointer(at);
await nextTask();
lines.push(state(what));
// The restyle of a hover asks for a rendering update, which comes at the frame's time.
time = at;
internals.injectRenderingOpportunity(time);
await untilLaneSettled();
await nextTask();
};
await frame(time + 2000, "at a frame 2s in");
await frame(time + 9000, "at a frame 9s in");
println(lines.join("\n"));
});
done();
});
</script>