browser_dbg_variables-view-reexpand-03.js 4.4 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. * Make sure that the variables view correctly re-expands *scopes* after pauses.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_scope-variable-4.html";
  8. function test() {
  9. // Debug test slaves are a bit slow at this test.
  10. requestLongerTimeout(4);
  11. let options = {
  12. source: TAB_URL,
  13. line: 1
  14. };
  15. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  16. const gTab = aTab;
  17. const gPanel = aPanel;
  18. const gDebugger = gPanel.panelWin;
  19. const gSources = gDebugger.DebuggerView.Sources;
  20. const gVariables = gDebugger.DebuggerView.Variables;
  21. const queries = gDebugger.require("./content/queries");
  22. const getState = gDebugger.DebuggerController.getState;
  23. const actions = bindActionCreators(gPanel);
  24. // Always expand all items between pauses.
  25. gVariables.commitHierarchyIgnoredItems = Object.create(null);
  26. function addBreakpoint() {
  27. return actions.addBreakpoint({
  28. actor: gSources.selectedValue,
  29. line: 18
  30. });
  31. }
  32. function pauseDebuggee() {
  33. callInTab(gTab, "test");
  34. return waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES);
  35. }
  36. function resumeDebuggee() {
  37. // Spin the event loop before causing the debuggee to pause, to allow
  38. // this function to return first.
  39. executeSoon(() => {
  40. EventUtils.sendMouseEvent({ type: "mousedown" },
  41. gDebugger.document.querySelector("#resume"),
  42. gDebugger);
  43. });
  44. return waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES);
  45. }
  46. function testVariablesExpand() {
  47. let localScope = gVariables.getScopeAtIndex(0);
  48. let functionScope = gVariables.getScopeAtIndex(1);
  49. let globalScope = gVariables.getScopeAtIndex(2);
  50. is(localScope.target.querySelector(".arrow").hasAttribute("open"), true,
  51. "The localScope arrow should still be expanded.");
  52. is(functionScope.target.querySelector(".arrow").hasAttribute("open"), true,
  53. "The functionScope arrow should still be expanded.");
  54. is(globalScope.target.querySelector(".arrow").hasAttribute("open"), false,
  55. "The globalScope arrow should not be expanded.");
  56. is(localScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
  57. "The localScope enumerables should still be expanded.");
  58. is(functionScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
  59. "The functionScope enumerables should still be expanded.");
  60. is(globalScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), false,
  61. "The globalScope enumerables should not be expanded.");
  62. is(localScope.expanded, true,
  63. "The localScope expanded getter should return true.");
  64. is(functionScope.expanded, true,
  65. "The functionScope expanded getter should return true.");
  66. is(globalScope.expanded, false,
  67. "The globalScope expanded getter should return false.");
  68. }
  69. function prepareScopes() {
  70. let localScope = gVariables.getScopeAtIndex(0);
  71. let functionScope = gVariables.getScopeAtIndex(1);
  72. let globalScope = gVariables.getScopeAtIndex(2);
  73. is(localScope.expanded, true,
  74. "The localScope should be expanded.");
  75. is(functionScope.expanded, false,
  76. "The functionScope should not be expanded yet.");
  77. is(globalScope.expanded, false,
  78. "The globalScope should not be expanded yet.");
  79. localScope.collapse();
  80. functionScope.expand();
  81. // Don't for any events to be triggered, because the Function scope is
  82. // an environment to which scope arguments and variables are already attached.
  83. is(localScope.expanded, false,
  84. "The localScope should not be expanded anymore.");
  85. is(functionScope.expanded, true,
  86. "The functionScope should now be expanded.");
  87. is(globalScope.expanded, false,
  88. "The globalScope should still not be expanded.");
  89. }
  90. Task.spawn(function* () {
  91. yield addBreakpoint();
  92. yield ensureThreadClientState(gPanel, "resumed");
  93. yield pauseDebuggee();
  94. yield prepareScopes();
  95. yield resumeDebuggee();
  96. yield testVariablesExpand();
  97. resumeDebuggerThenCloseAndFinish(gPanel);
  98. });
  99. });
  100. }