| <!doctype HTML> |
| <html> |
| <meta charset="utf8"> |
| <title>Display Locking: measure forced layout</title> |
| <link rel="author" title="Vladimir Levin" href="mailto:vmpstr@chromium.org"> |
| <link rel="help" href="https://github.com/WICG/display-locking"> |
| |
| <style> |
| .contained { |
| contain: style layout; |
| background: lightgreen; |
| } |
| #large { |
| width: 200px; |
| height: 200px; |
| } |
| .child { |
| width: 20px; |
| height: 20%; |
| background: cyan; |
| } |
| #spacer { |
| width: 150px; |
| height: 150px; |
| background: green; |
| } |
| </style> |
| |
| <div id="parent"><div class="contained" id="small"><div id="large"></div></div></div> |
| <div id="spacer"></div> |
| |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| |
| <script> |
| async_test((t) => { |
| function createChild(id) { |
| const child = document.createElement("div"); |
| child.classList = "child"; |
| child.id = id; |
| return child; |
| } |
| |
| function measureForced() { |
| t.step(() => { |
| // Ensure children are laid out; this forces a layout. |
| assert_equals(document.getElementById("0").offsetTop, 0, "0 forced"); |
| assert_equals(document.getElementById("1").offsetTop, 40, "1 forced"); |
| assert_equals(document.getElementById("2").offsetTop, 80, "2 forced"); |
| // Parent should be 100 height, since its child is locked. |
| assert_equals(document.getElementById("parent").offsetTop, 8, "parent forced"); |
| assert_equals(document.getElementById("spacer").offsetTop, 108, "spacer forced"); |
| }); |
| } |
| |
| function measureInCommit() { |
| t.step(() => { |
| // Ensure children are still laid out. |
| assert_equals(document.getElementById("0").offsetTop, 0, "0 in commit"); |
| assert_equals(document.getElementById("1").offsetTop, 40, "1 in commit"); |
| assert_equals(document.getElementById("2").offsetTop, 80, "2 in commit"); |
| // Now the parent should encompass an unlocked container, so spacer is pushed down more. |
| assert_equals(document.getElementById("parent").offsetTop, 8, "parent in commit"); |
| assert_equals(document.getElementById("spacer").offsetTop, 208, "spacer in commit"); |
| }); |
| } |
| |
| function construct(container) { |
| container.appendChild(createChild("0")); |
| container.appendChild(createChild("1")); |
| container.appendChild(createChild("2")); |
| } |
| |
| async function runTest() { |
| const container = document.getElementById("small"); |
| await container.displayLock.acquire({ timeout: Infinity, size: [100, 100] }); |
| |
| construct(document.getElementById("large")); |
| measureForced(); |
| |
| container.displayLock.commit().then(() => { |
| measureInCommit(); |
| t.done(); |
| }); |
| } |
| |
| window.onload = function() { |
| requestAnimationFrame(() => requestAnimationFrame(runTest)); |
| }; |
| }, "Measure Forced Layout"); |
| </script> |
| |
| </html> |