blob: 5554624aa768a7c45fbf0afe571588983f2c87c3 [file] [log] [blame]
<!doctype HTML>
<!--
Runs an acquireDisplayLock which constructs and measures a subtree.
This should do a forced layout.
-->
<style>
#container {
contain: content;
width: 100px;
height: 100px;
background: lightgreen;
}
.child {
width: 20px;
height: 20%;
background: cyan;
}
#spacer {
width: 150px;
height: 150px;
background: green;
}
</style>
<div id="parent"></div>
<div id="spacer"></div>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
async_test((t) => {
function createChild(id) {
let child = document.createElement("div");
child.classList = "child";
child.id = id;
return child;
}
function measure(context) {
context.lockedElement.appendChild(createChild("0"));
context.lockedElement.appendChild(createChild("1"));
context.lockedElement.appendChild(createChild("2"));
t.step(() => {
// Ensure children are laid out; this forces a layout.
assert_equals(document.getElementById("0").offsetTop, 0, "0 in measure");
assert_equals(document.getElementById("1").offsetTop, 20, "1 in measure");
assert_equals(document.getElementById("2").offsetTop, 40, "2 in measure");
// Both parent should be 0 height, since it's locked. Both parent and spacers
// should have 8 offsetTop.
assert_equals(document.getElementById("parent").offsetTop, 8, "parent in measure");
assert_equals(document.getElementById("spacer").offsetTop, 8, "spacer in measure");
});
}
function acquire() {
let container = document.createElement("div");
container.id = "container";
container.acquireDisplayLock(measure).then(() => {
// We have to do the final measurement on the next frame, since in the promise
// resolution we still can be relocked.
window.requestAnimationFrame(() => {
t.step(() => {
// Ensure children are still laid out.
assert_equals(document.getElementById("0").offsetTop, 0, "0 in completion");
assert_equals(document.getElementById("1").offsetTop, 20, "1 in completion");
assert_equals(document.getElementById("2").offsetTop, 40, "2 in completion");
// Now the parent should encompass a container, so spacer is pushed down.
assert_equals(document.getElementById("parent").offsetTop, 8, "parent in completion");
assert_equals(document.getElementById("spacer").offsetTop, 108, "spacer in completion");
});
t.done();
});
});
document.getElementById("parent").appendChild(container);
}
acquire();
}, "Measure Forced Layout");
</script>