summaryrefslogtreecommitdiffstats
path: root/toolkit/components/printing/tests/browser_print_duplex.js
blob: 5fa59f46723de1a96bca40446fcace217f808572 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function testPDFPrinterIsNonDuplex() {
  await PrintHelper.withTestPage(async helper => {
    await helper.startPrint();
    await helper.openMoreSettings();

    is(
      helper.settings.printerName,
      "Mozilla Save to PDF",
      "Mozilla Save to PDF is the current printer."
    );

    const duplexSection = helper.get("two-sided-printing");
    ok(
      duplexSection.hidden,
      "The two-sided printing section should be hidden when the printer does not support duplex."
    );

    helper.assertSettingsMatch({ duplex: Ci.nsIPrintSettings.kSimplex });

    await helper.closeDialog();
  });
});

add_task(async function testToggleDuplexWithPortraitOrientation() {
  const mockPrinterName = "DuplexWithPortrait";
  await PrintHelper.withTestPage(async helper => {
    const printer = helper.addMockPrinter(mockPrinterName);
    printer.supportsDuplex = Promise.resolve(true);

    await helper.startPrint();
    await helper.dispatchSettingsChange({ printerName: mockPrinterName });
    await helper.awaitAnimationFrame();
    await helper.openMoreSettings();

    is(
      helper.settings.printerName,
      mockPrinterName,
      "The Fake Printer is current printer"
    );

    const duplexSection = helper.get("two-sided-printing");
    ok(
      !duplexSection.hidden,
      "The two-sided printing section should not be hidden when the printer supports duplex."
    );

    helper.assertSettingsMatch({
      orientation: Ci.nsIPrintSettings.kPortraitOrientation,
      duplex: Ci.nsIPrintSettings.kSimplex,
    });

    await helper.click(helper.get("duplex-enabled"));
    helper.assertSettingsMatch({
      orientation: Ci.nsIPrintSettings.kPortraitOrientation,
      duplex: Ci.nsIPrintSettings.kDuplexHorizontal,
    });

    await helper.click(helper.get("duplex-enabled"));
    helper.assertSettingsMatch({
      orientation: Ci.nsIPrintSettings.kPortraitOrientation,
      duplex: Ci.nsIPrintSettings.kSimplex,
    });

    await helper.closeDialog();
  });
});

add_task(async function testToggleDuplexWithLandscapeOrientation() {
  const mockPrinterName = "DuplexWithLandscape";
  await PrintHelper.withTestPage(async helper => {
    const printer = helper.addMockPrinter(mockPrinterName);
    printer.supportsDuplex = Promise.resolve(true);

    await helper.startPrint();
    await helper.dispatchSettingsChange({ printerName: mockPrinterName });
    await helper.awaitAnimationFrame();
    await helper.openMoreSettings();

    is(
      helper.settings.printerName,
      mockPrinterName,
      "The Fake Printer is current printer"
    );

    const duplexSection = helper.get("two-sided-printing");
    ok(
      !duplexSection.hidden,
      "The two-sided printing section should not be hidden when the printer supports duplex."
    );

    await helper.assertSettingsMatch({
      orientation: Ci.nsIPrintSettings.kPortraitOrientation,
      duplex: Ci.nsIPrintSettings.kSimplex,
    });

    await helper.dispatchSettingsChange({ orientation: 1 });
    await helper.awaitAnimationFrame();
    await helper.assertSettingsMatch({
      orientation: Ci.nsIPrintSettings.kLandscapeOrientation,
      duplex: Ci.nsIPrintSettings.kSimplex,
    });

    await helper.click(helper.get("duplex-enabled"));
    await helper.assertSettingsMatch({
      orientation: Ci.nsIPrintSettings.kLandscapeOrientation,
      duplex: Ci.nsIPrintSettings.kDuplexHorizontal,
    });

    await helper.click(helper.get("duplex-enabled"));
    await helper.assertSettingsMatch({
      orientation: Ci.nsIPrintSettings.kLandscapeOrientation,
      duplex: Ci.nsIPrintSettings.kSimplex,
    });

    await helper.closeDialog();
  });
});

add_task(async function testSwitchOrientationWithDuplexEnabled() {
  const mockPrinterName = "ToggleOrientationPrinter";
  await PrintHelper.withTestPage(async helper => {
    const printer = helper.addMockPrinter(mockPrinterName);
    printer.supportsDuplex = Promise.resolve(true);

    await helper.startPrint();
    await helper.dispatchSettingsChange({ printerName: mockPrinterName });
    await helper.awaitAnimationFrame();
    await helper.openMoreSettings();

    is(
      helper.settings.printerName,
      mockPrinterName,
      "The Fake Printer is current printer"
    );

    const duplexSection = helper.get("two-sided-printing");
    ok(
      !duplexSection.hidden,
      "The two-sided printing section should not be hidden when the printer supports duplex."
    );

    await helper.assertSettingsMatch({
      orientation: Ci.nsIPrintSettings.kPortraitOrientation,
      duplex: Ci.nsIPrintSettings.kSimplex,
    });

    await helper.click(helper.get("duplex-enabled"));
    await helper.assertSettingsMatch({
      orientation: Ci.nsIPrintSettings.kPortraitOrientation,
      duplex: Ci.nsIPrintSettings.kDuplexHorizontal,
    });

    await helper.dispatchSettingsChange({ orientation: 1 });
    await helper.awaitAnimationFrame();
    await helper.assertSettingsMatch({
      orientation: Ci.nsIPrintSettings.kLandscapeOrientation,
      duplex: Ci.nsIPrintSettings.kDuplexHorizontal,
    });

    await helper.dispatchSettingsChange({ orientation: 0 });
    await helper.awaitAnimationFrame();
    await helper.assertSettingsMatch({
      orientation: Ci.nsIPrintSettings.kPortraitOrientation,
      duplex: Ci.nsIPrintSettings.kDuplexHorizontal,
    });

    await helper.closeDialog();
  });
});