layout/base/tests/chrome/test_get_printer_paper_sizes.html
author Serban Stanca <sstanca@mozilla.com>
Mon, 14 Jul 2025 00:37:50 +0300 (8 hours ago)
changeset 796395 57c30f1adca5fb5ccd4a9a09192c41e207e28d88
parent 644779 6f6c3f9376ee26f1300da7dee4a5d8b96b28744f
permissions -rw-r--r--
Revert "Bug 1950748 part 3: Don't return a caret inside an editor when no editor is focused. r=morgan" as requested for causing accessibility crashes (bug 1977012). This reverts commit aaf970807d281c28c1e937491719d996cb11648a. This reverts commit f5f2e3cf4d34c2430372ba790d77620837d56b75. This reverts commit 5565c5899c32c0b0f5446561a21c5b6499fd44c6.
<!DOCTYPE HTML>
<html>
<head>
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body onload="run()">
<script type="application/javascript">

SimpleTest.waitForExplicitFinish();

async function run() {
  try {
    let printerList = Cc["@mozilla.org/gfx/printerlist;1"].getService(
      Ci.nsIPrinterList
    );
    let printers = await printerList.printers;
    if (printers.length == 0) {
      ok(true, "There were no printers to iterate through.");
    }

    for (let printer of printers) {
      printer.QueryInterface(Ci.nsIPrinter);
      is(typeof(printer.name), 'string', "Printer name should be a string.");
      isnot(printer.name, "", "Printer name should never be empty.");

      info(printer.name);
      info("duplex(" + printer.supportsDuplex + ")");

      let printerInfo = await printer.printerInfo;
      for (let paper of printerInfo.paperList) {
        paper.QueryInterface(Ci.nsIPaper);

        info(`${paper.name}: ${paper.width}x${paper.height}`);

        is(typeof(paper.name), 'string', "Paper name should be a string.");
        isnot(paper.name, "", "Paper name should never be empty.");

        is(typeof(paper.width), 'number', "Paper width should be a number.");
        ok(paper.width > 0.0, "Paper width should be greater than zero.");

        is(typeof(paper.height), 'number', "Paper height should be a number.");
        ok(paper.height > 0.0, "Paper height should be greater than zero.");

        let margin = await paper.unwriteableMargin;
        margin.QueryInterface(Ci.nsIPaperMargin);

        info(`with margin: ${margin.top} ${margin.right} ${margin.bottom} ${margin.left}`);

        is(typeof(margin.top),    'number', "Paper unwriteable margin top should be a number.");
        is(typeof(margin.right),  'number', "Paper unwriteable margin right should be a number.");
        is(typeof(margin.bottom), 'number', "Paper unwriteable margin bottom should be a number.");
        is(typeof(margin.left),   'number', "Paper unwriteable margin left should be a number.");

        ok(margin.top    >= 0.0, "Paper unwriteable margin top should be greater than or equal to zero.");
        ok(margin.right  >= 0.0, "Paper unwriteable margin right should be greater than or equal to zero.");
        ok(margin.bottom >= 0.0, "Paper unwriteable bottom right should be greater than or equal to zero.");
        ok(margin.left   >= 0.0, "Paper unwriteable margin left should be greater than or equal to zero.");
      }
    }
  } catch (e) {
    ok(false, `Shouldn't throw: ${e}`);
    console.error(e);
  }
  SimpleTest.finish();
}

</script>
</body>
</html>