diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /devtools/server/tests/browser/test-spawn-actor-in-parent.js | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/tests/browser/test-spawn-actor-in-parent.js')
-rw-r--r-- | devtools/server/tests/browser/test-spawn-actor-in-parent.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/devtools/server/tests/browser/test-spawn-actor-in-parent.js b/devtools/server/tests/browser/test-spawn-actor-in-parent.js new file mode 100644 index 0000000000..eeb9a4ef4e --- /dev/null +++ b/devtools/server/tests/browser/test-spawn-actor-in-parent.js @@ -0,0 +1,94 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const protocol = require("devtools/shared/protocol"); +const { FrontClassWithSpec } = protocol; +const { + DevToolsServerConnection, +} = require("devtools/server/devtools-server-connection"); +const Services = require("Services"); + +const inContentSpec = protocol.generateActorSpec({ + typeName: "inContent", + + methods: { + isInContent: { + request: {}, + response: { + isInContent: protocol.RetVal("boolean"), + }, + }, + spawnInParent: { + request: { + url: protocol.Arg(0), + }, + response: protocol.RetVal("json"), + }, + }, +}); + +exports.InContentActor = protocol.ActorClassWithSpec(inContentSpec, { + initialize: function(conn) { + protocol.Actor.prototype.initialize.call(this, conn); + }, + + isInContent: function() { + return ( + Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT + ); + }, + + spawnInParent: async function(url) { + const actorID = await this.conn.spawnActorInParentProcess(this.actorID, { + module: url, + constructor: "InParentActor", + // In the browser mochitest script, we are asserting these arguments passed to + // InParentActor constructor + args: [1, 2, 3], + }); + return { + inParentActor: actorID, + }; + }, +}); + +class InContentFront extends FrontClassWithSpec(inContentSpec) {} +exports.InContentFront = InContentFront; + +const inParentSpec = protocol.generateActorSpec({ + typeName: "inParent", + + methods: { + test: { + request: {}, + response: protocol.RetVal("json"), + }, + }, +}); + +exports.InParentActor = protocol.ActorClassWithSpec(inParentSpec, { + initialize: function(conn, a1, a2, a3, mm) { + protocol.Actor.prototype.initialize.call(this, conn); + // We save all arguments to later assert them in `test` request + this.conn = conn; + this.args = [a1, a2, a3]; + this.mm = mm; + }, + + test: function() { + return { + args: this.args, + isInParent: + Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_DEFAULT, + conn: this.conn instanceof DevToolsServerConnection, + // We don't have access to MessageListenerManager in Sandboxes, + // so fallback to constructor name checks... + mm: Object.getPrototypeOf(this.mm).constructor.name, + }; + }, +}); + +class InParentFront extends FrontClassWithSpec(inParentSpec) {} +exports.InParentFront = InParentFront; |