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 /layout/style/test/test_css_parse_error_smoketest.html | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.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 'layout/style/test/test_css_parse_error_smoketest.html')
-rw-r--r-- | layout/style/test/test_css_parse_error_smoketest.html | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/layout/style/test/test_css_parse_error_smoketest.html b/layout/style/test/test_css_parse_error_smoketest.html new file mode 100644 index 0000000000..96d8edce3a --- /dev/null +++ b/layout/style/test/test_css_parse_error_smoketest.html @@ -0,0 +1,160 @@ +<!doctype html> +<html> +<head> + <meta charset="utf-8"> + <title>Test for CSS parser reporting parsing errors with expected precision</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" href="/tests/SimpleTest/test.css"> +</head> +<body> +<style id="testbench"></style> +<script> + SpecialPowers.wrap(window).docShell.cssErrorReportingEnabled = true; + // Tests that apply to all types of style sheets + var tests = [ + { + css: "@unknown {}", + error: "Unrecognized at-rule or error parsing at-rule ‘@unknown’.", + }, { + css: "x { color: invalid; }", + error: "Expected color but found ‘invalid’. Error in parsing value for ‘color’. Declaration dropped.", + cssSelectors: "x", + }, { + css: "x { filter: alpha(foo); }", + error: "Expected ‘none’, URL, or filter function but found ‘alpha(’. Error in parsing value for ‘filter’. Declaration dropped.", + cssSelectors: "x", + }, { + css: "x { color: red; abc; }", + error: "Unknown property ‘abc;’. Declaration dropped.", + cssSelectors: "x", + }, { + css: "x { filter: 5; }", + error: "Expected ‘none’, URL, or filter function but found ‘5’. Error in parsing value for ‘filter’. Declaration dropped.", + cssSelectors: "x", + }, { + css: "::unknown {}", + error: "Unknown pseudo-class or pseudo-element ‘unknown’. Ruleset ignored due to bad selector.", + }, { + css: ":unknown {}", + error: "Unknown pseudo-class or pseudo-element ‘unknown’. Ruleset ignored due to bad selector.", + }, { + css: "::5 {}", + error: "Expected identifier for pseudo-class or pseudo-element but found ‘5’. Ruleset ignored due to bad selector.", + }, { + css: ": {}", + error: "Expected identifier for pseudo-class or pseudo-element but found ‘ ’. Ruleset ignored due to bad selector.", + }, { + css: "x[a.]{}", + error: "Unexpected token in attribute selector: ‘.’. Ruleset ignored due to bad selector.", + }, { + css: "x[*a]{}", + error: "Expected ‘|’ but found ‘a’. Ruleset ignored due to bad selector.", + }, { + css: "x[a=5]{}", + error: "Expected identifier or string for value in attribute selector but found ‘5’. Ruleset ignored due to bad selector.", + }, { + css: "x[$] {}", + error: "Expected attribute name or namespace but found ‘$’. Ruleset ignored due to bad selector.", + }, { + css: "a[|5] {}", + error: "Expected identifier for attribute name but found ‘5’. Ruleset ignored due to bad selector.", + }, { + css: "a[x|] {}", + error: "Unknown namespace prefix ‘x’. Ruleset ignored due to bad selector.", + }, { + css: "x| {}", + error: "Unknown namespace prefix ‘x’. Ruleset ignored due to bad selector.", + }, { + css: "a> {}", + error: "Dangling combinator. Ruleset ignored due to bad selector.", + }, { + css: "~ {}", + error: "Selector expected. Ruleset ignored due to bad selector.", + }, { + css: "| {}", + error: "Expected element name or ‘*’ but found ‘ ’. Ruleset ignored due to bad selector.", + }, { + css: ". {}", + error: "Expected identifier for class selector but found ‘ ’. Ruleset ignored due to bad selector.", + }, { + css: ":not() {}", + error: "Selector expected. Ruleset ignored due to bad selector.", + }, { + css: "* { -webkit-text-size-adjust: 100% }", + error: "Error in parsing value for ‘-webkit-text-size-adjust’. Declaration dropped.", + cssSelectors: "*", + }, { + css: "@media (totally-unknown-feature) {}", + error: "Expected media feature name but found ‘totally-unknown-feature’.", + }, { + css: "@media \"foo\" {}", + error: "Unexpected token ‘\"foo\"’ in media list.", + }, { + css: "@media (min-width) {}", + error: "Media features with min- or max- must have a value.", + }, { + css: "@media (min-width >= 3px) {}", + error: "Unexpected operator in media list.", + }, { + css: "@media (device-height: three) {}", + error: "Found invalid value for media feature.", + }, { + css: "@media (min-width: foo) {}", + error: "Found invalid value for media feature.", + }, { + css: "@media (min-resolution: 2) {}", + error: "Found invalid value for media feature.", + }, { + css: "@media (min-monochrome: 1.1) {}", + error: "Found invalid value for media feature.", + }, { + css: "@media (min-aspect-ratio: 1 invalid) {}", + error: "Unexpected token ‘invalid’ in media list.", + }, { + css: "@media (min-aspect-ratio: 1 / invalid) {}", + error: "Found invalid value for media feature.", + }, { + css: "@media (orientation: invalid-orientation-value) {}", + error: "Found invalid value for media feature.", + }, { + css: "a, .b, #c { unknown: invalid; }", + error: "Unknown property ‘unknown’. Declaration dropped.", + cssSelectors: "a, .b, #c" + }, + { + css: ":host:hover { color: red; }", + error: ":host selector in ‘:host:hover’ is not featureless and will never match. Maybe you intended to use :host()?" + }, + ]; + + // Tests that apply only to constructed style sheets + var constructedSheetTests = [ + { + css: '@import url("sheet.css");', + error: "@import rules are not yet valid in constructed stylesheets." + } + ]; + + function assertMessages(messages, action) { + return new Promise(resolve => { + SimpleTest.expectConsoleMessages(action, messages, resolve); + }); + } + + async function runTests() { + for (let {css, cssSelectors = "", error} of tests) { + let messages = [ { cssSelectors, errorMessage: error } ]; + await assertMessages(messages, () => { testbench.innerHTML = css }); + await assertMessages(messages, () => { new CSSStyleSheet().replaceSync(css) }); + await assertMessages(messages, async () => { await new CSSStyleSheet().replace(css) }); + } + for (let {css, cssSelectors = "", error} of constructedSheetTests) { + let messages = [ { cssSelectors, errorMessage: error } ]; + await assertMessages(messages, () => { new CSSStyleSheet().replaceSync(css) }); + await assertMessages(messages, async () => { await new CSSStyleSheet().replace(css) }); + } + } + + add_task(runTests); + +</script> |