Bug 1662331 - Part 1: Use the sheetCount from printPreview directly r=emalysz

Differential Revision: https://phabricator.services.mozilla.com/D95332
This commit is contained in:
Mark Striemer 2020-11-06 17:30:43 +00:00
Родитель a295cfacfd
Коммит 12bc99eb13
2 изменённых файлов: 32 добавлений и 10 удалений

Просмотреть файл

@ -641,12 +641,12 @@ var PrintEventHandler = {
.add(elapsed);
}
// This resolves with a PrintPreviewSuccessInfo dictionary. That also has
// a `sheetCount` property available which we should use (bug 1662331).
let totalPageCount, hasSelection;
let totalPageCount, sheetCount, hasSelection;
try {
// This resolves with a PrintPreviewSuccessInfo dictionary.
({
totalPageCount,
sheetCount,
hasSelection,
} = await previewBrowser.frameLoader.printPreview(settings, sourceWinId));
} catch (e) {
@ -654,18 +654,12 @@ var PrintEventHandler = {
throw e;
}
// Send the page count and show the preview.
let numPages = totalPageCount;
// Adjust number of pages if the user specifies the pages they want printed
if (settings.printRange == Ci.nsIPrintSettings.kRangeSpecifiedPageRange) {
numPages = settings.endPageRange - settings.startPageRange + 1;
}
// Update the settings print options on whether there is a selection.
settings.isPrintSelectionRBEnabled = hasSelection;
document.dispatchEvent(
new CustomEvent("page-count", {
detail: { numPages, totalPages: totalPageCount },
detail: { numPages: sheetCount, totalPages: totalPageCount },
})
);

Просмотреть файл

@ -91,3 +91,31 @@ add_task(async function testSheetCount() {
await helper.closeDialog();
});
});
add_task(async function testSheetCountPageRange() {
await PrintHelper.withTestPage(async helper => {
await helper.startPrint();
await helper.waitForPreview(() =>
helper.dispatchSettingsChange({
shrinkToFit: false,
scaling: 2,
})
);
let sheetCount = helper.get("sheet-count");
let sheets = getSheetCount(sheetCount);
ok(sheets >= 3, "There are at least 3 pages");
// Set page range to 2-3, sheet count should be 2.
await helper.waitForPreview(() =>
helper.dispatchSettingsChange({
printRange: helper.settings.kRangeSpecifiedPageRange,
startPageRange: 2,
endPageRange: 3,
})
);
sheets = getSheetCount(sheetCount);
is(sheets, 2, "There are now only 2 pages shown");
});
});