summaryrefslogtreecommitdiffstats
path: root/remote/test/browser/browser_main_target.js
blob: 117c55f2b0859494fb7c2ffd2b2e88cdf1310f5a (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test very basic CDP features.

add_task(async function({ CDP }) {
  const { mainProcessTarget } = RemoteAgent.targets;
  ok(
    mainProcessTarget,
    "The main process target is instantiated after the call to `listen`"
  );

  const targetURL = mainProcessTarget.wsDebuggerURL;

  const client = await CDP({ target: targetURL });
  info("CDP client has been instantiated");

  try {
    const { Browser, Target } = client;
    ok(Browser, "The main process target exposes Browser domain");
    ok(Target, "The main process target exposes Target domain");

    const version = await Browser.getVersion();

    const { isHeadless } = Cc["@mozilla.org/gfx/info;1"].getService(
      Ci.nsIGfxInfo
    );
    const expectedProduct = isHeadless ? "Headless Firefox" : "Firefox";
    is(version.product, expectedProduct, "Browser.getVersion works");

    const { webSocketDebuggerUrl } = await CDP.Version();
    is(
      webSocketDebuggerUrl,
      targetURL,
      "Version endpoint refers to the same Main process target"
    );
  } finally {
    await client.close();
  }
});