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

"use strict";

add_task(async function test_download_shortcut() {
  await SpecialPowers.pushPrefEnv({
    set: [["browser.download.useDownloadDir", true]],
  });

  let publicDownloads = await Downloads.getList(Downloads.PUBLIC);
  // First ensure we catch the download finishing.
  let downloadFinishedPromise = new Promise(resolve => {
    publicDownloads.addView({
      onDownloadChanged(download) {
        info("Download changed!");
        if (download.succeeded || download.error) {
          info("Download succeeded or errored");
          publicDownloads.removeView(this);
          resolve(download);
        }
      },
    });
  });

  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: TEST_PAGE,
    },
    async browser => {
      let helper = new ScreenshotsHelper(browser);

      helper.triggerUIFromToolbar();
      await helper.waitForOverlay();
      await helper.dragOverlay(10, 10, 500, 500);

      let screenshotExit = TestUtils.topicObserved("screenshots-exit");

      await SpecialPowers.spawn(browser, [], async () => {
        EventUtils.synthesizeKey("s", { accelKey: true }, content);
      });

      info("wait for download to finish");
      let download = await downloadFinishedPromise;

      ok(download.succeeded, "Download should succeed");

      await publicDownloads.removeFinished();
      await screenshotExit;

      helper.triggerUIFromToolbar();
      await helper.waitForOverlay();

      let screenshotReady = TestUtils.topicObserved(
        "screenshots-preview-ready"
      );

      let visibleButton = await helper.getPanelButton(".visible-page");
      visibleButton.click();

      await screenshotReady;

      screenshotExit = TestUtils.topicObserved("screenshots-exit");

      EventUtils.synthesizeKey("s", { accelKey: true });

      info("wait for download to finish");
      download = await downloadFinishedPromise;

      ok(download.succeeded, "Download should succeed");

      await publicDownloads.removeFinished();
      await screenshotExit;
    }
  );
});

add_task(async function test_copy_shortcut() {
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: TEST_PAGE,
    },
    async browser => {
      let helper = new ScreenshotsHelper(browser);
      let contentInfo = await helper.getContentDimensions();
      ok(contentInfo, "Got dimensions back from the content");

      helper.triggerUIFromToolbar();
      await helper.waitForOverlay();
      await helper.dragOverlay(10, 10, 500, 500);

      let screenshotExit = TestUtils.topicObserved("screenshots-exit");
      let clipboardChanged = helper.waitForRawClipboardChange(490, 490);

      await SpecialPowers.spawn(browser, [], async () => {
        EventUtils.synthesizeKey("c", { accelKey: true }, content);
      });

      await clipboardChanged;
      await screenshotExit;

      helper.triggerUIFromToolbar();
      await helper.waitForOverlay();

      let screenshotReady = TestUtils.topicObserved(
        "screenshots-preview-ready"
      );

      let visibleButton = await helper.getPanelButton(".visible-page");
      visibleButton.click();

      await screenshotReady;

      clipboardChanged = helper.waitForRawClipboardChange(
        contentInfo.clientWidth,
        contentInfo.clientHeight
      );
      screenshotExit = TestUtils.topicObserved("screenshots-exit");

      EventUtils.synthesizeKey("c", { accelKey: true });

      await clipboardChanged;
      await screenshotExit;
    }
  );
});