1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="flags" content="dom">
<title>CSS Test: CSSOM View matchMedia and MediaQueryList</title>
<link rel="author" title="Rune Lillesveen" href="mailto:rune@opera.com">
<link rel="help" href="https://www.w3.org/TR/cssom-view-1/#dom-window-matchmedia">
<link rel="help" href="https://www.w3.org/TR/cssom-view-1/#the-mediaquerylist-interface">
<link rel="help" href="https://www.w3.org/TR/cssom-1/#serializing-media-queries">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/matchMedia.js"></script>
<div id="log"></div>
<script>
"use strict";
test(() => {
assert_equals(
typeof window.matchMedia,
"function",
"FATAL ERROR: The window.matchMedia function is not present. The rest of the testsuite will fail to run."
);
}, "window.matchMedia is a function");
test(() => {
const mql = window.matchMedia("all");
assert_equals(mql.media, "all");
assert_true(mql.matches);
}, 'window.matchMedia("all") matches');
test(() => {
const mql = window.matchMedia("");
assert_equals(mql.media, "");
assert_true(mql.matches);
}, 'window.matchMedia("") matches');
test(() => {
const mql = window.matchMedia("(min-width: 1px)");
assert_equals(mql.media, "(min-width: 1px)");
assert_true(mql.matches);
}, 'window.matchMedia("(min-width: 1px)") matches');
test(() => {
const mql = window.matchMedia("::");
assert_true(mql instanceof MediaQueryList);
assert_equals(mql.media, "not all");
assert_false(mql.matches);
}, 'media query with syntax error is serialized as "not all"');
promise_test(async t => {
const iframe = await createIFrame(t, 200);
const mql = iframe.contentWindow.matchMedia("(max-width: 199px), all and (min-width: 200px)");
assert_equals(mql.media, "(max-width: 199px), (min-width: 200px)");
assert_true(mql.matches);
}, 'iframe.matchMedia("(max-width: 199px), all and (min-width: 200px)") is serialized w/o "all"');
promise_test(async t => {
const iframe = await createIFrame(t);
const mql = iframe.contentWindow.matchMedia("(min-aspect-ratio: 1/1)");
assert_true(mql.matches);
}, 'iframe.matchMedia("(min-aspect-ratio: 1/1)") matches');
promise_test(async t => {
const iframe = await createIFrame(t, 200);
const mql = iframe.contentWindow.matchMedia("(width: 200px)");
assert_true(mql.matches);
}, 'iframe.matchMedia("(width: 200px)") matches');
promise_test(async t => {
const iframe = await createIFrame(t, 200, 100);
const mql = iframe.contentWindow.matchMedia("(max-height: 50px)");
assert_false(mql.matches);
}, 'iframe.matchMedia("(max-height: 50px)") matches');
promise_test(async t => {
const iframe = await createIFrame(t, 200, 100);
const mql = iframe.contentWindow.matchMedia("(min-width: 150px)");
assert_true(mql.matches);
}, 'iframe.matchMedia("(min-width: 150px)") matches');
</script>
|