From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../test/browser/browser_ext_openPanel.js | 152 +++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 browser/components/extensions/test/browser/browser_ext_openPanel.js (limited to 'browser/components/extensions/test/browser/browser_ext_openPanel.js') diff --git a/browser/components/extensions/test/browser/browser_ext_openPanel.js b/browser/components/extensions/test/browser/browser_ext_openPanel.js new file mode 100644 index 0000000000..105cdc834b --- /dev/null +++ b/browser/components/extensions/test/browser/browser_ext_openPanel.js @@ -0,0 +1,152 @@ +/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set sts=2 sw=2 et tw=80: */ +"use strict"; + +add_task(async function test_openPopup_requires_user_interaction() { + async function backgroundScript() { + browser.tabs.onUpdated.addListener(async (tabId, changeInfo, tabInfo) => { + if (changeInfo.status != "complete") { + return; + } + await browser.pageAction.show(tabId); + + await browser.test.assertRejects( + browser.pageAction.openPopup(), + "pageAction.openPopup may only be called from a user input handler", + "The error is informative." + ); + await browser.test.assertRejects( + browser.sidebarAction.open(), + "sidebarAction.open may only be called from a user input handler", + "The error is informative." + ); + await browser.test.assertRejects( + browser.sidebarAction.close(), + "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"); + browser.test.sendMessage("panel-opened"); + }); + + browser.test.sendMessage("ready"); + }); + browser.tabs.create({ url: "tab.html" }); + } + + let extensionData = { + background: backgroundScript, + manifest: { + browser_action: { + default_popup: "panel.html", + }, + page_action: { + default_popup: "panel.html", + }, + sidebar_action: { + default_panel: "panel.html", + }, + }, + // We don't want the panel open automatically, so need a non-default reason. + startupReason: "APP_STARTUP", + + files: { + "tab.html": ` + + + + + + + + + `, + "panel.html": ` + + + + + `, + "tab.js": function () { + document.getElementById("openPageAction").addEventListener( + "click", + () => { + browser.pageAction.openPopup(); + }, + { once: true } + ); + document.getElementById("openSidebarAction").addEventListener( + "click", + () => { + browser.sidebarAction.open(); + }, + { once: true } + ); + document.getElementById("closeSidebarAction").addEventListener( + "click", + () => { + browser.sidebarAction.close(); + }, + { 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"); + }, + }, + }; + + let extension = ExtensionTestUtils.loadExtension(extensionData); + + async function click(id) { + let open = extension.awaitMessage("panel-opened"); + await BrowserTestUtils.synthesizeMouseAtCenter( + id, + {}, + gBrowser.selectedBrowser + ); + return open; + } + + await extension.startup(); + await extension.awaitMessage("ready"); + + await click("#openPageAction"); + closePageAction(extension); + await new Promise(resolve => setTimeout(resolve, 0)); + + await click("#openSidebarAction"); + + await BrowserTestUtils.synthesizeMouseAtCenter( + "#closeSidebarAction", + {}, + gBrowser.selectedBrowser + ); + await TestUtils.waitForCondition(() => !SidebarUI.isOpen); + + await click("#toggleSidebarAction"); + await TestUtils.waitForCondition(() => SidebarUI.isOpen); + await BrowserTestUtils.synthesizeMouseAtCenter( + "#toggleSidebarAction", + {}, + gBrowser.selectedBrowser + ); + await TestUtils.waitForCondition(() => !SidebarUI.isOpen); + + BrowserTestUtils.removeTab(gBrowser.selectedTab); + await extension.unload(); +}); -- cgit v1.2.3