Skip to content

Commit

Permalink
Bug 1888988 [wpt PR 45457] - Fix <meta> post-insertion steps expect…
Browse files Browse the repository at this point in the history
…ations, a=testonly

Automatic update from web-platform-tests
Fix `<meta>` post-insertion steps expectations

See whatwg/html#10241 for the recommendation
to change these test expectations to align with Chromium and WebKit's
behavior.

FWIW, I did try and change the processing of these kinds of meta tags
in Chromium to use the insertion steps [1], and without any extra work
at least, this caused a bunch of crashes [2].

So this change (changing the test expectations) is easier, and aligns
with more browsers.

[1]: https://crrev.com/c/5399060
[2]: https://crbug.com/330694762

[email protected]

Bug: 40150299, 330694762
Change-Id: I60f8ba556984bc1e8df4ba6e1dc375b1dfb7823d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5410497
Reviewed-by: Noam Rosenthal <[email protected]>
Commit-Queue: Dominic Farolino <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1281241}

--

wpt-commits: 38c6d6793e349f48b44950428bccd0f96d113b4e
wpt-pr: 45457
  • Loading branch information
domfarolino authored and moz-wptsync-bot committed Apr 10, 2024
1 parent 3747c6a commit 6a1f0ed
Showing 1 changed file with 35 additions and 11 deletions.
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>

0 comments on commit 6a1f0ed

Please sign in to comment.