summaryrefslogtreecommitdiffstats
path: root/remote/shared/messagehandler/test/browser/browser_session_data_constructor_race.js
blob: 03ed59166fabdd0229ecee201db6f780a588ff9a (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
39
40
41
42
43
44
45
46
47
48
49
50
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TEST_PAGE = "https://example.com/document-builder.sjs?html=tab";

/**
 * Check that modules created early for session data are still created with a
 * fully initialized MessageHandler. See Bug 1743083.
 */
add_task(async function () {
  const tab = BrowserTestUtils.addTab(gBrowser, TEST_PAGE);
  await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
  const browsingContext = tab.linkedBrowser.browsingContext;

  const root = createRootMessageHandler("session-id-event");

  info("Add some session data for the command module");
  await root.addSessionDataItem({
    moduleName: "command",
    category: "testCategory",
    contextDescriptor: contextDescriptorAll,
    values: ["some-value"],
  });

  info("Reload the current tab to create new message handlers and modules");
  await BrowserTestUtils.reloadTab(tab);

  info(
    "Check if the command module was created by the MessageHandler constructor"
  );
  const isCreatedByMessageHandlerConstructor = await root.handleCommand({
    moduleName: "command",
    commandName: "testIsCreatedByMessageHandlerConstructor",
    destination: {
      type: WindowGlobalMessageHandler.type,
      id: browsingContext.id,
    },
  });

  is(
    isCreatedByMessageHandlerConstructor,
    false,
    "The command module from session data should not be created by the MessageHandler constructor"
  );
  root.destroy();

  gBrowser.removeTab(tab);
});