1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993
|
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<window onload="runTests()"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<iframe style="min-height: 200px; min-width: 600px" type="content"></iframe>
<iframe style="min-height: 200px; min-width: 600px" type="content"></iframe>
<script type="application/javascript">
<![CDATA[
// Note: We can't use window.frames directly here because the type="content"
// attributes isolate the frames into their own BrowsingContext hierarchies.
let frameElts = document.getElementsByTagName("iframe");
var is = window.arguments[0].is;
var isnot = window.arguments[0].isnot;
var ok = window.arguments[0].ok;
var todo = window.arguments[0].todo;
var info = window.arguments[0].info;
var SimpleTest = window.arguments[0].SimpleTest;
var gWbp;
var gPrintPreviewWindow;
var gPrintPreviewBrowser;
var ctx1;
var ctx2;
var counter = 0;
var file = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("TmpD", Ci.nsIFile);
filePath = file.path;
function printpreview(options = {}) {
let resolve;
let promise = new Promise(r => { resolve = r });
var listener = {
onLocationChange: function(webProgress, request, location, flags) { },
onProgressChange: function(webProgress, request, curSelfProgress,
maxSelfProgress, curTotalProgress,
maxTotalProgress) {
info("onProgressChange", [...arguments].join(", "));
},
onSecurityChange: function(webProgress, request, state) { },
onStateChange: function(webProgress, request, stateFlags, status) {
info("onStateChange", [...arguments].join(", "));
if (stateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
setTimeout(resolve, 0);
}
},
onStatusChange: function(webProgress, request, status, message) {
info("onStatusChange", [...arguments].join(", "));
},
onContentBlockingEvent: function(webProgress, request, event) {
info("onContentBlockingEvent", [...arguments].join(", "));
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIWebProgressListener) ||
iid.equals(Ci.nsISupportsWeakReference))
return this;
throw Components.Exception("", Cr.NS_NOINTERFACE);
}
}
var settings = Cc["@mozilla.org/gfx/printsettings-service;1"]
.getService(Ci.nsIPrintSettingsService).createNewPrintSettings();
settings.printBGColors = true;
settings.headerStrLeft = "";
settings.headerStrRight = "";
settings.footerStrLeft = "";
settings.footerStrRight = "";
settings.unwriteableMarginTop = 0;
settings.unwriteableMarginRight = 0;
settings.unwriteableMarginLeft = 0;
settings.unwriteableMarginBottom = 0;
if (options.settings) {
for (let key in options.settings) {
settings[key] = options.settings[key];
}
}
var before = 0;
var after = 0;
function beforeprint() { ++before; }
function afterprint() { ++after; }
frameElts[0].contentWindow.addEventListener("beforeprint", beforeprint, true);
frameElts[0].contentWindow.addEventListener("afterprint", afterprint, true);
{
let bc = frameElts[0].contentWindow.browsingContext;
let browser = document.createXULElement("browser");
browser.setAttribute("type", "content");
browser.style.minHeight = "800px";
browser.style.maxWidth = browser.style.minWidth = "800px";
browser.setAttribute("initialBrowsingContextGroupId", bc.group.id);
browser.setAttribute("nodefaultsrc", "true");
document.documentElement.appendChild(browser);
gPrintPreviewBrowser = browser;
// Force docViewer creation and layout.
browser.browsingContext.docShell.document;
browser.getBoundingClientRect();
gPrintPreviewWindow = frameElts[0].contentWindow.printPreview(settings, listener, browser.browsingContext.docShell);
}
gWbp = gPrintPreviewWindow.docShell.docViewer;
gWbp.QueryInterface(Ci.nsIWebBrowserPrint);
is(before, 1, "Should have called beforeprint listener!");
if (!options.hasMozPrintCallback) {
// If there's a mozPrintCallback the after print event won't fire until
// later.
is(after, 1, "Should have called afterprint listener!");
}
frameElts[0].contentWindow.removeEventListener("beforeprint", beforeprint, true);
frameElts[0].contentWindow.removeEventListener("afterprint", afterprint, true);
return promise;
}
function exitprintpreview() {
gPrintPreviewWindow.docShell.exitPrintPreview();
gPrintPreviewBrowser.remove();
}
function finish() {
SimpleTest.finish();
window.close();
}
async function runTests()
{
// This ensures we actually test the lazy-load of images in printpreview_images.
await SpecialPowers.pushPrefEnv({
set: [
["dom.image-lazy-loading.root-margin.top", 0],
["dom.image-lazy-loading.root-margin.bottom", 0],
["dom.image-lazy-loading.root-margin.left", 0],
["dom.image-lazy-loading.root-margin.right", 0],
],
});
startTest1();
}
function compareCanvases(options = {}) {
const canvas1 = document.getElementsByTagName("canvas")[0];
const canvas2 = document.getElementsByTagName("canvas")[1];
let maxDifference = {};
const differingPixels = window.windowUtils.compareCanvases(canvas1, canvas2, maxDifference);
if (differingPixels) {
todo(false, "different: " + differingPixels + ", maxDifference: " + maxDifference.value);
todo(false, "TEST CASE: " + canvas1.toDataURL());
todo(false, "REFERENCE: " + canvas2.toDataURL());
}
let maxAllowedDifferent = options.maxDifferent || 0;
let maxAllowedDifference = options.maxDifference || 0;
return differingPixels <= maxAllowedDifferent && maxDifference.value <= maxAllowedDifference;
}
function addHTMLContent(parent) {
var n = parent.ownerDocument.createElement("div");
parent.appendChild(n);
var s = "<iframe width='500' height='40' src='data:text/plain,ThisIsAnIframeCreatedDuringPrintPreview'></iframe>";
s += "<table>";
for (var i = 1; i < 501; ++i) {
s += "<tr><td>Cell A" + i + "</td><td>Cell B" + i + "</td><td>Cell C" + i + "</td></tr>";
}
s += "</table>";
n.innerHTML = s;
}
async function startTest1() {
ctx1 = document.getElementsByTagName("canvas")[0].getContext("2d");
ctx2 = document.getElementsByTagName("canvas")[1].getContext("2d");
frameElts[0].contentDocument.body.innerHTML = "<div> </div><div>" + counter + " timers</div><div> </div>";
// Note this timeout is needed so that we can check that timers run
// after print preview, but not during it.
frameElts[0].contentWindow.wrappedJSObject.counter = counter;
frameElts[0].contentWindow.counterTimeout = "document.body.firstChild.nextSibling.innerHTML = ++counter + ' timers';" +
"window.setTimeout(counterTimeout, 0);";
frameElts[0].contentWindow.setTimeout(frameElts[0].contentWindow.counterTimeout, 0);
frameElts[0].contentDocument.body.firstChild.innerHTML = "Print preview";
await printpreview();
drawPrintPreviewWindow(ctx1);
frameElts[0].contentDocument.body.firstChild.innerHTML = "Galley presentation";
// Add some elements.
addHTMLContent(frameElts[0].contentDocument.body.lastChild);
// Delete them.
frameElts[0].contentDocument.body.lastChild.innerHTML = "";
// And readd.
addHTMLContent(frameElts[0].contentDocument.body.lastChild);
setTimeout(finalizeTest1, 1000);
}
function finalizeTest1() {
drawPrintPreviewWindow(ctx2);
exitprintpreview();
ok(compareCanvases(), "Canvas should be the same!");
counter = frameElts[0].contentWindow.counter;
// This timeout is needed so that we can check that timers do run after
// print preview.
setTimeout(runTest2, 1000);
}
function runTest2() {
isnot(frameElts[0].contentDocument.body.firstChild.nextSibling.textContent, "0 timers", "Timers should have run!");
isnot(frameElts[0].contentWindow.counter, 0, "Timers should have run!");
counter = frameElts[0].contentWindow.counter;
frameElts[0].contentWindow.counterTimeout = "";
setTimeout(runTest3, 0);
}
var elementIndex = 0;
var compareEmptyElement = true;
var emptyFormElements =
["<input type='text'>",
"<input type='password'>",
"<input type='file'>",
"<input type='button'>",
"<input type='submit'>",
"<input type='reset'>",
"<input type='checkbox'>",
"<input type='radio'>",
"<select></select>",
"<select size='5'></select>",
"<textarea></textarea>"];
var formElements =
["<input type='text' value='text'>",
"<input type='password' value='password'>",
"<input type='file' value='" + filePath + "'>",
"<input type='button' value='button'>",
"<input type='submit' value='submit button'>",
"<input type='reset' value='reset button'>",
"<input type='checkbox' checked>",
"<input type='radio' checked>",
"<select><option>option1</option></select>",
"<select size='5'><option>1</option><option>2</option><option>3</option></select>",
"<textarea value='textarea'>textarea</textarea>"];
function runTest3() {
if (compareEmptyElement) {
var currentIndex = elementIndex;
++elementIndex;
if (elementIndex >= emptyFormElements.length) {
elementIndex = 0;
compareEmptyElement = false;
}
compareFormElementPrint(emptyFormElements[currentIndex], emptyFormElements[currentIndex], true);
return;
} else if (elementIndex < emptyFormElements.length) {
var currentIndex = elementIndex;
++elementIndex;
compareFormElementPrint(emptyFormElements[currentIndex], formElements[currentIndex], false);
return;
}
setTimeout(runTest4, 0)
}
async function compareFormElementPrint(el1, el2, equals) {
frameElts[0].contentDocument.body.innerHTML = el1;
frameElts[0].contentDocument.body.firstChild.value =
frameElts[0].contentDocument.body.firstChild.getAttribute('value');
await printpreview();
drawPrintPreviewWindow(ctx1);
exitprintpreview();
frameElts[0].contentDocument.body.innerHTML = el2;
frameElts[0].contentDocument.body.firstChild.value =
frameElts[0].contentDocument.body.firstChild.getAttribute('value');
await printpreview();
drawPrintPreviewWindow(ctx2);
exitprintpreview();
is(compareCanvases(), equals,
"Comparing print preview didn't succeed [" + el1 + " : " + el2 + "]");
setTimeout(runTest3, 100);
}
// This is a crash test for bug 539060.
function runTest4() {
frameElts[0].contentDocument.body.innerHTML =
"<iframe style='display: none;' src='data:text/html,<iframe>'></iframe>";
setTimeout(runTest4end, 500);
}
async function runTest4end() {
await printpreview();
exitprintpreview();
runTest5();
}
// This is a crash test for bug 595337
async function runTest5() {
frameElts[0].contentDocument.body.innerHTML =
'<iframe style="position: fixed; visibility: hidden; bottom: 10em;"></iframe>' +
'<input contenteditable="true" style="display: table; page-break-before: left; width: 10000px;">';
await printpreview();
exitprintpreview();
setTimeout(runTest6, 0);
}
// Crash test for bug 878037
function runTest6() {
frameElts[0].contentDocument.body.innerHTML =
'<style> li { list-style-image: url("animated.gif"); } </style>' +
'<li>Firefox will crash if you try and print this page</li>';
setTimeout(runTest6end, 500);
}
async function runTest6end() {
await printpreview();
exitprintpreview();
requestAnimationFrame(function() { setTimeout(runTest7); } );
}
async function runTest7() {
var contentText = "<a href='#'>mozilla</a><input>test<select><option>option1</option></select>";
// Create normal content
frameElts[0].contentDocument.body.innerHTML =
"<div>" + contentText + "</div>";
frameElts[0].contentDocument.body.firstChild.value =
frameElts[0].contentDocument.body.firstChild.getAttribute('value');
await printpreview();
drawPrintPreviewWindow(ctx1);
exitprintpreview();
frameElts[0].contentDocument.body.innerHTML = "<div></div>";
var sr = frameElts[0].contentDocument.body.firstChild.attachShadow({mode: "open"});
sr.innerHTML = contentText;
await printpreview();
drawPrintPreviewWindow(ctx2);
exitprintpreview();
ok(compareCanvases(), "Printing light DOM and shadow DOM should create same output");
requestAnimationFrame(function() { setTimeout(runTest8); } );
}
async function runTest8() {
// Test that fonts loaded with CSS and JS are printed the same.
const iframeElement = document.getElementsByTagName("iframe")[0];
// First, snapshot the page with font defined in CSS.
await new Promise((resolve) => {
iframeElement.addEventListener("load", resolve, { capture: true, once: true });
iframeElement.setAttribute("src", "printpreview_font_api_ref.html");
});
await printpreview();
drawPrintPreviewWindow(ctx1);
exitprintpreview();
// Second, snapshot the page with font loaded in JS.
await new Promise((resolve) => {
iframeElement.addEventListener("message", resolve, { capture: true, once: true });
iframeElement.setAttribute("src", "printpreview_font_api.html");
});
await printpreview();
drawPrintPreviewWindow(ctx2);
exitprintpreview();
ok(compareCanvases(), "Printing pages with fonts loaded from CSS and JS should be the same.");
requestAnimationFrame(function() { setTimeout(runTest9); } );
}
// Test for bug 1487649
async function runTest9() {
frameElts[0].contentDocument.body.innerHTML = `
<svg width="100" height="100">
<rect width='100' height='100' fill='lime'/>
</svg>
`;
await printpreview();
drawPrintPreviewWindow(ctx1);
exitprintpreview();
frameElts[0].contentDocument.body.innerHTML = `
<svg width="100" height="100">
<defs>
<g id="useme">
<rect width='100' height='100' fill='lime'/>
</g>
</defs>
<use />
</svg>
`;
// Set the attribute explicitly because this is a chrome document, and the
// href attribute would get sanitized.
frameElts[0].contentDocument.querySelector("use").setAttribute("href", "#useme");
// Ensure the <use> shadow tree is created so we test what we want to test.
frameElts[0].contentDocument.body.offsetTop;
await printpreview();
drawPrintPreviewWindow(ctx2);
exitprintpreview();
ok(compareCanvases(), "Printing <use> subtrees should create same output");
requestAnimationFrame(function() { setTimeout(runTest10); } );
}
function drawPrintPreviewWindow(ctx) {
let width = gPrintPreviewWindow.innerWidth;
let height = gPrintPreviewWindow.innerHeight;
ctx.canvas.width = width;
ctx.canvas.height = height;
ctx.drawWindow(gPrintPreviewWindow, 0, 0, width, height, "rgb(255, 255, 255)");
}
// Test for bug 1524640
async function runTest10() {
// Test that fonts loaded during mozprint callback are loaded into the cloned
// document.
const iframeElement = document.getElementsByTagName("iframe")[0];
// First, snapshot the page with font defined in CSS.
await new Promise((resolve) => {
iframeElement.addEventListener("load", resolve, { capture: true, once: true });
iframeElement.setAttribute("src", "printpreview_font_mozprintcallback_ref.html");
});
let mozPrintCallbackDone = new Promise((resolve) => {
iframeElement.addEventListener("message", resolve, { capture: true, once: true });
});
await printpreview({ hasMozPrintCallback: true });
await mozPrintCallbackDone;
drawPrintPreviewWindow(ctx1);
exitprintpreview();
// Second, snapshot the page with font loaded in JS.
await new Promise((resolve) => {
iframeElement.addEventListener("load", resolve, { capture: true, once: true });
iframeElement.setAttribute("src", "printpreview_font_mozprintcallback.html");
});
mozPrintCallbackDone = new Promise((resolve) => {
iframeElement.addEventListener("message", resolve, { capture: true, once: true });
});
await printpreview({ hasMozPrintCallback: true });
// Wait for the mozprintcallback to finish.
await mozPrintCallbackDone;
drawPrintPreviewWindow(ctx2);
exitprintpreview();
ok(compareCanvases(), "Printing pages with fonts loaded from a mozPrintCallback should be the same.");
requestAnimationFrame(function() { setTimeout(runTest11); } );
}
async function compareFiles(src1, src2, options = {}) {
const BASE = "https://example.org/chrome/layout/base/tests/chrome/";
info(`Comparing ${src1} with ${src2}`);
const iframeElement = document.getElementsByTagName("iframe")[0];
let messagePromise = null;
if (options.waitForMessage) {
messagePromise = new Promise(resolve => {
iframeElement.addEventListener("message", resolve, { capture: true, once: true });
});
}
await new Promise((resolve) => {
iframeElement.addEventListener("load", resolve, { capture: true, once: true });
iframeElement.setAttribute("src", new URL(src1, BASE).href);
});
let mediaElements = iframeElement.contentDocument.querySelectorAll(
"audio, video"
);
for (let mediaElement of mediaElements) {
let { widget } = SpecialPowers.wrap(iframeElement.contentWindow)
.windowGlobalChild.getActor("UAWidgets")
.widgets.get(mediaElement);
await widget.impl.Utils.l10n.translateRoots();
}
if (messagePromise) {
info("awaiting for message to arrive");
await messagePromise;
}
await printpreview(options.test || options);
drawPrintPreviewWindow(ctx1);
exitprintpreview();
await new Promise((resolve) => {
iframeElement.addEventListener("load", resolve, { capture: true, once: true });
iframeElement.setAttribute("src", new URL(src2, BASE).href);
});
mediaElements = iframeElement.contentDocument.querySelectorAll(
"audio, video"
);
for (let mediaElement of mediaElements) {
let { widget } = SpecialPowers.wrap(iframeElement.contentWindow)
.windowGlobalChild.getActor("UAWidgets")
.widgets.get(mediaElement);
await widget.impl.Utils.l10n.translateRoots();
}
await printpreview(options.ref || options);
drawPrintPreviewWindow(ctx2);
exitprintpreview();
is(compareCanvases(options), !options.expectDifference, `Printing ${src1} and ${src2} should${options.expectDifference ? ' not' : ''} produce the same results`);
}
// bug 1567105
async function runTest11() {
await compareFiles("printpreview_quirks.html", "printpreview_quirks_ref.html");
requestAnimationFrame(function() { setTimeout(runTest12); } );
}
// bug 1621415
async function runTest12() {
await compareFiles("test_document_adopted_styles.html", "test_document_adopted_styles_ref.html");
requestAnimationFrame(function() { setTimeout(runTest13); } );
}
// bug 1621415
async function runTest13() {
await compareFiles("test_shadow_root_adopted_styles.html", "test_shadow_root_adopted_styles_ref.html");
requestAnimationFrame(function() { setTimeout(runTest14); } );
}
// bug 1622322
async function runTest14() {
await compareFiles("test_shared_adopted_styles.html", "test_shared_adopted_styles_ref.html");
requestAnimationFrame(function() { setTimeout(runTest15); } );
}
// Crash test for bug 1615261
async function runTest15() {
frameElts[0].contentDocument.body.innerHTML =
'<style>div { width: 100px; height: 100px; background-image: url("animated.gif"); } </style>' +
'<div>Firefox will crash if you try and print this page</div>';
// XXX Is there a more reliable way to wait for the background-image to load?
await new Promise(resolve => setTimeout(resolve, 500));
await printpreview();
await exitprintpreview();
requestAnimationFrame(function() { setTimeout(runTest16); } );
}
// Various image tests.
async function runTest16() {
// fuzzy: SVG image in the test pixel-snaps different than <div> in the ref.
// (And on WebRender, the pixel-snapping seems to shift some pixels over a
// bit such that they're fully white vs. fully blue; hence 255 as the allowed
// color-channel difference.)
// XXXdholbert We should revisit this and adjust these thresholds (hopefully
// lower) after bug 1602410 lands.
await compareFiles("printpreview_images.html", "printpreview_images_ref.html", { maxDifferent: 118, maxDifference: 255 });
requestAnimationFrame(function() { setTimeout(runTest17); } );
}
async function runTest17() {
// fuzzy: SVG image in the test pixel-snaps different than <div> in the ref.
// (And on WebRender, the pixel-snapping seems to shift some pixels over a
// bit such that they're fully white vs. fully blue; hence 255 as the allowed
// color-channel difference.)
// XXXdholbert We should revisit this and adjust these thresholds (hopefully
// lower) after bug 1602410 lands.
await compareFiles("printpreview_images_sw.html", "printpreview_images_sw_ref.html", { waitForMessage: true, maxDifferent: 118, maxDifference: 255 });
requestAnimationFrame(() => setTimeout(runTest18));
}
async function runTest18() {
await compareFiles("printpreview_quirks.html", "printpreview_quirks_ref.html", {
settings: {
marginTop: 22,
marginBottom: 22,
marginLeft: 22,
marginRight: 22,
},
});
requestAnimationFrame(() => setTimeout(runTest19));
}
async function runTest19() {
await compareFiles("color_adjust.html", "color_adjust_ref.html", {
test: {
settings: {
printBGColors: false,
printBGImages: false,
},
},
ref: {
settings: {
printBGColors: true,
printBGImages: true,
},
},
});
requestAnimationFrame(() => setTimeout(runTest20));
}
async function runTest20() {
frameElts[0].contentDocument.body.innerHTML =
'<style>div { page-break-after: always; }</style>' +
'<div>1</div>' +
'<div>2</div>' +
'<div>3</div>';
await printpreview();
is(gWbp.printPreviewCurrentPageNumber, 1,
"The initial current page number should be 1");
// Scroll to the second page.
gWbp.printPreviewScrollToPage(Ci.nsIWebBrowserPrint.PRINTPREVIEW_GOTO_PAGENUM, 2);
is(gWbp.printPreviewCurrentPageNumber, 2,
"The current page number should be 2");
// Scroll to the last page.
gWbp.printPreviewScrollToPage(Ci.nsIWebBrowserPrint.PRINTPREVIEW_END, 0);
is(gWbp.printPreviewCurrentPageNumber, 3,
"The current page number should be 3");
exitprintpreview();
requestAnimationFrame(() => setTimeout(runTest21));
}
async function runTest21() {
await compareFiles("data:text/html,<audio controls>", "data:text/html,<audio controls >"); // Shouldn't crash.
requestAnimationFrame(() => setTimeout(runTest22));
}
async function runTest22() {
// Similar to above runtTest20 but more specific for the logic to choose
// the current page in the new print preview UI so this test works only
// in the new print preview.
frameElts[0].contentDocument.body.innerHTML =
'<style>div { page-break-after: always; max-height: 2in; }</style>' +
'<div>1</div>' +
'<div>2</div>' +
'<div>3</div>' +
'<div>4</div>' +
'<div>5</div>' +
'<div>6</div>' +
'<div>7</div>' +
'<div>8</div>' +
'<div>9</div>' +
'<div>10</div>';
await printpreview({ settings: { paperHeight: 3 } });
const initialCurrentPageNumber = gWbp.printPreviewCurrentPageNumber;
// NOTE: In the cases the page hight is less than the half height of the
// print preview scroll port height, the initial current page number will
// not be 1.
ok(initialCurrentPageNumber >= 1,
"The initial current page number should be equal to or greater than 1");
const totalPageNumber = gWbp.printPreviewNumPages;
for (let n = initialCurrentPageNumber;
n <= totalPageNumber - initialCurrentPageNumber;
n++) {
// Scroll to the given page number and check the current page number.
gWbp.printPreviewScrollToPage(
Ci.nsIWebBrowserPrint.PRINTPREVIEW_GOTO_PAGENUM, n);
is(gWbp.printPreviewCurrentPageNumber, n,
`The current page number should be ${n}`);
}
// Scroll to the end of the scroll region.
gWbp.printPreviewScrollToPage(Ci.nsIWebBrowserPrint.PRINTPREVIEW_END, 0);
// Same as the initial current page number case, the last page might not
// be the current page if the page height is less than the half of the scroll
// port.
is(gWbp.printPreviewCurrentPageNumber,
totalPageNumber + 1 - initialCurrentPageNumber,
`The current page number should be ${totalPageNumber + 1 - initialCurrentPageNumber}`);
exitprintpreview();
requestAnimationFrame(() => setTimeout(runTest23));
}
async function runTest23() {
await compareFiles("printpreview_prettyprint.xml", "printpreview_prettyprint_ref.xhtml");
requestAnimationFrame(() => setTimeout(runTest24));
}
async function runTest24() {
await compareFiles("printpreview_mask.html", "data:text/html,", {
settings: {
printBGColors: false,
printBGImages: false,
},
expectDifference: true,
});
requestAnimationFrame(() => setTimeout(runTest25));
}
async function runTest25() {
await compareFiles("printpreview_downloadable_font.html", "printpreview_downloadable_font_ref.html");
requestAnimationFrame(() => setTimeout(runTest26));
}
async function runTest26() {
await compareFiles("printpreview_downloadable_font_in_iframe.html", "printpreview_downloadable_font_in_iframe_ref.html");
requestAnimationFrame(() => setTimeout(runTest27));
}
async function runTest27() {
await compareFiles("data:text/html,<style>:root { background-color: red; background-image: linear-gradient(red, red) }</style>", "data:text/html,", {
settings: {
printBGColors: false,
printBGImages: false,
}
});
requestAnimationFrame(() => setTimeout(runTest28));
}
async function runTest28() {
await compareFiles("data:text/html,<style>@page { margin: 0 }</style>Foo", "data:text/html,Foo", {
settings: {
honorPageRuleMargins: false,
marginTop: 1,
}
});
requestAnimationFrame(() => setTimeout(runTest29));
}
async function runTest29() {
await compareFiles("data:text/html,<style>@page { margin: 0 }</style>Foo", "data:text/html,Foo", {
settings: {
honorPageRuleMargins: true,
marginTop: 1,
},
expectDifference: true,
});
requestAnimationFrame(() => setTimeout(runTest30));
}
// Helper function to test trivial/unsupported pages-per-sheet values which we
// just treat as 1 page-per-sheet (as if the attribute were unset.)
// NOTE: The second data-URI's explicit "<body>" tag is not meant to affect the
// rendering -- it's just a hack to ensure that the URIs themselves are
// different, so that compareFiles() sees the two URIs as different and gets
// the "load" notification that it depends on after switching between them.
// We also include numPages in the tested URL/content here, so that if we get
// a test-failure, it's easy to figure out which call to this function had the
// failure.
async function checkTrivialPagesPerSheetValue(numPages) {
let stringToDisplay = "TrivialPagesPerSheetVal" + numPages;
await compareFiles("data:text/html," + stringToDisplay,
"data:text/html,<body>" + stringToDisplay, {
test: {
settings: {
numPagesPerSheet: numPages,
},
},
ref: { settings: {} },
});
}
async function runTest30() {
await checkTrivialPagesPerSheetValue(1);
await checkTrivialPagesPerSheetValue(0);
await checkTrivialPagesPerSheetValue(-5);
await checkTrivialPagesPerSheetValue(7);
await checkTrivialPagesPerSheetValue(500);
requestAnimationFrame(() => setTimeout(runTest31));
}
// Helper function to test supported pages-per-sheet values that actually do
// tiling (i.e. values greater than 1). We render the testcase and reference
// case with zero page-margins and zero unwritable margins. (This makes it
// tractable to create a reference case without having to account for margins
// that are outside of the content area.)
async function checkSupportedPagesPerSheetValue(src1, src2, numPages, fuzz) {
await compareFiles(src1, src2, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
numPagesPerSheet: numPages,
},
},
ref: {
settings: {
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
},
},
});
}
// Pages-per-sheet: test the supported values.
// First we test the perfect-square values: 4, 9, 16.
// Then we test the other values, 2 and 6. (They require some extra bespoke
// configuration to mock up their page-rotation, so their runTest functions are
// a bit more verbose.)
async function runTest31() {
// XXXdholbert On windows, our zero-margin settings aren't reliably respected
// for some reason; see bug 1680838. For now, we just account for that with a
// hefty amount of fuzz, guarded behind a platform-specific check so that we
// can keep this strict on other platforms.
let fuzz = navigator.platform.includes("Win") ?
{ maxDifferent: 101278, maxDifference: 255 } :
{ maxDifferent: 0, maxDifference: 0 };
await checkSupportedPagesPerSheetValue("printpreview_pps4.html",
"printpreview_pps4_ref.html", 4, fuzz);
requestAnimationFrame(() => setTimeout(runTest32));
}
async function runTest32() {
let fuzz = navigator.platform.includes("Win") ?
{ maxDifferent: 130170, maxDifference: 255 } :
{ maxDifferent: 0, maxDifference: 0 };
await checkSupportedPagesPerSheetValue("printpreview_pps9.html",
"printpreview_pps9_ref.html", 9, fuzz);
requestAnimationFrame(() => setTimeout(runTest33));
}
async function runTest33() {
let fuzz = navigator.platform.includes("Win") ?
{ maxDifferent: 145706, maxDifference: 255 } :
{ maxDifferent: 0, maxDifference: 0 };
await checkSupportedPagesPerSheetValue("printpreview_pps16.html",
"printpreview_pps16_ref.html", 16,
fuzz);
requestAnimationFrame(() => setTimeout(runTest34));
}
async function runTest34() {
let fuzz = navigator.platform.includes("Win") ? // Workaround for bug 1680838
{ maxDifferent: 44256, maxDifference: 255 } :
{ maxDifferent: 0, maxDifference: 0 };
let test = "printpreview_pps2.html";
let ref = "printpreview_pps2_ref.html";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
paperWidth: 8,
paperHeight: 10,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
numPagesPerSheet: 2,
},
},
ref: {
settings: {
paperWidth: 8,
paperHeight: 10,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
orientation: 1, /* Landscape mode */
},
},
});
requestAnimationFrame(() => setTimeout(runTest35));
}
async function runTest35() {
let fuzz = navigator.platform.includes("Win") ? // Workaround for bug 1680838
{ maxDifferent: 88751, maxDifference: 255 } :
{ maxDifferent: 0, maxDifference: 0 };
let test = "printpreview_pps6.html";
let ref = "printpreview_pps6_ref.html";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
paperWidth: 5,
paperHeight: 6,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
numPagesPerSheet: 6,
orientation: 1, /* Landscape mode */
},
},
ref: {
settings: {
paperWidth: 5,
paperHeight: 6,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
},
},
});
requestAnimationFrame(() => setTimeout(runTest36));
}
// Testcases for pages-per-sheet with nonzero unwriteable margin values:
// ---------------------------------------------------------------------
// In this subtest, the vertical scale-factor is more-severe and hence ends up
// "winning", and we have a bit of extra space in the horizontal axis which we
// distribute equally on either side (see the _ref.html file used below for
// more details).
async function runTest36() {
let fuzz = navigator.platform.includes("Win") ?
{ maxDifferent: 139464, maxDifference: 255 } :
{ maxDifferent: 0, maxDifference: 0 };
let test = "printpreview_pps_uw4.html";
let ref = "printpreview_pps_uw4_ref.html";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
paperWidth: 4,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0.6,
unwriteableMarginRight: 0.1,
unwriteableMarginBottom: 0.4,
unwriteableMarginLeft: 0.3,
numPagesPerSheet: 4,
},
},
ref: {
settings: {
paperWidth: 4,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
},
},
});
requestAnimationFrame(() => setTimeout(runTest37));
}
// In this subtest, the horizontal scale-factor is more-severe and hence ends
// up "winning", and we have a bit of extra space in the vertical axis which we
// distribute equally on either side (see the _ref.html file used below for
// more details).
async function runTest37() {
let fuzz = navigator.platform.includes("Win") ?
{ maxDifferent: 152268, maxDifference: 255 } :
{ maxDifferent: 0, maxDifference: 0 };
let test = "printpreview_pps_uw9.html";
let ref = "printpreview_pps_uw9_ref.html";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
paperWidth: 5,
paperHeight: 10,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0.2,
unwriteableMarginRight: 0.8,
unwriteableMarginBottom: 0.4,
unwriteableMarginLeft: 1.2,
numPagesPerSheet: 9,
},
},
ref: {
settings: {
paperWidth: 5,
paperHeight: 10,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
},
},
});
requestAnimationFrame(() => setTimeout(runTest38));
}
async function runTest38() {
let fuzz = navigator.platform.includes("Win") ? // Workaround for bug 1680838
{ maxDifferent: 117744, maxDifference: 255 } :
{ maxDifferent: 0, maxDifference: 0 };
let test = "printpreview_pps_uw2.html";
let ref = "printpreview_pps_uw2_ref.html";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
paperWidth: 8,
paperHeight: 10,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0.8,
unwriteableMarginRight: 0.6,
unwriteableMarginBottom: 1.2,
unwriteableMarginLeft: 0.4,
numPagesPerSheet: 2,
},
},
ref: {
settings: {
paperWidth: 8,
paperHeight: 10,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
/* Note: These are the same values we used for 'test' above, except
that here we've rotated the margins counterclockwise through the
sides, to account for the fact that we're specifying these margins
for a landscape-orientation page here vs. portrait-mode above.*/
unwriteableMarginTop: 0.6,
unwriteableMarginRight: 1.2,
unwriteableMarginBottom: 0.4,
unwriteableMarginLeft: 0.8,
orientation: 1, /* Landscape mode */
},
},
});
requestAnimationFrame(() => setTimeout(runTest39));
}
// In this subtest, the vertical unwriteable margins exactly consume the full
// pageHeight, so we don't have any space available for printing and we just
// print a blank sheet. (This is mostly a stress test to be sure we don't
// crash, hang, divide-by-zero, etc. in this edge case.)
async function runTest39() {
let fuzz = navigator.platform.includes("Win") ?
{ maxDifferent: 254, maxDifference: 255 } :
{ maxDifferent: 0, maxDifference: 0 };
let test = "data:text/html,Unwriteable-Margins-Too-Tall-To-See-This";
let ref = "data:text/html,<!-- runTest39 -->";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
paperWidth: 4,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
unwriteableMarginTop: 3,
unwriteableMarginBottom: 2,
numPagesPerSheet: 4,
},
},
ref: {
settings: {
paperWidth: 4,
paperHeight: 5,
},
},
});
requestAnimationFrame(() => setTimeout(runTest40));
}
// In this subtest, the horizontal unwriteable margins consume more than the
// full pageWidth, so we don't have any space available for printing and we
// just print a blank sheet. (This is mostly a stress test to be sure we don't
// crash, hang, divide-by-zero, etc. in this edge case.)
async function runTest40() {
let fuzz = navigator.platform.includes("Win") ?
{ maxDifferent: 172, maxDifference: 255 } :
{ maxDifferent: 0, maxDifference: 0 };
let test = "data:text/html,Unwriteable-Margins-Too-Wide-To-See-This";
let ref = "data:text/html,<!-- runTest40 -->";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
paperWidth: 4,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
unwriteableMarginRight: 3,
unwriteableMarginLeft: 4,
numPagesPerSheet: 9,
},
},
ref: {
settings: {
paperWidth: 4,
paperHeight: 5,
},
},
});
requestAnimationFrame(() => setTimeout(runTest41));
}
// Drawing headers/footers with very large unwriteable margins. The specific
// bug occurs when combined unwriteable are larger than half of the page's
// dimensions.
async function runTest41() {
// This test compares a rendered page to the headers/footers that print code
// generates. On Windows, workaround bug 1680838. On OS X, the headers/
// footers are sometimes slightly offset. See bug 1714217.
// It's not too big a deal to have a higher fuzz factor, since when
// bug 1713404 occurs no headers/footers at all are rendered. These higher
// fuzz factors will still catch this worst case on OS X.
if (navigator.platform.includes("Win")) {
var fuzz = { maxDifferent: 256, maxDifference: 255 }; // Bug 1680838
}
else if (navigator.platform.includes("Mac")) {
var fuzz = { maxDifferent: 60, maxDifference: 200 }; // Bug 1714217
}
else {
var fuzz = { maxDifferent: 14, maxDifference: 16 };
}
let test = "data:text/html,<!-- runTest41 -->";
let ref = "printpreview_bug1713404_ref.html";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
paperWidth: 5,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
unwriteableMarginLeft: 2,
unwriteableMarginRight: 2,
unwriteableMarginTop: 2,
unwriteableMarginBottom: 2,
headerStrLeft: "|",
headerStrRight: "||",
footerStrLeft: "|||",
footerStrRight: "||||",
},
},
ref: {
settings: {
paperWidth: 5,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
unwriteableMarginLeft: 0,
unwriteableMarginRight: 0,
unwriteableMarginTop: 0,
unwriteableMarginBottom: 0,
},
},
});
requestAnimationFrame(() => setTimeout(runTest42));
}
// Test that @page{ size: ... } works correctly with a smaller specified
// @page{ size: ... } than the paper we are printing to. The test and ref use
// varying margin and size properties to place elements in the same location.
// This depends on Firefox's current behavior of putting undersized pages into
// the upper left corner, rather than scaling or centering the page.
async function runTest42() {
if (navigator.platform.includes("Mac")) {
var fuzz = { maxDifferent: 15, maxDifference: 8 };
}
let test = "print_page_size1.html";
let ref = "print_page_size1_ref.html";
await compareFiles(test, ref, fuzz);
requestAnimationFrame(() => setTimeout(runTest43));
}
// Test that @page{ size: ... } works correctly with a larger specified
// @page{ size: ... } than the paper we are printing to. This specifically
// tests scaling when only one page edge is too large.
// This depends on Firefox's current behavior of scaling down any oversized
// pages to fit onto a single physical page, and putting this aligned to the
// upper left corner rather than centering the page.
async function runTest43() {
if (navigator.platform.includes("Mac")) {
var fuzz = { maxDifferent: 15, maxDifference: 8 };
}
let test = "print_page_size2.html";
let ref = "print_page_size2_ref.html";
await compareFiles(test, ref, fuzz);
requestAnimationFrame(() => setTimeout(runTest44));
}
// Test that @page{ size: ... } works correctly with a smaller specified
// @page{ size: ... } than the paper we are printing to. The test case uses
// only the size property and the ref case uses only absolute positioning.
// This depends on Firefox's current behavior of putting undersized pages into
// the upper left corner, rather than scaling or centering the page.
async function runTest44() {
if (navigator.platform.includes("Mac")) {
var fuzz = { maxDifferent: 15, maxDifference: 8 };
}
let test = "print_page_size3.html";
let ref = "print_page_size3_ref.html";
await compareFiles(test, ref, fuzz);
requestAnimationFrame(() => setTimeout(runTest45));
}
// Test that @page{ size: ... } results in scaling down the contents to fit on
// a smaller paper size.
// This depends on Firefox's current behavior of scaling oversized pages down
// to fit onto the paper size.
async function runTest45() {
if (navigator.platform.includes("Mac")) {
var fuzz = { maxDifferent: 15, maxDifference: 8 };
}
let test = "print_page_size4.html";
let ref = "print_page_size4_ref.html";
await compareFiles(test, ref, fuzz);
requestAnimationFrame(() => setTimeout(runTest46));
}
// Test that small elements don't get clipped from the bottom of the page when
// using a < 1.0 scaling factor.
async function runTest46() {
var fuzz = { maxDifferent: 0, maxDifference: 0 };
let test = "bug1722890.html";
let ref = "bug1722890_ref.html";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
scaling: 0.5,
shrinkToFit: false
}
},
ref: {
settings: {
scaling: 1.0,
shrinkToFit: false
}
}
});
requestAnimationFrame(() => setTimeout(runTest47));
}
// Test for header/footer text clipping when printing with scaling factor.
async function runTest47() {
// This test compares a rendered page to the headers/footers that print code
// generates. On Windows, workaround bug 1680838. On OS X, the headers/
// footers are sometimes slightly offset. See bug 1714217.
// It's not too big a deal to have a higher fuzz factor, since when
// bug 1730091 occurs most of the headers/footers are not rendered at all,
// and these fuzz factors will still catch that.
if (navigator.platform.includes("Win")) {
var fuzz = { maxDifferent: 200, maxDifference: 255 }; // Bug 1680838
}
else if (navigator.platform.includes("Mac")) {
var fuzz = { maxDifferent: 180, maxDifference: 255 }; // Bug 1714217
}
else {
var fuzz = { maxDifferent: 6, maxDifference: 16 };
}
let test = "data:text/html,<!-- runTest47 -->";
let ref = "printpreview_bug1730091_ref.html";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
scaling: 1.3,
shrinkToFit: false,
paperWidth: 5,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
unwriteableMarginLeft: 0,
unwriteableMarginRight: 0,
unwriteableMarginTop: 0,
unwriteableMarginBottom: 0,
headerStrLeft: "||||",
headerStrRight: "||||",
footerStrLeft: "||||",
footerStrRight: "||||",
},
},
ref: {
settings: {
paperWidth: 5,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
unwriteableMarginLeft: 0,
unwriteableMarginRight: 0,
unwriteableMarginTop: 0,
unwriteableMarginBottom: 0,
},
},
});
requestAnimationFrame(() => setTimeout(runTest48));
}
// Test that even when downscaling happens due to CSS page-size, the
// unwriteable margins are in units applicable to the resulting page as it is
// actually printed.
// https://bugzilla.mozilla.org/1769161
async function runTest48() {
if (navigator.platform.includes("Win")) {
var fuzz = { maxDifferent: 816, maxDifference: 255 }; // Bug 1680838
} else {
var fuzz = { maxDifferent: 16, maxDifference: 255 };
}
let test = "bug1769161_1.html";
let ref = "bug1769161_1_ref.html";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
settings: {
paperWidth: 5,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
unwriteableMarginLeft: 1,
unwriteableMarginRight: 1,
unwriteableMarginTop: 1,
unwriteableMarginBottom: 1,
},
});
requestAnimationFrame(() => setTimeout(runTest49));
}
// Same as runTest48, but uses different scaling factors.
async function runTest49() {
if (navigator.platform.includes("Win")) {
var fuzz = { maxDifferent: 6472, maxDifference: 255 }; // Bug 1680838
} else {
var fuzz = { maxDifferent: 24, maxDifference: 255 };
}
let test = "bug1769161_2.html";
let ref = "bug1769161_2_ref.html";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
settings: {
paperWidth: 5,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
unwriteableMarginLeft: 1,
unwriteableMarginRight: 1,
unwriteableMarginTop: 1,
unwriteableMarginBottom: 1,
},
});
requestAnimationFrame(() => setTimeout(runTest50));
}
// Test that when downscaling happens due to CSS page-size, the unwriteable
// margins are equivalent to the @page margins after those margins are scaled.
// https://bugzilla.mozilla.org/1769161
async function runTest50() {
if (navigator.platform.includes("Win")) {
var fuzz = { maxDifferent: 816, maxDifference: 255 }; // Bug 1680838
} else {
var fuzz = { maxDifferent: 16, maxDifference: 255 };
}
let test = "bug1769161_3.html";
let ref = "bug1769161_3_ref.html";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
paperWidth: 5,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
unwriteableMarginLeft: 1,
unwriteableMarginRight: 1,
unwriteableMarginTop: 1,
unwriteableMarginBottom: 1,
},
},
ref: {
settings: {
paperWidth: 5,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
unwriteableMarginLeft: 0,
unwriteableMarginRight: 0,
unwriteableMarginTop: 0,
unwriteableMarginBottom: 0,
},
},
});
requestAnimationFrame(() => setTimeout(runTest51));
}
// Same as runTest50, but uses different scaling factors.
async function runTest51() {
if (navigator.platform.includes("Win")) {
var fuzz = { maxDifferent: 11764, maxDifference: 255 }; // Bug 1680838
} else {
var fuzz = { maxDifferent: 24, maxDifference: 255 };
}
let test = "bug1769161_4.html";
let ref = "bug1769161_4_ref.html";
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
paperWidth: 5,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
unwriteableMarginLeft: 1,
unwriteableMarginRight: 1,
unwriteableMarginTop: 1,
unwriteableMarginBottom: 1,
},
},
ref: {
settings: {
paperWidth: 5,
paperHeight: 5,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
unwriteableMarginLeft: 0,
unwriteableMarginRight: 0,
unwriteableMarginTop: 0,
unwriteableMarginBottom: 0,
},
},
});
requestAnimationFrame(() => setTimeout(runTest52));
}
async function runTest52() {
// Unwriteable margins can be ignored by setting the appropriate flag.
// Slightly different to avoid hang.
await compareFiles("data:text/html,Foo", "data:text/html,<div>Foo", {
maxDifferent: 0,
maxDifference: 0,
test: {
settings: {
paperWidth: 8,
paperHeight: 10,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 1,
unwriteableMarginRight: 1,
unwriteableMarginBottom: 1,
unwriteableMarginLeft: 1,
ignoreUnwriteableMargins: true,
},
},
ref: {
settings: {
paperWidth: 8,
paperHeight: 10,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
},
},
});
requestAnimationFrame(() => setTimeout(runTest53));
}
async function runTest53() {
// Ensure that even when unwriteable margins are set to be taken into
// account, page rule margins can override it.
await compareFiles(
"data:text/html,<style>@page { margin: 0 }</style>Foo",
"data:text/html,<div>Foo",
{
maxDifferent: 0,
maxDifference: 0,
test: {
settings: {
paperWidth: 8,
paperHeight: 10,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 1,
unwriteableMarginRight: 1,
unwriteableMarginBottom: 1,
unwriteableMarginLeft: 1,
ignoreUnwriteableMargins: false,
honorPageRuleMargins: true,
},
},
ref: {
settings: {
paperWidth: 8,
paperHeight: 10,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
},
},
});
requestAnimationFrame(() => setTimeout(runTest54));
}
async function runTest54() {
// `ignoreUnwriteableMargins` lets author-specified margins ignore
// unwriteable margins as well. Without this flag, the unwriteable
// margin is ignored iff `Margins: Default` is set (i.e.
// `honorPageRuleMargins` set) and the author specified CSS page
// margin is zero.
// Note: At least currently, both `ignoreUnwriteableMargins`
// and `honorPageRuleMargins` cannot be set through the printing UI.
// TODO: If this behaviour is desired is up for debate.
await compareFiles(
"data:text/html,<style>@page { margin: 0.1in }</style>Foo",
"data:text/html,<div>Foo",
{
maxDifferent: 0,
maxDifference: 0,
test: {
settings: {
paperWidth: 8,
paperHeight: 10,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 1,
unwriteableMarginRight: 1,
unwriteableMarginBottom: 1,
unwriteableMarginLeft: 1,
ignoreUnwriteableMargins: true,
honorPageRuleMargins: true,
},
},
ref: {
settings: {
paperWidth: 8,
paperHeight: 10,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0.1,
marginRight: 0.1,
marginBottom: 0.1,
marginLeft: 0.1,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
},
},
});
requestAnimationFrame(() => setTimeout(runTest55));
}
async function runTest55() {
let test = "printpreview_pps_uw2.html";
let ref = "printpreview_pps_uw2_no_margin_ref.html";
let fuzz = navigator.platform.includes("Win") ? // Workaround for bug 1680838
{ maxDifferent: 12870, maxDifference: 255 } :
{ maxDifferent: 0, maxDifference: 0 };
// Unwriteable margins are successfully ignored, if requested,
// for pages-per-sheet.
await compareFiles(test, ref, {
maxDifferent: fuzz.maxDifferent,
maxDifference: fuzz.maxDifference,
test: {
settings: {
paperWidth: 8,
paperHeight: 10,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0.8,
unwriteableMarginRight: 0.6,
unwriteableMarginBottom: 1.2,
unwriteableMarginLeft: 0.4,
numPagesPerSheet: 2,
ignoreUnwriteableMargins: true,
},
},
ref: {
settings: {
paperWidth: 8,
paperHeight: 10,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
orientation: 1, /* Landscape mode */
},
},
});
requestAnimationFrame(() => setTimeout(runTest56));
}
async function runTest56() {
await compareFiles("printpreview_image_select.html", "printpreview_image_select_ref.html");
requestAnimationFrame(() => setTimeout(runTest57));
}
// Tests that printing with mixed page sizes doesn't crash.
// These tests can't actually compare any pages after the first, so this only
// verifies that we don't crash reflowing.
async function runTest57() {
let test = "printpreview_mixed_page_size_001.html";
// The params are just to give the file unique URLs.
await compareFiles(test + "?test", test + "?ref");
requestAnimationFrame(() => setTimeout(runTest58));
}
// As with runTest57, this is only testing for crashes.
// This includes fixed-position content, as this is the only way to get content
// within the same chain of continuations onto pages with different sizes.
async function runTest58() {
let test = "printpreview_mixed_page_size_002.html";
// The params are just to give the file unique URLs.
await compareFiles(test + "?test", test + "?ref");
requestAnimationFrame(() => setTimeout(runTest59));
}
// Creates a data URL that has a single div of |divSize| em square, on a page
// of size |pageSize| inches square.
// |center| determines if the div should be centered horizontally.
function createScalingTestSource(pageSize, center, name) {
// Styling always used.
let baseStyle = 'background: blue;';
if (center) {
baseStyle += 'margin: auto;';
}
const div = '<div style="width: 100px; height: 100px;' + baseStyle + '"></div>';
const style = '<style>@page{size:' + pageSize + 'in}body{margin:0}</style>';
// Add the name as a comment, to ensure every test has a unique source even
// if the parameters are identical.
const comment = '<!-- ' + name + ' -->';
return 'data:text/html,' + style + div + comment;
}
async function runScalingCenteredTest(refPageSize, testPageSize, paperSize,
name, center = true, fuzz = null) {
const printSettings = {
settings: {
paperWidth: paperSize,
paperHeight: paperSize,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
}
};
let settings = Object.create(fuzz, {
ref: {value: printSettings},
test: {value: printSettings}
});
const testSrc = createScalingTestSource(testPageSize, center, name);
const refSrc = createScalingTestSource(refPageSize, center, name);
return compareFiles(testSrc, refSrc, settings);
}
// Tests that auto-detection and use of page centering.
// Has a smaller page on a larger sheet, where the difference is within the
// tolerance for auto-detection.
async function runTest59() {
await SpecialPowers.pushPrefEnv({
set: [["print.center_page_on_sheet", 2]]
});
// See bug 1680838
const fuzz = navigator.platform.includes("Win") ?
{ maxDifferent: 180, maxDifference: 255 } :
null;
await runScalingCenteredTest(10, 9.5, 10, "runTest59", true, fuzz);
await SpecialPowers.popPrefEnv();
requestAnimationFrame(() => setTimeout(runTest60));
}
// Tests that centering won't occur when the pref disables it, using the same
// values as runTest59.
async function runTest60() {
await SpecialPowers.pushPrefEnv({
set: [["print.center_page_on_sheet", 0]]
});
// See bug 1680838
const fuzz = navigator.platform.includes("Win") ?
{ maxDifferent: 180, maxDifference: 255 } :
null;
await runScalingCenteredTest(10, 9.5, 10, "runTest60", false, fuzz);
await SpecialPowers.popPrefEnv();
requestAnimationFrame(() => setTimeout(runTest61));
}
// Tests that auto-detection will reject too big a difference for page
// centering. Has a much smaller page on a larger sheet, where the difference
// is outside the threshold for auto-detection.
async function runTest61() {
await SpecialPowers.pushPrefEnv({
set: [["print.center_page_on_sheet", 2]]
});
// See bug 1680838
const fuzz = navigator.platform.includes("Win") ?
{ maxDifferent: 450, maxDifference: 255 } :
null;
await runScalingCenteredTest(10, 8.9, 10, "runTest61", false, fuzz);
await SpecialPowers.popPrefEnv();
requestAnimationFrame(() => setTimeout(runTest62));
}
// Tests that we can force page centering with the pref, using the same values
// as runTest61.
async function runTest62() {
await SpecialPowers.pushPrefEnv({
set: [["print.center_page_on_sheet", 1]]
});
// See bug 1680838
const fuzz = navigator.platform.includes("Win") ?
{ maxDifferent: 450, maxDifference: 255 } :
null;
await runScalingCenteredTest(10, 8.9, 10, "runTest62", true, fuzz);
await SpecialPowers.popPrefEnv();
requestAnimationFrame(() => setTimeout(runTest63));
}
// Tests that centering will always happen if the pref forces it.
// The sizes used in these files are very large and the scale factor very high
// here to ensure that any errors in the calculation for centering will be
// magnified.
async function runTest63() {
let test = "printpreview_scale_test_001.html";
let ref = "printpreview_scale_test_001_ref.html";
await SpecialPowers.pushPrefEnv({
set: [["print.center_page_on_sheet", 1]]
});
await compareFiles(test, ref, {
test: {
settings: {
paperWidth: 8.5,
paperHeight: 11,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
},
},
ref: {
settings: {
paperWidth: 8.5,
paperHeight: 11,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
},
},
});
await SpecialPowers.popPrefEnv();
requestAnimationFrame(() => setTimeout(runTest64));
}
// Tests that printing A4 pages on US Letter will be a close enough fit
// that we will automatically center the page.
async function runTest64() {
let test = "printpreview_scale_test_002.html";
let ref = "printpreview_scale_test_002_ref.html";
await SpecialPowers.pushPrefEnv({
set: [["print.center_page_on_sheet", 2]]
});
await compareFiles(test, ref, {
test: {
settings: {
paperWidth: 8.5,
paperHeight: 11,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
},
},
ref: {
settings: {
paperWidth: 8.5,
paperHeight: 11,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
},
},
});
await SpecialPowers.popPrefEnv();
requestAnimationFrame(() => setTimeout(runTest65));
}
// Tests that auto-detection will reject a large enough difference in width
// when downscaling is used to make the page fit on the paper.
async function runTest65() {
let test = "printpreview_scale_test_003.html";
let ref = "printpreview_scale_test_003_ref.html";
await SpecialPowers.pushPrefEnv({
set: [["print.center_page_on_sheet", 2]]
});
await compareFiles(test, ref, {
test: {
settings: {
paperWidth: 8.5,
paperHeight: 11,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
},
},
ref: {
settings: {
paperWidth: 8.5,
paperHeight: 11,
paperSizeUnit: Ci.nsIPrintSettings.kPaperSizeInches,
marginTop: 0,
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
unwriteableMarginTop: 0,
unwriteableMarginRight: 0,
unwriteableMarginBottom: 0,
unwriteableMarginLeft: 0,
},
},
});
await SpecialPowers.popPrefEnv();
requestAnimationFrame(() => setTimeout(runTest66));
}
// Basic test for black-and-white rendering. This is mostly a crashtest for
// bug 1961975, but it also serves to verify that a blank page looks the same
// whether rendered in color vs. in black-and-white.
// (Actual content -- even black-and-white content -- is harder to test because
// our black-and-white filter adds some subtle antialiasing effects.)
async function runTest66() {
// Note: these test/ref URIs are both blank; we're testing a blank page
// rendered under two different configurations. The HTML comments are
// only there to make the data-URIs different, so that a navigation
// actually happens -- and the 'load' event fires, etc. -- when we set the
// reference-case-URI.
let test = `data:text/html,<!--test-->`;
let ref = `data:text/html,<!--ref-->`;
await compareFiles(test, ref, {
test: {
settings: {
printInColor: false,
},
},
ref: {
settings: {
printInColor: true,
},
},
});
finish();
}
]]></script>
<table style="border: 1px solid black;" xmlns="http://www.w3.org/1999/xhtml">
<tr><th>Print preview canvas 1</th><th>Print preview canvas 2</th></tr>
<tr>
<td><canvas height="800" width="800"></canvas></td>
<td><canvas height="800" width="800"></canvas></td>
</tr></table>
</window>
|