diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/css/mediaqueries/resources | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/css/mediaqueries/resources')
5 files changed, 100 insertions, 0 deletions
diff --git a/testing/web-platform/tests/css/mediaqueries/resources/matchmedia-utils.js b/testing/web-platform/tests/css/mediaqueries/resources/matchmedia-utils.js new file mode 100644 index 0000000000..327e8f69fe --- /dev/null +++ b/testing/web-platform/tests/css/mediaqueries/resources/matchmedia-utils.js @@ -0,0 +1,76 @@ +'use strict'; + +function query_is_css_parseable(query) { + const style = document.createElement('style'); + style.type = 'text/css'; + document.head.appendChild(style); + + const sheet = style.sheet; + try { + sheet.insertRule("@media " + query + "{}", 0); + return sheet.cssRules.length == 1 && + sheet.cssRules[0].media.mediaText != "not all"; + } finally { + while (sheet.cssRules.length) + sheet.deleteRule(0); + style.remove(); + } +} + +function query_should_be_css_parseable(query) { + test(() => { + assert_true(query_is_css_parseable(query)); + }, "Should be parseable in a CSS stylesheet: '" + query + "'"); +} + +function query_should_not_be_css_parseable(query) { + test(() => { + assert_false(query_is_css_parseable(query)); + }, "Should not be parseable in a CSS stylesheet: '" + query + "'"); +} + +function query_is_js_parseable(query) { + // We cannot rely on whether a given feature is on or off, so only check the + // 'media' member of the result. + const match = window.matchMedia(query); + return match.media == query; +} + +function query_should_be_js_parseable(query) { + test(() => { + assert_true(query_is_js_parseable(query)); + }, "Should be parseable in JS: '" + query + "'"); +} + +function query_should_not_be_js_parseable(query) { + test(() => { + assert_false(query_is_js_parseable(query)); + }, "Should not be parseable in JS: '" + query + "'"); +} + +function query_is_known(query) { + return window.matchMedia(`${query}, not all and ${query}`).matches; +} + +function query_is_unknown(query) { + return !window.matchMedia(`${query}, not all and ${query}`).matches; +} + +function query_should_be_known(query) { + test(() => { + assert_true(query_is_js_parseable(query), "Can parse with JS"); + assert_true(query_is_css_parseable(query), "Can parse with CSS"); + assert_true(query_is_known(query)); + }, "Should be known: '" + query + "'"); +} + +function query_should_be_unknown(query) { + test(() => { + assert_true(query_is_js_parseable(query), "Can parse with JS"); + assert_true(query_is_css_parseable(query), "Can parse with CSS"); + }, "Should be parseable: '" + query + "'"); + + test(() => { + assert_true(query_is_unknown(query)); + }, "Should be unknown: '" + query + "'"); +} diff --git a/testing/web-platform/tests/css/mediaqueries/resources/mq-non-matching-lazy-load-style.css b/testing/web-platform/tests/css/mediaqueries/resources/mq-non-matching-lazy-load-style.css new file mode 100644 index 0000000000..b128f7398e --- /dev/null +++ b/testing/web-platform/tests/css/mediaqueries/resources/mq-non-matching-lazy-load-style.css @@ -0,0 +1,3 @@ +body { + background-color: lightblue; +} diff --git a/testing/web-platform/tests/css/mediaqueries/resources/prefers-color-scheme-dark.svg b/testing/web-platform/tests/css/mediaqueries/resources/prefers-color-scheme-dark.svg new file mode 100644 index 0000000000..f65fce76ec --- /dev/null +++ b/testing/web-platform/tests/css/mediaqueries/resources/prefers-color-scheme-dark.svg @@ -0,0 +1,6 @@ +<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"> + <style> + :root { color: purple } + </style> + <rect fill="currentColor" width="32" height="32"/> +</svg> diff --git a/testing/web-platform/tests/css/mediaqueries/resources/prefers-color-scheme-light.svg b/testing/web-platform/tests/css/mediaqueries/resources/prefers-color-scheme-light.svg new file mode 100644 index 0000000000..23ac2ad949 --- /dev/null +++ b/testing/web-platform/tests/css/mediaqueries/resources/prefers-color-scheme-light.svg @@ -0,0 +1,6 @@ +<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"> + <style> + :root { color: blue } + </style> + <rect fill="currentColor" width="32" height="32"/> +</svg> diff --git a/testing/web-platform/tests/css/mediaqueries/resources/prefers-color-scheme.svg b/testing/web-platform/tests/css/mediaqueries/resources/prefers-color-scheme.svg new file mode 100644 index 0000000000..5523ff39fa --- /dev/null +++ b/testing/web-platform/tests/css/mediaqueries/resources/prefers-color-scheme.svg @@ -0,0 +1,9 @@ +<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"> + <style> + :root { color: blue } + @media (prefers-color-scheme: dark) { + :root { color: purple } + } + </style> + <rect fill="currentColor" width="32" height="32"/> +</svg> |