Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /css/cssom/page-descriptors.html - WPT Dashboard Interop Dashboard
<!DOCTYPE HTML>
<html>
<head>
<title>CSSPageDescriptors properties tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@page {
size: a3;
page-orientation: rotate-right;
margin: 1em 24px 2in 101.5mm;
}
@page {
size: jis-b5 landscape;
}
@page {
size: 216mm;
}
</style>
</head>
<body>
<script>
'use strict';
// `size` is both an @page descriptor and a width/height shorthand property, with no
// relation between the two (w3c/csswg-drafts#820). The split is covered by
// css/css-sizing/parsing/size-invalid.html, so it is not retested here.
let styleSheet = document.styleSheets[0];
let marginNames = ["left", "right", "top", "bottom"];
let pageDescriptors = ["margin", "page-orientation", "size"];
marginNames.forEach(function(n){
pageDescriptors.push("margin-" + n);
pageDescriptors.push("margin" + n[0].toUpperCase() + n.slice(1));
});
// One test per descriptor so an unimplemented one doesn't hide the rest.
pageDescriptors.forEach(function(prop){
test(() => {
assert_own_property(styleSheet.cssRules[0].style.__proto__, prop,
"CSSPageDescriptors should have property " + prop);
}, `CSSPageDescriptors exposes "${prop}"`);
});
test(() => {
assert_equals(styleSheet.cssRules[0].style.size, "a3");
assert_equals(styleSheet.cssRules[1].style.size, "jis-b5 landscape");
assert_equals(styleSheet.cssRules[2].style.size, "216mm");
}, "@page size descriptor is parsed and serialized from CSS");
test(() => {
assert_equals(styleSheet.cssRules[0].style.pageOrientation, "rotate-right");
assert_equals(styleSheet.cssRules[0].style.getPropertyValue("page-orientation"), "rotate-right",
'Value of page-orientation should match pageOrientation from CSS');
}, "@page page-orientation descriptor is parsed and serialized from CSS");
test(() => {
// Ensure we can set the size property to a valid value.
styleSheet.cssRules[2].style.size = "portrait";
assert_equals(styleSheet.cssRules[2].style.size, "portrait",
'Should have been able to set size property to "portrait" on CSSPageDescriptors');
// Ensure we cannot set the size property to an invalid property.
styleSheet.cssRules[2].style.size = "notarealsize";
assert_equals(styleSheet.cssRules[2].style.size, "portrait",
'Should not have been able to set size property to "notarealsize" on CSSPageDescriptors');
}, "@page size descriptor can be set from script");
test(() => {
// Ensure we can set the orientation property to a valid value.
styleSheet.cssRules[2].style.pageOrientation = "rotate-left";
assert_equals(styleSheet.cssRules[2].style.pageOrientation, "rotate-left",
'Should have been able to set pageOrientation property to "rotate-left" on CSSPageDescriptors');
assert_equals(styleSheet.cssRules[2].style.getPropertyValue("page-orientation"), "rotate-left",
'Value of page-orientation should match pageOrientation after setting from script');
// Ensure we cannot set the orientation property to an invalid property.
styleSheet.cssRules[2].style.pageOrientation = "schmotate-schmeft";
assert_equals(styleSheet.cssRules[2].style.pageOrientation, "rotate-left",
'Should not have been able to set pageOrientation property to "schmotate-schmeft" on CSSPageDescriptors');
}, "@page page-orientation descriptor can be set from script");
test(() => {
// Ensure we cannot set invalid page properties.
styleSheet.cssRules[2].style.setProperty("float", "left");
assert_equals(styleSheet.cssRules[2].style.cssFloat, undefined);
}, "CSSPageDescriptors does not expose properties that are not @page descriptors");
test(() => {
assert_equals(styleSheet.cssRules[0].style.marginLeft, "101.5mm");
assert_equals(styleSheet.cssRules[0].style.marginRight, "24px");
assert_equals(styleSheet.cssRules[0].style.marginTop, "1em");
assert_equals(styleSheet.cssRules[0].style.marginBottom, "2in");
}, "@page margin descriptor expands to its longhands");
marginNames.forEach(function(name){
test(() => {
let name1 = "margin-" + name;
let name2 = "margin" + name[0].toUpperCase() + name.slice(1);
assert_equals(styleSheet.cssRules[0].style[name1],
styleSheet.cssRules[0].style[name2],
"CSSPageDescriptors " + name1 + " and " + name2 + " should be the same.");
// Attempt setting through each name and ensure it is represented in the other.
styleSheet.cssRules[0].style[name1] = "99px";
assert_equals(styleSheet.cssRules[0].style[name1], "99px",
"Should have been able to set " + name1 + " property on CSSPageDescriptors");
assert_equals(styleSheet.cssRules[0].style[name2], "99px",
"Setting " + name1 + " on CSSPageDescriptors should also set " + name2);
styleSheet.cssRules[0].style[name2] = "216px";
assert_equals(styleSheet.cssRules[0].style[name2], "216px",
"Should have been able to set " + name2 + " property on CSSPageDescriptors");
assert_equals(styleSheet.cssRules[0].style[name1], "216px",
"Setting " + name2 + " on CSSPageDescriptors should also set " + name1);
}, `@page margin-${name} and margin${name[0].toUpperCase() + name.slice(1)} are aliases`);
});
</script>
</body>
</html>