Bug 1408949 - Convert browser_webconsole_split.js for the new console frontend;r=Honza draft
authorBrian Grinstead <bgrinstead@mozilla.com>
Fri, 01 Dec 2017 10:33:27 -0800
changeset 706408 9bdd6d2470aa72924d43c2106da5e0947caf8150
parent 706205 781485c695e1f07b8782427d556f6570e4a8072f
child 706409 70788abbfc86a5838626fb5f1f17d03537c2830c
push id91787
push userbgrinstead@mozilla.com
push dateFri, 01 Dec 2017 20:58:01 +0000
reviewersHonza
bugs1408949
milestone59.0a1
Bug 1408949 - Convert browser_webconsole_split.js for the new console frontend;r=Honza MozReview-Commit-ID: C5A44X3FO45
devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_split.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -392,17 +392,16 @@ skip-if = true #	Bug 1403454
 skip-if = true #	Bug 1404359
 [browser_webconsole_show_subresource_security_errors.js]
 [browser_webconsole_shows_reqs_in_netmonitor.js]
 [browser_webconsole_sourcemap_css.js]
 [browser_webconsole_sourcemap_error.js]
 [browser_webconsole_sourcemap_invalid.js]
 [browser_webconsole_sourcemap_nosource.js]
 [browser_webconsole_split.js]
-skip-if = true # Bug 1408949
 [browser_webconsole_split_escape_key.js]
 skip-if = true #	Bug 1405647
 [browser_webconsole_split_focus.js]
 skip-if = true #	Bug 1405648
 [browser_webconsole_split_persist.js]
 skip-if = true #	Bug 1405649
 [browser_webconsole_stacktrace_location_debugger_link.js]
 [browser_webconsole_stacktrace_location_scratchpad_link.js]
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_split.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_split.js
@@ -1,255 +1,209 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const TEST_URI = "data:text/html;charset=utf-8,Web Console test for splitting";
+const {Toolbox} = require("devtools/client/framework/toolbox");
 
