diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/shared/protocol/tests/xpcshell/test_protocol_stack.js | |
parent | Initial commit. (diff) | |
download | firefox-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 'devtools/shared/protocol/tests/xpcshell/test_protocol_stack.js')
-rw-r--r-- | devtools/shared/protocol/tests/xpcshell/test_protocol_stack.js | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/devtools/shared/protocol/tests/xpcshell/test_protocol_stack.js b/devtools/shared/protocol/tests/xpcshell/test_protocol_stack.js new file mode 100644 index 0000000000..faf8402ea6 --- /dev/null +++ b/devtools/shared/protocol/tests/xpcshell/test_protocol_stack.js @@ -0,0 +1,98 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Client request stacks should span the entire process from before making the + * request to handling the reply from the server. The server frames are not + * included, nor can they be in most cases, since the server can be a remote + * device. + */ + +var protocol = require("resource://devtools/shared/protocol.js"); +var { RetVal } = protocol; + +const rootSpec = protocol.generateActorSpec({ + typeName: "root", + + methods: { + simpleReturn: { + response: { value: RetVal() }, + }, + }, +}); + +class RootActor extends protocol.Actor { + constructor(conn) { + super(conn, rootSpec); + + // Root actor owns itself. + this.manage(this); + this.actorID = "root"; + this.sequence = 0; + } + + sayHello() { + return { + from: "root", + applicationType: "xpcshell-tests", + traits: [], + }; + } + + simpleReturn() { + return this.sequence++; + } +} + +class RootFront extends protocol.FrontClassWithSpec(rootSpec) { + constructor(client) { + super(client); + this.actorID = "root"; + // Root owns itself. + this.manage(this); + } +} +protocol.registerFront(RootFront); + +function run_test() { + DevToolsServer.createRootActor = conn => new RootActor(conn); + DevToolsServer.init(); + + const trace = connectPipeTracing(); + const client = new DevToolsClient(trace); + let rootFront; + + client.connect().then(function onConnect() { + rootFront = client.mainRoot; + + rootFront + .simpleReturn() + .then( + () => { + let stack = Components.stack; + while (stack) { + info(stack.name); + if (stack.name.includes("onConnect")) { + // Reached back to outer function before request + ok(true, "Complete stack"); + return; + } + stack = stack.asyncCaller || stack.caller; + } + ok(false, "Incomplete stack"); + }, + () => { + ok(false, "Request failed unexpectedly"); + } + ) + .then(() => { + client.close().then(() => { + do_test_finished(); + }); + }); + }); + + do_test_pending(); +} |