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.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * This if the debugger's layout is correctly modified when the toolbox's
     6  * host changes.
     7  */
     9 let gDefaultHostType = Services.prefs.getCharPref("devtools.toolbox.host");
    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 }
    22 function testHosts(aHostTypes, aLayoutTypes) {
    23   let [firstHost, secondHost, thirdHost] = aHostTypes;
    24   let [firstLayout, secondLayout, thirdLayout] = aLayoutTypes;
    26   Services.prefs.setCharPref("devtools.toolbox.host", firstHost);
    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 }
    37 function switchAndTestHost(aTab, aDebuggee, aPanel, aHostType, aLayoutType) {
    38   let gToolbox = aPanel._toolbox;
    39   let gDebugger = aPanel.panelWin;
    41   return Task.spawn(function() {
    42     let layoutChanged = once(gDebugger, gDebugger.EVENTS.LAYOUT_CHANGED);
    43     let hostChanged = gToolbox.switchHost(aHostType);
    45     yield hostChanged;
    46     ok(true, "The toolbox's host has changed.");
    48     yield layoutChanged;
    49     ok(true, "The debugger's layout has changed.");
    51     yield testHost(aTab, aDebuggee, aPanel, aHostType, aLayoutType);
    52   });
    54   function once(aTarget, aEvent) {
    55     let deferred = promise.defer();
    56     aTarget.once(aEvent, deferred.resolve);
    57     return deferred.promise;
    58   }
    59 }
    61 function testHost(aTab, aDebuggee, aPanel, aHostType, aLayoutType) {
    62   let gDebugger = aPanel.panelWin;
    63   let gView = gDebugger.DebuggerView;
    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).");
    70   is(gView._body.getAttribute("layout"), aLayoutType,
    71     "The default host type is present as an attribute on the panel's body.");
    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   }
    85   let widgets = gDebugger.document.getElementById("debugger-widgets").childNodes;
    86   let panes = gDebugger.document.getElementById("vertical-layout-panes-container").childNodes;
    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 }
   101 registerCleanupFunction(function() {
   102   Services.prefs.setCharPref("devtools.toolbox.host", gDefaultHostType);
   103   gDefaultHostType = null;
   104 });

mercurial