summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/browser/browser_ext_sidebarAction.js
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/extensions/test/browser/browser_ext_sidebarAction.js')
-rw-r--r--browser/components/extensions/test/browser/browser_ext_sidebarAction.js61
1 files changed, 48 insertions, 13 deletions
diff --git a/browser/components/extensions/test/browser/browser_ext_sidebarAction.js b/browser/components/extensions/test/browser/browser_ext_sidebarAction.js
index afc1e4f9b9..8498f73071 100644
--- a/browser/components/extensions/test/browser/browser_ext_sidebarAction.js
+++ b/browser/components/extensions/test/browser/browser_ext_sidebarAction.js
@@ -204,14 +204,16 @@ add_task(async function sidebar_isOpen() {
});
add_task(async function testShortcuts() {
- function verifyShortcut(id, commandKey) {
+ function verifyShortcut(id, commandKey, win = window) {
+ const doc = win.document;
// We're just testing the command key since the modifiers have different
// icons on different platforms.
- let menuitem = document.getElementById(
+ let menuitem = doc.getElementById(
`sidebarswitcher_menu_${makeWidgetId(id)}-sidebar-action`
);
+ ok(menuitem, `Expect a menuitem for ${id}`);
ok(menuitem.hasAttribute("key"), "The menu item has a key specified");
- let key = document.getElementById(menuitem.getAttribute("key"));
+ let key = doc.getElementById(menuitem.getAttribute("key"));
ok(key, "The key attribute finds the related key element");
ok(
menuitem.getAttribute("acceltext").endsWith(commandKey),
@@ -219,6 +221,16 @@ add_task(async function testShortcuts() {
);
}
+ async function toggleSwitcherPanel(win = window) {
+ // Open and close the switcher panel to trigger shortcut content rendering.
+ let switcherPanelShown = promisePopupShown(win.SidebarUI._switcherPanel);
+ win.SidebarUI.showSwitcherPanel();
+ await switcherPanelShown;
+ let switcherPanelHidden = promisePopupHidden(win.SidebarUI._switcherPanel);
+ win.SidebarUI.hideSwitcherPanel();
+ await switcherPanelHidden;
+ }
+
let extension1 = ExtensionTestUtils.loadExtension(
getExtData({
commands: {
@@ -244,25 +256,48 @@ add_task(async function testShortcuts() {
await extension1.startup();
await extension1.awaitMessage("sidebar");
+ await extension2.startup();
+ await extension2.awaitMessage("sidebar");
- // Open and close the switcher panel to trigger shortcut content rendering.
- let switcherPanelShown = promisePopupShown(SidebarUI._switcherPanel);
- SidebarUI.showSwitcherPanel();
- await switcherPanelShown;
- let switcherPanelHidden = promisePopupHidden(SidebarUI._switcherPanel);
- SidebarUI.hideSwitcherPanel();
- await switcherPanelHidden;
+ info("Open a second window");
+ const win = await BrowserTestUtils.openNewBrowserWindow();
+ info("Wait for extension2 sidebar to be open in the new window");
+ await extension2.awaitMessage("sidebar");
+
+ info("Toggle switcher panel");
+ await toggleSwitcherPanel();
+ await toggleSwitcherPanel(win);
// Test that the key is set for the extension after the shortcuts are rendered.
verifyShortcut(extension1.id, "I");
-
- await extension2.startup();
- await extension2.awaitMessage("sidebar");
+ verifyShortcut(extension1.id, "I", win);
// Once the switcher panel has been opened new shortcuts should be added
// automatically.
verifyShortcut(extension2.id, "E");
+ verifyShortcut(extension2.id, "E", win);
+
+ // Regression test (see Bug 1881820).
+ info(
+ "Reload the addon and verify the sidebar shortcut still works as expected"
+ );
+ const addon = await AddonManager.getAddonByID(extension1.id);
+ await addon.reload();
+
+ const keysetId1 = `#ext-keyset-id-${makeWidgetId(extension1.id)}`;
+ Assert.equal(
+ window.document.querySelectorAll(keysetId1).length,
+ 1,
+ "Expect no keyset leaked in the 1st window after addon reload"
+ );
+ Assert.equal(
+ win.document.querySelectorAll(keysetId1).length,
+ 1,
+ "Expect no keyset leaked in the 2nd window after addon reload"
+ );
await extension1.unload();
await extension2.unload();
+
+ await BrowserTestUtils.closeWindow(win);
});