Skip to content

Commit 381e7ff

Browse files
test: read quirks mode off the doctype rather than off the parse (#22164)
The twelve WebKit differences filed as `compatMode` are one cause, and it is not a printer defect: every one of those files is a fragment carrying no doctype, and with none `document.compatMode` reports what the engine defaults a parsed document to rather than anything webpack printed. Measured in Chrome 147: the mode is a function of the doctype alone, so where a doctype exists the facet already carried it and the mode was a second reading of the same line — which is why it masked the cause, reporting `CSS1Compat vs BackCompat` for a dropped doctype and for a shortened one alike. The doctype now comes first and the mode is compared only beside it. A page that loses its doctype or has it rewritten still fails, in every engine, and the new case pins both directions.
1 parent 5a10675 commit 381e7ff

2 files changed

Lines changed: 49 additions & 54 deletions

File tree

‎test/helpers/syntaxEquivalence.js‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,13 +1330,17 @@ const installHelpers = (generics) => {
13301330
}
13311331
}
13321332
const doctype = doc.doctype;
1333-
// Quirks mode changes layout, so the doctype has to survive as one.
1334-
facets.document = [
1335-
doc.compatMode,
1333+
// WHY: Quirks mode changes layout, so a doctype has to survive as one —
1334+
// but `compatMode` is a function of the doctype alone, so with none it
1335+
// reports what the engine defaults a parsed document to rather than
1336+
// anything the printer wrote, and WebKit answers that unlike Blink.
1337+
facets.document =
13361338
doctype === null
1337-
? "no doctype"
1338-
: `${doctype.name}|${doctype.publicId}|${doctype.systemId}`
1339-
];
1339+
? ["no doctype"]
1340+
: [
1341+
`${doctype.name}|${doctype.publicId}|${doctype.systemId}`,
1342+
doc.compatMode
1343+
];
13401344
// What the page renders: the title, whose getter strips and collapses ASCII
13411345
// whitespace as the spec says a title is read, and the body's text. A `<script>`
13421346
// or `<style>` body is data, and a `<template>`'s content does not render.

‎test/specCases/syntaxEquivalence.spectest.js‎

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -170,54 +170,6 @@ const FILED_CONFIG_HTML_DEFECTS = new Map([
170170
"test/configCases/html/attribute-tables/page.html",
171171
"firefox, webkit only: not a printer defect — an IDL attribute the engine does not implement falls back to the attribute as written, so a normalization reads as a difference. Measured in Firefox 156: `writingSuggestions` and `blocking` both read `undefined` where Chrome 147 reflects `false` and `render`; WebKit reads `autofocus`, `enterkeyhint` and `inputmode` apart from Blink the same way"
172172
],
173-
[
174-
"test/configCases/html/parser-as-fragment/div.html",
175-
"webkit only: not a printer defect, not yet diagnosed — WebKit reads a different `document.compatMode` for the source and the printed form where Blink and Gecko read one. Measured in the first WebKit run: eleven files report `BackCompat vs CSS1Compat` and two the reverse, and a direction that flips per file points at how the harness builds the document rather than at what the printer wrote"
176-
],
177-
[
178-
"test/configCases/asset-modules/minimize-embedded-asset-source/text.html",
179-
"webkit only: the `compatMode` the harness reads again — see `parser-as-fragment/div.html`"
180-
],
181-
[
182-
"test/configCases/embedded/everything/inline.html",
183-
"webkit only: the `compatMode` the harness reads again — see `parser-as-fragment/div.html`"
184-
],
185-
[
186-
"test/configCases/embedded/everything/source.html",
187-
"webkit only: the `compatMode` the harness reads again — see `parser-as-fragment/div.html`"
188-
],
189-
[
190-
"test/configCases/html/fragment-context-select/page.html",
191-
"webkit only: the `compatMode` the harness reads again — see `parser-as-fragment/div.html`"
192-
],
193-
[
194-
"test/configCases/html/minify-embedded-html-in-js/page.html",
195-
"webkit only: the `compatMode` the harness reads again — see `parser-as-fragment/div.html`"
196-
],
197-
[
198-
"test/configCases/html/minimize-embedded-in-js/page.html",
199-
"webkit only: the `compatMode` the harness reads again — see `parser-as-fragment/div.html`"
200-
],
201-
[
202-
"test/configCases/html/minimize-round-trip/cases/adoption.html",
203-
"webkit only: the `compatMode` the harness reads again — see `parser-as-fragment/div.html`"
204-
],
205-
[
206-
"test/configCases/html/minimize-round-trip/cases/attributes.html",
207-
"webkit only: the `compatMode` the harness reads again — see `parser-as-fragment/div.html`"
208-
],
209-
[
210-
"test/configCases/html/parser-as-fragment/document.html",
211-
"webkit only: the `compatMode` the harness reads again — see `parser-as-fragment/div.html`"
212-
],
213-
[
214-
"test/configCases/html/parser-as-fragment/tbody.html",
215-
"webkit only: the `compatMode` the harness reads again — see `parser-as-fragment/div.html`"
216-
],
217-
[
218-
"test/configCases/html/parser-as-fragment/template.html",
219-
"webkit only: the `compatMode` the harness reads again — see `parser-as-fragment/div.html`"
220-
],
221173
[
222174
"test/configCases/html/minimize-round-trip/cases/reflected.html",
223175
"firefox only: the unimplemented `blocking` IDL again — see `attribute-tables`"
@@ -801,6 +753,45 @@ describe(`printer output in real ${ENGINE}`, () => {
801753
);
802754
}
803755

756+
// WHY: `compatMode` is a function of the doctype alone — measured in
757+
// Chrome 147, any two that read back as the same doctype compute the same
758+
// mode — so with none it reports what the engine defaults a parsed document
759+
// to, which WebKit and Blink answer differently. Only the doctype is the
760+
// printer's to keep, so a page carrying one is still held to its effect.
761+
it(
762+
"reads quirks mode off the doctype rather than off the parse",
763+
async () => {
764+
const differences = await comparePages(
765+
[
766+
{
767+
name: "doctype-absent",
768+
raw: '<p class="a">a<b>b<i>c</p>d</i>e</b>f',
769+
min: "<p class=a>a<b>b<i>c</p>d</i>e</b>f"
770+
},
771+
{
772+
name: "doctype-dropped",
773+
raw: "<!DOCTYPE html><p>x</p>",
774+
min: "<p>x</p>"
775+
},
776+
{
777+
name: "doctype-shortened",
778+
raw: '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><p>x</p>',
779+
min: '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><p>x</p>'
780+
}
781+
],
782+
false
783+
);
784+
expect(differences).toEqual([
785+
{ name: "doctype-dropped", why: "document: 2 vs 1" },
786+
{
787+
name: "doctype-shortened",
788+
why: "document 0: html|-//W3C//DTD HTML 4.01 Transitional//EN|http://www.w3.org/TR/html4/loose.dtd vs html|-//W3C//DTD HTML 4.01 Transitional//EN|"
789+
}
790+
]);
791+
},
792+
FILE_TIMEOUT
793+
);
794+
804795
// A `)` inside a quoted `url()` belongs to the address; one met after an
805796
// illegal quote ends the bad url, and the rest is a color again.
806797
it(

0 commit comments

Comments
 (0)