browser/devtools/debugger/test/browser_dbg_host-layout.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:e4de50508f2d
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * This if the debugger's layout is correctly modified when the toolbox's
6 * host changes.
7 */
8
9 let gDefaultHostType = Services.prefs.getCharPref("devtools.toolbox.host");
10
11 function test() {
12 Task.spawn(function() {
13 yield testHosts(["bottom", "side", "window"], ["horizontal", "vertical", "horizontal"]);
14 yield testHosts(["side", "bottom", "side"], ["vertical", "horizontal", "vertical"]);
15 yield testHosts(["bottom", "side", "bottom"], ["horizontal", "vertical", "horizontal"]);
16 yield testHosts(["side", "window", "side"], ["vertical", "horizontal", "vertical"]);
17 yield testHosts(["window", "side", "window"], ["horizontal", "vertical", "horizontal"]);
18 finish();
19 });
20 }
21
22 function testHosts(aHostTypes, aLayoutTypes) {
23 let [firstHost, secondHost, thirdHost] = aHostTypes;
24 let [firstLayout, secondLayout, thirdLayout] = aLayoutTypes;
25
26 Services.prefs.setCharPref("devtools.toolbox.host", firstHost);
27
28 return Task.spawn(function() {
29 let [tab, debuggee, panel] = yield initDebugger("about:blank");
30 yield testHost(tab, debuggee, panel, firstHost, firstLayout);
31 yield switchAndTestHost(tab, debuggee, panel, secondHost, secondLayout);
32 yield switchAndTestHost(tab, debuggee, panel, thirdHost, thirdLayout);
33 yield teardown(panel);
34 });
35 }
36
37 function switchAndTestHost(aTab, aDebuggee, aPanel, aHostType, aLayoutType) {
38 let gToolbox = aPanel._toolbox;
39 let gDebugger = aPanel.panelWin;
40
41 return Task.spawn(function() {
42 let layoutChanged = once(gDebugger, gDebugger.EVENTS.LAYOUT_CHANGED);
43 let hostChanged = gToolbox.switchHost(aHostType);
44
45 yield hostChanged;
46 ok(true, "The toolbox's host has changed.");
47
48 yield layoutChanged;
49 ok(true, "The debugger's layout has changed.");
50
51 yield testHost(aTab, aDebuggee, aPanel, aHostType, aLayoutType);
52 });
53
54 function once(aTarget, aEvent) {
55 let deferred = promise.defer();
56 aTarget.once(aEvent, deferred.resolve);
57 return deferred.promise;
58 }
59 }
60
61 function testHost(aTab, aDebuggee, aPanel, aHostType, aLayoutType) {
62 let gDebugger = aPanel.panelWin;
63 let gView = gDebugger.DebuggerView;
64
65 is(gView._hostType, aHostType,
66 "The default host type should've been set on the panel window (1).");
67 is(gDebugger.gHostType, aHostType,
68 "The default host type should've been set on the panel window (2).");
69
70 is(gView._body.getAttribute("layout"), aLayoutType,
71 "The default host type is present as an attribute on the panel's body.");
72
73 if (aLayoutType == "horizontal") {
74 is(gView._sourcesPane.parentNode.id, "debugger-widgets",
75 "The sources pane's parent is correct for the horizontal layout.");
76 is(gView._instrumentsPane.parentNode.id, "debugger-widgets",
77 "The instruments pane's parent is correct for the horizontal layout.");
78 } else {
79 is(gView._sourcesPane.parentNode.id, "vertical-layout-panes-container",
80 "The sources pane's parent is correct for the vertical layout.");
81 is(gView._instrumentsPane.parentNode.id, "vertical-layout-panes-container",
82 "The instruments pane's parent is correct for the vertical layout.");
83 }
84
85 let widgets = gDebugger.document.getElementById("debugger-widgets").childNodes;
86 let panes = gDebugger.document.getElementById("vertical-layout-panes-container").childNodes;
87
88 if (aLayoutType == "horizontal") {
89 is(widgets.length, 7, // 2 panes, 1 editor, 3 splitters and a phantom box.
90 "Found the correct number of debugger widgets.");
91 is(panes.length, 1, // 1 lonely splitter in the phantom box.
92 "Found the correct number of debugger panes.");
93 } else {
94 is(widgets.length, 5, // 1 editor, 3 splitters and a phantom box.
95 "Found the correct number of debugger widgets.");
96 is(panes.length, 3, // 2 panes and 1 splitter in the phantom box.
97 "Found the correct number of debugger panes.");
98 }
99 }
100
101 registerCleanupFunction(function() {
102 Services.prefs.setCharPref("devtools.toolbox.host", gDefaultHostType);
103 gDefaultHostType = null;
104 });

mercurial