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_pageAction_simple.js | 213 +++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 browser/components/extensions/test/browser/browser_ext_pageAction_simple.js (limited to 'browser/components/extensions/test/browser/browser_ext_pageAction_simple.js') diff --git a/browser/components/extensions/test/browser/browser_ext_pageAction_simple.js b/browser/components/extensions/test/browser/browser_ext_pageAction_simple.js new file mode 100644 index 0000000000..dc323afd94 --- /dev/null +++ b/browser/components/extensions/test/browser/browser_ext_pageAction_simple.js @@ -0,0 +1,213 @@ +/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set sts=2 sw=2 et tw=80: */ +"use strict"; + +const BASE = + "http://example.com/browser/browser/components/extensions/test/browser/"; + +add_task(async function test_pageAction_basic() { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + page_action: { + default_popup: "popup.html", + unrecognized_property: "with-a-random-value", + }, + }, + + files: { + "popup.html": ` + + + + + `, + + "popup.js": function () { + browser.runtime.sendMessage("from-popup"); + }, + }, + + background: function () { + browser.runtime.onMessage.addListener(msg => { + browser.test.assertEq(msg, "from-popup", "correct message received"); + browser.test.sendMessage("popup"); + }); + browser.tabs.query({ active: true, currentWindow: true }, tabs => { + let tabId = tabs[0].id; + + browser.pageAction.show(tabId).then(() => { + browser.test.sendMessage("page-action-shown"); + }); + }); + }, + }); + + SimpleTest.waitForExplicitFinish(); + let waitForConsole = new Promise(resolve => { + SimpleTest.monitorConsole(resolve, [ + { + message: + /Reading manifest: Warning processing page_action.unrecognized_property: An unexpected property was found/, + }, + ]); + }); + + ExtensionTestUtils.failOnSchemaWarnings(false); + await extension.startup(); + ExtensionTestUtils.failOnSchemaWarnings(true); + await extension.awaitMessage("page-action-shown"); + + let elem = await getPageActionButton(extension); + let parent = window.document.getElementById("page-action-buttons"); + is( + elem && elem.parentNode, + parent, + `pageAction pinned to urlbar ${elem.parentNode.getAttribute("id")}` + ); + + clickPageAction(extension); + + await extension.awaitMessage("popup"); + + await extension.unload(); + + SimpleTest.endMonitorConsole(); + await waitForConsole; +}); + +add_task(async function test_pageAction_pinned() { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + page_action: { + default_popup: "popup.html", + pinned: false, + }, + }, + + files: { + "popup.html": ` + + + + `, + }, + + background: function () { + browser.tabs.query({ active: true, currentWindow: true }, tabs => { + let tabId = tabs[0].id; + + browser.pageAction.show(tabId).then(() => { + browser.test.sendMessage("page-action-shown"); + }); + }); + }, + }); + + await extension.startup(); + await extension.awaitMessage("page-action-shown"); + + // There are plenty of tests for the main action button, we just verify + // that we've properly set the pinned value. + // This test used to check that the button was not pinned, but that is no + // longer supported. + // TODO bug 1703537: consider removal of the pinned property. + let action = PageActions.actionForID(makeWidgetId(extension.id)); + ok(action && action.pinnedToUrlbar, "Check pageAction pinning"); + + await extension.unload(); +}); + +add_task(async function test_pageAction_icon_on_subframe_navigation() { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + page_action: { + default_popup: "popup.html", + }, + }, + + files: { + "popup.html": ` + + + + `, + }, + + background: function () { + browser.tabs.query({ active: true, currentWindow: true }, tabs => { + let tabId = tabs[0].id; + + browser.pageAction.show(tabId).then(() => { + browser.test.sendMessage("page-action-shown"); + }); + }); + }, + }); + + await navigateTab( + gBrowser.selectedTab, + "data:text/html,

Top Level Frame

" + ); + + await extension.startup(); + await extension.awaitMessage("page-action-shown"); + + const pageActionId = BrowserPageActions.urlbarButtonNodeIDForActionID( + makeWidgetId(extension.id) + ); + + await BrowserTestUtils.waitForCondition(() => { + return document.getElementById(pageActionId); + }, "pageAction is initially visible"); + + info("Create a sub-frame"); + + let subframeURL = `${BASE}#subframe-url-1`; + await SpecialPowers.spawn( + gBrowser.selectedBrowser, + [subframeURL], + async url => { + const iframe = this.content.document.createElement("iframe"); + iframe.setAttribute("id", "test-subframe"); + iframe.setAttribute("src", url); + iframe.setAttribute("style", "height: 200px; width: 200px"); + + // Await the initial url to be loaded in the subframe. + await new Promise(resolve => { + iframe.onload = resolve; + this.content.document.body.appendChild(iframe); + }); + } + ); + + await BrowserTestUtils.waitForCondition(() => { + return document.getElementById(pageActionId); + }, "pageAction should be visible when a subframe is created"); + + info("Navigating the sub-frame"); + + subframeURL = `${BASE}/file_dummy.html#subframe-url-2`; + await SpecialPowers.spawn( + gBrowser.selectedBrowser, + [subframeURL], + async url => { + const iframe = this.content.document.querySelector( + "iframe#test-subframe" + ); + + // Await the subframe navigation. + await new Promise(resolve => { + iframe.onload = resolve; + iframe.setAttribute("src", url); + }); + } + ); + + info("Subframe location changed"); + + await BrowserTestUtils.waitForCondition(() => { + return document.getElementById(pageActionId); + }, "pageAction should be visible after a subframe navigation"); + + await extension.unload(); +}); -- cgit v1.2.3