browser/devtools/debugger/test/browser_dbg_on-pause-raise.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:91c351fec862
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Tests that the toolbox is raised when the debugger gets paused.
6 */
7
8 const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
9
10 let gTab, gDebuggee, gPanel, gDebugger;
11 let gNewTab, gFocusedWindow, gToolbox, gToolboxTab;
12
13 function test() {
14 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
15 gTab = aTab;
16 gDebuggee = aDebuggee;
17 gPanel = aPanel;
18 gDebugger = gPanel.panelWin;
19 gToolbox = gPanel._toolbox;
20 gToolboxTab = gToolbox.doc.getElementById("toolbox-tab-jsdebugger");
21
22 waitForSourceShown(gPanel, ".html").then(performTest);
23 });
24 }
25
26 function performTest() {
27 addTab(TAB_URL).then(aTab => {
28 isnot(aTab, gTab,
29 "The newly added tab is different from the debugger's tab.");
30 is(gBrowser.selectedTab, aTab,
31 "Debugger's tab is not the selected tab.");
32
33 gNewTab = aTab;
34 gFocusedWindow = window;
35 testPause();
36 });
37 }
38
39 function focusMainWindow() {
40 // Make sure toolbox is not focused.
41 window.addEventListener("focus", onFocus, true);
42 info("Focusing main window.")
43
44 // Execute soon to avoid any race conditions between toolbox and main window
45 // getting focused.
46 executeSoon(() => {
47 window.focus();
48 });
49 }
50
51 function onFocus() {
52 window.removeEventListener("focus", onFocus, true);
53 info("Main window focused.")
54
55 gFocusedWindow = window;
56 testPause();
57 }
58
59 function testPause() {
60 is(gDebugger.gThreadClient.paused, false,
61 "Should be running after starting the test.");
62
63 is(gFocusedWindow, window,
64 "Main window is the top level window before pause.");
65
66 if (gToolbox.hostType == devtools.Toolbox.HostType.WINDOW) {
67 gToolbox._host._window.onfocus = () => {
68 gFocusedWindow = gToolbox._host._window;
69 };
70 }
71
72 gDebugger.gThreadClient.addOneTimeListener("paused", () => {
73 if (gToolbox.hostType == devtools.Toolbox.HostType.WINDOW) {
74 is(gFocusedWindow, gToolbox._host._window,
75 "Toolbox window is the top level window on pause.");
76 } else {
77 is(gBrowser.selectedTab, gTab,
78 "Debugger's tab got selected.");
79 }
80 gToolbox.selectTool("webconsole").then(() => {
81 ok(gToolboxTab.hasAttribute("highlighted") &&
82 gToolboxTab.getAttribute("highlighted") == "true",
83 "The highlighted class is present");
84 ok(!gToolboxTab.hasAttribute("selected") ||
85 gToolboxTab.getAttribute("selected") != "true",
86 "The tab is not selected");
87 }).then(() => gToolbox.selectTool("jsdebugger")).then(() => {
88 ok(gToolboxTab.hasAttribute("highlighted") &&
89 gToolboxTab.getAttribute("highlighted") == "true",
90 "The highlighted class is present");
91 ok(gToolboxTab.hasAttribute("selected") &&
92 gToolboxTab.getAttribute("selected") == "true",
93 "...and the tab is selected, so the glow will not be present.");
94 }).then(testResume);
95 });
96
97 EventUtils.sendMouseEvent({ type: "mousedown" },
98 gDebugger.document.getElementById("resume"),
99 gDebugger);
100 }
101
102 function testResume() {
103 gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
104 gToolbox.selectTool("webconsole").then(() => {
105 ok(!gToolboxTab.hasAttribute("highlighted") ||
106 gToolboxTab.getAttribute("highlighted") != "true",
107 "The highlighted class is not present now after the resume");
108 ok(!gToolboxTab.hasAttribute("selected") ||
109 gToolboxTab.getAttribute("selected") != "true",
110 "The tab is not selected");
111 }).then(maybeEndTest);
112 });
113
114 EventUtils.sendMouseEvent({ type: "mousedown" },
115 gDebugger.document.getElementById("resume"),
116 gDebugger);
117 }
118
119 function maybeEndTest() {
120 if (gToolbox.hostType == devtools.Toolbox.HostType.BOTTOM) {
121 info("Switching to a toolbox window host.");
122 gToolbox.switchHost(devtools.Toolbox.HostType.WINDOW).then(focusMainWindow);
123 } else {
124 info("Switching to main window host.");
125 gToolbox.switchHost(devtools.Toolbox.HostType.BOTTOM).then(() => closeDebuggerAndFinish(gPanel));
126 }
127 }
128
129 registerCleanupFunction(function() {
130 // Revert to the default toolbox host, so that the following tests proceed
131 // normally and not inside a non-default host.
132 Services.prefs.setCharPref("devtools.toolbox.host", devtools.Toolbox.HostType.BOTTOM);
133
134 gTab = null;
135 gDebuggee = null;
136 gPanel = null;
137 gDebugger = null;
138
139 removeTab(gNewTab);
140 gNewTab = null;
141 gFocusedWindow = null;
142 gToolbox = null;
143 gToolboxTab = null;
144 });

mercurial