fune/toolkit/components/printing/tests/browser_print_settings_fallback.js
Fred Chasen f63a70052e Bug 1790757 - Add fallback when getting print settings r=mstriemer
If the printer info returns without a name, or otherwise errors when checking the settings, it will prevent the print dialog from opening and switching to a different printer.

This wraps the intial refreshSettings call and tries to fallback to another printer if the last used one fails.

Differential Revision: https://phabricator.services.mozilla.com/D162437
2023-01-09 21:38:37 +00:00

39 lines
1,000 B
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
let badPrinterName = "Bad";
let otherPrinterName = "Fallback";
async function setupPrinters(helper) {
let badPrinter = helper.addMockPrinter({
name: badPrinterName,
});
let badPrinterInfo = await badPrinter.printerInfo;
badPrinterInfo.defaultSettings.printerName = "";
helper.addMockPrinter(otherPrinterName);
await SpecialPowers.pushPrefEnv({
set: [["print_printer", badPrinterName]],
});
}
add_task(async function testBadPrinterSettings() {
await PrintHelper.withTestPage(async helper => {
await setupPrinters(helper);
await helper.startPrint();
let destinationPicker = helper.get("printer-picker");
// Fallback can be any other printer, the fallback or save to pdf printer.
isnot(
destinationPicker.value,
badPrinterName,
"A fallback printer is selected"
);
await helper.closeDialog();
});
});