browser/devtools/webconsole/test/browser_webconsole_split.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 /* vim:set ts=2 sw=2 sts=2 et: */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 function test()
     7 {
     8   // Test is slow on Linux EC2 instances - Bug 962931
     9   requestLongerTimeout(2);
    11   let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
    12   let {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
    13   let Toolbox = devtools.Toolbox;
    14   let toolbox;
    16   addTab("data:text/html;charset=utf-8,Web Console test for splitting");
    17   browser.addEventListener("load", function onLoad() {
    18     browser.removeEventListener("load", onLoad, true);
    19     testConsoleLoadOnDifferentPanel()
    20   }, true);
    22   function testConsoleLoadOnDifferentPanel()
    23   {
    24     info("About to check console loads even when non-webconsole panel is open");
    26     openPanel("inspector").then(() => {
    27       toolbox.on("webconsole-ready", () => {
    28         ok(true, "Webconsole has been triggered as loaded while another tool is active");
    29         testKeyboardShortcuts();
    30       });
    32       // Opens split console.
    33       toolbox.toggleSplitConsole();
    34     });
    35   }
    37   function testKeyboardShortcuts()
    38   {
    39     info("About to check that panel responds to ESCAPE keyboard shortcut");
    41     toolbox.once("split-console", () => {
    42       ok(true, "Split console has been triggered via ESCAPE keypress");
    43       checkAllTools();
    44     });
    46     // Closes split console.
    47     EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow);
    48   }
    50   function checkAllTools()
    51   {
    52     info("About to check split console with each panel individually.");
    54     Task.spawn(function() {
    55       yield openAndCheckPanel("jsdebugger");
    56       yield openAndCheckPanel("inspector");
    57       yield openAndCheckPanel("styleeditor");
    58       yield openAndCheckPanel("jsprofiler");
    59       yield openAndCheckPanel("netmonitor");
    61       yield checkWebconsolePanelOpened();
    62       testBottomHost();
    63     });
    64   }
    66   function getCurrentUIState()
    67   {
    68     let win = toolbox.doc.defaultView;
    69     let deck = toolbox.doc.querySelector("#toolbox-deck");
    70     let webconsolePanel = toolbox.doc.querySelector("#toolbox-panel-webconsole");
    71     let splitter = toolbox.doc.querySelector("#toolbox-console-splitter");
    73     let containerHeight = parseFloat(win.getComputedStyle(deck.parentNode).getPropertyValue("height"));
    74     let deckHeight = parseFloat(win.getComputedStyle(deck).getPropertyValue("height"));
    75     let webconsoleHeight = parseFloat(win.getComputedStyle(webconsolePanel).getPropertyValue("height"));
    76     let splitterVisibility = !splitter.getAttribute("hidden");
    77     let openedConsolePanel = toolbox.currentToolId === "webconsole";
    78     let cmdButton = toolbox.doc.querySelector("#command-button-splitconsole");
    80     return {
    81       deckHeight: deckHeight,
    82       containerHeight: containerHeight,
    83       webconsoleHeight: webconsoleHeight,
    84       splitterVisibility: splitterVisibility,
    85       openedConsolePanel: openedConsolePanel,
    86       buttonSelected: cmdButton.hasAttribute("checked")
    87     };
    88   }
    90   function checkWebconsolePanelOpened()
    91   {
    92     info("About to check special cases when webconsole panel is open.");
    94     let deferred = promise.defer();
    96     // Start with console split, so we can test for transition to main panel.
    97     toolbox.toggleSplitConsole();
    99     let currentUIState = getCurrentUIState();
   101     ok (currentUIState.splitterVisibility, "Splitter is visible when console is split");
   102     ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split");
   103     ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split");
   104     ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool");
   105     ok (currentUIState.buttonSelected, "The command button is selected");
   107     openPanel("webconsole").then(() => {
   109       let currentUIState = getCurrentUIState();
   111       ok (!currentUIState.splitterVisibility, "Splitter is hidden when console is opened.");
   112       is (currentUIState.deckHeight, 0, "Deck has a height == 0 when console is opened.");
   113       is (currentUIState.webconsoleHeight, currentUIState.containerHeight, "Web console is full height.");
   114       ok (currentUIState.openedConsolePanel, "The console panel is the current tool");
   115       ok (currentUIState.buttonSelected, "The command button is still selected.");
   117       // Make sure splitting console does nothing while webconsole is opened
   118       toolbox.toggleSplitConsole();
   120       let currentUIState = getCurrentUIState();
   122       ok (!currentUIState.splitterVisibility, "Splitter is hidden when console is opened.");
   123       is (currentUIState.deckHeight, 0, "Deck has a height == 0 when console is opened.");
   124       is (currentUIState.webconsoleHeight, currentUIState.containerHeight, "Web console is full height.");
   125       ok (currentUIState.openedConsolePanel, "The console panel is the current tool");
   126       ok (currentUIState.buttonSelected, "The command button is still selected.");
   128       // Make sure that split state is saved after opening another panel
   129       openPanel("inspector").then(() => {
   130         let currentUIState = getCurrentUIState();
   131         ok (currentUIState.splitterVisibility, "Splitter is visible when console is split");
   132         ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split");
   133         ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split");
   134         ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool");
   135         ok (currentUIState.buttonSelected, "The command button is still selected.");
   137         toolbox.toggleSplitConsole();
   138         deferred.resolve();
   140       });
   141     });
   142     return deferred.promise;
   143   }
   145   function openPanel(toolId, callback)
   146   {
   147     let deferred = promise.defer();
   148     let target = TargetFactory.forTab(gBrowser.selectedTab);
   149     gDevTools.showToolbox(target, toolId).then(function(box) {
   150       toolbox = box;
   151       deferred.resolve();
   152     }).then(null, console.error);
   153     return deferred.promise;
   154   }
   156   function openAndCheckPanel(toolId)
   157   {
   158     let deferred = promise.defer();
   159     openPanel(toolId).then(() => {
   160       info ("Checking toolbox for " + toolId);
   161       checkToolboxUI(toolbox.getCurrentPanel());
   162       deferred.resolve();
   163     });
   164     return deferred.promise;
   165   }
   167   function checkToolboxUI()
   168   {
   169     let currentUIState = getCurrentUIState();
   171     ok (!currentUIState.splitterVisibility, "Splitter is hidden by default");
   172     is (currentUIState.deckHeight, currentUIState.containerHeight, "Deck has a height > 0 by default");
   173     is (currentUIState.webconsoleHeight, 0, "Web console is collapsed by default");
   174     ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool");
   175     ok (!currentUIState.buttonSelected, "The command button is not selected.");
   177     toolbox.toggleSplitConsole();
   179     let currentUIState = getCurrentUIState();
   181     ok (currentUIState.splitterVisibility, "Splitter is visible when console is split");
   182     ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split");
   183     ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split");
   184     is (currentUIState.deckHeight + currentUIState.webconsoleHeight,
   185           currentUIState.containerHeight,
   186         "Everything adds up to container height");
   187     ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool");
   188     ok (currentUIState.buttonSelected, "The command button is selected.");
   190     toolbox.toggleSplitConsole();
   192     let currentUIState = getCurrentUIState();
   194     ok (!currentUIState.splitterVisibility, "Splitter is hidden after toggling");
   195     is (currentUIState.deckHeight, currentUIState.containerHeight, "Deck has a height > 0 after toggling");
   196     is (currentUIState.webconsoleHeight, 0, "Web console is collapsed after toggling");
   197     ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool");
   198     ok (!currentUIState.buttonSelected, "The command button is not selected.");
   199   }
   201   function testBottomHost()
   202   {
   203     checkHostType(Toolbox.HostType.BOTTOM);
   205     checkToolboxUI();
   207     toolbox.switchHost(Toolbox.HostType.SIDE).then(testSidebarHost);
   208   }
   210   function testSidebarHost()
   211   {
   212     checkHostType(Toolbox.HostType.SIDE);
   214     checkToolboxUI();
   216     toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost);
   217   }
   219   function testWindowHost()
   220   {
   221     checkHostType(Toolbox.HostType.WINDOW);
   223     checkToolboxUI();
   225     toolbox.switchHost(Toolbox.HostType.BOTTOM).then(testDestroy);
   226   }
   228   function checkHostType(hostType)
   229   {
   230     is(toolbox.hostType, hostType, "host type is " + hostType);
   232     let pref = Services.prefs.getCharPref("devtools.toolbox.host");
   233     is(pref, hostType, "host pref is " + hostType);
   234   }
   236   function testDestroy()
   237   {
   238     toolbox.destroy().then(function() {
   239       let target = TargetFactory.forTab(gBrowser.selectedTab);
   240       gDevTools.showToolbox(target).then(finish);
   241     });
   242   }
   244   function finish()
   245   {
   246     toolbox = null;
   247     finishTest();
   248   }
   249 }

mercurial