summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser_eval_in_debugger_stackframe2.js
blob: bc116d443cf7e5c3e6c3df59501f4d411ee8c94c (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
/* -*- 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 to make sure that web console commands can fire while paused at a
// breakpoint that was triggered from a JS call.  Relies on asynchronous js
// evaluation over the protocol - see Bug 1088861.

"use strict";

const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
                 "test/test-eval-in-stackframe.html";

// Force the old debugger UI since it's directly used (see Bug 1301705)
Services.prefs.setBoolPref("devtools.debugger.new-debugger-frontend", false);
registerCleanupFunction(function* () {
  Services.prefs.clearUserPref("devtools.debugger.new-debugger-frontend");
});

add_task(function* () {
  yield loadTab(TEST_URI);

  info("open the web console");
  let hud = yield openConsole();
  let {jsterm} = hud;

  info("open the debugger");
  let {panelWin} = yield openDebugger();
  let {DebuggerController} = panelWin;
  let {activeThread} = DebuggerController;

  let firstCall = promise.defer();
  let frameAdded = promise.defer();
  executeSoon(() => {
    info("Executing firstCall");
    activeThread.addOneTimeListener("framesadded", () => {
      executeSoon(frameAdded.resolve);
    });
    jsterm.execute("firstCall()").then(firstCall.resolve);
  });

  info("Waiting for a frame to be added");
  yield frameAdded.promise;

  info("Executing basic command while paused");
  yield executeAndConfirm(jsterm, "1 + 2", "3");

  info("Executing command using scoped variables while paused");
  yield executeAndConfirm(jsterm, "foo + foo2",
                          '"globalFooBug783499foo2SecondCall"');

  info("Resuming the thread");
  activeThread.resume();

  info("Checking the first command, which is the last to resolve since it " +
       "paused");
  let node = yield firstCall.promise;
  is(node.querySelector(".message-body").textContent,
     "undefined",
     "firstCall() returned correct value");
});

function* executeAndConfirm(jsterm, input, output) {
  info("Executing command `" + input + "`");

  let node = yield jsterm.execute(input);

  is(node.querySelector(".message-body").textContent, output,
     "Expected result from call to " + input);
}