summaryrefslogtreecommitdiffstats
path: root/embedding/components/windowwatcher/test/browser_new_sized_window.js
blob: f4b1890b1edb4be78a120dbd984d7995b33e40cf (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
"use strict";

/**
 * Tests that content can open windows at requested dimensions
 * of height and width.
 */

/**
 * This utility function does most of the actual testing. We
 * construct a feature string suitable for the passed in width
 * and height, and then run that script in content to open the
 * new window. When the new window comes up, this function tests
 * to ensure that the content area of the initial browser is the
 * requested dimensions. Finally, we also ensure that we're not
 * persisting the position, size or sizemode of the new browser
 * window.
 */
function test_dimensions({ width, height}) {
  let features = [];
  if (width) {
    features.push(`width=${width}`);
  }
  if (height) {
    features.push(`height=${height}`);
  }
  const FEATURE_STR = features.join(",");
  const SCRIPT_PAGE = `data:text/html,<script>window.open("about:blank", "_blank", "${FEATURE_STR}");</script>`;

  let newWinPromise = BrowserTestUtils.waitForNewWindow();

  return BrowserTestUtils.withNewTab({
    gBrowser,
    url: SCRIPT_PAGE,
  }, function*(browser) {
    let win = yield newWinPromise;
    let rect = win.gBrowser.selectedBrowser.getBoundingClientRect();

    if (width) {
      Assert.equal(rect.width, width, "Should have the requested width");
    }

    if (height) {
      Assert.equal(rect.height, height, "Should have the requested height");
    }

    let treeOwner = win.QueryInterface(Ci.nsIInterfaceRequestor)
                       .getInterface(Ci.nsIDocShell)
                       .QueryInterface(Ci.nsIDocShellTreeItem)
                       .treeOwner;
    let persistPosition = {};
    let persistSize = {};
    let persistSizeMode = {};
    treeOwner.getPersistence(persistPosition, persistSize, persistSizeMode);

    Assert.ok(!persistPosition.value, "Should not persist position");
    Assert.ok(!persistSize.value, "Should not persist size");
    Assert.ok(!persistSizeMode.value, "Should not persist size mode");

    yield BrowserTestUtils.closeWindow(win);
  });
}

add_task(function* test_new_sized_window() {
  yield test_dimensions({ width: 100 });
  yield test_dimensions({ height: 150 });
  yield test_dimensions({ width: 300, height: 200 });
});