summaryrefslogtreecommitdiffstats
path: root/remote/shared/messagehandler/test/browser/browser_registry.js
blob: 271597526e7a20897caeff9a06c3ef28d0abf798 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const { MessageHandlerRegistry } = ChromeUtils.importESModule(
  "chrome://remote/content/shared/messagehandler/MessageHandlerRegistry.sys.mjs"
);
const { RootMessageHandler } = ChromeUtils.importESModule(
  "chrome://remote/content/shared/messagehandler/RootMessageHandler.sys.mjs"
);

add_task(async function test_messageHandlerRegistry_API() {
  const sessionId = 1;
  const type = RootMessageHandler.type;

  const rootMessageHandlerRegistry = new MessageHandlerRegistry(type);

  const rootMessageHandler = rootMessageHandlerRegistry.getOrCreateMessageHandler(
    sessionId
  );
  ok(rootMessageHandler, "Valid ROOT MessageHandler created");

  const contextId = rootMessageHandler.contextId;
  ok(contextId, "ROOT MessageHandler has a valid contextId");

  is(
    rootMessageHandler,
    rootMessageHandlerRegistry.getExistingMessageHandler(sessionId),
    "ROOT MessageHandler can be retrieved from the registry"
  );

  rootMessageHandler.destroy();
  ok(
    !rootMessageHandlerRegistry.getExistingMessageHandler(sessionId),
    "Destroyed ROOT MessageHandler is no longer returned by the Registry"
  );
});