ladybird/Tests/LibWeb/Text/input/content-blocker-srcdoc-frame-cosmetic-source.html
Sam Atkins d3e7a332b3 Tests: Make srcdoc content blocker test deterministic
This test previously did not wait for the iframe to load before it read
its contentDocument, meaning it would sometimes read the blank default
document instead. Add an explicit listener for the iframe's load event,
to make this more predictable.

Also simplify the test by setting the base URL instead of spinning up an
echo server.
2026-06-04 23:44:18 +09:00

33 lines
1.1 KiB
HTML

<!DOCTYPE html>
<script src="./include.js"></script>
<script>
asyncTest(async done => {
// The srcdoc iframe inherits its base URL from its parent document. We need it to be localhost so that the
// content blocker's matching rule will apply to it.
const base = document.createElement("base");
base.href = "http://localhost/";
document.head.appendChild(base);
try {
const iframe = document.createElement("iframe");
const loaded = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
iframe.srcdoc = `<div class="ad"></div>`;
document.body.appendChild(iframe);
await loaded;
const target = iframe.contentDocument.querySelector(".ad");
println(getComputedStyle(target).display);
internals.setContentBlockers("localhost##.ad");
println(getComputedStyle(target).display);
internals.setContentBlockers("");
println(getComputedStyle(target).display);
} finally {
internals.setContentBlockers("");
}
done();
});
</script>