summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-pretty-print-console.js
blob: e6aa266b26a6f2438a888961f4e0af562271497f (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

// The test has a lot of interactions between debugger and console panels which
// might take more than 30s to complete on a slow machine.

"use strict";

requestLongerTimeout(2);

// Tests that pretty-printing updates console messages.
add_task(async function () {
  const dbg = await initDebugger("doc-minified.html");
  invokeInTab("arithmetic");

  info("Switch to console and check message");
  const minifiedLink = await waitForConsoleLink(
    dbg,
    "arithmetic",
    "math.min.js:3:73"
  );

  info("Click on the link to open the debugger");
  minifiedLink.click();
  await waitForSelectedSource(dbg, "math.min.js");
  await waitForSelectedLocation(dbg, 3);

  info("Click on pretty print button and wait for the file to be formatted");
  clickElement(dbg, "prettyPrintButton");
  await waitForSelectedSource(dbg, "math.min.js:formatted");

  info("Switch back to console and check message");
  const formattedLink = await waitForConsoleLink(
    dbg,
    "arithmetic",
    "math.min.js:formatted:31:24"
  );
  ok(true, "Message location was updated as expected");

  info(
    "Click on the link again and check the debugger opens in formatted file"
  );
  formattedLink.click();
  await selectSource(dbg, "math.min.js:formatted");
  await waitForSelectedLocation(dbg, 31);
});

async function waitForConsoleLink(dbg, messageText, linkText) {
  const { toolbox } = dbg;
  await toolbox.selectTool("webconsole");

  return waitFor(async () => {
    // Wait until the message updates.
    const [message] = await findConsoleMessages(toolbox, messageText);
    if (!message) {
      return false;
    }
    const linkEl = message.querySelector(".frame-link-source");
    if (!linkEl) {
      return false;
    }

    return linkEl.textContent == linkText ? linkEl : false;
  });
}