summaryrefslogtreecommitdiffstats
path: root/devtools/shared/commands/resource/tests/browser_browser_resources_console_messages.js
blob: 1c6c776e64ed51d434853cb7deee0d09d8798549 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test the ResourceCommand API around CONSOLE_MESSAGE for the whole browser

const TEST_URL = URL_ROOT_SSL + "early_console_document.html";

add_task(async function () {
  // Enable Multiprocess Browser Toolbox.
  await pushPref("devtools.browsertoolbox.scope", "everything");

  const { client, resourceCommand, targetCommand } =
    await initMultiProcessResourceCommand();

  const d = Date.now();
  const CACHED_MESSAGE_TEXT = `cached-${d}`;
  const LIVE_MESSAGE_TEXT = `live-${d}`;

  info(
    "Log some messages *before* calling ResourceCommand.watchResources in order to " +
      "assert the behavior of already existing messages."
  );
  console.log(CACHED_MESSAGE_TEXT);

  info("Wait for existing browser mochitest log");
  const { onResource } = await resourceCommand.waitForNextResource(
    resourceCommand.TYPES.CONSOLE_MESSAGE,
    {
      ignoreExistingResources: false,
      predicate({ message }) {
        return message.arguments[0] === CACHED_MESSAGE_TEXT;
      },
    }
  );
  const existingMsg = await onResource;
  ok(existingMsg, "The existing log was retrieved");
  is(
    existingMsg.isAlreadyExistingResource,
    true,
    "isAlreadyExistingResource is true for the existing message"
  );

  const { onResource: onMochitestRuntimeLog } =
    await resourceCommand.waitForNextResource(
      resourceCommand.TYPES.CONSOLE_MESSAGE,
      {
        ignoreExistingResources: false,
        predicate({ message }) {
          return message.arguments[0] === LIVE_MESSAGE_TEXT;
        },
      }
    );
  console.log(LIVE_MESSAGE_TEXT);

  info("Wait for runtime browser mochitest log");
  const runtimeLogResource = await onMochitestRuntimeLog;
  ok(runtimeLogResource, "The runtime log was retrieved");
  is(
    runtimeLogResource.isAlreadyExistingResource,
    false,
    "isAlreadyExistingResource is false for the runtime message"
  );

  const { onResource: onEarlyLog } = await resourceCommand.waitForNextResource(
    resourceCommand.TYPES.CONSOLE_MESSAGE,
    {
      ignoreExistingResources: true,
      predicate({ message }) {
        return message.arguments[0] === "early-page-log";
      },
    }
  );
  await addTab(TEST_URL);
  info("Wait for early page log");
  const earlyResource = await onEarlyLog;
  ok(earlyResource, "The early page log was retrieved");
  is(
    earlyResource.isAlreadyExistingResource,
    false,
    "isAlreadyExistingResource is false for the early message"
  );

  targetCommand.destroy();
  await client.close();
});