summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_console_clear_cache.js
blob: 1cf1da4689b60272ba5e263baab8dfa3c4aeb922 (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
/* 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/. */

// Check that clearing the browser console output also clears the console cache.

"use strict";

const TEST_URI = "data:text/html;charset=utf8,Test browser console clear cache";

add_task(async function() {
  await pushPref("devtools.browserconsole.contentMessages", true);
  // Bug 1605036: Disable Multiprocess Browser Toolbox for now as it introduces intermittent failure in this test
  await pushPref("devtools.browsertoolbox.fission", false);

  await addTab(TEST_URI);
  let hud = await BrowserConsoleManager.toggleBrowserConsole();
  const CACHED_MESSAGE = "CACHED_MESSAGE";
  await logTextToConsole(hud, CACHED_MESSAGE);

  info("Click the clear output button");
  const onBrowserConsoleOutputCleared = waitFor(
    () => !findMessage(hud, CACHED_MESSAGE)
  );
  hud.ui.window.document.querySelector(".devtools-clear-icon").click();
  await onBrowserConsoleOutputCleared;

  // Check that there are no other messages logged (see Bug 1457478).
  // Log a message to make sure the console handled any prior log.
  await logTextToConsole(hud, "after clear");
  const messages = hud.ui.outputNode.querySelectorAll(".message");
  is(messages.length, 1, "There is only the new message in the output");

  info("Close and re-open the browser console");
  await safeCloseBrowserConsole();
  hud = await BrowserConsoleManager.toggleBrowserConsole();

  info("Log a smoke message in order to know that the console is ready");
  await logTextToConsole(hud, "Smoke message");
  is(
    findMessage(hud, CACHED_MESSAGE),
    undefined,
    "The cached message is not visible anymore"
  );
});

function logTextToConsole(hud, text) {
  const onMessage = waitForMessage(hud, text);
  SpecialPowers.spawn(gBrowser.selectedBrowser, [text], function(str) {
    content.wrappedJSObject.console.log(str);
  });
  return onMessage;
}