summaryrefslogtreecommitdiffstats
path: root/browser/components/pocket/test/unit/panels
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/components/pocket/test/unit/panels
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/pocket/test/unit/panels')
-rw-r--r--browser/components/pocket/test/unit/panels/browser.ini5
-rw-r--r--browser/components/pocket/test/unit/panels/browser_pocket_main.js49
-rw-r--r--browser/components/pocket/test/unit/panels/head.js24
3 files changed, 78 insertions, 0 deletions
diff --git a/browser/components/pocket/test/unit/panels/browser.ini b/browser/components/pocket/test/unit/panels/browser.ini
new file mode 100644
index 0000000000..66642d3745
--- /dev/null
+++ b/browser/components/pocket/test/unit/panels/browser.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+support-files =
+ head.js
+
+[browser_pocket_main.js]
diff --git a/browser/components/pocket/test/unit/panels/browser_pocket_main.js b/browser/components/pocket/test/unit/panels/browser_pocket_main.js
new file mode 100644
index 0000000000..c40ad4d5d4
--- /dev/null
+++ b/browser/components/pocket/test/unit/panels/browser_pocket_main.js
@@ -0,0 +1,49 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+function test_runner(test) {
+ let testTask = async () => {
+ // Before each
+ const sandbox = sinon.createSandbox();
+ try {
+ await test({
+ sandbox,
+ pktPanelMessaging: testGlobal.window.pktPanelMessaging,
+ });
+ } finally {
+ // After each
+ sandbox.restore();
+ }
+ };
+
+ // Copy the name of the test function to identify the test
+ Object.defineProperty(testTask, "name", { value: test.name });
+ add_task(testTask);
+}
+
+test_runner(async function test_clickHelper({ sandbox, pktPanelMessaging }) {
+ // Create a button to test the click helper with.
+ const button = document.createElement("button");
+ button.setAttribute("href", "http://example.com");
+
+ // Setup a stub for the click itself.
+ sandbox.stub(pktPanelMessaging, "sendMessage");
+
+ // Create the click helper and trigger the click.
+ pktPanelMessaging.clickHelper(button, { source: "test-click", position: 2 });
+ button.click();
+
+ Assert.ok(
+ pktPanelMessaging.sendMessage.calledOnce,
+ "Should fire sendMessage once with clickHelper click"
+ );
+ Assert.ok(
+ pktPanelMessaging.sendMessage.calledWith("PKT_openTabWithUrl", {
+ url: "http://example.com",
+ source: "test-click",
+ position: 2,
+ }),
+ "Should send expected values to sendMessage with clickHelper click"
+ );
+});
diff --git a/browser/components/pocket/test/unit/panels/head.js b/browser/components/pocket/test/unit/panels/head.js
new file mode 100644
index 0000000000..cc6ba440f1
--- /dev/null
+++ b/browser/components/pocket/test/unit/panels/head.js
@@ -0,0 +1,24 @@
+const { sinon } = ChromeUtils.importESModule(
+ "resource://testing-common/Sinon.sys.mjs"
+);
+
+const testGlobal = {
+ PKT_PANEL_OVERLAY: class {
+ create() {}
+ },
+ RPMRemoveMessageListener: () => {},
+ RPMAddMessageListener: () => {},
+ RPMSendAsyncMessage: () => {},
+ window: {},
+ self: {},
+};
+
+Services.scriptloader.loadSubScript(
+ "chrome://pocket/content/panels/js/vendor.bundle.js",
+ testGlobal
+);
+
+Services.scriptloader.loadSubScript(
+ "chrome://pocket/content/panels/js/main.bundle.js",
+ testGlobal
+);