summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/browser/browser_ext_browserAction_popup_resize.js
blob: 4a7ec8f2b7fbd83581b338f4ea806f56cb209839 (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
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";

loadTestSubscript("head_browserAction.js");

add_task(async function testBrowserActionPopupResize() {
  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      browser_action: {
        default_popup: "popup.html",
        default_area: "navbar",
        browser_style: true,
      },
    },

    files: {
      "popup.html":
        '<!DOCTYPE html><html><head><meta charset="utf-8"></head></html>',
    },
  });

  await extension.startup();

  let browser = await openBrowserActionPanel(extension, undefined, true);

  async function checkSize(expected) {
    let dims = await promiseContentDimensions(browser);

    Assert.lessOrEqual(
      Math.abs(dims.window.innerHeight - expected),
      1,
      `Panel window should be ${expected}px tall (was ${dims.window.innerHeight})`
    );
    is(
      dims.body.clientHeight,
      dims.body.scrollHeight,
      "Panel body should be tall enough to fit its contents"
    );

    // Tolerate if it is 1px too wide, as that may happen with the current resizing method.
    Assert.lessOrEqual(
      Math.abs(dims.window.innerWidth - expected),
      1,
      `Panel window should be ${expected}px wide`
    );
    is(
      dims.body.clientWidth,
      dims.body.scrollWidth,
      "Panel body should be wide enough to fit its contents"
    );
  }

  function setSize(size) {
    content.document.body.style.height = `${size}px`;
    content.document.body.style.width = `${size}px`;
  }

  let sizes = [200, 400, 300];

  for (let size of sizes) {
    await alterContent(browser, setSize, size);
    await checkSize(size);
  }

  let popup = getBrowserActionPopup(extension);
  await closeBrowserAction(extension);
  is(popup.state, "closed", "browserAction popup has been closed");

  await extension.unload();
});

add_task(async function testBrowserActionMenuResizeStandards() {
  await testPopupSize(true);
});

add_task(async function testBrowserActionMenuResizeQuirks() {
  await testPopupSize(false);
});