tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_printer_default_settings.html (2420B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      5 </head>
      6 <body onload="run()">
      7 <script type="application/javascript">
      8 
      9 SimpleTest.waitForExplicitFinish();
     10 
     11 async function run() {
     12  try {
     13    let printerList = Cc["@mozilla.org/gfx/printerlist;1"].getService(
     14      Ci.nsIPrinterList
     15    );
     16    let printers = await printerList.printers;
     17    if (printers.length == 0) {
     18      ok(true, "There were no printers to iterate through.");
     19    }
     20 
     21    for (let printer of printers) {
     22      printer.QueryInterface(Ci.nsIPrinter);
     23      info(printer.name);
     24      info("duplex(" + await printer.supportsDuplex + ")");
     25 
     26      const printerInfo = await printer.printerInfo;
     27      const settings = printerInfo.defaultSettings;
     28      settings.QueryInterface(Ci.nsIPrintSettings);
     29 
     30      is(typeof settings.printerName, "string", "Printer name should be a string.");
     31      is(settings.printerName, printer.name, "Print settings' printer should match the printer that created them.");
     32 
     33      is(typeof settings.paperId, "string", "Paper ID should never be null.");
     34      is(typeof settings.paperWidth, "number", "Paper width should never be null.");
     35      is(typeof settings.paperHeight, "number", "Paper height should never be null.");
     36 
     37      if (settings.paperId != "") {
     38        info(`Paper: ${settings.paperId}`);
     39        info(`Size:  (${settings.paperWidth} x ${settings.paperHeight})`);
     40        ok(settings.paperWidth  > 0.0, "Paper width should be greater than zero.");
     41        ok(settings.paperHeight > 0.0, "Paper height should be greater than zero.");
     42      }
     43 
     44      ok(settings.marginTop    >= 0.0, "Paper margins should be greater than or equal to zero.");
     45      ok(settings.marginRight  >= 0.0, "Paper margins should be greater than or equal to zero.");
     46      ok(settings.marginBottom >= 0.0, "Paper margins should be greater than or equal to zero.");
     47      ok(settings.marginLeft   >= 0.0, "Paper margins should be greater than or equal to zero.");
     48 
     49      is(settings.printInColor, await printer.supportsColor, "Print settings' color mode should match the printer's color support.");
     50 
     51      ok(settings.isInitializedFromPrinter, "Print settings were initialized from printer");
     52      ok(!settings.isInitializedFromPrefs);
     53    }
     54  } catch (e) {
     55    ok(false, `Shouldn't throw: ${e}`);
     56    console.error(e);
     57  }
     58  SimpleTest.finish();
     59 }
     60 
     61 </script>
     62 </body>
     63 </html>