From aa67c5a592026cf42e15b02371259d808d086eb3 Mon Sep 17 00:00:00 2001 From: Matthew Noorenberghe Date: Tue, 13 Jul 2021 00:25:38 +0000 Subject: [PATCH] Bug 1670027 - Always compute isPrintSelectionRBEnabled for the settings passed to the system print dialog. r=mstriemer When the Mozilla PDF printer is selected, a new settings object was created without the value of isPrintSelectionRBEnabled computed. Differential Revision: https://phabricator.services.mozilla.com/D119578 --- toolkit/components/printing/content/print.js | 3 ++ .../printing/tests/browser_print_selection.js | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/toolkit/components/printing/content/print.js b/toolkit/components/printing/content/print.js index db85fe39d60d..cba429ece713 100644 --- a/toolkit/components/printing/content/print.js +++ b/toolkit/components/printing/content/print.js @@ -307,6 +307,9 @@ var PrintEventHandler = { ? PrintUtils.getPrintSettings(this.viewSettings.defaultSystemPrinter) : this.settings.clone(); settings.showPrintProgress = false; + // Update the settings print options on whether there is a selection since + // getPrintSettings won't have the correct value. + settings.isPrintSelectionRBEnabled = this.hasSelection; // We set the title so that if the user chooses save-to-PDF from the // system dialog the title will be used to generate the prepopulated // filename in the file picker. diff --git a/toolkit/components/printing/tests/browser_print_selection.js b/toolkit/components/printing/tests/browser_print_selection.js index 9fb66e0f1a58..1a02fff63796 100644 --- a/toolkit/components/printing/tests/browser_print_selection.js +++ b/toolkit/components/printing/tests/browser_print_selection.js @@ -148,3 +148,47 @@ add_task(async function print_selection_switch() { await helper.closeDialog(); }); }); + +add_task(async function open_system_print_with_selection_and_pdf() { + await BrowserTestUtils.withNewTab( + "data:text/html," + sources[0], + async function(browser) { + let frameBC = browser.browsingContext.children[0]; + await SpecialPowers.spawn(frameBC, [], () => { + let element = content.document.getElementById("other"); + content.focus(); + content.getSelection().selectAllChildren(element); + }); + + let helper = new PrintHelper(browser); + + // Add another printer so the system dialog link is shown on Windows. + helper.addMockPrinter("A printer"); + + PrintUtils.startPrintWindow(frameBC, {}); + + await waitForPreviewVisible(); + + // Ensure that the PDF printer is selected since the way settings are + // cloned is different in this case. + is( + helper.settings.printerName, + "Mozilla Save to PDF", + "Mozilla Save to PDF is the current printer." + ); + + await helper.setupMockPrint(); + + helper.click(helper.get("open-dialog-link")); + await helper.withClosingFn(() => { + helper.resolveShowSystemDialog(); + helper.resolvePrint(); + }); + + helper.assertPrintedWithSettings({ + isPrintSelectionRBEnabled: true, + }); + PrintHelper.resetPrintPrefs(); + } + ); +});