From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../test/browser/browser_commands_registration.js | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 devtools/shared/webconsole/test/browser/browser_commands_registration.js (limited to 'devtools/shared/webconsole/test/browser/browser_commands_registration.js') 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,
"); + + 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_/"' + ); + }); +} -- cgit v1.2.3