browser/devtools/webconsole/test/browser_webconsole_split_escape_key.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_split_escape_key.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,171 @@
     1.4 +/*
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.7 + */
     1.8 +
     1.9 +function test() {
    1.10 +  info("Test various cases where the escape key should hide the split console.");
    1.11 +
    1.12 +  let toolbox;
    1.13 +  let hud;
    1.14 +  let jsterm;
    1.15 +  let hudMessages;
    1.16 +  let variablesView;
    1.17 +
    1.18 +  Task.spawn(runner).then(finish);
    1.19 +
    1.20 +  function* runner() {
    1.21 +    let {tab} = yield loadTab("data:text/html;charset=utf-8,<p>Web Console test for splitting");
    1.22 +    let target = TargetFactory.forTab(tab);
    1.23 +    toolbox = yield gDevTools.showToolbox(target, "inspector");
    1.24 +
    1.25 +    yield testCreateSplitConsoleAfterEscape();
    1.26 +
    1.27 +    yield showAutoCompletePopoup();
    1.28 +
    1.29 +    yield testHideAutoCompletePopupAfterEscape();
    1.30 +
    1.31 +    yield executeJS();
    1.32 +    yield clickMessageAndShowVariablesView();
    1.33 +    jsterm.inputNode.focus();
    1.34 +
    1.35 +    yield testHideVariablesViewAfterEscape();
    1.36 +
    1.37 +    yield clickMessageAndShowVariablesView();
    1.38 +    yield startPropertyEditor();
    1.39 +
    1.40 +    yield testCancelPropertyEditorAfterEscape();
    1.41 +    yield testHideVariablesViewAfterEscape();
    1.42 +    yield testHideSplitConsoleAfterEscape();
    1.43 +  }
    1.44 +
    1.45 +  function testCreateSplitConsoleAfterEscape() {
    1.46 +    let result = toolbox.once("webconsole-ready", () => {
    1.47 +      hud = toolbox.getPanel("webconsole").hud;
    1.48 +      jsterm = hud.jsterm;
    1.49 +      ok(toolbox.splitConsole, "Split console is created.");
    1.50 +    });
    1.51 +
    1.52 +    let contentWindow = toolbox.frame.contentWindow;
    1.53 +    contentWindow.focus();
    1.54 +    EventUtils.sendKey("ESCAPE", contentWindow);
    1.55 +
    1.56 +    return result;
    1.57 +  }
    1.58 +
    1.59 +  function testShowSplitConsoleAfterEscape() {
    1.60 +    let result = toolbox.once("split-console", () => {
    1.61 +      ok(toolbox.splitConsole, "Split console is shown.");
    1.62 +    });
    1.63 +    EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow);
    1.64 +
    1.65 +    return result;
    1.66 +  }
    1.67 +
    1.68 +  function testHideSplitConsoleAfterEscape() {
    1.69 +    let result = toolbox.once("split-console", () => {
    1.70 +      ok(!toolbox.splitConsole, "Split console is hidden.");
    1.71 +    });
    1.72 +    EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow);
    1.73 +
    1.74 +    return result;
    1.75 +  }
    1.76 +
    1.77 +  function testHideVariablesViewAfterEscape() {
    1.78 +    let result = jsterm.once("sidebar-closed", () => {
    1.79 +      ok(!hud.ui.jsterm.sidebar,
    1.80 +        "Variables view is hidden.");
    1.81 +      ok(toolbox.splitConsole,
    1.82 +        "Split console is open after hiding the variables view.");
    1.83 +    });
    1.84 +    EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow);
    1.85 +
    1.86 +    return result;
    1.87 +  }
    1.88 +
    1.89 +  function testHideAutoCompletePopupAfterEscape() {
    1.90 +    let deferred = promise.defer();
    1.91 +    let popup = jsterm.autocompletePopup;
    1.92 +
    1.93 +    popup._panel.addEventListener("popuphidden", function popupHidden() {
    1.94 +      popup._panel.removeEventListener("popuphidden", popupHidden, false);
    1.95 +      ok(!popup.isOpen,
    1.96 +        "Auto complete popup is hidden.");
    1.97 +      ok(toolbox.splitConsole,
    1.98 +        "Split console is open after hiding the autocomplete popup.");
    1.99 +
   1.100 +      deferred.resolve();
   1.101 +    }, false);
   1.102 +
   1.103 +    EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow);
   1.104 +
   1.105 +    return deferred.promise;
   1.106 +  }
   1.107 +
   1.108 +  function testCancelPropertyEditorAfterEscape() {
   1.109 +    EventUtils.sendKey("ESCAPE", variablesView.window);
   1.110 +    ok(hud.ui.jsterm.sidebar,
   1.111 +      "Variables view is open after canceling property editor.");
   1.112 +    ok(toolbox.splitConsole,
   1.113 +      "Split console is open after editing.");
   1.114 +  }
   1.115 +
   1.116 +  function executeJS() {
   1.117 +    jsterm.execute("var foo = { bar: \"baz\" }; foo;");
   1.118 +    hudMessages = yield waitForMessages({
   1.119 +      webconsole: hud,
   1.120 +      messages: [{
   1.121 +        text: "Object { bar: \"baz\" }",
   1.122 +        category: CATEGORY_OUTPUT,
   1.123 +        objects: true
   1.124 +      }],
   1.125 +    });
   1.126 +  }
   1.127 +
   1.128 +  function clickMessageAndShowVariablesView() {
   1.129 +    let result = jsterm.once("variablesview-fetched", (event, vview) => {
   1.130 +      variablesView = vview;
   1.131 +    });
   1.132 +
   1.133 +    let clickable = hudMessages[0].clickableElements[0];
   1.134 +    EventUtils.synthesizeMouse(clickable, 2, 2, {}, hud.iframeWindow);
   1.135 +
   1.136 +    return result;
   1.137 +  }
   1.138 +
   1.139 +  function startPropertyEditor() {
   1.140 +    let results = yield findVariableViewProperties(variablesView, [
   1.141 +      {name: "bar", value: "baz"}
   1.142 +    ], {webconsole: hud});
   1.143 +    results[0].matchedProp.focus();
   1.144 +    EventUtils.synthesizeKey("VK_RETURN", variablesView.window);
   1.145 +  }
   1.146 +
   1.147 +  function showAutoCompletePopoup() {
   1.148 +    let deferred = promise.defer();
   1.149 +    let popupPanel = jsterm.autocompletePopup._panel;
   1.150 +
   1.151 +    popupPanel.addEventListener("popupshown", function popupShown() {
   1.152 +      popupPanel.removeEventListener("popupshown", popupShown, false);
   1.153 +      deferred.resolve();
   1.154 +    }, false);
   1.155 +
   1.156 +    jsterm.inputNode.focus();
   1.157 +    jsterm.setInputValue("document.location.");
   1.158 +    EventUtils.sendKey("TAB", hud.iframeWindow);
   1.159 +
   1.160 +    return deferred.promise;
   1.161 +  }
   1.162 +
   1.163 +  function finish() {
   1.164 +    toolbox.destroy().then(() => {
   1.165 +      toolbox = null;
   1.166 +      hud = null;
   1.167 +      jsterm = null;
   1.168 +      hudMessages = null;
   1.169 +      variablesView = null;
   1.170 +
   1.171 +      finishTest();
   1.172 +    });
   1.173 +  }
   1.174 +}

mercurial