tor-browser

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

browser_inspector_use-in-console-conflict.js (1749B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Tests "Use in Console" menu item with conflicting binding in the web content.
      6 
      7 const TEST_URL = `data:text/html;charset=utf-8,<!DOCTYPE html>
      8 <p id="console-var">Paragraph for testing console variables</p>
      9 <script>
     10  /* Verify that the conflicting binding on user code doesn't break the
     11   * functionality. */
     12  var $0 = "user-defined variable";
     13 </script>`;
     14 
     15 add_task(async function () {
     16  // Disable eager evaluation to avoid intermittent failures due to pending
     17  // requests to evaluateJSAsync.
     18  await pushPref("devtools.webconsole.input.eagerEvaluation", false);
     19 
     20  const { inspector, toolbox } = await openInspectorForURL(TEST_URL);
     21 
     22  info("Testing 'Use in Console' menu item.");
     23 
     24  await selectNode("#console-var", inspector);
     25  const container = await getContainerForSelector("#console-var", inspector);
     26  const allMenuItems = openContextMenuAndGetAllItems(inspector, {
     27    target: container.tagLine,
     28  });
     29  const menuItem = allMenuItems.find(i => i.id === "node-menu-useinconsole");
     30  const onConsoleVarReady = inspector.once("console-var-ready");
     31 
     32  menuItem.click();
     33 
     34  await onConsoleVarReady;
     35 
     36  const hud = toolbox.getPanel("webconsole").hud;
     37 
     38  const getConsoleResults = () => hud.ui.outputNode.querySelectorAll(".result");
     39 
     40  is(hud.getInputValue(), "temp0", "first console variable is named temp0");
     41  hud.ui.wrapper.dispatchEvaluateExpression();
     42 
     43  await waitUntil(() => getConsoleResults().length === 1);
     44  const result = getConsoleResults()[0];
     45  ok(
     46    result.textContent.includes('<p id="console-var">'),
     47    "variable temp0 references correct node"
     48  );
     49 
     50  hud.ui.wrapper.dispatchClearHistory();
     51 });