5 <title>Test for CSS parser reporting parsing errors with expected precision
</title>
6 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
7 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
10 <style id=
"testbench"></style>
12 SpecialPowers
.wrap(window
).docShell
.cssErrorReportingEnabled
= true;
13 // Tests that apply to all types of style sheets
17 error
: "Unrecognized at-rule or error parsing at-rule ‘@unknown’.",
19 css
: "x { color: invalid; }",
20 error
: "Expected color but found ‘invalid’. Error in parsing value for ‘color’. Declaration dropped.",
23 css
: "x { filter: alpha(foo); }",
24 error
: "Expected ‘none’, URL, or filter function but found ‘alpha(’. Error in parsing value for ‘filter’. Declaration dropped.",
27 css
: "x { color: red; abc; }",
28 error
: "Unknown property ‘abc;’. Declaration dropped.",
31 css
: "x { filter: 5; }",
32 error
: "Expected ‘none’, URL, or filter function but found ‘5’. Error in parsing value for ‘filter’. Declaration dropped.",
36 error
: "Unknown pseudo-class or pseudo-element ‘unknown’. Ruleset ignored due to bad selector.",
39 error
: "Unknown pseudo-class or pseudo-element ‘unknown’. Ruleset ignored due to bad selector.",
42 error
: "Expected identifier for pseudo-class or pseudo-element but found ‘5’. Ruleset ignored due to bad selector.",
45 error
: "Expected identifier for pseudo-class or pseudo-element but found ‘ ’. Ruleset ignored due to bad selector.",
48 error
: "Unexpected token in attribute selector: ‘.’. Ruleset ignored due to bad selector.",
51 error
: "Expected ‘|’ but found ‘a’. Ruleset ignored due to bad selector.",
54 error
: "Expected identifier or string for value in attribute selector but found ‘5’. Ruleset ignored due to bad selector.",
57 error
: "Expected attribute name or namespace but found ‘$’. Ruleset ignored due to bad selector.",
60 error
: "Expected identifier for attribute name but found ‘5’. Ruleset ignored due to bad selector.",
63 error
: "Unknown namespace prefix ‘x’. Ruleset ignored due to bad selector.",
66 error
: "Unknown namespace prefix ‘x’. Ruleset ignored due to bad selector.",
69 error
: "Dangling combinator. Ruleset ignored due to bad selector.",
72 error
: "Selector expected. Ruleset ignored due to bad selector.",
75 error
: "Expected element name or ‘*’ but found ‘ ’. Ruleset ignored due to bad selector.",
78 error
: "Expected identifier for class selector but found ‘ ’. Ruleset ignored due to bad selector.",
81 error
: "Selector expected. Ruleset ignored due to bad selector.",
83 css
: "* { -webkit-text-size-adjust: 100% }",
84 error
: "Error in parsing value for ‘-webkit-text-size-adjust’. Declaration dropped.",
87 css
: "@media (totally-unknown-feature) {}",
88 error
: "Expected media feature name but found ‘totally-unknown-feature’.",
90 css
: "@media \"foo\" {}",
91 error
: "Unexpected token ‘\"foo\"’ in media list.",
93 css
: "@media (min-width) {}",
94 error
: "Media features with min- or max- must have a value.",
96 css
: "@media (min-width >= 3px) {}",
97 error
: "Unexpected operator in media list.",
99 css
: "@media (device-height: three) {}",
100 error
: "Found invalid value for media feature.",
102 css
: "@media (min-width: foo) {}",
103 error
: "Found invalid value for media feature.",
105 css
: "@media (min-resolution: 2) {}",
106 error
: "Found invalid value for media feature.",
108 css
: "@media (min-monochrome: 1.1) {}",
109 error
: "Found invalid value for media feature.",
111 css
: "@media (min-aspect-ratio: 1 invalid) {}",
112 error
: "Unexpected token ‘invalid’ in media list.",
114 css
: "@media (min-aspect-ratio: 1 / invalid) {}",
115 error
: "Found invalid value for media feature.",
117 css
: "@media (orientation: invalid-orientation-value) {}",
118 error
: "Found invalid value for media feature.",
120 css
: "a, .b, #c { unknown: invalid; }",
121 error
: "Unknown property ‘unknown’. Declaration dropped.",
122 cssSelectors
: "a, .b, #c"
125 css
: ":host:hover { color: red; }",
126 error
: ":host selector in ‘:host:hover’ is not featureless and will never match. Maybe you intended to use :host()?"
130 // Tests that apply only to constructed style sheets
131 var constructedSheetTests
= [
133 css
: '@import url("sheet.css");',
134 error
: "@import rules are not yet valid in constructed stylesheets."
138 function assertMessages(messages
, action
) {
139 return new Promise(resolve
=> {
140 SimpleTest
.expectConsoleMessages(action
, messages
, resolve
);
144 async
function runTests() {
145 for (let {css
, cssSelectors
= "", error
} of tests
) {
146 let messages
= [ { cssSelectors
, errorMessage
: error
} ];
147 await
assertMessages(messages
, () => { testbench
.innerHTML
= css
});
148 await
assertMessages(messages
, () => { new CSSStyleSheet().replaceSync(css
) });
149 await
assertMessages(messages
, async () => { await
new CSSStyleSheet().replace(css
) });
151 for (let {css
, cssSelectors
= "", error
} of constructedSheetTests
) {
152 let messages
= [ { cssSelectors
, errorMessage
: error
} ];
153 await
assertMessages(messages
, () => { new CSSStyleSheet().replaceSync(css
) });
154 await
assertMessages(messages
, async () => { await
new CSSStyleSheet().replace(css
) });