browser_webconsole_split_focus.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. "use strict";
  5. function test() {
  6. info("Test that the split console state is persisted");
  7. let toolbox;
  8. let TEST_URI = "data:text/html;charset=utf-8,<p>Web Console test for " +
  9. "splitting</p>";
  10. Task.spawn(runner).then(finish);
  11. function* runner() {
  12. info("Opening a tab while there is no user setting on split console pref");
  13. let {tab} = yield loadTab(TEST_URI);
  14. let target = TargetFactory.forTab(tab);
  15. toolbox = yield gDevTools.showToolbox(target, "inspector");
  16. ok(!toolbox.splitConsole, "Split console is hidden by default");
  17. info("Focusing the search box before opening the split console");
  18. let inspector = toolbox.getPanel("inspector");
  19. inspector.searchBox.focus();
  20. let activeElement = getActiveElement(inspector.panelDoc);
  21. is(activeElement, inspector.searchBox, "Search box is focused");
  22. yield toolbox.openSplitConsole();
  23. ok(toolbox.splitConsole, "Split console is now visible");
  24. // Use the binding element since jsterm.inputNode is a XUL textarea element.
  25. activeElement = getActiveElement(toolbox.doc);
  26. activeElement = activeElement.ownerDocument.getBindingParent(activeElement);
  27. let inputNode = toolbox.getPanel("webconsole").hud.jsterm.inputNode;
  28. is(activeElement, inputNode, "Split console input is focused by default");
  29. yield toolbox.closeSplitConsole();
  30. info("Making sure that the search box is refocused after closing the " +
  31. "split console");
  32. activeElement = getActiveElement(inspector.panelDoc);
  33. is(activeElement, inspector.searchBox, "Search box is focused");
  34. yield toolbox.destroy();
  35. }
  36. function getActiveElement(doc) {
  37. let activeElement = doc.activeElement;
  38. while (activeElement && activeElement.contentDocument) {
  39. activeElement = activeElement.contentDocument.activeElement;
  40. }
  41. return activeElement;
  42. }
  43. function finish() {
  44. toolbox = TEST_URI = null;
  45. Services.prefs.clearUserPref("devtools.toolbox.splitconsoleEnabled");
  46. Services.prefs.clearUserPref("devtools.toolbox.splitconsoleHeight");
  47. finishTest();
  48. }
  49. }