2 <html id=
"html_element">
3 <head id=
"head_element">
4 <script src=
"../resources/js-test.js"></script>
7 <p id=
"description"></p>
8 <div id=
"console"></div>
10 description("This tests page style selection.");
12 function appendStyle(styleString
)
14 var styleElement
= document
.createElement("style");
15 styleElement
.innerHTML
= styleString
;
16 document
.getElementById("head_element").appendChild(styleElement
);
19 if (window
.testRunner
) {
20 testRunner
.dumpAsText();
22 debug("Default margin is auto.");
23 shouldBeEqualToString("internals.pageProperty('margin-left', 0)", "auto");
24 shouldBeEqualToString("internals.pageProperty('margin-left', 1)", "auto");
25 shouldBeEqualToString("internals.pageProperty('margin-left', 2)", "auto");
26 shouldBeEqualToString("internals.pageProperty('margin-left', 3)", "auto");
27 shouldBeEqualToString("internals.pageProperty('margin-left', 4)", "auto");
29 debug("Set margin to 100px.");
30 appendStyle("@page { margin:100px; }");
31 shouldBeEqualToString("internals.pageProperty('margin-left', 0)", "100");
32 shouldBeEqualToString("internals.pageProperty('margin-left', 1)", "100");
33 shouldBeEqualToString("internals.pageProperty('margin-left', 2)", "100");
34 shouldBeEqualToString("internals.pageProperty('margin-left', 3)", "100");
35 shouldBeEqualToString("internals.pageProperty('margin-left', 4)", "100");
37 debug("Set margin for right pages to 50px. The first page is a right page.");
38 appendStyle("@page :right { margin:50px; }");
39 shouldBeEqualToString("internals.pageProperty('margin-left', 0)", "50");
40 shouldBeEqualToString("internals.pageProperty('margin-left', 1)", "100");
41 shouldBeEqualToString("internals.pageProperty('margin-left', 2)", "50");
42 shouldBeEqualToString("internals.pageProperty('margin-left', 3)", "100");
43 shouldBeEqualToString("internals.pageProperty('margin-left', 4)", "50");
45 debug("Set margin for left pages to 75px.");
46 appendStyle("@page :left { margin:75px; }");
47 shouldBeEqualToString("internals.pageProperty('margin-left', 0)", "50");
48 shouldBeEqualToString("internals.pageProperty('margin-left', 1)", "75");
49 shouldBeEqualToString("internals.pageProperty('margin-left', 2)", "50");
50 shouldBeEqualToString("internals.pageProperty('margin-left', 3)", "75");
51 shouldBeEqualToString("internals.pageProperty('margin-left', 4)", "50");
53 debug("Set margin for the first page to 125px.");
54 appendStyle("@page :first { margin:125px; }");
55 shouldBeEqualToString("internals.pageProperty('margin-left', 0)", "125");
56 shouldBeEqualToString("internals.pageProperty('margin-left', 1)", "75");
57 shouldBeEqualToString("internals.pageProperty('margin-left', 2)", "50");
58 shouldBeEqualToString("internals.pageProperty('margin-left', 3)", "75");
59 shouldBeEqualToString("internals.pageProperty('margin-left', 4)", "50");
61 debug("Change the document direction to RTL. This makes the first page a left page.");
62 document
.getElementById("html_element").setAttribute("dir", "rtl");
63 shouldBeEqualToString("internals.pageProperty('margin-left', 0)", "125");
64 shouldBeEqualToString("internals.pageProperty('margin-left', 1)", "50");
65 shouldBeEqualToString("internals.pageProperty('margin-left', 2)", "75");
66 shouldBeEqualToString("internals.pageProperty('margin-left', 3)", "50");
67 shouldBeEqualToString("internals.pageProperty('margin-left', 4)", "75");
69 debug("Check font update and line height override.");
70 appendStyle("@page { line-height:1em; }");
71 appendStyle("@page { font-family:Futura; }");
72 appendStyle("@page { font:15px/6em Arial; }");
73 appendStyle("@page { zoom:200%; }");
74 shouldBeEqualToString("internals.pageProperty('line-height', 0)", "180");
75 shouldBeEqualToString("internals.pageProperty('font-family', 0)", "Arial");
76 shouldBeEqualToString("internals.pageProperty('font-size', 0)", "30");
77 appendStyle("@page { zoom:100%; }");
79 debug("Check @media rules.");
80 appendStyle("@page { size:100px 200px; }");
81 shouldBeEqualToString("internals.pageProperty('size', 0)", "100 200");
82 appendStyle("@media print { @page { size:150px 250px; } }");
83 shouldBeEqualToString("internals.pageProperty('size', 0)", "150 250");
84 appendStyle("@media screen { @page { size:300px 500px; } }");
85 shouldBeEqualToString("internals.pageProperty('size', 0)", "150 250");
88 testFailed("This test can be run only with window.testRunner");