mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Bug 1882890 Part 2 - Add tests for centering the page when printing. r=dholbert
Because the properties of the tests are all just size relations, it's easy to generate some of the source directly and provide it as a data URL. This should test all three states for the pref. Differential Revision: https://phabricator.services.mozilla.com/D204134
This commit is contained in:
parent
f72bc84eb6
commit
7dc693b68b
@ -66,6 +66,12 @@ support-files = [
|
||||
"printpreview_pps16_ref.html",
|
||||
"printpreview_prettyprint.xml",
|
||||
"printpreview_prettyprint_ref.xhtml",
|
||||
"printpreview_scale_test_001.html",
|
||||
"printpreview_scale_test_001_ref.html",
|
||||
"printpreview_scale_test_002.html",
|
||||
"printpreview_scale_test_002_ref.html",
|
||||
"printpreview_scale_test_003.html",
|
||||
"printpreview_scale_test_003_ref.html",
|
||||
"printpreview_mask.html",
|
||||
"print_page_size1.html",
|
||||
"print_page_size1_ref.html",
|
||||
|
@ -1708,9 +1708,252 @@ 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();
|
||||
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>
|
||||
|
21
layout/base/tests/chrome/printpreview_scale_test_001.html
Normal file
21
layout/base/tests/chrome/printpreview_scale_test_001.html
Normal file
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<style>
|
||||
@page {
|
||||
size: 10in 22in;
|
||||
margin: 0;
|
||||
}
|
||||
body{
|
||||
margin:0;
|
||||
}
|
||||
div{
|
||||
width: 2in;
|
||||
height: 2in;
|
||||
background: blue;
|
||||
margin-left: 4in;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div></div>
|
||||
</body>
|
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<style>
|
||||
@page {
|
||||
size: 4in 44in;
|
||||
margin: 0;
|
||||
}
|
||||
body{
|
||||
margin:0;
|
||||
}
|
||||
div{
|
||||
height: 4in;
|
||||
width: 4in;
|
||||
background: blue;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div></div>
|
||||
</body>
|
21
layout/base/tests/chrome/printpreview_scale_test_002.html
Normal file
21
layout/base/tests/chrome/printpreview_scale_test_002.html
Normal file
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<style>
|
||||
@page {
|
||||
size: A4;
|
||||
margin: 0;
|
||||
}
|
||||
body{
|
||||
margin:0;
|
||||
}
|
||||
div{
|
||||
height: 200px;
|
||||
width: 200px;
|
||||
background: blue;
|
||||
margin: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div></div>
|
||||
</body>
|
@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<style>
|
||||
@page {
|
||||
size: letter;
|
||||
margin: 0;
|
||||
}
|
||||
body{
|
||||
margin:0;
|
||||
}
|
||||
div{
|
||||
/* A4-on-letter requires a 0.9407 downscale. 11in = 279.4mm, and
|
||||
* 279.4mm / 297mm = 0.9407407407..
|
||||
* The unscaled reference case has a 200px square div, so reverse the scale
|
||||
* to match that (rounding to 0.940741)
|
||||
*/
|
||||
height: calc(0.940741 * 200px);
|
||||
width: calc(0.940741 * 200px);
|
||||
background: blue;
|
||||
margin: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div></div>
|
||||
</body>
|
21
layout/base/tests/chrome/printpreview_scale_test_003.html
Normal file
21
layout/base/tests/chrome/printpreview_scale_test_003.html
Normal file
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<style>
|
||||
@page {
|
||||
size: 8.5in 13in;
|
||||
margin: 0;
|
||||
}
|
||||
body{
|
||||
margin:0;
|
||||
}
|
||||
div{
|
||||
/* 13in / 11in = 1.1818181... */
|
||||
height: calc(1.1818182 * 200px);
|
||||
width: calc(1.1818182 * 200px);
|
||||
background: blue;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div></div>
|
||||
</body>
|
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<style>
|
||||
@page {
|
||||
size: 8.5in 11in;
|
||||
margin: 0;
|
||||
}
|
||||
body{
|
||||
margin:0;
|
||||
}
|
||||
div{
|
||||
/* 11in / 13in = 0.8461538 */
|
||||
height: 200px;
|
||||
width: 200px;
|
||||
background: blue;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div></div>
|
||||
</body>
|
Loading…
Reference in New Issue
Block a user