summaryrefslogtreecommitdiff
path: root/toolkit/devtools/debugger/test/browser_dbg_pretty-print-03.js
blob: 888fbcc0271a6c5541fce3c3aec67667c5a9f3fb (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Make sure that we have the correct line selected after pretty printing.
 */

const TAB_URL = EXAMPLE_URL + "doc_pretty-print.html";

let gTab, gPanel, gDebugger;

function test() {
  initDebugger(TAB_URL).then(([aTab,, aPanel]) => {
    gTab = aTab;
    gPanel = aPanel;
    gDebugger = gPanel.panelWin;

    waitForSourceShown(gPanel, "code_ugly.js")
      .then(runCodeAndPause)
      .then(() => {
        const sourceShown = waitForSourceShown(gPanel, "code_ugly.js");
        const caretUpdated = waitForCaretUpdated(gPanel, 7);
        const finished = promise.all([sourceShown, caretUpdated]);
        clickPrettyPrintButton();
        return finished;
      })
      .then(resumeDebuggerThenCloseAndFinish.bind(null, gPanel))
      .then(null, aError => {
        ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError));
      });
  });
}

function runCodeAndPause() {
  const deferred = promise.defer();
  once(gDebugger.gThreadClient, "paused").then(deferred.resolve);
  callInTab(gTab, "foo");
  return deferred.promise;
}

function clickPrettyPrintButton() {
  gDebugger.document.getElementById("pretty-print").click();
}

registerCleanupFunction(function() {
  gTab = null;
  gPanel = null;
  gDebugger = null;
});