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

"use strict";

function assertRange(lhs, rhsMin, rhsMax, msg) {
  Assert.ok(lhs >= rhsMin && lhs <= rhsMax, msg);
}

add_task(async function test_fullpageScreenshot() {
  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");

      // click toolbar button so panel shows
      helper.triggerUIFromToolbar();

      let panel = await helper.waitForPanel();

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

      // click the full page button in panel
      let visiblePage = panel
        .querySelector("screenshots-buttons")
        .shadowRoot.querySelector(".full-page");
      visiblePage.click();

      let dialog = helper.getDialog();

      await screenshotReady;

      let copyButton = dialog._frame.contentDocument.getElementById("copy");
      ok(copyButton, "Got the copy button");

      let clipboardChanged = helper.waitForRawClipboardChange();

      // click copy button on dialog box
      copyButton.click();

      info("Waiting for clipboard change");
      await clipboardChanged;

      let result = await helper.getImageSizeAndColorFromClipboard();
      info("result: " + JSON.stringify(result, null, 2));
      info("contentInfo: " + JSON.stringify(contentInfo, null, 2));

      Assert.equal(
        contentInfo.scrollWidth,
        result.width,
        "Widths should be equal"
      );

      Assert.equal(
        contentInfo.scrollHeight,
        result.height,
        "Heights should be equal"
      );

      // top left
      assertRange(result.color.topLeft[0], 110, 111, "R color value");
      assertRange(result.color.topLeft[1], 110, 111, "G color value");
      assertRange(result.color.topLeft[2], 110, 111, "B color value");

      // top right
      assertRange(result.color.topRight[0], 55, 56, "R color value");
      assertRange(result.color.topRight[1], 155, 156, "G color value");
      assertRange(result.color.topRight[2], 155, 156, "B color value");

      // bottom left
      assertRange(result.color.bottomLeft[0], 105, 106, "R color value");
      assertRange(result.color.bottomLeft[1], 55, 56, "G color value");
      assertRange(result.color.bottomLeft[2], 105, 106, "B color value");

      // bottom right
      assertRange(result.color.bottomRight[0], 52, 53, "R color value");
      assertRange(result.color.bottomRight[1], 127, 128, "G color value");
      assertRange(result.color.bottomRight[2], 152, 153, "B color value");
    }
  );
});

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

      await SpecialPowers.spawn(browser, [], () => {
        content.scrollTo(0, 2008);
      });
      let contentInfo = await helper.getContentDimensions();
      ok(contentInfo, "Got dimensions back from the content");

      // click toolbar button so panel shows
      helper.triggerUIFromToolbar();
      await helper.waitForOverlay();

      let panel = await helper.waitForPanel();

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

      // click the full page button in panel
      let visiblePage = panel
        .querySelector("screenshots-buttons")
        .shadowRoot.querySelector(".full-page");
      visiblePage.click();

      let dialog = helper.getDialog();

      await screenshotReady;

      let copyButton = dialog._frame.contentDocument.getElementById("copy");
      ok(copyButton, "Got the copy button");

      let clipboardChanged = helper.waitForRawClipboardChange();

      // click copy button on dialog box
      copyButton.click();

      info("Waiting for clipboard change");
      await clipboardChanged;

      let result = await helper.getImageSizeAndColorFromClipboard();
      info("result: " + JSON.stringify(result, null, 2));
      info("contentInfo: " + JSON.stringify(contentInfo, null, 2));

      Assert.equal(
        contentInfo.scrollWidth,
        result.width,
        "Widths should be equal"
      );

      Assert.equal(
        contentInfo.scrollHeight,
        result.height,
        "Heights should be equal"
      );

      // top left
      assertRange(result.color.topLeft[0], 110, 111, "R color value");
      assertRange(result.color.topLeft[1], 110, 111, "G color value");
      assertRange(result.color.topLeft[2], 110, 111, "B color value");

      // top right
      assertRange(result.color.topRight[0], 55, 56, "R color value");
      assertRange(result.color.topRight[1], 155, 156, "G color value");
      assertRange(result.color.topRight[2], 155, 156, "B color value");

      // bottom left
      assertRange(result.color.bottomLeft[0], 105, 106, "R color value");
      assertRange(result.color.bottomLeft[1], 55, 56, "G color value");
      assertRange(result.color.bottomLeft[2], 105, 106, "B color value");

      // bottom right
      assertRange(result.color.bottomRight[0], 52, 53, "R color value");
      assertRange(result.color.bottomRight[1], 127, 128, "G color value");
      assertRange(result.color.bottomRight[2], 152, 153, "B color value");
    }
  );
});