summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_cmd-break.js
blob: 121bc5e998eff216109d44c15daa7b0e49fb5f16 (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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* -*- 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/ */

/**
 * Tests that the break commands works as they should.
 */

const TAB_URL = EXAMPLE_URL + "doc_cmd-break.html";
var TAB_URL_ACTOR;

function test() {
  let gPanel, gDebugger, gThreadClient, gSources;
  let gLineNumber;

  let expectedActorObj = {
    value: null,
    message: ""
  };

  helpers.addTabWithToolbar(TAB_URL, aOptions => {
    return Task.spawn(function* () {
      yield helpers.audit(aOptions, [{
        setup: "break",
        check: {
          input:  "break",
          hints:       " add line",
          markup: "IIIII",
          status: "ERROR",
        }
      }]);

      yield helpers.audit(aOptions, [{
        setup: "break add",
        check: {
          input:  "break add",
          hints:           " line",
          markup: "IIIIIVIII",
          status: "ERROR"
        }
      }]);

      yield helpers.audit(aOptions, [{
        setup: "break add line",
        check: {
          input:  "break add line",
          hints:                " <file> <line>",
          markup: "VVVVVVVVVVVVVV",
          status: "ERROR"
        }
      }]);

      yield helpers.audit(aOptions, [{
        name: "open toolbox",
        setup: Task.async(function* () {
          let [aTab, aDebuggee, aPanel] = yield initDebugger(gBrowser.selectedTab);

          // Spin the event loop before causing the debuggee to pause, to allow this
          // function to return first.
          executeSoon(() => aDebuggee.firstCall());

          yield waitForSourceAndCaretAndScopes(aPanel, ".html", 1);

          gPanel = aPanel;
          gDebugger = gPanel.panelWin;
          gThreadClient = gPanel.panelWin.gThreadClient;
          gLineNumber = yield ContentTask.spawn(aOptions.browser, {}, function* () {
            return "" + content.wrappedJSObject.gLineNumber;
          });
          gSources = gDebugger.DebuggerView.Sources;

          expectedActorObj.value = getSourceActor(gSources, TAB_URL);
        }),
        post: function () {
          ok(gThreadClient, "Debugger client exists.");
          is(gLineNumber, 14, "gLineNumber is correct.");
        },
      }]);

      yield helpers.audit(aOptions, [{
        name: "break add line .../doc_cmd-break.html 14",
        setup: function () {
          // We have to setup in a function to allow gLineNumber to be initialized.
          let line = "break add line " + TAB_URL + " " + gLineNumber;
          return helpers.setInput(aOptions, line);
        },
        check: {
          hints: "",
          status: "VALID",
          message: "",
          args: {
            file: expectedActorObj,
            line: { value: 14 }
          }
        },
        exec: {
          output: "Added breakpoint"
        }
      }]);

      yield helpers.audit(aOptions, [{
        setup: "break add line " + TAB_URL + " 17",
        check: {
          hints: "",
          status: "VALID",
          message: "",
          args: {
            file: expectedActorObj,
            line: { value: 17 }
          }
        },
        exec: {
          output: "Added breakpoint"
        }
      }]);

      yield helpers.audit(aOptions, [{
        setup: "break list",
        check: {
          input:  "break list",
          hints:            "",
          markup: "VVVVVVVVVV",
          status: "VALID"
        },
        exec: {
          output: [
            /Source/, /Remove/,
            /doc_cmd-break\.html:14/,
            /doc_cmd-break\.html:17/
          ]
        }
      }]);

      yield helpers.audit(aOptions, [{
        name: "cleanup",
        setup: function () {
          let deferred = promise.defer();
          gThreadClient.resume(deferred.resolve);
          return deferred.promise;
        }
      }]);

      yield helpers.audit(aOptions, [{
        setup: "break del 14",
        check: {
          input:  "break del 14",
          hints:              " -> doc_cmd-break.html:14",
          markup: "VVVVVVVVVVII",
          status: "ERROR",
          args: {
            breakpoint: {
              status: "INCOMPLETE",
              message: "Value required for \u2018breakpoint\u2019."
            }
          }
        }
      }]);

      yield helpers.audit(aOptions, [{
        setup: "break del doc_cmd-break.html:14",
        check: {
          input:  "break del doc_cmd-break.html:14",
          hints:                                 "",
          markup: "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",
          status: "VALID",
          args: {
            breakpoint: { arg: " doc_cmd-break.html:14" },
          }
        },
        exec: {
          output: "Breakpoint removed"
        }
      }]);

      yield helpers.audit(aOptions, [{
        setup: "break list",
        check: {
          input:  "break list",
          hints:            "",
          markup: "VVVVVVVVVV",
          status: "VALID"
        },
        exec: {
          output: [
            /Source/, /Remove/,
            /doc_cmd-break\.html:17/
          ]
        }
      }]);

      yield helpers.audit(aOptions, [{
        setup: "break del doc_cmd-break.html:17",
        check: {
          input:  "break del doc_cmd-break.html:17",
          hints:                                 "",
          markup: "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",
          status: "VALID",
          args: {
            breakpoint: { arg: " doc_cmd-break.html:17" },
          }
        },
        exec: {
          output: "Breakpoint removed"
        }
      }]);

      yield helpers.audit(aOptions, [{
        setup: "break list",
        check: {
          input:  "break list",
          hints:            "",
          markup: "VVVVVVVVVV",
          status: "VALID"
        },
        exec: {
          output: "No breakpoints set"
        },
        post: function () {
          return teardown(gPanel, { noTabRemoval: true });
        }
      }]);
    });
  }).then(finish);
}