summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_console_nsiconsolemessage.js
blob: a1f1b8566985d44a88c1d36eb43dabe3142f18a7 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Check that nsIConsoleMessages are displayed in the Browser Console.

"use strict";

const TEST_URI = `data:text/html;charset=utf8,<!DOCTYPE html>
<title>browser_console_nsiconsolemessage.js</title>
<p>hello world<p>
nsIConsoleMessages ftw!`;

add_task(async function () {
  // We don't use `openNewTabAndConsole()` here because we need to log a message
  // before opening the web console.
  await addTab(TEST_URI);

  // Test for cached nsIConsoleMessages.
  Services.console.logStringMessage("cachedBrowserConsoleMessage");

  info("open web console");
  let hud = await openConsole();

  ok(hud, "web console opened");

  // This "liveBrowserConsoleMessage" message should not be displayed.
  Services.console.logStringMessage("liveBrowserConsoleMessage");

  // Log a "foobarz" message so that we can be certain the previous message is
  // not displayed.
  let text = "foobarz";
  const onFooBarzMessage = waitForMessageByType(hud, text, ".console-api");
  SpecialPowers.spawn(gBrowser.selectedBrowser, [text], function (msg) {
    content.console.log(msg);
  });
  await onFooBarzMessage;
  ok(true, `"${text}" log is displayed in the Web Console as expected`);

  // Ensure the "liveBrowserConsoleMessage" and "cachedBrowserConsoleMessage"
  // messages are not displayed.
  text = hud.ui.outputNode.textContent;
  ok(
    !text.includes("cachedBrowserConsoleMessage"),
    "cached nsIConsoleMessages are not displayed"
  );
  ok(
    !text.includes("liveBrowserConsoleMessage"),
    "nsIConsoleMessages are not displayed"
  );

  await closeConsole();

  info("web console closed");
  hud = await BrowserConsoleManager.toggleBrowserConsole();
  ok(hud, "browser console opened");

  await waitFor(() =>
    findConsoleAPIMessage(hud, "cachedBrowserConsoleMessage")
  );
  Services.console.logStringMessage("liveBrowserConsoleMessage2");
  await waitFor(() => findConsoleAPIMessage(hud, "liveBrowserConsoleMessage2"));

  const msg = await waitFor(() =>
    findConsoleAPIMessage(hud, "liveBrowserConsoleMessage")
  );
  ok(msg, "message element for liveBrowserConsoleMessage (nsIConsoleMessage)");

  // Disable the log filter.
  await setFilterState(hud, {
    log: false,
  });

  // And then checking that the log messages are hidden.
  await waitFor(
    () =>
      findConsoleAPIMessages(hud, "cachedBrowserConsoleMessage").length === 0
  );
  await waitFor(
    () => findConsoleAPIMessages(hud, "liveBrowserConsoleMessage").length === 0
  );
  await waitFor(
    () => findConsoleAPIMessages(hud, "liveBrowserConsoleMessage2").length === 0
  );

  resetFilters(hud);
});