summaryrefslogtreecommitdiffstats
path: root/layout/base/tests/chrome/test_get_printer_paper_sizes.html
blob: 4ebe462ac6fe3783b9946b28b18fd5ee2e2a3f44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!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>