Skip to content

Commit 90aa0c2

Browse files
committed
test: keep a condition apart on the dimension nothing sampled
Where the engine answers no media emulation, the signature was the viewport bits alone — measured in Firefox 156, `print`, `speech` and both `color-gamut` values all answer `0000`, so a rewrite from one to another read as equivalent. What no viewport varies is carried as text beside the bits now: the media type and every feature but the dimensions, with `min-x: v` written as `x >= v` so the two spellings of one query still meet.
1 parent 94ba8e8 commit 90aa0c2

2 files changed

Lines changed: 57 additions & 5 deletions

File tree

‎test/helpers/syntaxEquivalence.js‎

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,52 @@ const emulatesMedia = async (page) => {
14511451
return can;
14521452
};
14531453

1454+
// The media types a condition can name, which no viewport varies.
1455+
const MEDIA_TYPES = new Set([
1456+
"all",
1457+
"aural",
1458+
"braille",
1459+
"embossed",
1460+
"handheld",
1461+
"print",
1462+
"projection",
1463+
"screen",
1464+
"speech",
1465+
"tty",
1466+
"tv"
1467+
]);
1468+
1469+
/**
1470+
* What a media condition asks that no viewport can answer: its media type and
1471+
* every feature but the dimensions, named once and in order. Built by taking
1472+
* what is left rather than by cutting the rest out, so a query reduces to the
1473+
* same text however its parts were spelled or joined.
1474+
* @param {string} condition the condition as written
1475+
* @returns {string} what the viewport did not sample
1476+
*/
1477+
const unsampledBy = (condition) => {
1478+
const parts = [];
1479+
for (const [word] of condition.toLowerCase().matchAll(/[a-z-]+/g)) {
1480+
if (MEDIA_TYPES.has(word)) parts.push(word);
1481+
}
1482+
for (const [feature] of condition
1483+
.toLowerCase()
1484+
.matchAll(/\([^()]*(?:\([^()]*\))?[^()]*\)/g)) {
1485+
if (/\b(?:min-|max-)?(?:width|height|aspect-ratio)\b/.test(feature)) {
1486+
continue;
1487+
}
1488+
// `min-x: v` and `x >= v` are one query written two ways (Media Queries 4
1489+
// §2.4), so the prefixed spelling is written as the range one.
1490+
parts.push(
1491+
feature
1492+
.replace(/\s+/g, "")
1493+
.replace(/^\(min-([a-z-]+):/, "($1>=")
1494+
.replace(/^\(max-([a-z-]+):/, "($1<=")
1495+
);
1496+
}
1497+
return parts.sort().join("&");
1498+
};
1499+
14541500
/**
14551501
* What the engine makes of every at-rule condition in a set of rules. A
14561502
* condition is not compared as text: `(min-width: 200px)` and
@@ -1560,10 +1606,16 @@ const conditionSignatures = async (page, groups) => {
15601606
// WHY: Both calls are CDP, which Gecko's WebDriver BiDi does not answer, and
15611607
// only `prefers-color-scheme` and `prefers-reduced-motion` have a launch
15621608
// preference standing in — set at launch, so not switchable per sample.
1563-
// There the signature carries the viewport dimension alone, which is the
1564-
// one the printer's own rewrites move (`(min-width:200px)` against
1565-
// `(width>=200px)`); two conditions differing only in media type or
1566-
// `color-gamut` would read alike, and that is the discrimination lost.
1609+
// Measured in Firefox 156: `print`, `speech` and both `color-gamut` values
1610+
// all answer `0000` across the viewports, so a signature of those bits
1611+
// alone would call them one condition. What the viewport cannot vary is
1612+
// carried as text instead, which keeps them apart while the widths still
1613+
// equate `(min-width:200px)` with `(width>=200px)`.
1614+
if (!(await emulatesMedia(page))) {
1615+
for (const [i, condition] of media.entries()) {
1616+
bits[i] += ` ${unsampledBy(condition)}`;
1617+
}
1618+
}
15671619
if (await emulatesMedia(page)) {
15681620
for (const type of ["screen", "print"]) {
15691621
for (const features of [[], ...featureSets]) {

‎test/wpt‎

Submodule wpt updated 921 files

0 commit comments

Comments
 (0)