0b5aaa08d2f504cfb6e651be8b9123326c3a8395
[WebKit-https.git] / LayoutTests / printing / page-rule-selection.html
1 <!DOCTYPE html>
2 <html id="html_element">
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 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
10 <script>
11     description("This tests page style selection.");
12
13     function appendStyle(styleString)
14     {
15         var styleElement = document.createElement("style");
16         styleElement.innerHTML = styleString;
17         document.getElementById("head_element").appendChild(styleElement);
18     }
19
20     if (window.layoutTestController) {
21         layoutTestController.dumpAsText();
22
23         debug("Default margin is 1in = 96px.");
24         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 0)", "96");
25         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 1)", "96");
26         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 2)", "96");
27         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 3)", "96");
28         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 4)", "96");
29
30         debug("Set margin to 200px via user style sheet.");
31         layoutTestController.addUserStyleSheet("@page { margin:200px; }");
32         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 0)", "200");
33         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 1)", "200");
34         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 2)", "200");
35         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 3)", "200");
36         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 4)", "200");
37
38         debug("Set margin to 100px.");
39         appendStyle("@page { margin:100px; }");
40         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 0)", "100");
41         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 1)", "100");
42         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 2)", "100");
43         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 3)", "100");
44         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 4)", "100");
45
46         debug("Set margin for right pages to 50px. The first page is a right page.");
47         appendStyle("@page :right { margin:50px; }");
48         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 0)", "50");
49         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 1)", "100");
50         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 2)", "50");
51         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 3)", "100");
52         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 4)", "50");
53
54         debug("Set margin for left pages to 75px.");
55         appendStyle("@page :left { margin:75px; }");
56         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 0)", "50");
57         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 1)", "75");
58         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 2)", "50");
59         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 3)", "75");
60         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 4)", "50");
61
62         debug("Set margin for the first page to 125px.");
63         appendStyle("@page :first { margin:125px; }");
64         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 0)", "125");
65         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 1)", "75");
66         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 2)", "50");
67         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 3)", "75");
68         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 4)", "50");
69
70         debug("Change the document direction to RTL. This makes the first page a left page.");
71         document.getElementById("html_element").setAttribute("dir", "rtl");
72         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 0)", "125");
73         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 1)", "50");
74         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 2)", "75");
75         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 3)", "50");
76         shouldBeEqualToString("layoutTestController.pageProperty('margin-left', 4)", "75");
77
78         debug("Check font update and line height override.");
79         appendStyle("@page { line-height:1em; }");
80         appendStyle("@page { font-family:Futura; }");
81         appendStyle("@page { font:15px/6em Arial; }");
82         appendStyle("@page { zoom:200%; }");
83         shouldBeEqualToString("layoutTestController.pageProperty('line-height', 0)", "180");
84         shouldBeEqualToString("layoutTestController.pageProperty('font-family', 0)", "Arial");
85         shouldBeEqualToString("layoutTestController.pageProperty('font-size', 0)", "30");
86         appendStyle("@page { zoom:100%; }");
87     } else {
88         testFailed("This test can be run only with window.layoutTestController");
89     }
90     var successfullyParsed = true;
91 </script>
92 <script src="../fast/js/resources/js-test-post.js"></script>
93 </body>
94 </html>