summaryrefslogtreecommitdiffstats
path: root/remote/cdp/test/browser/browser_main_target.js
blob: b3b18b4c0cd27dceb309604870ffa45e0893d245 (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
51
52
53
54
55
56
/* 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.cdp.targetList;
  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" : "") +
      `${Services.appinfo.name}/${Services.appinfo.version}`;
    is(version.product, expectedProduct, "Browser.getVersion works");

    is(
      version.revision,
      Services.appinfo.sourceURL.split("/").pop(),
      "Browser.getVersion().revision is correct"
    );

    is(
      version.jsVersion,
      Services.appinfo.version,
      "Browser.getVersion().jsVersion is correct"
    );

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