summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_pretty-print-on-paused.js
blob: 12e3a20fce60a98a05fc1a9688eb8cbe655f00e3 (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Test that pretty printing when the debugger is paused does not switch away
 * from the selected source.
 */

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

var gTab, gPanel, gDebugger, gThreadClient, gSources;

const SECOND_SOURCE_VALUE = EXAMPLE_URL + "code_ugly-2.js";

function test() {
  // Wait for debugger panel to be fully set and break on debugger statement
  let options = {
    source: EXAMPLE_URL + "code_script-switching-02.js",
    line: 1
  };
  initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
    gTab = aTab;
    gPanel = aPanel;
    gDebugger = gPanel.panelWin;
    gThreadClient = gDebugger.gThreadClient;
    gSources = gDebugger.DebuggerView.Sources;

    Task.spawn(function* () {
      try {
        yield doInterrupt(gPanel);

        let source = gThreadClient.source(getSourceForm(gSources, SECOND_SOURCE_VALUE));
        yield source.setBreakpoint({
          line: 6
        });
        yield doResume(gPanel);

        const bpHit = waitForCaretAndScopes(gPanel, 6);
        callInTab(gTab, "secondCall");
        yield bpHit;

        info("Switch to the second source.");
        const sourceShown = waitForSourceShown(gPanel, SECOND_SOURCE_VALUE);
        gSources.selectedValue = getSourceActor(gSources, SECOND_SOURCE_VALUE);
        yield sourceShown;

        info("Pretty print the source.");
        const prettyPrinted = waitForSourceShown(gPanel, SECOND_SOURCE_VALUE);
        gDebugger.document.getElementById("pretty-print").click();
        yield prettyPrinted;

        yield resumeDebuggerThenCloseAndFinish(gPanel);
      } catch (e) {
        DevToolsUtils.reportException("browser_dbg_pretty-print-on-paused.js", e);
        ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
      }
    });
  });
}

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