d13dcdb686e8c01271b19e82819c88c8e9fd6eed
[WebKit-https.git] / LayoutTests / printing / page-format-data.html
1 <!DOCTYPE html>
2 <html>
3 <head id="head_element">
4 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
5 <script src="../fast/js/resources/js-test-pre.js"></script>
6 <style>
7 </style>
8 </head>
9 <body>
10 <p id="description"></p>
11 <div id="console"></div>
12 <script>
13     description("This tests page format data");
14
15     function appendStyle(styleString)
16     {
17         var styleElement = document.createElement("style");
18         styleElement.innerHTML = styleString;
19         document.getElementById("head_element").appendChild(styleElement);
20     }
21
22     function inchSize(width, height)
23     {
24         return "(" + Math.floor(width * 96) + "," + Math.floor(height * 96) + ")";
25     }
26
27     function mmSize(width, height)
28     {
29         return "(" + Math.floor(width * 96 / 25.4) + "," + Math.floor(height * 96 / 25.4) + ")";
30     }
31
32     if (window.layoutTestController) {
33         layoutTestController.dumpAsText();
34
35         // Page box visibility tests.
36
37         debug("Test default visibility");
38         shouldBe("layoutTestController.isPageBoxVisible(0)", "true");
39
40         debug("Test display: none. display property doesn't apply to @page");
41         appendStyle("@page {display:none;}");
42         shouldBe("layoutTestController.isPageBoxVisible(0)", "true");
43
44         debug("Test display: inline. display property doesn't apply to @page");
45         appendStyle("@page {display:inline;}");
46         shouldBe("layoutTestController.isPageBoxVisible(0)", "true");
47
48         debug("Test visibility: hidden");
49         appendStyle("@page {visibility:hidden;}");
50         shouldBe("layoutTestController.isPageBoxVisible(0)", "false");
51
52         debug("Test visibility: visible");
53         appendStyle("@page {visibility:visible;}");
54         shouldBe("layoutTestController.isPageBoxVisible(0)", "true");
55
56         debug("");
57
58         // Page size tests
59
60         debug("Test default page size");
61         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(8.5, 11)"); // Letter
62
63         debug("Test auto page size");
64         appendStyle("@page {size:auto;}");
65         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(8.5, 11)");
66
67         debug("Test landscape");
68         appendStyle("@page {size:landscape;}");
69         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(11, 8.5)");
70
71         debug("Test portrait");
72         appendStyle("@page {size:portrait;}");
73         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(8.5, 11)");
74
75         debug("Test a5");
76         appendStyle("@page {size:a5;}");
77         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(148, 210)");
78
79         debug("Test a5 landscape");
80         appendStyle("@page {size:a5 landscape;}");
81         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(210, 148)");
82
83         debug("Test portrait a4");
84         appendStyle("@page {size:portrait a4;}");
85         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(210, 297)");
86
87         debug("Test a3");
88         appendStyle("@page {size:a3;}");
89         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(297, 420)");
90
91         debug("Test b5");
92         appendStyle("@page {size:b5;}");
93         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(176, 250)");
94
95         debug("Test b4");
96         appendStyle("@page {size:b4;}");
97         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(250, 353)");
98
99         debug("Test letter");
100         appendStyle("@page {size:letter;}");
101         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(8.5, 11)");
102
103         debug("Test legal");
104         appendStyle("@page {size:legal;}");
105         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(8.5, 14)");
106
107         debug("Test ledger");
108         appendStyle("@page {size:ledger;}");
109         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "inchSize(11, 17)");
110
111         debug("Test 10cm");
112         appendStyle("@page {size:10cm;}");
113         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(100, 100)");
114
115         debug("Test 20cm x 30cm");
116         appendStyle("@page {size:20cm 30cm;}");
117         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "mmSize(200, 300)");
118
119         debug("Test 10000px 20000px");
120         appendStyle("@page {size:10000px 20000px;}");
121         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
122
123         debug("Test invalid page size: -10cm");
124         appendStyle("@page {size:-10cm;}");
125         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
126
127         debug("Test invalid page size: a4 a4");
128         appendStyle("@page {size:a4 a4;}");
129         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
130
131         debug("Test invalid page size: landscape portrait");
132         appendStyle("@page {size:landscape portrait;}");
133         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
134
135         debug("Test invalid page size: 10cm letter");
136         appendStyle("@page {size:10cm letter;}");
137         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
138
139         debug("Test invalid page size: 10cm 10cm 10cm");
140         appendStyle("@page {size:10cm 10cm 10cm;}");
141         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
142
143         debug("Test invalid page size: empty");
144         appendStyle("@page {size:;}");
145         shouldBe("layoutTestController.preferredPageSizeInPixels(0)", "'(10000,20000)'");
146
147         debug("");
148
149         // Page area tests
150
151         debug("Test page area when margin, padding, and border are 0px");
152         appendStyle("@page {margin:0px;padding:0px;border:0px;}");
153         shouldBe("layoutTestController.pageAreaRectInPixels(0)", "'(0,0,10000,20000)'");
154
155         debug("Test non-zero margin, padding, and border");
156         appendStyle("@page {margin:1px 2px 4px 8px; padding:16px 32px 64px 128px; border-width:256px 512px 1024px 2048px;}"); // top, right, bottom, left
157         shouldBe("layoutTestController.pageAreaRectInPixels(0)", "'(2184,273,7270,18635)'");
158
159         debug("Test percentage margin and padding");
160         appendStyle("@page {margin:20% 10%; padding:5%; border-width:0px;}");
161         shouldBe("layoutTestController.pageAreaRectInPixels(0)", "'(1500,2500,7000,15000)'");
162
163         debug("Test visibility: hidden");
164         appendStyle("@page {visibility:hidden}");
165         shouldBe("layoutTestController.pageAreaRectInPixels(0)", "'(1500,2500,7000,15000)'");
166
167         debug("");
168
169     } else {
170         testFailed("This test can be run only with window.layoutTestController");
171     }
172     var successfullyParsed = true;
173 </script>
174 <script src="../fast/js/resources/js-test-post.js"></script>
175 </body>
176 </html>