summaryrefslogtreecommitdiffstats
path: root/remote/shared/messagehandler/test/browser/broadcast/browser_two_tabs_with_params.js
blob: 261b8c4cd66c1b22485bb83a9a949247cd62387e (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
/* 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";

add_task(async function test_broadcasting_two_tabs_with_params_command() {
  info("Navigate the initial tab to the test URL");
  const tab1 = gBrowser.selectedTab;
  await loadURL(tab1.linkedBrowser, TEST_PAGE);
  const browsingContext1 = tab1.linkedBrowser.browsingContext;

  info("Open a new tab on the same test URL");
  const tab2 = await addTab(TEST_PAGE);
  const browsingContext2 = tab2.linkedBrowser.browsingContext;

  const rootMessageHandler = createRootMessageHandler(
    "session-id-broadcasting_two_tabs_command"
  );

  const broadcastValue = await sendTestBroadcastCommand(
    "commandwindowglobalonly",
    "testBroadcastWithParameter",
    {
      value: "some-value",
    },
    contextDescriptorAll,
    rootMessageHandler
  );
  ok(
    Array.isArray(broadcastValue),
    "The broadcast returned an array of values"
  );

  is(broadcastValue.length, 2, "The broadcast returned 2 values as expected");

  ok(
    broadcastValue.includes("broadcast-" + browsingContext1.id + "-some-value"),
    "The broadcast returned the expected value from tab1"
  );
  ok(
    broadcastValue.includes("broadcast-" + browsingContext2.id + "-some-value"),
    "The broadcast returned the expected value from tab2"
  );
  rootMessageHandler.destroy();
});