summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_break-on-next-console.js
blob: c306945209225ddcf0cf9d38825a1fd27c2eb16b (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
/* -*- 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 if 'break on next' functionality works from executions
 * in content triggered by the console in the toolbox.
 */

const TAB_URL = EXAMPLE_URL + "doc_script-eval.html";

function test() {
  let gTab, gPanel, gDebugger;
  let gSources, gBreakpoints, gTarget, gResumeButton, gResumeKey, gThreadClient;

  let options = {
    source: EXAMPLE_URL + "code_script-eval.js",
    line: 1
  };
  initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
    gTab = aTab;
    gPanel = aPanel;
    gDebugger = gPanel.panelWin;
    gSources = gDebugger.DebuggerView.Sources;
    gTarget = gDebugger.gTarget;
    gThreadClient = gDebugger.gThreadClient;
    gResumeButton = gDebugger.document.getElementById("resume");
    gResumeKey = gDebugger.document.getElementById("resumeKey");

    testConsole()
      .then(() => closeDebuggerAndFinish(gPanel));
  });

  let testConsole = Task.async(function* () {
    info("Starting testConsole");

    let oncePaused = gTarget.once("thread-paused");
    EventUtils.sendMouseEvent({ type: "mousedown" }, gResumeButton, gDebugger);
    let jsterm = yield getSplitConsole(gDevTools.getToolbox(gPanel.target));
    let executed = jsterm.execute("1+1");
    yield oncePaused;

    let updatedFrame = yield waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES);
    let variables = gDebugger.DebuggerView.Variables;

    is(variables._store.length, 3, "Correct number of scopes available");
    is(variables.getScopeAtIndex(0).name, "With scope [Object]",
        "Paused with correct scope (0)");
    is(variables.getScopeAtIndex(1).name, "Block scope",
        "Paused with correct scope (1)");
    is(variables.getScopeAtIndex(2).name, "Global scope [Window]",
        "Paused with correct scope (2)");

    let onceResumed = gTarget.once("thread-resumed");
    EventUtils.sendMouseEvent({ type: "mousedown" }, gResumeButton, gDebugger);
    yield onceResumed;

    yield executed;
  });
}