tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_console_clear_cache.js (1675B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 // Check that clearing the browser console output also clears the console cache.
      6 
      7 "use strict";
      8 
      9 const TEST_URI =
     10  "data:text/html;charset=utf8,<!DOCTYPE html>Test browser console clear cache";
     11 
     12 add_task(async function () {
     13  await pushPref("devtools.browsertoolbox.scope", "everything");
     14 
     15  await addTab(TEST_URI);
     16  let hud = await BrowserConsoleManager.toggleBrowserConsole();
     17 
     18  const CACHED_MESSAGE = "CACHED_MESSAGE";
     19  await logTextInContentAndWaitForMessage(hud, CACHED_MESSAGE);
     20 
     21  info("Click the clear output button");
     22  const onBrowserConsoleOutputCleared = waitFor(
     23    () => !findConsoleAPIMessage(hud, CACHED_MESSAGE)
     24  );
     25  hud.ui.window.document.querySelector(".devtools-clear-icon").click();
     26  await onBrowserConsoleOutputCleared;
     27  ok(true, "Message was cleared");
     28 
     29  info("Close and re-open the browser console");
     30  await safeCloseBrowserConsole();
     31  hud = await BrowserConsoleManager.toggleBrowserConsole();
     32 
     33  info("Log a smoke message in order to know that the console is ready");
     34  await logTextInContentAndWaitForMessage(hud, "Smoke message");
     35  is(
     36    findConsoleAPIMessage(hud, CACHED_MESSAGE),
     37    undefined,
     38    "The cached message is not visible anymore"
     39  );
     40 });
     41 
     42 function logTextInContentAndWaitForMessage(hud, text) {
     43  const onMessage = waitForMessageByType(hud, text, ".console-api");
     44  SpecialPowers.spawn(gBrowser.selectedBrowser, [text], function (str) {
     45    content.wrappedJSObject.console.log(str);
     46  });
     47  return onMessage;
     48 }