browser_dbg_on-pause-raise.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. /**
  5. * Tests that the toolbox is raised when the debugger gets paused.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
  8. add_task(function *() {
  9. let options = {
  10. source: TAB_URL,
  11. line: 1
  12. };
  13. let [tab,, panel] = yield initDebugger(TAB_URL, options);
  14. let panelWin = panel.panelWin;
  15. let toolbox = panel._toolbox;
  16. let toolboxTab = toolbox.doc.getElementById("toolbox-tab-jsdebugger");
  17. let newTab = yield addTab(TAB_URL);
  18. isnot(newTab, tab,
  19. "The newly added tab is different from the debugger's tab.");
  20. is(gBrowser.selectedTab, newTab,
  21. "Debugger's tab is not the selected tab.");
  22. info("Run tests against bottom host.");
  23. yield testPause();
  24. yield testResume();
  25. // testResume selected the console, select back the debugger.
  26. yield toolbox.selectTool("jsdebugger");
  27. info("Switching to a toolbox window host.");
  28. yield toolbox.switchHost(Toolbox.HostType.WINDOW);
  29. info("Run tests against window host.");
  30. yield testPause();
  31. yield testResume();
  32. info("Cleanup after the test.");
  33. yield toolbox.switchHost(Toolbox.HostType.BOTTOM);
  34. yield closeDebuggerAndFinish(panel);
  35. function* testPause() {
  36. is(panelWin.gThreadClient.paused, false,
  37. "Should be running after starting the test.");
  38. let onFocus, onTabSelect;
  39. if (toolbox.hostType == Toolbox.HostType.WINDOW) {
  40. onFocus = new Promise(done => {
  41. toolbox.win.parent.addEventListener("focus", function onFocus() {
  42. toolbox.win.parent.removeEventListener("focus", onFocus, true);
  43. done();
  44. }, true);
  45. });
  46. } else {
  47. onTabSelect = new Promise(done => {
  48. tab.parentNode.addEventListener("TabSelect", function listener({type}) {
  49. tab.parentNode.removeEventListener(type, listener);
  50. done();
  51. });
  52. });
  53. }
  54. let onPaused = waitForPause(panelWin.gThreadClient);
  55. // Evaluate a script to fully pause the debugger
  56. evalInTab(tab, "debugger;");
  57. yield onPaused;
  58. yield onFocus;
  59. yield onTabSelect;
  60. if (toolbox.hostType != Toolbox.HostType.WINDOW) {
  61. is(gBrowser.selectedTab, tab,
  62. "Debugger's tab got selected.");
  63. }
  64. yield toolbox.selectTool("webconsole");
  65. ok(toolboxTab.hasAttribute("highlighted") &&
  66. toolboxTab.getAttribute("highlighted") == "true",
  67. "The highlighted class is present");
  68. ok(!toolboxTab.hasAttribute("selected") ||
  69. toolboxTab.getAttribute("selected") != "true",
  70. "The tab is not selected");
  71. yield toolbox.selectTool("jsdebugger");
  72. ok(toolboxTab.hasAttribute("highlighted") &&
  73. toolboxTab.getAttribute("highlighted") == "true",
  74. "The highlighted class is present");
  75. ok(toolboxTab.hasAttribute("selected") &&
  76. toolboxTab.getAttribute("selected") == "true",
  77. "...and the tab is selected, so the glow will not be present.");
  78. }
  79. function* testResume() {
  80. let onPaused = waitForEvent(panelWin.gThreadClient, "resumed");
  81. EventUtils.sendMouseEvent({ type: "mousedown" },
  82. panelWin.document.getElementById("resume"),
  83. panelWin);
  84. yield onPaused;
  85. yield toolbox.selectTool("webconsole");
  86. ok(!toolboxTab.hasAttribute("highlighted") ||
  87. toolboxTab.getAttribute("highlighted") != "true",
  88. "The highlighted class is not present now after the resume");
  89. ok(!toolboxTab.hasAttribute("selected") ||
  90. toolboxTab.getAttribute("selected") != "true",
  91. "The tab is not selected");
  92. }
  93. });
  94. registerCleanupFunction(function () {
  95. // Revert to the default toolbox host, so that the following tests proceed
  96. // normally and not inside a non-default host.
  97. Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM);
  98. });