summaryrefslogtreecommitdiffstats
path: root/remote/test/browser/browser_cdp.js
blob: 971bff6b5d9d4064a891da5b126b36ed1776bef8 (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
57
58
59
60
61
/* 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 testCDP({ client }) {
  const { Browser, Log, Page } = client;

  ok("Browser" in client, "Browser domain is available");
  ok("Log" in client, "Log domain is available");
  ok("Page" in client, "Page domain is available");

  const version = await Browser.getVersion();
  const { isHeadless } = Cc["@mozilla.org/gfx/info;1"].getService(
    Ci.nsIGfxInfo
  );
  is(
    version.product,
    isHeadless ? "Headless Firefox" : "Firefox",
    "Browser.getVersion works and depends on headless mode"
  );
  is(
    version.userAgent,
    window.navigator.userAgent,
    "Browser.getVersion().userAgent is correct"
  );

  // receive console.log messages and print them
  let result = await Log.enable();
  info("Log domain has been enabled");
  Assert.deepEqual(result, {}, "Got expected result value");

  Log.entryAdded(({ entry }) => {
    const { timestamp, level, text, args } = entry;
    const msg = text || args.join(" ");
    console.log(`${new Date(timestamp)}\t${level.toUpperCase()}\t${msg}`);
  });

  // turn on navigation related events, such as DOMContentLoaded et al.
  result = await Page.enable();
  info("Page domain has been enabled");
  Assert.deepEqual(result, {}, "Got expected result value");

  const frameStoppedLoading = Page.frameStoppedLoading();
  const navigatedWithinDocument = Page.navigatedWithinDocument();
  const loadEventFired = Page.loadEventFired();
  await Page.navigate({
    url: toDataURL(`<script>console.log("foo")</script>`),
  });
  info("A new page has been requested");

  await loadEventFired;
  info("`Page.loadEventFired` fired");

  await frameStoppedLoading;
  info("`Page.frameStoppedLoading` fired");

  await navigatedWithinDocument;
  info("`Page.navigatedWithinDocument` fired");
});