browser_dbg_variables-view-reexpand-02.js 9.7 KB

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