browser/devtools/webconsole/test/browser_console_click_focus.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_console_click_focus.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,60 @@
     1.4 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +// Tests that the input field is focused when the console is opened.
    1.10 +
    1.11 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html";
    1.12 +
    1.13 +function test() {
    1.14 +  addTab(TEST_URI);
    1.15 +  browser.addEventListener("DOMContentLoaded", testInputFocus, false);
    1.16 +}
    1.17 +
    1.18 +function testInputFocus() {
    1.19 +  browser.removeEventListener("DOMContentLoaded", testInputFocus, false);
    1.20 +
    1.21 +  openConsole().then((hud) => {
    1.22 +    waitForMessages({
    1.23 +      webconsole: hud,
    1.24 +      messages: [{
    1.25 +        text: "Dolske Digs Bacon",
    1.26 +        category: CATEGORY_WEBDEV,
    1.27 +        severity: SEVERITY_LOG,
    1.28 +      }],
    1.29 +    }).then(([result]) => {
    1.30 +      let msg = [...result.matched][0];
    1.31 +      let outputItem = msg.querySelector(".message-body");
    1.32 +      ok(outputItem, "found a logged message");
    1.33 +      let inputNode = hud.jsterm.inputNode;
    1.34 +      ok(inputNode.getAttribute("focused"), "input node is focused, first");
    1.35 +
    1.36 +      let lostFocus = () => {
    1.37 +        inputNode.removeEventListener("blur", lostFocus);
    1.38 +        info("input node lost focus");
    1.39 +      }
    1.40 +
    1.41 +      inputNode.addEventListener("blur", lostFocus);
    1.42 +
    1.43 +      browser.ownerDocument.getElementById("urlbar").click();
    1.44 +
    1.45 +      ok(!inputNode.getAttribute("focused"), "input node is not focused");
    1.46 +
    1.47 +      EventUtils.sendMouseEvent({type: "click"}, hud.outputNode);
    1.48 +
    1.49 +      ok(inputNode.getAttribute("focused"), "input node is focused, second time")
    1.50 +
    1.51 +      // test click-drags are not focusing the input element.
    1.52 +      EventUtils.sendMouseEvent({type: "mousedown", clientX: 3, clientY: 4},
    1.53 +        outputItem);
    1.54 +      EventUtils.sendMouseEvent({type: "click", clientX: 15, clientY: 5},
    1.55 +        outputItem);
    1.56 +
    1.57 +      executeSoon(() => {
    1.58 +        todo(!inputNode.getAttribute("focused"), "input node is not focused after drag");
    1.59 +        finishTest();
    1.60 +      });
    1.61 +    });
    1.62 +  });
    1.63 +}

mercurial