1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 15:54:58 +00:00
serenity/Tests/LibWeb/Text/input/ResizeObserver/disconnect.html
2024-02-20 10:55:10 +01:00

72 lines
1.7 KiB
HTML

<!DOCTYPE html>
<head>
<style>
#outer {
width: 200px;
height: 200px;
background-color: lightblue;
}
#inner {
width: 100px;
height: 100px;
background-color: pink;
}
</style>
</head>
<body>
<div id="outer">
<div id="inner"></div>
</div>
</body>
<script src="../include.js"></script>
<script>
asyncTest(async done => {
const outerBox = document.getElementById("outer");
const innerBox = document.getElementById("inner");
function createTimeoutPromise(timeout) {
return new Promise(r => {
setTimeout(r, timeout);
});
}
function createResizeObserverCallback() {
let resolve;
const promise = new Promise(r => {
resolve = r;
});
const callback = (entries) => {
for (let entry of entries) {
const { width, height } = entry.contentRect;
println(`Size changed: ${width}px x ${height}px`);
}
resolve();
};
return { promise, callback };
}
const { callback, promise } = createResizeObserverCallback();
const resizeObserver = new ResizeObserver(callback);
resizeObserver.observe(innerBox);
resizeObserver.observe(outerBox);
await promise;
resizeObserver.disconnect();
innerBox.style.width = "500px";
outerBox.style.width = "600px";
// Let event loop run to ensure that observer callback is not invoked.
await createTimeoutPromise(0);
done();
});
</script>