browser_console_click_focus.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. // Tests that the input field is focused when the console is opened.
  5. "use strict";
  6. const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
  7. "test/test-console.html";
  8. add_task(function* () {
  9. yield loadTab(TEST_URI);
  10. let hud = yield openConsole();
  11. let [result] = yield waitForMessages({
  12. webconsole: hud,
  13. messages: [{
  14. text: "Dolske Digs Bacon",
  15. category: CATEGORY_WEBDEV,
  16. severity: SEVERITY_LOG,
  17. }],
  18. });
  19. let msg = [...result.matched][0];
  20. let outputItem = msg.querySelector(".message-body");
  21. ok(outputItem, "found a logged message");
  22. let inputNode = hud.jsterm.inputNode;
  23. ok(inputNode.getAttribute("focused"), "input node is focused, first");
  24. yield waitForBlurredInput(inputNode);
  25. EventUtils.sendMouseEvent({type: "click"}, hud.outputNode);
  26. ok(inputNode.getAttribute("focused"), "input node is focused, second time");
  27. yield waitForBlurredInput(inputNode);
  28. info("Setting a text selection and making sure a click does not re-focus");
  29. let selection = hud.iframeWindow.getSelection();
  30. selection.selectAllChildren(outputItem);
  31. EventUtils.sendMouseEvent({type: "click"}, hud.outputNode);
  32. ok(!inputNode.getAttribute("focused"),
  33. "input node is not focused after drag");
  34. });
  35. function waitForBlurredInput(inputNode) {
  36. return new Promise(resolve => {
  37. let lostFocus = () => {
  38. inputNode.removeEventListener("blur", lostFocus);
  39. ok(!inputNode.getAttribute("focused"), "input node is not focused");
  40. resolve();
  41. };
  42. inputNode.addEventListener("blur", lostFocus);
  43. document.getElementById("urlbar").click();
  44. });
  45. }