зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1453355 - Add sidebarAction.toggle() to WebExtensions API r=mixedpuppy
Differential Revision: https://phabricator.services.mozilla.com/D54005 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
85b60ab28d
Коммит
6180dbb2e7
|
@ -420,6 +420,24 @@ this.sidebarAction = class extends ExtensionAPI {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toogles this sidebar action for the given window
|
||||
*
|
||||
* @param {ChromeWindow} window
|
||||
*/
|
||||
toggle(window) {
|
||||
let { SidebarUI } = window;
|
||||
if (!SidebarUI || !this.extension.canAccessWindow(window)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.isOpen(window)) {
|
||||
SidebarUI.show(this.id);
|
||||
} else {
|
||||
SidebarUI.hide();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this sidebar action is open in the given window.
|
||||
*
|
||||
|
@ -488,6 +506,13 @@ this.sidebarAction = class extends ExtensionAPI {
|
|||
}
|
||||
},
|
||||
|
||||
toggle() {
|
||||
let window = windowTracker.topWindow;
|
||||
if (context.canAccessWindow(window)) {
|
||||
sidebarAction.toggle(window);
|
||||
}
|
||||
},
|
||||
|
||||
isOpen(details) {
|
||||
let { windowId } = details;
|
||||
if (windowId == null) {
|
||||
|
|
|
@ -241,6 +241,14 @@
|
|||
"async": true,
|
||||
"parameters": []
|
||||
},
|
||||
{
|
||||
"name": "toggle",
|
||||
"type": "function",
|
||||
"requireUserInput": true,
|
||||
"description": "Toggles the extension sidebar in the active window.",
|
||||
"async": true,
|
||||
"parameters": []
|
||||
},
|
||||
{
|
||||
"name": "isOpen",
|
||||
"type": "function",
|
||||
|
|
|
@ -35,6 +35,11 @@ add_task(async function test_openPopup_requires_user_interaction() {
|
|||
"sidebarAction.close may only be called from a user input handler",
|
||||
"The error is informative."
|
||||
);
|
||||
await browser.test.assertRejects(
|
||||
browser.sidebarAction.toggle(),
|
||||
"sidebarAction.toggle may only be called from a user input handler",
|
||||
"The error is informative."
|
||||
);
|
||||
|
||||
browser.runtime.onMessage.addListener(async msg => {
|
||||
browser.test.assertEq(msg, "from-panel", "correct message received");
|
||||
|
@ -68,6 +73,7 @@ add_task(async function test_openPopup_requires_user_interaction() {
|
|||
<button id="openPageAction">openPageAction</button>
|
||||
<button id="openSidebarAction">openSidebarAction</button>
|
||||
<button id="closeSidebarAction">closeSidebarAction</button>
|
||||
<button id="toggleSidebarAction">toggleSidebarAction</button>
|
||||
<script src="tab.js"></script>
|
||||
</body></html>
|
||||
`,
|
||||
|
@ -106,6 +112,13 @@ add_task(async function test_openPopup_requires_user_interaction() {
|
|||
},
|
||||
{ once: true }
|
||||
);
|
||||
/* eslint-disable mozilla/balanced-listeners */
|
||||
document
|
||||
.getElementById("toggleSidebarAction")
|
||||
.addEventListener("click", () => {
|
||||
browser.sidebarAction.toggle();
|
||||
});
|
||||
/* eslint-enable mozilla/balanced-listeners */
|
||||
},
|
||||
"panel.js": function() {
|
||||
browser.runtime.sendMessage("from-panel");
|
||||
|
@ -155,6 +168,15 @@ add_task(async function test_openPopup_requires_user_interaction() {
|
|||
);
|
||||
await BrowserTestUtils.waitForCondition(() => !SidebarUI.isOpen);
|
||||
|
||||
await click("#toggleSidebarAction");
|
||||
await BrowserTestUtils.waitForCondition(() => SidebarUI.isOpen);
|
||||
await BrowserTestUtils.synthesizeMouseAtCenter(
|
||||
"#toggleSidebarAction",
|
||||
{},
|
||||
gBrowser.selectedBrowser
|
||||
);
|
||||
await BrowserTestUtils.waitForCondition(() => !SidebarUI.isOpen);
|
||||
|
||||
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
await extension.unload();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче