summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_pause-exceptions-02.js
blob: 21b28ce26f4c98fa1e0cd27e20472796d06a0f26 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/* -*- 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/ */

/**
 * Make sure that pausing on exceptions works after reload.
 */

const TAB_URL = EXAMPLE_URL + "doc_pause-exceptions.html";

var gTab, gPanel, gDebugger;
var gFrames, gVariables, gPrefs, gOptions;

function test() {
  let options = {
    source: TAB_URL,
    line: 1
  };
  initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
    gTab = aTab;
    gPanel = aPanel;
    gDebugger = gPanel.panelWin;
    gFrames = gDebugger.DebuggerView.StackFrames;
    gVariables = gDebugger.DebuggerView.Variables;
    gPrefs = gDebugger.Prefs;
    gOptions = gDebugger.DebuggerView.Options;

    is(gPrefs.pauseOnExceptions, false,
      "The pause-on-exceptions pref should be disabled by default.");
    isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true",
      "The pause-on-exceptions menu item should not be checked.");

    enablePauseOnExceptions()
      .then(disableIgnoreCaughtExceptions)
      .then(() => reloadActiveTab(gPanel, gDebugger.EVENTS.SOURCE_SHOWN))
      .then(() => {
        generateMouseClickInTab(gTab, "content.document.querySelector('button')");
      })
      .then(testPauseOnExceptionsAfterReload)
      .then(disablePauseOnExceptions)
      .then(enableIgnoreCaughtExceptions)
      .then(() => closeDebuggerAndFinish(gPanel))
      .then(null, aError => {
        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
      });
  });
}

function testPauseOnExceptionsAfterReload() {
  let finished = waitForCaretAndScopes(gPanel, 19).then(() => {
    info("Testing enabled pause-on-exceptions.");

    is(gDebugger.gThreadClient.state, "paused",
      "Should only be getting stack frames while paused.");
    ok(isCaretPos(gPanel, 19),
      "Should be paused on the debugger statement.");

    let innerScope = gVariables.getScopeAtIndex(0);
    let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes;

    is(gFrames.itemCount, 1,
      "Should have one frame.");
    is(gVariables._store.length, 4,
      "Should have four scopes.");

    is(innerNodes[0].querySelector(".name").getAttribute("value"), "<exception>",
      "Should have the right property name for <exception>.");
    is(innerNodes[0].querySelector(".value").getAttribute("value"), "Error",
      "Should have the right property value for <exception>.");

    let finished = waitForCaretAndScopes(gPanel, 26).then(() => {
      info("Testing enabled pause-on-exceptions and resumed after pause.");

      is(gDebugger.gThreadClient.state, "paused",
        "Should only be getting stack frames while paused.");
      ok(isCaretPos(gPanel, 26),
        "Should be paused on the debugger statement.");

      let innerScope = gVariables.getScopeAtIndex(0);
      let innerNodes = innerScope.target.querySelector(".variables-view-element-details").childNodes;

      is(gFrames.itemCount, 1,
        "Should have one frame.");
      is(gVariables._store.length, 4,
        "Should have four scopes.");

      is(innerNodes[0].querySelector(".name").getAttribute("value"), "this",
        "Should have the right property name for 'this'.");
      is(innerNodes[0].querySelector(".value").getAttribute("value"), "<button>",
        "Should have the right property value for 'this'.");

      let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
        isnot(gDebugger.gThreadClient.state, "paused",
          "Should not be paused after resuming.");
        ok(isCaretPos(gPanel, 26),
          "Should be idle on the debugger statement.");

        ok(true, "Frames were cleared, debugger didn't pause again.");
      });

      EventUtils.sendMouseEvent({ type: "mousedown" },
        gDebugger.document.getElementById("resume"),
        gDebugger);

      return finished;
    });

    EventUtils.sendMouseEvent({ type: "mousedown" },
      gDebugger.document.getElementById("resume"),
      gDebugger);

    return finished;
  });

  generateMouseClickInTab(gTab, "content.document.querySelector('button')");

  return finished;
}

function enablePauseOnExceptions() {
  let deferred = promise.defer();

  gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
    is(gPrefs.pauseOnExceptions, true,
      "The pause-on-exceptions pref should now be enabled.");
    is(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true",
      "The pause-on-exceptions menu item should now be checked.");

    ok(true, "Pausing on exceptions was enabled.");
    deferred.resolve();
  });

  gOptions._pauseOnExceptionsItem.setAttribute("checked", "true");
  gOptions._togglePauseOnExceptions();
  return deferred.promise;
}

function disablePauseOnExceptions() {
  let deferred = promise.defer();

  gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
    is(gPrefs.pauseOnExceptions, false,
      "The pause-on-exceptions pref should now be disabled.");
    isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true",
      "The pause-on-exceptions menu item should now be unchecked.");

    ok(true, "Pausing on exceptions was disabled.");
    deferred.resolve();
  });

  gOptions._pauseOnExceptionsItem.setAttribute("checked", "false");
  gOptions._togglePauseOnExceptions();

  return deferred.promise;
}

function enableIgnoreCaughtExceptions() {
  let deferred = promise.defer();

  gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
    is(gPrefs.ignoreCaughtExceptions, true,
      "The ignore-caught-exceptions pref should now be enabled.");
    is(gOptions._ignoreCaughtExceptionsItem.getAttribute("checked"), "true",
      "The ignore-caught-exceptions menu item should now be checked.");

    ok(true, "Ignore caught exceptions was enabled.");
    deferred.resolve();
  });

  gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "true");
  gOptions._toggleIgnoreCaughtExceptions();

  return deferred.promise;
}

function disableIgnoreCaughtExceptions() {
  let deferred = promise.defer();

  gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
    is(gPrefs.ignoreCaughtExceptions, false,
      "The ignore-caught-exceptions pref should now be disabled.");
    isnot(gOptions._ignoreCaughtExceptionsItem.getAttribute("checked"), "true",
      "The ignore-caught-exceptions menu item should now be unchecked.");

    ok(true, "Ignore caught exceptions was disabled.");
    deferred.resolve();
  });

  gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "false");
  gOptions._toggleIgnoreCaughtExceptions();

  return deferred.promise;
}

registerCleanupFunction(function () {
  gTab = null;
  gPanel = null;
  gDebugger = null;
  gFrames = null;
  gVariables = null;
  gPrefs = null;
  gOptions = null;
});