| <!DOCTYPE html> |
| <script src="../../../resources/js-test.js"></script> |
| <body> |
| <div id="container" style="position: relative;"></div> |
| <script> |
| description('offsetParent should not leak nodes in user agent Shadow DOM.'); |
| |
| if (!window.internals) |
| fail('This test requires window.internals to manipulate user agent Shadow DOM.'); |
| |
| function configureShadowRoot(shadow) { |
| shadow.innerHTML = |
| '<div id="x" style="position: relative;"><slot></slot></div>'; |
| shadow.positionedElement = shadow.querySelector('#x'); |
| } |
| |
| function configureUAShadowRoot(shadow) { |
| const slot = shadow.querySelector('slot'); |
| const div = document.createElement('div'); |
| div.style = 'position: relative;'; |
| div.appendChild(slot); |
| shadow.appendChild(div); |
| shadow.positionedElement = div; |
| } |
| |
| var container = document.querySelector('#container'); |
| |
| // Test that offsetParent works in author Shadow DOM |
| var host = document.createElement('div'); |
| container.appendChild(host); |
| var child = document.createElement('div'); |
| host.appendChild(child); |
| var shadow = host.attachShadow({mode: 'open'}); |
| configureShadowRoot(shadow); |
| shouldBe('child.offsetParent', 'shadow.positionedElement'); |
| |
| // Test that offsetParent works 'through' Shadow DOM when there is no |
| // positioned ancestor in user agent Shadow DOM |
| shadow.positionedElement.removeAttribute('style'); |
| shouldBe('child.offsetParent', 'container'); |
| |
| // Test that when the offsetParent is in user agent Shadow DOM, it is |
| // not exposed to script, but its shadow host or the host's ancestor |
| // which is appropriate as an offsetParent is returned. |
| host = document.createElement('details'); |
| container.appendChild(host); |
| host.setAttribute('open', 'open'); |
| host.appendChild(child); |
| var shadow = internals.shadowRoot(host); // this is a UA shadow root |
| configureUAShadowRoot(shadow); |
| shouldBe('child.offsetParent', 'container'); |
| |
| // Test that offsetParent works 'through' user agent Shadow DOM when there is no |
| // positioned ancestor in user agent Shadow DOM |
| shadow.positionedElement.removeAttribute('style'); |
| shouldBe('child.offsetParent', 'container'); |
| |
| container.remove(); |
| |
| successfullyParsed = true; |
| </script> |