1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_host-layout.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,104 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * This if the debugger's layout is correctly modified when the toolbox's 1.9 + * host changes. 1.10 + */ 1.11 + 1.12 +let gDefaultHostType = Services.prefs.getCharPref("devtools.toolbox.host"); 1.13 + 1.14 +function test() { 1.15 + Task.spawn(function() { 1.16 + yield testHosts(["bottom", "side", "window"], ["horizontal", "vertical", "horizontal"]); 1.17 + yield testHosts(["side", "bottom", "side"], ["vertical", "horizontal", "vertical"]); 1.18 + yield testHosts(["bottom", "side", "bottom"], ["horizontal", "vertical", "horizontal"]); 1.19 + yield testHosts(["side", "window", "side"], ["vertical", "horizontal", "vertical"]); 1.20 + yield testHosts(["window", "side", "window"], ["horizontal", "vertical", "horizontal"]); 1.21 + finish(); 1.22 + }); 1.23 +} 1.24 + 1.25 +function testHosts(aHostTypes, aLayoutTypes) { 1.26 + let [firstHost, secondHost, thirdHost] = aHostTypes; 1.27 + let [firstLayout, secondLayout, thirdLayout] = aLayoutTypes; 1.28 + 1.29 + Services.prefs.setCharPref("devtools.toolbox.host", firstHost); 1.30 + 1.31 + return Task.spawn(function() { 1.32 + let [tab, debuggee, panel] = yield initDebugger("about:blank"); 1.33 + yield testHost(tab, debuggee, panel, firstHost, firstLayout); 1.34 + yield switchAndTestHost(tab, debuggee, panel, secondHost, secondLayout); 1.35 + yield switchAndTestHost(tab, debuggee, panel, thirdHost, thirdLayout); 1.36 + yield teardown(panel); 1.37 + }); 1.38 +} 1.39 + 1.40 +function switchAndTestHost(aTab, aDebuggee, aPanel, aHostType, aLayoutType) { 1.41 + let gToolbox = aPanel._toolbox; 1.42 + let gDebugger = aPanel.panelWin; 1.43 + 1.44 + return Task.spawn(function() { 1.45 + let layoutChanged = once(gDebugger, gDebugger.EVENTS.LAYOUT_CHANGED); 1.46 + let hostChanged = gToolbox.switchHost(aHostType); 1.47 + 1.48 + yield hostChanged; 1.49 + ok(true, "The toolbox's host has changed."); 1.50 + 1.51 + yield layoutChanged; 1.52 + ok(true, "The debugger's layout has changed."); 1.53 + 1.54 + yield testHost(aTab, aDebuggee, aPanel, aHostType, aLayoutType); 1.55 + }); 1.56 + 1.57 + function once(aTarget, aEvent) { 1.58 + let deferred = promise.defer(); 1.59 + aTarget.once(aEvent, deferred.resolve); 1.60 + return deferred.promise; 1.61 + } 1.62 +} 1.63 + 1.64 +function testHost(aTab, aDebuggee, aPanel, aHostType, aLayoutType) { 1.65 + let gDebugger = aPanel.panelWin; 1.66 + let gView = gDebugger.DebuggerView; 1.67 + 1.68 + is(gView._hostType, aHostType, 1.69 + "The default host type should've been set on the panel window (1)."); 1.70 + is(gDebugger.gHostType, aHostType, 1.71 + "The default host type should've been set on the panel window (2)."); 1.72 + 1.73 + is(gView._body.getAttribute("layout"), aLayoutType, 1.74 + "The default host type is present as an attribute on the panel's body."); 1.75 + 1.76 + if (aLayoutType == "horizontal") { 1.77 + is(gView._sourcesPane.parentNode.id, "debugger-widgets", 1.78 + "The sources pane's parent is correct for the horizontal layout."); 1.79 + is(gView._instrumentsPane.parentNode.id, "debugger-widgets", 1.80 + "The instruments pane's parent is correct for the horizontal layout."); 1.81 + } else { 1.82 + is(gView._sourcesPane.parentNode.id, "vertical-layout-panes-container", 1.83 + "The sources pane's parent is correct for the vertical layout."); 1.84 + is(gView._instrumentsPane.parentNode.id, "vertical-layout-panes-container", 1.85 + "The instruments pane's parent is correct for the vertical layout."); 1.86 + } 1.87 + 1.88 + let widgets = gDebugger.document.getElementById("debugger-widgets").childNodes; 1.89 + let panes = gDebugger.document.getElementById("vertical-layout-panes-container").childNodes; 1.90 + 1.91 + if (aLayoutType == "horizontal") { 1.92 + is(widgets.length, 7, // 2 panes, 1 editor, 3 splitters and a phantom box. 1.93 + "Found the correct number of debugger widgets."); 1.94 + is(panes.length, 1, // 1 lonely splitter in the phantom box. 1.95 + "Found the correct number of debugger panes."); 1.96 + } else { 1.97 + is(widgets.length, 5, // 1 editor, 3 splitters and a phantom box. 1.98 + "Found the correct number of debugger widgets."); 1.99 + is(panes.length, 3, // 2 panes and 1 splitter in the phantom box. 1.100 + "Found the correct number of debugger panes."); 1.101 + } 1.102 +} 1.103 + 1.104 +registerCleanupFunction(function() { 1.105 + Services.prefs.setCharPref("devtools.toolbox.host", gDefaultHostType); 1.106 + gDefaultHostType = null; 1.107 +});