3 <head id="head_element">
4 <script src="../fast/js/resources/js-test-pre.js"></script>
9 <p id="description"></p>
10 <div id="console"></div>
12 description("This tests page format data");
14 function appendStyle(styleString)
16 var styleElement = document.createElement("style");
17 styleElement.innerHTML = styleString;
18 document.getElementById("head_element").appendChild(styleElement);
21 function inchSize(width, height)
23 return "(" + Math.floor(width * 96) + ", " + Math.floor(height * 96) + ")";
26 function mmSize(width, height)
28 return "(" + Math.floor(width * 96 / 25.4) + ", " + Math.floor(height * 96 / 25.4) + ")";
31 function pxMargins(top, right, bottom, left)
33 return " " + top + " " + right + " " + bottom + " " + left;
36 if (window.testRunner) {
37 testRunner.dumpAsText();
39 // Page box visibility tests.
41 debug("Test default visibility");
42 shouldBe("internals.isPageBoxVisible(document, 0)", "true");
44 debug("Test display: none. display property doesn't apply to @page");
45 appendStyle("@page {display:none;}");
46 shouldBe("internals.isPageBoxVisible(document, 0)", "true");
48 debug("Test display: inline. display property doesn't apply to @page");
49 appendStyle("@page {display:inline;}");
50 shouldBe("internals.isPageBoxVisible(document, 0)", "true");
52 debug("Test visibility: hidden");
53 appendStyle("@page {visibility:hidden;}");
54 shouldBe("internals.isPageBoxVisible(document, 0)", "false");
56 debug("Test visibility: visible");
57 appendStyle("@page {visibility:visible;}");
58 shouldBe("internals.isPageBoxVisible(document, 0)", "true");
64 debug("Test default page size");
65 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(100, 200)' + pxMargins(1, 2, 3, 4)");
67 debug("Test auto page size");
68 appendStyle("@page {size:auto;}");
69 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(100, 200)' + pxMargins(1, 2, 3, 4)");
71 debug("Test landscape");
72 appendStyle("@page {size:landscape;}");
73 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(200, 100)' + pxMargins(1, 2, 3, 4)");
74 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 200, 100, 1, 2, 3, 4)", "'(200, 100)' + pxMargins(1, 2, 3, 4)");
76 debug("Test portrait");
77 appendStyle("@page {size:portrait;}");
78 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(100, 200)' + pxMargins(1, 2, 3, 4)");
79 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 200, 100, 1, 2, 3, 4)", "'(100, 200)' + pxMargins(1, 2, 3, 4)");
82 appendStyle("@page {size:a5;}");
83 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(148, 210) + pxMargins(1, 2, 3, 4)");
85 debug("Test a5 landscape");
86 appendStyle("@page {size:a5 landscape;}");
87 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(210, 148) + pxMargins(1, 2, 3, 4)");
89 debug("Test portrait a4");
90 appendStyle("@page {size:portrait a4;}");
91 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(210, 297) + pxMargins(1, 2, 3, 4)");
94 appendStyle("@page {size:a3;}");
95 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(297, 420) + pxMargins(1, 2, 3, 4)");
98 appendStyle("@page {size:b5;}");
99 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(176, 250) + pxMargins(1, 2, 3, 4)");
102 appendStyle("@page {size:b4;}");
103 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(250, 353) + pxMargins(1, 2, 3, 4)");
105 debug("Test letter");
106 appendStyle("@page {size:letter;}");
107 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "inchSize(8.5, 11) + pxMargins(1, 2, 3, 4)");
110 appendStyle("@page {size:legal;}");
111 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "inchSize(8.5, 14) + pxMargins(1, 2, 3, 4)");
113 debug("Test ledger");
114 appendStyle("@page {size:ledger;}");
115 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "inchSize(11, 17) + pxMargins(1, 2, 3, 4)");
118 appendStyle("@page {size:10cm;}");
119 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(100, 100) + pxMargins(1, 2, 3, 4)");
121 debug("Test 20cm x 30cm");
122 appendStyle("@page {size:20cm 30cm;}");
123 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(200, 300) + pxMargins(1, 2, 3, 4)");
125 debug("Test 10000px 20000px");
126 appendStyle("@page {size:10000px 20000px;}");
127 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
129 debug("Test invalid page size: -10cm");
130 appendStyle("@page {size:-10cm;}");
131 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
133 debug("Test invalid page size: a4 a4");
134 appendStyle("@page {size:a4 a4;}");
135 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
137 debug("Test invalid page size: landscape portrait");
138 appendStyle("@page {size:landscape portrait;}");
139 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
141 debug("Test invalid page size: 10cm letter");
142 appendStyle("@page {size:10cm letter;}");
143 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
145 debug("Test invalid page size: 10cm 10cm 10cm");
146 appendStyle("@page {size:10cm 10cm 10cm;}");
147 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
149 debug("Test invalid page size: empty");
150 appendStyle("@page {size:;}");
151 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
157 debug("Test 0px margins");
158 appendStyle("@page {margin:0px;}");
159 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(0, 0, 0, 0)");
161 debug("Test non-zero margins");
162 appendStyle("@page {margin:10px 20px 40px 80px;}");
163 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(10, 20, 40, 80)");
165 debug("Test percentage margin");
166 appendStyle("@page {margin: 8% 4% 2% 1%;}");
167 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 400, 200, 100)");
169 debug("Test margin: auto 4% 2% 1%");
170 appendStyle("@page {margin: auto 4% 2% 1%;}");
171 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 400, 200, 100)");
173 debug("Test margin: 8% auto 2% 1%");
174 appendStyle("@page {margin: 8% auto 2% 1%;}");
175 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 2, 200, 100)");
177 debug("Test margin: 8% 4% auto 1%");
178 appendStyle("@page {margin: 8% 4% auto 1%;}");
179 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 400, 3, 100)");
181 debug("Test margin: 8% 4% 2% auto");
182 appendStyle("@page {margin: 8% 4% 2% auto;}");
183 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 400, 200, 4)");
185 debug("Test visibility: hidden");
186 appendStyle("@page {visibility:hidden}");
187 shouldBe("testRunner.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 400, 200, 4)");
192 testFailed("This test can be run only with window.testRunner");
195 <script src="../fast/js/resources/js-test-post.js"></script>