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

"use strict";

/**
 * This test ensures the overlay is covering the entire window event thought
 * the body is smaller than the viewport
 */
add_task(async function test_overlay() {
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: SHORT_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 dimensions = await helper.getSelectionLayerDimensions();
      Assert.equal(
        dimensions.scrollWidth,
        contentInfo.clientWidth,
        "The overlay spans the width of the window"
      );

      Assert.equal(
        dimensions.scrollHeight,
        contentInfo.clientHeight,
        "The overlay spans the height of the window"
      );
    }
  );
});

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

      const originalWindowWidth = window.outerWidth;
      const originalWindowHeight = window.outerHeight;

      const BIG_WINDOW_SIZE = 920;
      const SMALL_WINDOW_SIZE = 620;

      window.resizeTo(SMALL_WINDOW_SIZE, SMALL_WINDOW_SIZE);
      await TestUtils.waitForCondition(() => {
        info(
          `Got ${window.outerWidth}x${
            window.outerHeight
          }. Expecting ${SMALL_WINDOW_SIZE}. ${
            window.outerHeight === SMALL_WINDOW_SIZE
          } ${window.outerWidth === SMALL_WINDOW_SIZE}`
        );
        return (
          window.outerHeight === SMALL_WINDOW_SIZE &&
          window.outerWidth === SMALL_WINDOW_SIZE
        );
      }, "Waiting for window to resize");

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

      let dimensions = await helper.getSelectionLayerDimensions();
      let oldWidth = dimensions.scrollWidth;
      let oldHeight = dimensions.scrollHeight;

      window.resizeTo(BIG_WINDOW_SIZE, BIG_WINDOW_SIZE);
      await TestUtils.waitForCondition(
        () =>
          window.outerHeight === BIG_WINDOW_SIZE &&
          window.outerWidth === BIG_WINDOW_SIZE,
        "Waiting for window to resize"
      );
      await helper.waitForSelectionLayerDimensionChange(oldWidth, oldHeight);

      contentInfo = await helper.getContentDimensions();
      dimensions = await helper.getSelectionLayerDimensions();
      Assert.equal(
        dimensions.scrollWidth,
        contentInfo.clientWidth,
        "The overlay spans the width of the window"
      );
      Assert.equal(
        dimensions.scrollHeight,
        contentInfo.clientHeight,
        "The overlay spans the height of the window"
      );

      oldWidth = dimensions.scrollWidth;
      oldHeight = dimensions.scrollHeight;

      window.resizeTo(SMALL_WINDOW_SIZE, SMALL_WINDOW_SIZE);
      await TestUtils.waitForCondition(
        () =>
          window.outerHeight === SMALL_WINDOW_SIZE &&
          window.outerWidth === SMALL_WINDOW_SIZE,
        "Waiting for window to resize"
      );
      await helper.waitForSelectionLayerDimensionChange(oldWidth, oldHeight);

      contentInfo = await helper.getContentDimensions();
      dimensions = await helper.getSelectionLayerDimensions();
      Assert.equal(
        dimensions.scrollWidth,
        contentInfo.clientWidth,
        "The overlay spans the width of the window"
      );
      Assert.equal(
        dimensions.scrollHeight,
        contentInfo.clientHeight,
        "The overlay spans the height of the window"
      );

      ok(
        dimensions.scrollWidth < BIG_WINDOW_SIZE,
        "Screenshots overlay is smaller than the big window width"
      );
      ok(
        dimensions.scrollHeight < BIG_WINDOW_SIZE,
        "Screenshots overlay is smaller than the big window height"
      );

      window.resizeTo(originalWindowWidth, originalWindowHeight);
      await TestUtils.waitForCondition(
        () =>
          window.outerHeight === originalWindowHeight &&
          window.outerWidth === originalWindowWidth,
        "Waiting for window to resize"
      );
    }
  );
});