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

"use strict";

// Check adding console calls as batch keep the order of the message.

const TEST_URI =
  "http://example.com/browser/devtools/client/webconsole/" +
  "test/browser/test-batching.html";
const {
  l10n,
} = require("resource://devtools/client/webconsole/utils/messages.js");

add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);
  const messageNumber = 100;
  await testSimpleBatchLogging(hud, messageNumber);
  await testBatchLoggingAndClear(hud, messageNumber);
});

async function testSimpleBatchLogging(hud, messageNumber) {
  await SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [messageNumber],
    function (numMessages) {
      content.wrappedJSObject.batchLog(numMessages);
    }
  );
  const allMessages = await waitFor(async () => {
    const msgs = await findAllMessagesVirtualized(hud);
    if (msgs.length == messageNumber) {
      return msgs;
    }
    return null;
  });
  for (let i = 0; i < messageNumber; i++) {
    const node = allMessages[i].querySelector(".message-body");
    is(
      node.textContent,
      i.toString(),
      `message at index "${i}" is the expected one`
    );
  }
}

async function testBatchLoggingAndClear(hud, messageNumber) {
  await SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [messageNumber],
    function (numMessages) {
      content.wrappedJSObject.batchLogAndClear(numMessages);
    }
  );
  await waitFor(() =>
    findConsoleAPIMessage(hud, l10n.getStr("consoleCleared"))
  );
  ok(true, "console cleared message is displayed");

  const messages = findAllMessages(hud);
  is(messages.length, 1, "console was cleared as expected");
}