Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!doctype html>
<title>Test for parsing of non-content-exposed media-queries.</title>
<script src="chrome-only-media-queries.js"></script>
<style></style>
<script>
const SHEET = document.querySelector('style');
SimpleTest.waitForExplicitFinish();
async function testWithPref() {
await new Promise(r => {
SpecialPowers.pushPrefEnv(
{
set: [
["layout.css.forced-colors.enabled", false],
],
},
r
);
});
expectKnown("(forced-colors: none)");
expectKnown("(forced-colors: active)");
expectKnown("(forced-colors)");
SimpleTest.finish();
}
function expect(q, shouldBeKnown) {
is(matchMedia(q).media, q, "Serialization should roundtrip");
is(matchMedia(`${q} or (not ${q})`).matches, shouldBeKnown, `Query should${shouldBeKnown ? "" : " not"} be known`);
}
function expectKnown(q) {
expect(q, true);
}
function expectUnkown(q) {
expect(q, false);
}
// Test a toggle that should always match for `1` or `0`.
function testToggle(toggle) {
expectKnown(`(${toggle})`);
expectKnown(`(${toggle}: 1)`);
expectKnown(`(${toggle}: 0)`);
expectUnkown(`(${toggle}: foo)`);
expectUnkown(`(${toggle}: true)`);
expectUnkown(`(${toggle}: false)`);
expectUnkown(`(${toggle}: -1)`);
expectUnkown(`(min-${toggle}: 0)`);
expectUnkown(`(max-${toggle}: 0)`);
expectUnkown(`(max-${toggle})`);
expectUnkown(`(min-${toggle})`);
let matches_1 = matchMedia(`(${toggle}: 1)`).matches;
let matches_0 = matchMedia(`(${toggle}: 0)`).matches;
isnot(matches_0, matches_1, `Should not match both true and false: ${toggle}`);
is(matches_0 || matches_1, true, `Should match at least one: ${toggle}`);
}
for (let toggle of CHROME_ONLY_TOGGLES) {
testToggle(toggle)
}
for (let query of CHROME_ONLY_QUERIES) {
expectKnown(query);
}
// These might be exposed to content by pref, we just want to make sure they're
// always exposed to chrome.
expectKnown("(prefers-contrast: more)")
expectKnown("(prefers-contrast: no-preference)")
expectKnown("(prefers-contrast: less)");
expectKnown("(prefers-contrast)")
expectKnown("(forced-colors: none)");
expectKnown("(forced-colors: active)");
expectKnown("(forced-colors)");
expectUnkown("(-moz-platform: )");
testWithPref();
</script>