browser_dbg_variables-view-reexpand-01.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 nodes after pauses.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_with-frame.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 except 'window' variables.
  25. gVariables.commitHierarchyIgnoredItems = Object.create(null, { window: { value: true } });
  26. function addBreakpoint() {
  27. return actions.addBreakpoint({
  28. actor: gSources.selectedValue,
  29. line: 21
  30. });
  31. }
  32. function pauseDebuggee() {
  33. generateMouseClickInTab(gTab, "content.document.querySelector('button')");
  34. // The first 'with' scope should be expanded by default, but the
  35. // variables haven't been fetched yet. This is how 'with' scopes work.
  36. return promise.all([
  37. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES),
  38. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES)
  39. ]);
  40. }
  41. function stepInDebuggee() {
  42. // Spin the event loop before causing the debuggee to pause, to allow
  43. // this function to return first.
  44. executeSoon(() => {
  45. EventUtils.sendMouseEvent({ type: "mousedown" },
  46. gDebugger.document.querySelector("#step-in"),
  47. gDebugger);
  48. });
  49. return promise.all([
  50. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES, 1),
  51. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES, 3),
  52. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1),
  53. ]);
  54. }
  55. function testVariablesExpand() {
  56. let localScope = gVariables.getScopeAtIndex(0);
  57. let withScope = gVariables.getScopeAtIndex(1);
  58. let functionScope = gVariables.getScopeAtIndex(2);
  59. let globalLexicalScope = gVariables.getScopeAtIndex(3);
  60. let globalScope = gVariables.getScopeAtIndex(4);
  61. let thisVar = localScope.get("this");
  62. let windowVar = thisVar.get("window");
  63. is(localScope.target.querySelector(".arrow").hasAttribute("open"), true,
  64. "The localScope arrow should still be expanded.");
  65. is(withScope.target.querySelector(".arrow").hasAttribute("open"), true,
  66. "The withScope arrow should still be expanded.");
  67. is(functionScope.target.querySelector(".arrow").hasAttribute("open"), true,
  68. "The functionScope arrow should still be expanded.");
  69. is(globalLexicalScope.target.querySelector(".arrow").hasAttribute("open"), true,
  70. "The globalLexicalScope arrow should still be expanded.");
  71. is(globalScope.target.querySelector(".arrow").hasAttribute("open"), true,
  72. "The globalScope arrow should still be expanded.");
  73. is(thisVar.target.querySelector(".arrow").hasAttribute("open"), true,
  74. "The thisVar arrow should still be expanded.");
  75. is(windowVar.target.querySelector(".arrow").hasAttribute("open"), false,
  76. "The windowVar arrow should not be expanded.");
  77. is(localScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
  78. "The localScope enumerables should still be expanded.");
  79. is(withScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
  80. "The withScope enumerables should still be expanded.");
  81. is(functionScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
  82. "The functionScope enumerables should still be expanded.");
  83. is(globalLexicalScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
  84. "The globalLexicalScope enumerables should still be expanded.");
  85. is(globalScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
  86. "The globalScope enumerables should still be expanded.");
  87. is(thisVar.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
  88. "The thisVar enumerables should still be expanded.");
  89. is(windowVar.target.querySelector(".variables-view-element-details").hasAttribute("open"), false,
  90. "The windowVar enumerables should not be expanded.");
  91. is(localScope.expanded, true,
  92. "The localScope expanded getter should return true.");
  93. is(withScope.expanded, true,
  94. "The withScope expanded getter should return true.");
  95. is(functionScope.expanded, true,
  96. "The functionScope expanded getter should return true.");
  97. is(globalLexicalScope.expanded, true,
  98. "The globalScope expanded getter should return true.");
  99. is(globalScope.expanded, true,
  100. "The globalScope expanded getter should return true.");
  101. is(thisVar.expanded, true,
  102. "The thisVar expanded getter should return true.");
  103. is(windowVar.expanded, false,
  104. "The windowVar expanded getter should return true.");
  105. }
  106. function prepareVariablesAndProperties() {
  107. let deferred = promise.defer();
  108. let localScope = gVariables.getScopeAtIndex(0);
  109. let withScope = gVariables.getScopeAtIndex(1);
  110. let functionScope = gVariables.getScopeAtIndex(2);
  111. let globalLexicalScope = gVariables.getScopeAtIndex(3);
  112. let globalScope = gVariables.getScopeAtIndex(4);
  113. is(localScope.expanded, true,
  114. "The localScope should be expanded.");
  115. is(withScope.expanded, false,
  116. "The withScope should not be expanded yet.");
  117. is(functionScope.expanded, false,
  118. "The functionScope should not be expanded yet.");
  119. is(globalLexicalScope.expanded, false,
  120. "The globalLexicalScope should not be expanded yet.");
  121. is(globalScope.expanded, false,
  122. "The globalScope should not be expanded yet.");
  123. // Wait for only two events to be triggered, because the Function scope is
  124. // an environment to which scope arguments and variables are already attached.
  125. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES, 2).then(() => {
  126. is(localScope.expanded, true,
  127. "The localScope should now be expanded.");
  128. is(withScope.expanded, true,
  129. "The withScope should now be expanded.");
  130. is(functionScope.expanded, true,
  131. "The functionScope should now be expanded.");
  132. is(globalLexicalScope.expanded, true,
  133. "The globalLexicalScope should now be expanded.");
  134. is(globalScope.expanded, true,
  135. "The globalScope should now be expanded.");
  136. let thisVar = localScope.get("this");
  137. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => {
  138. let windowVar = thisVar.get("window");
  139. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => {
  140. let documentVar = windowVar.get("document");
  141. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => {
  142. let locationVar = documentVar.get("location");
  143. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => {
  144. is(thisVar.expanded, true,
  145. "The local scope 'this' should be expanded.");
  146. is(windowVar.expanded, true,
  147. "The local scope 'this.window' should be expanded.");
  148. is(documentVar.expanded, true,
  149. "The local scope 'this.window.document' should be expanded.");
  150. is(locationVar.expanded, true,
  151. "The local scope 'this.window.document.location' should be expanded.");
  152. deferred.resolve();
  153. });
  154. locationVar.expand();
  155. });
  156. documentVar.expand();
  157. });
  158. windowVar.expand();
  159. });
  160. thisVar.expand();
  161. });
  162. withScope.expand();
  163. functionScope.expand();
  164. globalLexicalScope.expand();
  165. globalScope.expand();
  166. return deferred.promise;
  167. }
  168. Task.spawn(function* () {
  169. yield addBreakpoint();
  170. yield ensureThreadClientState(gPanel, "resumed");
  171. yield pauseDebuggee();
  172. yield prepareVariablesAndProperties();
  173. yield stepInDebuggee();
  174. yield testVariablesExpand();
  175. resumeDebuggerThenCloseAndFinish(gPanel);
  176. });
  177. });
  178. }