Revision control

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