From c2e71162b402d087bd0e82f8374e5716d60db505 Mon Sep 17 00:00:00 2001 From: Tomislav Jovanovic Date: Tue, 3 Oct 2023 14:33:53 +0000 Subject: [PATCH] Bug 1815314 - Tests for pageAction and browserAction persistent events r=willdurand Differential Revision: https://phabricator.services.mozilla.com/D189876 --- .../extensions/test/mochitest/head.js | 38 +++++++++++++++++++ .../test_ext_browserAction_onClicked.html | 35 ++++++++++++++++- .../test_ext_pageAction_onClicked.html | 35 ++++++++++++++++- 3 files changed, 104 insertions(+), 4 deletions(-) diff --git a/toolkit/components/extensions/test/mochitest/head.js b/toolkit/components/extensions/test/mochitest/head.js index ad8fb2052ff35..48ed27a1ab849 100644 --- a/toolkit/components/extensions/test/mochitest/head.js +++ b/toolkit/components/extensions/test/mochitest/head.js @@ -115,3 +115,41 @@ function waitForState(sw, state) { }); }); } + +/* exported assertPersistentListeners */ +async function assertPersistentListeners( + extWrapper, + apiNs, + apiEvents, + expected +) { + const stringErr = await SpecialPowers.spawnChrome( + [extWrapper.id, apiNs, apiEvents, expected], + async (id, apiNs, apiEvents, expected) => { + try { + const { ExtensionTestCommon } = ChromeUtils.importESModule( + "resource://testing-common/ExtensionTestCommon.sys.mjs" + ); + const ext = { id }; + for (const event of apiEvents) { + ExtensionTestCommon.testAssertions.assertPersistentListeners( + ext, + apiNs, + event, + { + primed: expected.primed, + persisted: expected.persisted, + primedListenersCount: expected.primedListenersCount, + } + ); + } + } catch (err) { + return String(err); + } + } + ); + ok( + stringErr == undefined, + stringErr ? stringErr : `Found expected primed and persistent listeners` + ); +} diff --git a/toolkit/components/extensions/test/mochitest/test_ext_browserAction_onClicked.html b/toolkit/components/extensions/test/mochitest/test_ext_browserAction_onClicked.html index 6044fa02cc5dc..48db7b0e92b6b 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_browserAction_onClicked.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_browserAction_onClicked.html @@ -13,10 +13,11 @@ diff --git a/toolkit/components/extensions/test/mochitest/test_ext_pageAction_onClicked.html b/toolkit/components/extensions/test/mochitest/test_ext_pageAction_onClicked.html index f1bf544dd94ab..5fce66159d1fc 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_pageAction_onClicked.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_pageAction_onClicked.html @@ -13,9 +13,10 @@