test_get_printer_paper_sizes.html (2649B)
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 is(typeof(printer.name), 'string', "Printer name should be a string."); 24 isnot(printer.name, "", "Printer name should never be empty."); 25 26 info(printer.name); 27 info("duplex(" + printer.supportsDuplex + ")"); 28 29 let printerInfo = await printer.printerInfo; 30 for (let paper of printerInfo.paperList) { 31 paper.QueryInterface(Ci.nsIPaper); 32 33 info(`${paper.name}: ${paper.width}x${paper.height}`); 34 35 is(typeof(paper.name), 'string', "Paper name should be a string."); 36 isnot(paper.name, "", "Paper name should never be empty."); 37 38 is(typeof(paper.width), 'number', "Paper width should be a number."); 39 ok(paper.width > 0.0, "Paper width should be greater than zero."); 40 41 is(typeof(paper.height), 'number', "Paper height should be a number."); 42 ok(paper.height > 0.0, "Paper height should be greater than zero."); 43 44 let margin = await paper.unwriteableMargin; 45 margin.QueryInterface(Ci.nsIPaperMargin); 46 47 info(`with margin: ${margin.top} ${margin.right} ${margin.bottom} ${margin.left}`); 48 49 is(typeof(margin.top), 'number', "Paper unwriteable margin top should be a number."); 50 is(typeof(margin.right), 'number', "Paper unwriteable margin right should be a number."); 51 is(typeof(margin.bottom), 'number', "Paper unwriteable margin bottom should be a number."); 52 is(typeof(margin.left), 'number', "Paper unwriteable margin left should be a number."); 53 54 ok(margin.top >= 0.0, "Paper unwriteable margin top should be greater than or equal to zero."); 55 ok(margin.right >= 0.0, "Paper unwriteable margin right should be greater than or equal to zero."); 56 ok(margin.bottom >= 0.0, "Paper unwriteable bottom right should be greater than or equal to zero."); 57 ok(margin.left >= 0.0, "Paper unwriteable margin left should be greater than or equal to zero."); 58 } 59 } 60 } catch (e) { 61 ok(false, `Shouldn't throw: ${e}`); 62 console.error(e); 63 } 64 SimpleTest.finish(); 65 } 66 67 </script> 68 </body> 69 </html>