-function test() {
-  waitForExplicitFinish();
-  // Test is slow on Linux EC2 instances - Bug 962931
-  requestLongerTimeout(2);
+// Test is slow on Linux EC2 instances - Bug 962931
+requestLongerTimeout(2);
 
-  let {Toolbox} = require("devtools/client/framework/toolbox");
+add_task(async function () {
   let toolbox;
 
-  loadTab(TEST_URI).then(testConsoleLoadOnDifferentPanel);
+  await addTab(TEST_URI);
+  await testConsoleLoadOnDifferentPanel();
+  await testKeyboardShortcuts();
+  await checkAllTools();
 
-  function testConsoleLoadOnDifferentPanel() {
+  info("Testing host types");
+  checkHostType(Toolbox.HostType.BOTTOM);
+  checkToolboxUI();
+  await toolbox.switchHost(Toolbox.HostType.SIDE);
+  checkHostType(Toolbox.HostType.SIDE);
+  checkToolboxUI();
+  await toolbox.switchHost(Toolbox.HostType.WINDOW);
+  checkHostType(Toolbox.HostType.WINDOW);
+  checkToolboxUI();
+  await toolbox.switchHost(Toolbox.HostType.BOTTOM);
+
+  async function testConsoleLoadOnDifferentPanel() {
     info("About to check console loads even when non-webconsole panel is open");
 
-    openPanel("inspector").then(() => {
-      toolbox.on("webconsole-ready", () => {
-        ok(true, "Webconsole has been triggered as loaded while another tool " +
-                 "is active");
-        testKeyboardShortcuts();
-      });
-
-      // Opens split console.
-      toolbox.toggleSplitConsole();
-    });
+    await openPanel("inspector");
+    let webconsoleReady = toolbox.once("webconsole-ready");
+    toolbox.toggleSplitConsole();
+    await webconsoleReady;
+    ok(true, "Webconsole has been triggered as loaded while another tool is active");
   }
 
-  function testKeyboardShortcuts() {
+  async function testKeyboardShortcuts() {
     info("About to check that panel responds to ESCAPE keyboard shortcut");
 
-    toolbox.once("split-console", () => {
-      ok(true, "Split console has been triggered via ESCAPE keypress");
-      checkAllTools();
-    });
-
-    // Closes split console.
+    let splitConsoleReady = toolbox.once("split-console");
     EventUtils.sendKey("ESCAPE", toolbox.win);
+    await splitConsoleReady;
+    ok(true, "Split console has been triggered via ESCAPE keypress");
   }
 
-  function checkAllTools() {
+  async function checkAllTools() {
     info("About to check split console with each panel individually.");
+    await openAndCheckPanel("jsdebugger");
+    await openAndCheckPanel("inspector");
+    await openAndCheckPanel("styleeditor");
+    await openAndCheckPanel("performance");
+    await openAndCheckPanel("netmonitor");
 
-    Task.spawn(function* () {
-      yield openAndCheckPanel("jsdebugger");
-      yield openAndCheckPanel("inspector");
-      yield openAndCheckPanel("styleeditor");
-      yield openAndCheckPanel("performance");
-      yield openAndCheckPanel("netmonitor");
-
-      yield checkWebconsolePanelOpened();
-      testBottomHost();
-    });
+    await checkWebconsolePanelOpened();
   }
 
   function getCurrentUIState() {
-    let win = toolbox.win;
     let deck = toolbox.doc.querySelector("#toolbox-deck");
     let webconsolePanel = toolbox.webconsolePanel;
     let splitter = toolbox.doc.querySelector("#toolbox-console-splitter");
 
-    let containerHeight = parseFloat(win.getComputedStyle(deck.parentNode)
-      .getPropertyValue("height"));
-    let deckHeight = parseFloat(win.getComputedStyle(deck)
-      .getPropertyValue("height"));
-    let webconsoleHeight = parseFloat(win.getComputedStyle(webconsolePanel)
-      .getPropertyValue("height"));
+    let containerHeight = deck.parentNode.getBoundingClientRect().height;
+    let deckHeight = deck.getBoundingClientRect().height;
+    let webconsoleHeight = webconsolePanel.getBoundingClientRect().height;
     let splitterVisibility = !splitter.getAttribute("hidden");
     let openedConsolePanel = toolbox.currentToolId === "webconsole";
     let cmdButton = toolbox.doc.querySelector("#command-button-splitconsole");
 
     return {
       deckHeight: deckHeight,
       containerHeight: containerHeight,
       webconsoleHeight: webconsoleHeight,
       splitterVisibility: splitterVisibility,
       openedConsolePanel: openedConsolePanel,
       buttonSelected: cmdButton.classList.contains("checked")
     };
   }
 
-  const checkWebconsolePanelOpened = Task.async(function* () {
+  async function checkWebconsolePanelOpened() {
     info("About to check special cases when webconsole panel is open.");
 
     // Start with console split, so we can test for transition to main panel.
-    yield toolbox.toggleSplitConsole();
+    await toolbox.toggleSplitConsole();
 
     let currentUIState = getCurrentUIState();
 
     ok(currentUIState.splitterVisibility,
        "Splitter is visible when console is split");
     ok(currentUIState.deckHeight > 0,
        "Deck has a height > 0 when console is split");
     ok(currentUIState.webconsoleHeight > 0,
        "Web console has a height > 0 when console is split");
     ok(!currentUIState.openedConsolePanel,
        "The console panel is not the current tool");
     ok(currentUIState.buttonSelected, "The command button is selected");
 
-    yield openPanel("webconsole");
+    await openPanel("webconsole");
     currentUIState = getCurrentUIState();
 
     ok(!currentUIState.splitterVisibility,
        "Splitter is hidden when console is opened.");
     is(currentUIState.deckHeight, 0,
        "Deck has a height == 0 when console is opened.");
     is(currentUIState.webconsoleHeight, currentUIState.containerHeight,
        "Web console is full height.");
     ok(currentUIState.openedConsolePanel,
        "The console panel is the current tool");
     ok(currentUIState.buttonSelected,
        "The command button is still selected.");
 
     // Make sure splitting console does nothing while webconsole is opened
-    yield toolbox.toggleSplitConsole();
+    await toolbox.toggleSplitConsole();
 
     currentUIState = getCurrentUIState();
 
     ok(!currentUIState.splitterVisibility,
        "Splitter is hidden when console is opened.");
     is(currentUIState.deckHeight, 0,
        "Deck has a height == 0 when console is opened.");
     is(currentUIState.webconsoleHeight, currentUIState.containerHeight,
        "Web console is full height.");
     ok(currentUIState.openedConsolePanel,
        "The console panel is the current tool");
     ok(currentUIState.buttonSelected,
        "The command button is still selected.");
 
     // Make sure that split state is saved after opening another panel
-    yield openPanel("inspector");
+    await openPanel("inspector");
     currentUIState = getCurrentUIState();
     ok(currentUIState.splitterVisibility,
        "Splitter is visible when console is split");
     ok(currentUIState.deckHeight > 0,
        "Deck has a height > 0 when console is split");
     ok(currentUIState.webconsoleHeight > 0,
        "Web console has a height > 0 when console is split");
     ok(!currentUIState.openedConsolePanel,
        "The console panel is not the current tool");
     ok(currentUIState.buttonSelected,
        "The command button is still selected.");
 
-    yield toolbox.toggleSplitConsole();
-  });
+    await toolbox.toggleSplitConsole();
+  }
 
-  const checkToolboxUI = Task.async(function* () {
+  async function checkToolboxUI() {
     let currentUIState = getCurrentUIState();
 
     ok(!currentUIState.splitterVisibility, "Splitter is hidden by default");
     is(currentUIState.deckHeight, currentUIState.containerHeight,
        "Deck has a height > 0 by default");
     is(currentUIState.webconsoleHeight, 0,
        "Web console is collapsed by default");
     ok(!currentUIState.openedConsolePanel,
        "The console panel is not the current tool");
     ok(!currentUIState.buttonSelected, "The command button is not selected.");
 
-    yield toolbox.toggleSplitConsole();
+    await toolbox.toggleSplitConsole();
 
     currentUIState = getCurrentUIState();
 
     ok(currentUIState.splitterVisibility,
        "Splitter is visible when console is split");
     ok(currentUIState.deckHeight > 0,
        "Deck has a height > 0 when console is split");
     ok(currentUIState.webconsoleHeight > 0,
        "Web console has a height > 0 when console is split");
     is(Math.round(currentUIState.deckHeight + currentUIState.webconsoleHeight),
        currentUIState.containerHeight,
        "Everything adds up to container height");
     ok(!currentUIState.openedConsolePanel,
        "The console panel is not the current tool");
     ok(currentUIState.buttonSelected, "The command button is selected.");
 
-    yield toolbox.toggleSplitConsole();
+    await toolbox.toggleSplitConsole();
 
     currentUIState = getCurrentUIState();
 
     ok(!currentUIState.splitterVisibility, "Splitter is hidden after toggling");
     is(currentUIState.deckHeight, currentUIState.containerHeight,
        "Deck has a height > 0 after toggling");
     is(currentUIState.webconsoleHeight, 0,
        "Web console is collapsed after toggling");
     ok(!currentUIState.openedConsolePanel,
        "The console panel is not the current tool");
     ok(!currentUIState.buttonSelected, "The command button is not selected.");
-  });
-
-  function openPanel(toolId) {
-    let deferred = defer();
-    let target = TargetFactory.forTab(gBrowser.selectedTab);
-    gDevTools.showToolbox(target, toolId).then(function (box) {
-      toolbox = box;
-      deferred.resolve();
-    }).catch(console.error);
-    return deferred.promise;
-  }
-
-  function openAndCheckPanel(toolId) {
-    return openPanel(toolId).then(() => {
-      info("Checking toolbox for " + toolId);
-      return checkToolboxUI(toolbox.getCurrentPanel());
-    });
   }
 
-  function testBottomHost() {
-    checkHostType(Toolbox.HostType.BOTTOM);
-
-    checkToolboxUI();
-
-    toolbox.switchHost(Toolbox.HostType.SIDE).then(testSidebarHost);
+  async function openPanel(toolId) {
+    let target = TargetFactory.forTab(gBrowser.selectedTab);
+    toolbox = await gDevTools.showToolbox(target, toolId);
   }
 
-  function testSidebarHost() {
-    checkHostType(Toolbox.HostType.SIDE);
-
-    checkToolboxUI();
-
-    toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost);
-  }
-
-  function testWindowHost() {
-    checkHostType(Toolbox.HostType.WINDOW);
-
-    checkToolboxUI();
-
-    toolbox.switchHost(Toolbox.HostType.BOTTOM).then(testDestroy);
+  async function openAndCheckPanel(toolId) {
+    await openPanel(toolId);
+    await checkToolboxUI(toolbox.getCurrentPanel());
   }
 
   function checkHostType(hostType) {
     is(toolbox.hostType, hostType, "host type is " + hostType);
 
     let pref = Services.prefs.getCharPref("devtools.toolbox.host");
     is(pref, hostType, "host pref is " + hostType);
   }
-
-  function testDestroy() {
-    toolbox.destroy().then(function () {
-      let target = TargetFactory.forTab(gBrowser.selectedTab);
-      gDevTools.showToolbox(target).then(finish);
-    });
-  }
-
-  function finish() {
-    toolbox = null;
-    finishTest();
-  }
-}
+});