Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /css/css-page/page-rule-declarations-003.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Paged Media: parsing @page selectors</title>
<meta name="assert" content="Test that @page selectors are parsed correctly.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@page a, B {
size: 1in;
}
@page A,b,C {
size: 2in;
}
@page auto {
size: 3in;
}
@page something, auto {
size: 4in;
}
@page auto, other_thing {
size: 5in;
}
@page _a, Z {
size: 6in;
}
@page -b, y {
size: 7in;
}
@page _abcd {
size: 8in;
}
@page n,-XYZ {
size: 9in;
}
</style>
<script>
let expectedForSelector = {
"a, B" : "size: 1in;",
"A, b, C" : "size: 2in;",
"auto" : "size: 3in;",
"something, auto" : "size: 4in;",
"auto, other_thing" : "size: 5in;",
"_a, Z" : "size: 6in;",
"-b, y" : "size: 7in;",
"_abcd" : "size: 8in;",
"n, -XYZ" : "size: 9in;"
};
let styleSheets = document.styleSheets;
for (let sheet of styleSheets) {
let rules = sheet.cssRules;
for (let rule of rules) {
if (rule.type == CSSRule.PAGE_RULE) {
let expected = expectedForSelector[rule.selectorText];
test(function(){
assert_equals(rule.style.cssText, expected, "unexpected @page contents");
}, "contents for selector ['" + rule.selectorText + "']");
delete expectedForSelector[rule.selectorText];
}
}
}
// Validate that we can assign an empty selector
test(function() {
let rule = styleSheets[0].cssRules[0];
assert_equals(rule.type, CSSRule.PAGE_RULE, "expected first rule to be @page");
rule.selectorText = "";
assert_equals(rule.selectorText, "", "unexpected selector when assigning blank string");
}, "expected empty selector when assigning blank string");
test(function() {
assert_equals(Object.keys(expectedForSelector).length, 0, "missing @page selectors");
});
</script>