summaryrefslogtreecommitdiffstats
path: root/devtools/shared/webconsole/test/browser/browser_commands_registration.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/shared/webconsole/test/browser/browser_commands_registration.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--devtools/shared/webconsole/test/browser/browser_commands_registration.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/devtools/shared/webconsole/test/browser/browser_commands_registration.js b/devtools/shared/webconsole/test/browser/browser_commands_registration.js
new file mode 100644
index 0000000000..5ab2c848c4
--- /dev/null
+++ b/devtools/shared/webconsole/test/browser/browser_commands_registration.js
@@ -0,0 +1,78 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test for Web Console commands registration.
+
+add_task(async function () {
+ const tab = await addTab("data:text/html,<div id=quack></div>");
+
+ const commands = await CommandsFactory.forTab(tab);
+ await commands.targetCommand.startListening();
+
+ // Fetch WebConsoleCommandsManager so that it is available for next Content Tasks
+ await ContentTask.spawn(gBrowser.selectedBrowser, null, function () {
+ const { require } = ChromeUtils.importESModule(
+ "resource://devtools/shared/loader/Loader.sys.mjs"
+ );
+ const {
+ WebConsoleCommandsManager,
+ } = require("resource://devtools/server/actors/webconsole/commands/manager.js");
+
+ // Bind the symbol on this in order to make it available for next tasks
+ this.WebConsoleCommandsManager = WebConsoleCommandsManager;
+ });
+
+ await registerNewCommand(commands);
+ await registerAccessor(commands);
+});
+
+async function evaluateJSAndCheckResult(commands, input, expected) {
+ const response = await commands.scriptCommand.execute(input);
+ checkObject(response, expected);
+}
+
+async function registerNewCommand(commands) {
+ await ContentTask.spawn(gBrowser.selectedBrowser, null, function () {
+ this.WebConsoleCommandsManager.register("setFoo", (owner, value) => {
+ owner.window.foo = value;
+ return "ok";
+ });
+ });
+
+ const command = "setFoo('bar')";
+ await evaluateJSAndCheckResult(commands, command, {
+ input: command,
+ result: "ok",
+ });
+
+ await ContentTask.spawn(gBrowser.selectedBrowser, null, function () {
+ is(content.top.foo, "bar", "top.foo should equal to 'bar'");
+ });
+}
+
+async function registerAccessor(commands) {
+ await ContentTask.spawn(gBrowser.selectedBrowser, null, function () {
+ this.WebConsoleCommandsManager.register("$foo", {
+ get(owner) {
+ const foo = owner.window.document.getElementById("quack");
+ return owner.makeDebuggeeValue(foo);
+ },
+ });
+ });
+
+ const command = "$foo.textContent = '>o_/'";
+ await evaluateJSAndCheckResult(commands, command, {
+ input: command,
+ result: ">o_/",
+ });
+
+ await ContentTask.spawn(gBrowser.selectedBrowser, null, function () {
+ is(
+ content.document.getElementById("quack").textContent,
+ ">o_/",
+ '#foo textContent should equal to ">o_/"'
+ );
+ });
+}