/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
var { MailServices } = ChromeUtils.importESModule(
"resource:///modules/MailServices.sys.mjs"
);
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
SmartMailboxUtils: "resource:///modules/SmartMailboxUtils.sys.mjs",
});
// Logs every window that opens during tests (esp. common dialogs).
(function installDialogLogger() {
const TOPIC = "domwindowopened";
function observer(subject, topic) {
if (topic !== TOPIC) {
return;
}
const win = subject;
win.addEventListener(
"load",
() => {
const doc = win.document;
const uri = doc.documentURI || "";
const wt = doc.documentElement?.getAttribute("windowtype") || "";
const title = doc.title || "";
info(
`[dialog] opened: windowtype="${wt}" uri="${uri}" title="${title}"`
);
},
{ once: true }
);
}
Services.obs.addObserver(observer, TOPIC);
registerCleanupFunction(() => Services.obs.removeObserver(observer, TOPIC));
})();
async function focusWindow(win) {
win.focus();
await TestUtils.waitForCondition(
() => Services.focus.focusedWindow?.browsingContext.topChromeWindow == win,
"waiting for window to be focused"
);
}
async function clickExtensionButton(win, buttonId) {
await focusWindow(win.top);
buttonId = CSS.escape(buttonId);
const actionButton = await TestUtils.waitForCondition(
() =>
win.document.querySelector(
`#${buttonId}, [item-id="${buttonId}"] button`
),
"waiting for the action button to exist"
);
await TestUtils.waitForCondition(
() => BrowserTestUtils.isVisible(actionButton),
"waiting for action button to be visible"
);
EventUtils.synthesizeMouseAtCenter(actionButton, {}, win);
return actionButton;
}
async function openExtensionPopup(win, buttonId) {
const actionButton = await clickExtensionButton(win, buttonId);
const panel = win.top.document.getElementById(
"webextension-remote-preload-panel"
);
const browser = panel.querySelector("browser");
await TestUtils.waitForCondition(
() => browser.clientWidth > 100,
"waiting for browser to resize"
);
return { actionButton, panel, browser };
}
function getSmartServer() {
const smartMailbox = lazy.SmartMailboxUtils.getSmartMailbox();
return smartMailbox.server;
}
function resetSmartMailboxes() {
// Clean up any leftover server from an earlier test.
lazy.SmartMailboxUtils.removeAll(false);
}
class MenuTestHelper {
/** @type {XULMenuElement} */
menu;
/**
* An object describing the state of a