michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * This if the debugger's layout is correctly modified when the toolbox's michael@0: * host changes. michael@0: */ michael@0: michael@0: let gDefaultHostType = Services.prefs.getCharPref("devtools.toolbox.host"); michael@0: michael@0: function test() { michael@0: Task.spawn(function() { michael@0: yield testHosts(["bottom", "side", "window"], ["horizontal", "vertical", "horizontal"]); michael@0: yield testHosts(["side", "bottom", "side"], ["vertical", "horizontal", "vertical"]); michael@0: yield testHosts(["bottom", "side", "bottom"], ["horizontal", "vertical", "horizontal"]); michael@0: yield testHosts(["side", "window", "side"], ["vertical", "horizontal", "vertical"]); michael@0: yield testHosts(["window", "side", "window"], ["horizontal", "vertical", "horizontal"]); michael@0: finish(); michael@0: }); michael@0: } michael@0: michael@0: function testHosts(aHostTypes, aLayoutTypes) { michael@0: let [firstHost, secondHost, thirdHost] = aHostTypes; michael@0: let [firstLayout, secondLayout, thirdLayout] = aLayoutTypes; michael@0: michael@0: Services.prefs.setCharPref("devtools.toolbox.host", firstHost); michael@0: michael@0: return Task.spawn(function() { michael@0: let [tab, debuggee, panel] = yield initDebugger("about:blank"); michael@0: yield testHost(tab, debuggee, panel, firstHost, firstLayout); michael@0: yield switchAndTestHost(tab, debuggee, panel, secondHost, secondLayout); michael@0: yield switchAndTestHost(tab, debuggee, panel, thirdHost, thirdLayout); michael@0: yield teardown(panel); michael@0: }); michael@0: } michael@0: michael@0: function switchAndTestHost(aTab, aDebuggee, aPanel, aHostType, aLayoutType) { michael@0: let gToolbox = aPanel._toolbox; michael@0: let gDebugger = aPanel.panelWin; michael@0: michael@0: return Task.spawn(function() { michael@0: let layoutChanged = once(gDebugger, gDebugger.EVENTS.LAYOUT_CHANGED); michael@0: let hostChanged = gToolbox.switchHost(aHostType); michael@0: michael@0: yield hostChanged; michael@0: ok(true, "The toolbox's host has changed."); michael@0: michael@0: yield layoutChanged; michael@0: ok(true, "The debugger's layout has changed."); michael@0: michael@0: yield testHost(aTab, aDebuggee, aPanel, aHostType, aLayoutType); michael@0: }); michael@0: michael@0: function once(aTarget, aEvent) { michael@0: let deferred = promise.defer(); michael@0: aTarget.once(aEvent, deferred.resolve); michael@0: return deferred.promise; michael@0: } michael@0: } michael@0: michael@0: function testHost(aTab, aDebuggee, aPanel, aHostType, aLayoutType) { michael@0: let gDebugger = aPanel.panelWin; michael@0: let gView = gDebugger.DebuggerView; michael@0: michael@0: is(gView._hostType, aHostType, michael@0: "The default host type should've been set on the panel window (1)."); michael@0: is(gDebugger.gHostType, aHostType, michael@0: "The default host type should've been set on the panel window (2)."); michael@0: michael@0: is(gView._body.getAttribute("layout"), aLayoutType, michael@0: "The default host type is present as an attribute on the panel's body."); michael@0: michael@0: if (aLayoutType == "horizontal") { michael@0: is(gView._sourcesPane.parentNode.id, "debugger-widgets", michael@0: "The sources pane's parent is correct for the horizontal layout."); michael@0: is(gView._instrumentsPane.parentNode.id, "debugger-widgets", michael@0: "The instruments pane's parent is correct for the horizontal layout."); michael@0: } else { michael@0: is(gView._sourcesPane.parentNode.id, "vertical-layout-panes-container", michael@0: "The sources pane's parent is correct for the vertical layout."); michael@0: is(gView._instrumentsPane.parentNode.id, "vertical-layout-panes-container", michael@0: "The instruments pane's parent is correct for the vertical layout."); michael@0: } michael@0: michael@0: let widgets = gDebugger.document.getElementById("debugger-widgets").childNodes; michael@0: let panes = gDebugger.document.getElementById("vertical-layout-panes-container").childNodes; michael@0: michael@0: if (aLayoutType == "horizontal") { michael@0: is(widgets.length, 7, // 2 panes, 1 editor, 3 splitters and a phantom box. michael@0: "Found the correct number of debugger widgets."); michael@0: is(panes.length, 1, // 1 lonely splitter in the phantom box. michael@0: "Found the correct number of debugger panes."); michael@0: } else { michael@0: is(widgets.length, 5, // 1 editor, 3 splitters and a phantom box. michael@0: "Found the correct number of debugger widgets."); michael@0: is(panes.length, 3, // 2 panes and 1 splitter in the phantom box. michael@0: "Found the correct number of debugger panes."); michael@0: } michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: Services.prefs.setCharPref("devtools.toolbox.host", gDefaultHostType); michael@0: gDefaultHostType = null; michael@0: });