From a2cbb78dbd89f3c005632d0e16b006a16f20ddc7 Mon Sep 17 00:00:00 2001 From: trickypr <23250792+trickypr@users.noreply.github.com> Date: Sat, 13 Apr 2024 20:00:31 +1000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Extension=20test=20support=20(#56)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ports over the changes from #55. Primarily for integration testing. ## Added - Window arguments (used for specifying browser urls) - Infra for creating tests extensions ## Changed - Use our own tap reporter with a less buggy parser --- apps/content/src/browser/browser.js | 18 ++ .../src/browser/components/PageAction.svelte | 18 +- .../src/browser/components/UrlBox.svelte | 4 +- .../browser/components/UrlBoxButton.svelte | 4 +- .../src/browser/components/pageAction.js | 3 +- .../src/browser/windowApi/WindowTabs.js | 28 +- apps/content/static/gtests.html | 7 +- apps/extensions/lib/parent/ext-pageAction.js | 1 + apps/modules/lib/EPageActions.sys.mjs | 3 +- apps/modules/lib/ExtensionTestUtils.sys.mjs | 264 ++++++++++++++++++ apps/modules/lib/TestManager.sys.mjs | 88 +++--- apps/tests/integrations/_index.sys.mjs | 11 +- .../integrations/extensions/pageAction.mjs | 89 ++++++ libs/link/types/globals/Elements.d.ts | 4 + libs/link/types/modules/EPageActions.d.ts | 2 + .../types/modules/ExtensionTestUtils.d.ts | 75 ++--- libs/link/types/modules/TestManager.d.ts | 22 +- package.json | 5 +- pnpm-lock.yaml | 196 +++---------- scripts/lib/tapReporter.ts | 59 ++++ scripts/scripts.d.ts | 14 - scripts/setup.ts | 2 +- scripts/unit-test.ts | 6 +- 23 files changed, 610 insertions(+), 313 deletions(-) create mode 100644 apps/modules/lib/ExtensionTestUtils.sys.mjs create mode 100644 apps/tests/integrations/extensions/pageAction.mjs create mode 100644 scripts/lib/tapReporter.ts delete mode 100644 scripts/scripts.d.ts diff --git a/apps/content/src/browser/browser.js b/apps/content/src/browser/browser.js index a42b5bd..98aff99 100644 --- a/apps/content/src/browser/browser.js +++ b/apps/content/src/browser/browser.js @@ -4,8 +4,26 @@ // @ts-check import BrowserWindow from './BrowserWindow.svelte' import './browser.css' +import * as WindowTabs from './windowApi/WindowTabs.js' import { registerEventBus } from './windowApi/eventBus.js' +// Handle window arguments +let rawArgs = window.arguments && window.arguments[0] +/** @type {Record} */ +let args = {} + +if (rawArgs && rawArgs instanceof Ci.nsISupports) { + args = rawArgs.wrappedJSObject || {} +} else if (rawArgs) { + args = rawArgs +} + +const initialUrls = args.initialUrl + ? [args.initialUrl] + : ['https://google.com/', 'https://svelte.dev/'] + +WindowTabs.initialize(initialUrls) + registerEventBus() new BrowserWindow({ target: document.body }) diff --git a/apps/content/src/browser/components/PageAction.svelte b/apps/content/src/browser/components/PageAction.svelte index 1cc455e..e943f67 100644 --- a/apps/content/src/browser/components/PageAction.svelte +++ b/apps/content/src/browser/components/PageAction.svelte @@ -12,9 +12,15 @@ /** @type {import('resource://app/modules/EPageActions.sys.mjs').PageActionImpl} */ export let pageAction + /** @type {number} */ + export let browserViewId const view = PageActionApi.setup(pageAction) const icons = PageActionApi.getIcons(view) + const extensionId = pageAction.extensionId + .replace('@', '') + .replace('}', '') + .replace('{', '') const trigger = view.trigger const panel = view.panel @@ -45,7 +51,11 @@ }) - + {#if $icons} {:else} @@ -54,7 +64,11 @@ {#if pageAction.popupUrl} - + {/if}