summaryrefslogtreecommitdiffstats
path: root/browser/components/customizableui/test/browser_panel_locationSpecific.js
blob: 9965a141b292a244d9e6b93d616a4b153a70c8e1 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/*
 * This test creates multiple panels, one that has been tagged as location specific
 * and one that isn't. When the location changes, the specific panel should close.
 * The non-specific panel should remain open.
 *
 */

add_task(async function () {
  let specificPanel = document.createXULElement("panel");
  specificPanel.setAttribute("locationspecific", "true");
  specificPanel.setAttribute("noautohide", "true");
  specificPanel.style.height = "100px";
  specificPanel.style.width = "100px";

  let generalPanel = document.createXULElement("panel");
  generalPanel.setAttribute("noautohide", "true");
  generalPanel.style.height = "100px";
  generalPanel.style.width = "100px";

  let anchor = document.getElementById(CustomizableUI.AREA_NAVBAR);

  anchor.appendChild(specificPanel);
  anchor.appendChild(generalPanel);
  is(specificPanel.state, "closed", "specificPanel starts as closed");
  is(generalPanel.state, "closed", "generalPanel starts as closed");

  let specificPanelPromise = BrowserTestUtils.waitForEvent(
    specificPanel,
    "popupshown"
  );

  specificPanel.openPopupAtScreen(0, 0);

  await specificPanelPromise;
  is(specificPanel.state, "open", "specificPanel has been opened");

  let generalPanelPromise = BrowserTestUtils.waitForEvent(
    generalPanel,
    "popupshown"
  );

  generalPanel.openPopupAtScreen(100, 0);

  await generalPanelPromise;
  is(generalPanel.state, "open", "generalPanel has been opened");

  let specificPanelHiddenPromise = BrowserTestUtils.waitForEvent(
    specificPanel,
    "popuphidden"
  );

  // Simulate a location change, and check which panel closes.
  let browser = gBrowser.selectedBrowser;
  let loaded = BrowserTestUtils.browserLoaded(browser);
  BrowserTestUtils.startLoadingURIString(browser, "http://mochi.test:8888/#0");
  await loaded;

  await specificPanelHiddenPromise;

  is(
    specificPanel.state,
    "closed",
    "specificPanel panel is closed after location change"
  );
  is(
    generalPanel.state,
    "open",
    "generalPanel is still open after location change"
  );

  specificPanel.remove();
  generalPanel.remove();
});