From 67402986174df40af80674be1f0233a1d3f02555 Mon Sep 17 00:00:00 2001 From: Haik Aftandilian Date: Fri, 15 Oct 2021 00:01:13 +0000 Subject: [PATCH] Bug 1735587 - "Sheets of paper" incorrect when numCopies>1 and sheetCount is odd r=emilio Multiply the sheet count by numCopies after accounting for duplex printing. Differential Revision: https://phabricator.services.mozilla.com/D128430 --- toolkit/components/printing/content/print.js | 4 +- .../printing/tests/browser_sheet_count.js | 70 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/toolkit/components/printing/content/print.js b/toolkit/components/printing/content/print.js index 7fa4a3981d95..8ad962939c72 100644 --- a/toolkit/components/printing/content/print.js +++ b/toolkit/components/printing/content/print.js @@ -2613,7 +2613,7 @@ class PageCount extends PrintUIControlMixin(HTMLElement) { return; } - let sheetCount = this.sheetCount * this.numCopies; + let sheetCount = this.sheetCount; // When printing to a printer (not to a file) update // the sheet count to account for duplex printing. @@ -2621,6 +2621,8 @@ class PageCount extends PrintUIControlMixin(HTMLElement) { sheetCount = Math.ceil(sheetCount / 2); } + sheetCount *= this.numCopies; + document.l10n.setAttributes(this, "printui-sheets-count", { sheetCount, }); diff --git a/toolkit/components/printing/tests/browser_sheet_count.js b/toolkit/components/printing/tests/browser_sheet_count.js index 3d28cbc96e6c..ffdcc9f79fe5 100644 --- a/toolkit/components/printing/tests/browser_sheet_count.js +++ b/toolkit/components/printing/tests/browser_sheet_count.js @@ -191,6 +191,76 @@ add_task(async function testSheetCountDuplex() { }); }); +// Test that enabling duplex printing with multiple copies updates the +// sheet count accordingly. +add_task(async function testSheetCountDuplexWithCopies() { + // Use different scale values to exercise printing of different page counts + for (let scale of [2, 3, 4, 5]) { + await TestDuplexNumCopiesAtScale(scale); + } +}); + +// Enable duplex and numCopies=2 with the provided scale value and check +// that the sheet count is correct. +async function TestDuplexNumCopiesAtScale(scale) { + await PrintHelper.withTestPage(async helper => { + const mockPrinterName = "DuplexCapablePrinter"; + const printer = helper.addMockPrinter(mockPrinterName); + printer.supportsDuplex = Promise.resolve(true); + + await helper.startPrint(); + await helper.dispatchSettingsChange({ printerName: mockPrinterName }); + + // Set scale and shinkToFit to make the document + // bigger so that it spans multiple pages. + await helper.waitForPreview(() => + helper.dispatchSettingsChange({ + shrinkToFit: false, + scaling: scale, + duplex: Ci.nsIPrintSettings.kDuplexNone, + }) + ); + await BrowserTestUtils.waitForCondition( + () => helper.sheetCount != 1, + "Wait for sheet count to update" + ); + let singleSidedSheets = helper.sheetCount; + + // Chnage to two copies + await helper.waitForSettingsEvent(() => + helper.dispatchSettingsChange({ + numCopies: 2, + }) + ); + await BrowserTestUtils.waitForCondition( + () => helper.sheetCount != singleSidedSheets, + "Wait for sheet count to update" + ); + let twoCopiesSheetCount = helper.sheetCount; + + // Turn on duplex printing. + await helper.waitForSettingsEvent(() => + helper.dispatchSettingsChange({ + duplex: Ci.nsIPrintSettings.kDuplexFlipOnLongEdge, + }) + ); + await BrowserTestUtils.waitForCondition( + () => helper.sheetCount != twoCopiesSheetCount, + "Wait for sheet count to update" + ); + let duplexTwoCopiesSheetCount = helper.sheetCount; + + // Check sheet count accounts for duplex and numCopies. + is( + duplexTwoCopiesSheetCount, + Math.ceil(singleSidedSheets / 2) * 2, + "Duplex with 2 copies sheet count is correct" + ); + + await helper.closeDialog(); + }); +} + add_task(async function testPagesPerSheetCount() { await PrintHelper.withTestPage(async helper => { let mockPrinterName = "A real printer!";