browser_webconsole_split_persist.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. ok(!isCommandButtonChecked(), "Split console button is unchecked by " +
  18. "default.");
  19. yield toggleSplitConsoleWithEscape();
  20. ok(toolbox.splitConsole, "Split console is now visible.");
  21. ok(isCommandButtonChecked(), "Split console button is now checked.");
  22. ok(getVisiblePrefValue(), "Visibility pref is true");
  23. is(getHeightPrefValue(), toolbox.webconsolePanel.height,
  24. "Panel height matches the pref");
  25. toolbox.webconsolePanel.height = 200;
  26. yield toolbox.destroy();
  27. info("Opening a tab while there is a true user setting on split console " +
  28. "pref");
  29. ({tab} = yield loadTab(TEST_URI));
  30. target = TargetFactory.forTab(tab);
  31. toolbox = yield gDevTools.showToolbox(target, "inspector");
  32. ok(toolbox.splitConsole, "Split console is visible by default.");
  33. ok(isCommandButtonChecked(), "Split console button is checked by default.");
  34. is(getHeightPrefValue(), 200, "Height is set based on panel height after " +
  35. "closing");
  36. // Use the binding element since jsterm.inputNode is a XUL textarea element.
  37. let activeElement = getActiveElement(toolbox.doc);
  38. activeElement = activeElement.ownerDocument.getBindingParent(activeElement);
  39. let inputNode = toolbox.getPanel("webconsole").hud.jsterm.inputNode;
  40. is(activeElement, inputNode, "Split console input is focused by default");
  41. toolbox.webconsolePanel.height = 1;
  42. ok(toolbox.webconsolePanel.clientHeight > 1,
  43. "The actual height of the console is bound with a min height");
  44. toolbox.webconsolePanel.height = 10000;
  45. ok(toolbox.webconsolePanel.clientHeight < 10000,
  46. "The actual height of the console is bound with a max height");
  47. yield toggleSplitConsoleWithEscape();
  48. ok(!toolbox.splitConsole, "Split console is now hidden.");
  49. ok(!isCommandButtonChecked(), "Split console button is now unchecked.");
  50. ok(!getVisiblePrefValue(), "Visibility pref is false");
  51. yield toolbox.destroy();
  52. is(getHeightPrefValue(), 10000,
  53. "Height is set based on panel height after closing");
  54. info("Opening a tab while there is a false user setting on split " +
  55. "console pref");
  56. ({tab} = yield loadTab(TEST_URI));
  57. target = TargetFactory.forTab(tab);
  58. toolbox = yield gDevTools.showToolbox(target, "inspector");
  59. ok(!toolbox.splitConsole, "Split console is hidden by default.");
  60. ok(!getVisiblePrefValue(), "Visibility pref is false");
  61. yield toolbox.destroy();
  62. }
  63. function getActiveElement(doc) {
  64. let activeElement = doc.activeElement;
  65. while (activeElement && activeElement.contentDocument) {
  66. activeElement = activeElement.contentDocument.activeElement;
  67. }
  68. return activeElement;
  69. }
  70. function getVisiblePrefValue() {
  71. return Services.prefs.getBoolPref("devtools.toolbox.splitconsoleEnabled");
  72. }
  73. function getHeightPrefValue() {
  74. return Services.prefs.getIntPref("devtools.toolbox.splitconsoleHeight");
  75. }
  76. function isCommandButtonChecked() {
  77. return toolbox.doc.querySelector("#command-button-splitconsole")
  78. .hasAttribute("checked");
  79. }
  80. function toggleSplitConsoleWithEscape() {
  81. let onceSplitConsole = toolbox.once("split-console");
  82. let contentWindow = toolbox.win;
  83. contentWindow.focus();
  84. EventUtils.sendKey("ESCAPE", contentWindow);
  85. return onceSplitConsole;
  86. }
  87. function finish() {
  88. toolbox = TEST_URI = null;
  89. Services.prefs.clearUserPref("devtools.toolbox.splitconsoleEnabled");
  90. Services.prefs.clearUserPref("devtools.toolbox.splitconsoleHeight");
  91. finishTest();
  92. }
  93. }