tor-browser

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

browser_webconsole_eval_sources.js (2616B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const TEST_URI =
      7  "https://example.com/browser/devtools/client/webconsole/" +
      8  "test/browser/test-eval-sources.html";
      9 
     10 // Test that stack/message links in console API and error messages originating
     11 // from eval code go to a source in the debugger. This should work even when the
     12 // console is opened first.
     13 add_task(async function () {
     14  const hud = await openNewTabAndConsole(TEST_URI);
     15  const toolbox = gDevTools.getToolboxForTab(gBrowser.selectedTab);
     16 
     17  let messageNode = await waitFor(() => findErrorMessage(hud, "BAR"));
     18  await clickFirstStackElement(hud.toolbox, messageNode, true, {
     19    // evaled sources have no URL
     20    url: null,
     21    line: 1,
     22    column: 33,
     23  });
     24 
     25  const dbg = toolbox.getPanel("jsdebugger");
     26 
     27  is(
     28    dbg._selectors.getSelectedSource(dbg._getState()).url,
     29    null,
     30    "expected source url"
     31  );
     32 
     33  await toolbox.selectTool("webconsole");
     34  await testOpenInDebugger(hud, {
     35    text: "FOO",
     36    typeSelector: ".console-api",
     37    // evaled sources have no URL
     38    url: null,
     39    line: 1,
     40    column: 35,
     41  });
     42 
     43  await toolbox.selectTool("webconsole");
     44  await testOpenInDebugger(hud, {
     45    text: "BAR",
     46    typeSelector: ".error",
     47    url: null,
     48    line: 1,
     49    column: 33,
     50  });
     51 
     52  // Test that links in the API work when the eval source has a sourceURL property
     53  // which is not considered to be a valid URL.
     54  await toolbox.selectTool("webconsole");
     55  await testOpenInDebugger(hud, {
     56    text: "BAZ",
     57    typeSelector: ".console-api",
     58    url: null,
     59    line: 2,
     60    column: 17,
     61  });
     62 
     63  // Test that stacks in console.trace() calls work.
     64  await toolbox.selectTool("webconsole");
     65  messageNode = await waitFor(() => findConsoleAPIMessage(hud, "TRACE"));
     66  await clickFirstStackElement(hud.toolbox, messageNode, false, {
     67    // Do not assert the url as it differs from Frame and Debugger
     68    // The Frame displays "my-foo.js", while the debugger resolves to an absolute URL.
     69    url: null,
     70    line: 3,
     71    column: 17,
     72  });
     73 
     74  is(
     75    /my-foo.js/.test(dbg._selectors.getSelectedSource(dbg._getState()).url),
     76    true,
     77    "expected source url"
     78  );
     79 });
     80 
     81 async function clickFirstStackElement(
     82  toolbox,
     83  message,
     84  needsExpansion,
     85  options
     86 ) {
     87  if (needsExpansion) {
     88    const button = message.querySelector(".collapse-button");
     89    ok(button, "has button");
     90    button.click();
     91  }
     92 
     93  const frameNode = await waitFor(() =>
     94    message.querySelector(".stacktrace .frame")
     95  );
     96 
     97  await clickAndAssertFrameLinkNode(toolbox, frameNode, options);
     98 }