mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:57:44 +00:00
LibWeb: Implement ResizeObserver::unobserve()
This commit is contained in:
parent
fcf293a8df
commit
70a0f07732
3 changed files with 66 additions and 3 deletions
55
Tests/LibWeb/Text/input/ResizeObserver/unobserve.html
Normal file
55
Tests/LibWeb/Text/input/ResizeObserver/unobserve.html
Normal file
|
@ -0,0 +1,55 @@
|
|||
<!DOCTYPE html>
|
||||
<head>
|
||||
<style>
|
||||
#box {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
background-color: lightblue;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="box"></div>
|
||||
</body>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
asyncTest(async done => {
|
||||
const box = document.getElementById("box");
|
||||
|
||||
let resolve = null;
|
||||
function createResizeObserverPromise() {
|
||||
return new Promise(r => {
|
||||
resolve = r;
|
||||
});
|
||||
}
|
||||
|
||||
function createTimeoutPromise(timeout) {
|
||||
return new Promise(r => {
|
||||
setTimeout(r, timeout);
|
||||
});
|
||||
}
|
||||
|
||||
const resizeObserver = new ResizeObserver(entries => {
|
||||
for (let entry of entries) {
|
||||
const { width, height } = entry.contentRect;
|
||||
println(`Size changed: ${width}px x ${height}px`);
|
||||
}
|
||||
|
||||
if (resolve) resolve();
|
||||
});
|
||||
|
||||
let observerCallbackInvocation = createResizeObserverPromise();
|
||||
resizeObserver.observe(box);
|
||||
await observerCallbackInvocation;
|
||||
|
||||
resizeObserver.unobserve(box);
|
||||
|
||||
box.style.width = "400px";
|
||||
box.style.height = "400px";
|
||||
|
||||
// Let event loop run to ensure that observer callback is not invoked.
|
||||
await createTimeoutPromise(0);
|
||||
|
||||
done();
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue