Repository navigation
Expand file tree
/
Copy pathpage-descriptors.html
More file actions
119 lines (109 loc) · 5.49 KB
/
Copy pathpage-descriptors.html
File metadata and controls
119 lines (109 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE HTML>
<html>
<head>
<link rel="author" title="Mozilla" href="https://mozilla.org">
<link rel="author" title="Andrew Martinez" href="https://github.com/AndrewJMart">
<link rel="help" href="https://drafts.csswg.org/cssom/#the-cssstyledeclaration-interface">
<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>