summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_on-pause-raise.js
blob: 6f6f152477b7bbefeb0591a578780203ce18a3bb (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
/* -*- 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 toolbox is raised when the debugger gets paused.
 */

const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";

add_task(function *() {
  let options = {
    source: TAB_URL,
    line: 1
  };
  let [tab,, panel] = yield initDebugger(TAB_URL, options);
  let panelWin = panel.panelWin;
  let toolbox = panel._toolbox;
  let toolboxTab = toolbox.doc.getElementById("toolbox-tab-jsdebugger");

  let newTab = yield addTab(TAB_URL);
  isnot(newTab, tab,
    "The newly added tab is different from the debugger's tab.");
  is(gBrowser.selectedTab, newTab,
    "Debugger's tab is not the selected tab.");

  info("Run tests against bottom host.");
  yield testPause();
  yield testResume();

  // testResume selected the console, select back the debugger.
  yield toolbox.selectTool("jsdebugger");

  info("Switching to a toolbox window host.");
  yield toolbox.switchHost(Toolbox.HostType.WINDOW);

  info("Run tests against window host.");
  yield testPause();
  yield testResume();

  info("Cleanup after the test.");
  yield toolbox.switchHost(Toolbox.HostType.BOTTOM);
  yield closeDebuggerAndFinish(panel);

  function* testPause() {
    is(panelWin.gThreadClient.paused, false,
      "Should be running after starting the test.");

    let onFocus, onTabSelect;
    if (toolbox.hostType == Toolbox.HostType.WINDOW) {
      onFocus = new Promise(done => {
        toolbox.win.parent.addEventListener("focus", function onFocus() {
          toolbox.win.parent.removeEventListener("focus", onFocus, true);
          done();
        }, true);
      });
    } else {
      onTabSelect = new Promise(done => {
        tab.parentNode.addEventListener("TabSelect", function listener({type}) {
          tab.parentNode.removeEventListener(type, listener);
          done();
        });
      });
    }

    let onPaused = waitForPause(panelWin.gThreadClient);

    // Evaluate a script to fully pause the debugger
    evalInTab(tab, "debugger;");

    yield onPaused;
    yield onFocus;
    yield onTabSelect;

    if (toolbox.hostType != Toolbox.HostType.WINDOW) {
      is(gBrowser.selectedTab, tab,
        "Debugger's tab got selected.");
    }

    yield toolbox.selectTool("webconsole");
    ok(toolboxTab.hasAttribute("highlighted") &&
       toolboxTab.getAttribute("highlighted") == "true",
      "The highlighted class is present");
    ok(!toolboxTab.hasAttribute("selected") ||
        toolboxTab.getAttribute("selected") != "true",
      "The tab is not selected");
    yield toolbox.selectTool("jsdebugger");
    ok(toolboxTab.hasAttribute("highlighted") &&
       toolboxTab.getAttribute("highlighted") == "true",
      "The highlighted class is present");
    ok(toolboxTab.hasAttribute("selected") &&
       toolboxTab.getAttribute("selected") == "true",
      "...and the tab is selected, so the glow will not be present.");
  }

  function* testResume() {
    let onPaused = waitForEvent(panelWin.gThreadClient, "resumed");

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

    yield onPaused;

    yield toolbox.selectTool("webconsole");
    ok(!toolboxTab.hasAttribute("highlighted") ||
        toolboxTab.getAttribute("highlighted") != "true",
      "The highlighted class is not present now after the resume");
    ok(!toolboxTab.hasAttribute("selected") ||
        toolboxTab.getAttribute("selected") != "true",
      "The tab is not selected");
  }
});

registerCleanupFunction(function () {
  // Revert to the default toolbox host, so that the following tests proceed
  // normally and not inside a non-default host.
  Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM);
});