summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_visibility_messages.js
blob: ac949e4079966de3329784eac199416ee79bf4ef (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

// Check messages logged when console not visible are displayed when
// the user show the console again.

const HTML = `
  <!DOCTYPE html>
  <html>
    <body>
      <h1>Test console visibility update</h1>
      <script>
        function log(str) {
          console.log(str);
        }
      </script>
    </body>
  </html>
`;
const TEST_URI = "data:text/html;charset=utf-8," + encodeURI(HTML);
const MESSAGES_COUNT = 10;

add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);
  const toolbox = hud.toolbox;

  info("Log one message in the console");
  SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
    content.wrappedJSObject.log("in-console log");
  });
  await waitFor(() => findConsoleAPIMessage(hud, "in-console log"));

  info("select the inspector");
  await toolbox.selectTool("inspector");

  info("Wait for console to be hidden");
  const { document } = hud.iframeWindow;
  await waitFor(() => document.visibilityState == "hidden");

  const onAllMessagesInStore = new Promise(done => {
    const store = hud.ui.wrapper.getStore();
    store.subscribe(() => {
      const messages = store.getState().messages.mutableMessagesById.size;
      // Also consider the "in-console log" message
      if (messages == MESSAGES_COUNT + 1) {
        done();
      }
    });
  });

  await SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [[MESSAGES_COUNT]],
    count => {
      for (let i = 1; i <= count; i++) {
        content.wrappedJSObject.log("in-inspector log " + i);
      }
    }
  );

  info("Waiting for all messages to be logged into the store");
  await onAllMessagesInStore;

  const inInspectorMessages = await findConsoleAPIMessages(hud, "in-inspector");
  is(
    inInspectorMessages.length,
    0,
    "No messages from the inspector actually appear in the console"
  );

  info("select back the console");
  await toolbox.selectTool("webconsole");

  info("And wait for all messages to be visible");
  const waitForMessagePromises = [];
  for (let j = 1; j <= MESSAGES_COUNT; j++) {
    waitForMessagePromises.push(
      waitFor(() => findConsoleAPIMessage(hud, "in-inspector log " + j))
    );
  }

  await Promise.all(waitForMessagePromises);
  ok(
    true,
    "All the messages logged when the console was hidden were displayed."
  );
});

// Similar scenario, but with the split console on the inspector panel.
// Here, the messages should still be logged.
add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);
  const toolbox = hud.toolbox;

  info("Log one message in the console");
  SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
    content.wrappedJSObject.log("in-console log");
  });
  await waitFor(() => findConsoleAPIMessage(hud, "in-console log"));

  info("select the inspector");
  await toolbox.selectTool("inspector");

  info("Wait for console to be hidden");
  const { document } = hud.iframeWindow;
  await waitFor(() => document.visibilityState == "hidden");

  await toolbox.openSplitConsole();

  await SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [[MESSAGES_COUNT]],
    count => {
      for (let i = 1; i <= count; i++) {
        content.wrappedJSObject.log("in-inspector log " + i);
      }
    }
  );

  info("Wait for all messages to be visible in the split console");
  await waitFor(
    async () =>
      (
        await findMessagesVirtualizedByType({
          hud,
          text: "in-inspector log ",
          typeSelector: ".console-api",
        })
      ).length === MESSAGES_COUNT
  );
  ok(true, "All the messages logged when we are using the split console");

  await toolbox.closeSplitConsole();
});