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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial