blob: eaccdf357e8c9baa88d406e51069b11dd93b3342 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head id="head_element">
<script src="../resources/js-test-pre.js"></script>
<style>
</style>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("This tests page format data");
function appendStyle(styleString)
{
var styleElement = document.createElement("style");
styleElement.innerHTML = styleString;
document.getElementById("head_element").appendChild(styleElement);
}
function inchSize(width, height)
{
return "(" + Math.floor(width * 96) + ", " + Math.floor(height * 96) + ")";
}
function mmSize(width, height)
{
return "(" + Math.floor(width * 96 / 25.4) + ", " + Math.floor(height * 96 / 25.4) + ")";
}
function pxMargins(top, right, bottom, left)
{
return " " + top + " " + right + " " + bottom + " " + left;
}
if (window.testRunner) {
testRunner.dumpAsText();
// Page box visibility tests.
debug("Test default visibility");
shouldBe("internals.isPageBoxVisible(0)", "true");
debug("Test display: none. display property doesn't apply to @page");
appendStyle("@page {display:none;}");
shouldBe("internals.isPageBoxVisible(0)", "true");
debug("Test display: inline. display property doesn't apply to @page");
appendStyle("@page {display:inline;}");
shouldBe("internals.isPageBoxVisible(0)", "true");
debug("Test visibility: hidden");
appendStyle("@page {visibility:hidden;}");
shouldBe("internals.isPageBoxVisible(0)", "false");
debug("Test visibility: visible");
appendStyle("@page {visibility:visible;}");
shouldBe("internals.isPageBoxVisible(0)", "true");
debug("");
// Page size tests
debug("Test default page size");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(100, 200)' + pxMargins(1, 2, 3, 4)");
debug("Test auto page size");
appendStyle("@page {size:auto;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(100, 200)' + pxMargins(1, 2, 3, 4)");
debug("Test landscape");
appendStyle("@page {size:landscape;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(200, 100)' + pxMargins(1, 2, 3, 4)");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 200, 100, 1, 2, 3, 4)", "'(200, 100)' + pxMargins(1, 2, 3, 4)");
debug("Test portrait");
appendStyle("@page {size:portrait;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(100, 200)' + pxMargins(1, 2, 3, 4)");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 200, 100, 1, 2, 3, 4)", "'(100, 200)' + pxMargins(1, 2, 3, 4)");
debug("Test a5");
appendStyle("@page {size:a5;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(148, 210) + pxMargins(1, 2, 3, 4)");
debug("Test a5 landscape");
appendStyle("@page {size:a5 landscape;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(210, 148) + pxMargins(1, 2, 3, 4)");
debug("Test portrait a4");
appendStyle("@page {size:portrait a4;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(210, 297) + pxMargins(1, 2, 3, 4)");
debug("Test a3");
appendStyle("@page {size:a3;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(297, 420) + pxMargins(1, 2, 3, 4)");
debug("Test b5");
appendStyle("@page {size:b5;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(176, 250) + pxMargins(1, 2, 3, 4)");
debug("Test b4");
appendStyle("@page {size:b4;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(250, 353) + pxMargins(1, 2, 3, 4)");
debug("Test letter");
appendStyle("@page {size:letter;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "inchSize(8.5, 11) + pxMargins(1, 2, 3, 4)");
debug("Test legal");
appendStyle("@page {size:legal;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "inchSize(8.5, 14) + pxMargins(1, 2, 3, 4)");
debug("Test ledger");
appendStyle("@page {size:ledger;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "inchSize(11, 17) + pxMargins(1, 2, 3, 4)");
debug("Test 10cm");
appendStyle("@page {size:10cm;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(100, 100) + pxMargins(1, 2, 3, 4)");
debug("Test 20cm x 30cm");
appendStyle("@page {size:20cm 30cm;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "mmSize(200, 300) + pxMargins(1, 2, 3, 4)");
debug("Test 10000px 20000px");
appendStyle("@page {size:10000px 20000px;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("Test invalid page size: -10cm");
appendStyle("@page {size:-10cm;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("Test invalid page size: a4 a4");
appendStyle("@page {size:a4 a4;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("Test invalid page size: landscape portrait");
appendStyle("@page {size:landscape portrait;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("Test invalid page size: 10cm letter");
appendStyle("@page {size:10cm letter;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("Test invalid page size: 10cm 10cm 10cm");
appendStyle("@page {size:10cm 10cm 10cm;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("Test invalid page size: empty");
appendStyle("@page {size:;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 2, 3, 4)");
debug("");
// Margin tests
debug("Test 0px margins");
appendStyle("@page {margin:0px;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(0, 0, 0, 0)");
debug("Test non-zero margins");
appendStyle("@page {margin:10px 20px 40px 80px;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(10, 20, 40, 80)");
debug("Test percentage margin");
appendStyle("@page {margin: 8% 4% 2% 1%;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 400, 200, 100)");
debug("Test margin: auto 4% 2% 1%");
appendStyle("@page {margin: auto 4% 2% 1%;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(1, 400, 200, 100)");
debug("Test margin: 8% auto 2% 1%");
appendStyle("@page {margin: 8% auto 2% 1%;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 2, 200, 100)");
debug("Test margin: 8% 4% auto 1%");
appendStyle("@page {margin: 8% 4% auto 1%;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 400, 3, 100)");
debug("Test margin: 8% 4% 2% auto");
appendStyle("@page {margin: 8% 4% 2% auto;}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 400, 200, 4)");
debug("Test visibility: hidden");
appendStyle("@page {visibility:hidden}");
shouldBe("internals.pageSizeAndMarginsInPixels(0, 100, 200, 1, 2, 3, 4)", "'(10000, 20000)' + pxMargins(800, 400, 200, 4)");
debug("");
} else {
testFailed("This test can be run only with window.testRunner");
}
</script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>