summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_eval_sources.js
blob: 6026f7039b40a18138a2de09ce111744dc43f06e (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TEST_URI =
  "http://example.com/browser/devtools/client/webconsole/" +
  "test/browser/test-eval-sources.html";

// Test that stack/message links in console API and error messages originating
// from eval code go to a source in the debugger. This should work even when the
// console is opened first.
add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);
  const toolbox = gDevTools.getToolboxForTab(gBrowser.selectedTab);

  let messageNode = await waitFor(() => findErrorMessage(hud, "BAR"));
  await clickFirstStackElement(hud, messageNode, true);

  const dbg = toolbox.getPanel("jsdebugger");

  is(
    dbg._selectors.getSelectedSource(dbg._getState()).url,
    null,
    "expected source url"
  );

  await testOpenInDebugger(hud, {
    text: "FOO",
    typeSelector: ".console-api",
    expectUrl: false,
  });
  await testOpenInDebugger(hud, {
    text: "BAR",
    typeSelector: ".error",
    expectUrl: false,
  });

  // Test that links in the API work when the eval source has a sourceURL property
  // which is not considered to be a valid URL.
  await testOpenInDebugger(hud, {
    text: "BAZ",
    typeSelector: ".console-api",
    expectUrl: false,
  });

  // Test that stacks in console.trace() calls work.
  messageNode = await waitFor(() => findConsoleAPIMessage(hud, "TRACE"));
  await clickFirstStackElement(hud, messageNode, false);

  is(
    /my-foo.js/.test(dbg._selectors.getSelectedSource(dbg._getState()).url),
    true,
    "expected source url"
  );
});

async function clickFirstStackElement(hud, message, needsExpansion) {
  if (needsExpansion) {
    const button = message.querySelector(".collapse-button");
    ok(button, "has button");
    button.click();
  }

  let frame;
  await waitUntil(() => {
    frame = message.querySelector(".stacktrace .frame");
    return !!frame;
  });

  const onSourceOpenedInDebugger = once(hud, "source-in-debugger-opened");
  EventUtils.sendMouseEvent({ type: "mousedown" }, frame);
  await onSourceOpenedInDebugger;
}