summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/popups/browser_popup_new_window_size.js
blob: 5f5d57e31e68bfe4ef1dd0ef09dc9d888b5accd0 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

const baseURL = getRootDirectory(gTestPath).replace(
  "chrome://mochitests/content",
  "https://example.com"
);

add_task(async function test_new_window_size() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    window.gBrowser,
    baseURL
  );

  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
    info("Opening popup.");
    let requestedWidth = 200;
    let requestedHeight = 200;
    let win = this.content.open(
      "popup_size.html",
      "",
      `width=${requestedWidth},height=${requestedHeight}`
    );

    let loadPromise = ContentTaskUtils.waitForEvent(win, "load");

    let { innerWidth: preLoadWidth, innerHeight: preLoadHeight } = win;
    is(preLoadWidth, requestedWidth, "Width before load event.");
    is(preLoadHeight, requestedHeight, "Height before load event.");

    await loadPromise;

    let { innerWidth: postLoadWidth, innerHeight: postLoadHeight } = win;
    is(postLoadWidth, requestedWidth, "Width after load event.");
    is(postLoadHeight, requestedHeight, "Height after load event.");

    await ContentTaskUtils.waitForCondition(
      () =>
        win.innerWidth == requestedWidth && win.innerHeight == requestedHeight,
      "Waiting for window to become request size."
    );

    let { innerWidth: finalWidth, innerHeight: finalHeight } = win;
    is(finalWidth, requestedWidth, "Final width.");
    is(finalHeight, requestedHeight, "Final height.");

    await SpecialPowers.spawn(
      win,
      [{ requestedWidth, requestedHeight }],
      async input => {
        let { initialSize, loadSize } = this.content.wrappedJSObject;
        is(
          initialSize.width,
          input.requestedWidth,
          "Content width before load event."
        );
        is(
          initialSize.height,
          input.requestedHeight,
          "Content height before load event."
        );
        is(
          loadSize.width,
          input.requestedWidth,
          "Content width after load event."
        );
        is(
          loadSize.height,
          input.requestedHeight,
          "Content height after load event."
        );
        is(
          this.content.innerWidth,
          input.requestedWidth,
          "Content final width."
        );
        is(
          this.content.innerHeight,
          input.requestedHeight,
          "Content final height."
        );
      }
    );

    info("Closing popup.");
    win.close();
  });

  await BrowserTestUtils.removeTab(tab);
});