tor-browser

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

browser_webconsole_close_sidebar.js (3424B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test that the sidebar is hidden for all methods of closing it.
      5 
      6 "use strict";
      7 
      8 const TEST_URI = "data:text/html;charset=utf8,<!DOCTYPE html>";
      9 
     10 add_task(async function () {
     11  // Should be removed when sidebar work is complete
     12  await pushPref("devtools.webconsole.sidebarToggle", true);
     13 
     14  const hud = await openNewTabAndConsole(TEST_URI);
     15  await showSidebar(hud);
     16 
     17  info("Click the clear console button");
     18  const clearButton = hud.ui.document.querySelector(".devtools-button");
     19  clearButton.click();
     20  await waitFor(() => !findAllMessages(hud).length);
     21  let sidebar = hud.ui.document.querySelector(".sidebar");
     22  ok(!sidebar, "Sidebar hidden after clear console button clicked");
     23 
     24  await showSidebar(hud);
     25 
     26  info("Send a console.clear()");
     27  const onMessagesCleared = waitForMessageByType(
     28    hud,
     29    "Console was cleared",
     30    ".console-api"
     31  );
     32  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     33    content.wrappedJSObject.console.clear();
     34  });
     35  await onMessagesCleared;
     36  sidebar = hud.ui.document.querySelector(".sidebar");
     37  ok(!sidebar, "Sidebar hidden after console.clear()");
     38 
     39  await showSidebar(hud);
     40 
     41  info("Send ctrl-l to clear console");
     42  let clearShortcut;
     43  if (Services.appinfo.OS === "Darwin") {
     44    clearShortcut = WCUL10n.getStr("webconsole.clear.keyOSX");
     45  } else {
     46    clearShortcut = WCUL10n.getStr("webconsole.clear.key");
     47  }
     48  synthesizeKeyShortcut(clearShortcut);
     49  await waitFor(() => !findAllMessages(hud).length);
     50  sidebar = hud.ui.document.querySelector(".sidebar");
     51  ok(!sidebar, "Sidebar hidden after ctrl-l");
     52 
     53  await showSidebar(hud);
     54 
     55  info("Click the close button");
     56  const closeButton = hud.ui.document.querySelector(".sidebar-close-button");
     57  const appNode = hud.ui.document.querySelector(".webconsole-app");
     58  let onSidebarShown = waitForNodeMutation(appNode, { childList: true });
     59  closeButton.click();
     60  await onSidebarShown;
     61  sidebar = hud.ui.document.querySelector(".sidebar");
     62  ok(!sidebar, "Sidebar hidden after clicking on close button");
     63 
     64  await showSidebar(hud);
     65 
     66  info("Send escape to hide sidebar");
     67  onSidebarShown = waitForNodeMutation(appNode, { childList: true });
     68  EventUtils.synthesizeKey("KEY_Escape");
     69  await onSidebarShown;
     70  sidebar = hud.ui.document.querySelector(".sidebar");
     71  ok(!sidebar, "Sidebar hidden after sending esc");
     72  ok(isInputFocused(hud), "console input is focused after closing the sidebar");
     73 });
     74 
     75 async function showSidebar(hud) {
     76  const onMessage = waitForMessageByType(hud, "Object", ".console-api");
     77  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     78    content.wrappedJSObject.console.log({ a: 1 });
     79  });
     80  await onMessage;
     81 
     82  const objectNode = hud.ui.outputNode.querySelector(
     83    ".object-inspector .objectBox"
     84  );
     85  const appNode = hud.ui.document.querySelector(".webconsole-app");
     86  const onSidebarShown = waitForNodeMutation(appNode, { childList: true });
     87 
     88  const contextMenu = await openContextMenu(hud, objectNode);
     89  const openInSidebar = contextMenu.querySelector("#console-menu-open-sidebar");
     90  openInSidebar.click();
     91  await onSidebarShown;
     92  await hideContextMenu(hud);
     93 
     94  // Let's wait for the object inside the sidebar to be expanded.
     95  await waitFor(
     96    () => appNode.querySelectorAll(".sidebar .tree-node").length > 1,
     97    null,
     98    100
     99  );
    100 }