Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!doctype html>
<!-- Any copyright is dedicated to the Public Domain.
<html>
<head>
<title>Test Panel List In XUL Panel</title>
<script type="text/javascript" src="head.js"></script>
<link
rel="stylesheet"
href="chrome://global/skin/global.css"
type="text/css"
/>
<link
rel="stylesheet"
type="text/css"
/>
</head>
<body>
<p id="display"></p>
<div id="content">
<button id="anchor-button">Open</button>
</div>
<script class="testbody" type="application/javascript">
const { BrowserTestUtils } = ChromeUtils.importESModule(
);
let xulPanel, anchorButton, panelList;
add_setup(function setup() {
// The HTML document parser doesn't let us put XUL elements in the markup, so
// we have to create the <xul:panel> programmatically with script.
let content = document.getElementById("content");
xulPanel = document.createXULElement("panel");
// Create panel-list programmatically so it's never connected outside XUL panel
panelList = document.createElement("panel-list");
panelList.id = "panel-list";
["one", "two", "three", "four", "five", "six"].forEach(text => {
let item = document.createElement("panel-item");
item.textContent = text;
panelList.appendChild(item);
});
xulPanel.appendChild(panelList);
content.appendChild(xulPanel);
anchorButton = document.getElementById("anchor-button");
anchorButton.addEventListener("click", e => panelList.toggle(e));
});
add_task(async function testSupportsPopover() {
ok(
!panelList.supportsPopover(),
"Panel list should not support popover when inside a XUL panel"
);
ok(
!panelList.hasAttribute("popover"),
"Panel list inside XUL panel should not have popover attribute"
);
});
add_task(async function testXULPanelOpenFromClicks() {
let xulPanelShown = BrowserTestUtils.waitForPopupEvent(
xulPanel,
"shown"
);
let shown = BrowserTestUtils.waitForEvent(panelList, "shown");
synthesizeMouseAtCenter(anchorButton, {});
await shown;
await xulPanelShown;
ok(
panelList.hasAttribute("inxulpanel"),
"Should have inxulpanel attribute set"
);
let style = window.getComputedStyle(panelList);
is(style.top, "0px", "computed top inline style should be 0px.");
is(style.left, "0px", "computed left inline style should be 0px.");
let xulPanelHidden = BrowserTestUtils.waitForPopupEvent(
xulPanel,
"hidden"
);
let hidden = BrowserTestUtils.waitForEvent(panelList, "hidden");
synthesizeKey("Escape", {});
await hidden;
await xulPanelHidden;
});
add_task(async function testXULPanelOpenProgrammatically() {
let xulPanelShown = BrowserTestUtils.waitForPopupEvent(
xulPanel,
"shown"
);
let shown = BrowserTestUtils.waitForEvent(panelList, "shown");
panelList.show();
await shown;
await xulPanelShown;
ok(
panelList.hasAttribute("inxulpanel"),
"Should have inxulpanel attribute set"
);
let style = window.getComputedStyle(panelList);
is(style.top, "0px", "computed top inline style should be 0px.");
is(style.left, "0px", "computed left inline style should be 0px.");
let xulPanelHidden = BrowserTestUtils.waitForPopupEvent(
xulPanel,
"hidden"
);
let hidden = BrowserTestUtils.waitForEvent(panelList, "hidden");
panelList.hide();
await hidden;
await xulPanelHidden;
});
</script>
</body>
</html>