Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix <meta> post-insertion steps expectations #45457

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,53 @@
<div id="div">hello</div>
<script>
let scriptRan = false;
let computedStyleDuringInsertion = null;
let computedStyleInPreScript = null;
let computedStyleInPostScript = null;
test(() => {
const div = document.getElementById("div");

// 1. Gets inserted *before* the `<meta>` tag. Cannot observe the meta tag's
// effect, because this script runs before the meta tag's post-insertion steps
// run, and the meta tag's post-insertion steps is where the default style
// sheet actually changes.
const preScript = document.createElement("script");
preScript.textContent = `
computedStyleInPreScript = getComputedStyle(div).display;
scriptRan = true;
`;

// 2. The `<meta>` tag itself.
const meta = document.createElement("meta");
meta.httpEquiv = "default-style";
meta.content = "alternative";
const script = document.createElement("script");
script.textContent = `
computedStyleDuringInsertion = getComputedStyle(div).display;

// 3. Gets inserted *after* the `<meta>` tag. Observes the meta tag's effect,
// because this script runs after the meta tag's post-insertion steps, which
// has the script-observable change to the default style sheet.
const postScript = document.createElement("script");
postScript.textContent = `
computedStyleInPostScript = getComputedStyle(div).display;
scriptRan = true;
`;

const df = document.createDocumentFragment();
df.appendChild(script);
df.appendChild(meta);
assert_equals(getComputedStyle(div).display, "block", "div has block display");
df.append(preScript, meta, postScript);

assert_equals(getComputedStyle(div).display, "block",
"div still has block display before meta insertion");
assert_false(scriptRan, "script has not run before insertion");

document.head.appendChild(df);
assert_true(scriptRan, "script has run after insertion");
assert_equals(computedStyleDuringInsertion, "none",
"display: none; style was applied during DOM insertion, before " +
"later-inserted script runs");
assert_equals(computedStyleInPreScript, "block",
"display: none; style was NOT applied during DOM insertion steps, " +
"before earlier-inserted script post-insertion steps run");
assert_equals(computedStyleInPostScript, "none",
"display: none; style WAS applied during DOM post-insertion steps, " +
"before later-inserted script runs");
assert_equals(getComputedStyle(div).display, "none",
"style remains display: none; after insertion");

}, "Inserting <meta> that uses alternate stylesheets, applies the style " +
"during DOM insertion, and before script runs as a result of any atomic insertions");
"during DOM post-insertion steps");
</script>