summaryrefslogtreecommitdiffstats
path: root/toolkit/components/printing/tests/browser_system_dialog_subdialog_hidden.js
blob: fb60af901c68ed3edad88803e8bc4501ef5618eb (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

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

    is(
      helper.get("printer-picker").options.length,
      1,
      "Only the Save to PDF printer is available"
    );

    let systemLink = helper.get("open-dialog-link");
    if (AppConstants.platform == "win") {
      ok(
        BrowserTestUtils.isHidden(systemLink),
        "Link is hidden on Windows with no extra printers"
      );
    } else {
      ok(
        BrowserTestUtils.isVisible(systemLink),
        "Link is visible on Linux/macOS"
      );
    }
  });
});

add_task(async function testModalPrintDialog() {
  await PrintHelper.withTestPage(async helper => {
    helper.addMockPrinter("A printer");
    await SpecialPowers.pushPrefEnv({
      set: [["print_printer", "A printer"]],
    });

    await helper.startPrint();

    helper.assertDialogOpen();

    helper.assertSettingsMatch({ printerName: "A printer" });
    await helper.setupMockPrint();

    helper.click(helper.get("open-dialog-link"));

    helper.assertDialogHidden();

    await helper.withClosingFn(() => {
      helper.resolveShowSystemDialog();
      helper.resolvePrint();
    });

    helper.assertDialogClosed();
  });
});

add_task(async function testModalPrintDialogCancelled() {
  await PrintHelper.withTestPage(async helper => {
    helper.addMockPrinter("A printer");
    await SpecialPowers.pushPrefEnv({
      set: [["print_printer", "A printer"]],
    });

    await helper.startPrint();

    helper.assertDialogOpen();

    helper.assertSettingsMatch({ printerName: "A printer" });
    await helper.setupMockPrint();

    helper.click(helper.get("open-dialog-link"));

    helper.assertDialogHidden();

    await helper.withClosingFn(() => {
      helper.resolveShowSystemDialog(false);
    });

    helper.assertDialogClosed();
  });
});

add_task(async function testPrintDoesNotWaitForPreview() {
  await PrintHelper.withTestPage(async helper => {
    helper.addMockPrinter("A printer");
    await SpecialPowers.pushPrefEnv({
      set: [["print_printer", "A printer"]],
    });

    await helper.startPrint({ waitFor: "loadComplete" });
    await helper.awaitAnimationFrame();

    helper.mockFilePicker("print_does_not_wait_for_preview.pdf");
    await helper.setupMockPrint();

    let systemPrint = helper.get("system-print");
    await BrowserTestUtils.waitForCondition(
      () => BrowserTestUtils.isVisible(systemPrint),
      "Wait for the system-print to be visible"
    );

    helper.click(helper.get("open-dialog-link"));

    helper.assertDialogHidden();
    await helper.withClosingFn(() => {
      helper.resolveShowSystemDialog();
      helper.resolvePrint();
    });

    helper.assertDialogClosed();
  });
});