browser_dbg_variables-view-02.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 creating, collapsing and expanding variables in the
  6. * variables view works as expected.
  7. */
  8. const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
  9. function test() {
  10. let options = {
  11. source: TAB_URL,
  12. line: 1
  13. };
  14. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  15. let variables = aPanel.panelWin.DebuggerView.Variables;
  16. let testScope = variables.addScope("test");
  17. let testVar = testScope.addItem("something");
  18. let duplVar = testScope.addItem("something");
  19. info("Scope id: " + testScope.id);
  20. info("Scope name: " + testScope.name);
  21. info("Variable id: " + testVar.id);
  22. info("Variable name: " + testVar.name);
  23. ok(testScope,
  24. "Should have created a scope.");
  25. is(duplVar, testVar,
  26. "Shouldn't be able to duplicate variables in the same scope.");
  27. ok(testVar,
  28. "Should have created a variable.");
  29. ok(testVar.id.includes("something"),
  30. "The newly created variable should have the default id set.");
  31. is(testVar.name, "something",
  32. "The newly created variable should have the desired name set.");
  33. ok(!testVar.displayValue,
  34. "The newly created variable should not have a displayed value yet (1).");
  35. ok(!testVar.displayValueClassName,
  36. "The newly created variable should not have a displayed value yet (2).");
  37. ok(testVar.target,
  38. "The newly created scope should point to a target node.");
  39. ok(testVar.target.id.includes("something"),
  40. "Should have the correct variable id on the element.");
  41. is(testVar.target.querySelector(".name").getAttribute("value"), "something",
  42. "Any new variable should have the designated name.");
  43. is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0,
  44. "Any new variable should have a container with no enumerable child nodes.");
  45. is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0,
  46. "Any new variable should have a container with no non-enumerable child nodes.");
  47. ok(!testVar.expanded,
  48. "Any new created scope should be initially collapsed.");
  49. ok(testVar.visible,
  50. "Any new created scope should be initially visible.");
  51. let expandCallbackArg = null;
  52. let collapseCallbackArg = null;
  53. let toggleCallbackArg = null;
  54. let hideCallbackArg = null;
  55. let showCallbackArg = null;
  56. testVar.onexpand = aScope => expandCallbackArg = aScope;
  57. testVar.oncollapse = aScope => collapseCallbackArg = aScope;
  58. testVar.ontoggle = aScope => toggleCallbackArg = aScope;
  59. testVar.onhide = aScope => hideCallbackArg = aScope;
  60. testVar.onshow = aScope => showCallbackArg = aScope;
  61. testVar.expand();
  62. ok(testVar.expanded,
  63. "The testVar shouldn't be collapsed anymore.");
  64. is(expandCallbackArg, testVar,
  65. "The expandCallback wasn't called as it should.");
  66. testVar.collapse();
  67. ok(!testVar.expanded,
  68. "The testVar should be collapsed again.");
  69. is(collapseCallbackArg, testVar,
  70. "The collapseCallback wasn't called as it should.");
  71. testVar.expanded = true;
  72. ok(testVar.expanded,
  73. "The testVar shouldn't be collapsed anymore.");
  74. testVar.toggle();
  75. ok(!testVar.expanded,
  76. "The testVar should be collapsed again.");
  77. is(toggleCallbackArg, testVar,
  78. "The toggleCallback wasn't called as it should.");
  79. testVar.hide();
  80. ok(!testVar.visible,
  81. "The testVar should be invisible after hiding.");
  82. is(hideCallbackArg, testVar,
  83. "The hideCallback wasn't called as it should.");
  84. testVar.show();
  85. ok(testVar.visible,
  86. "The testVar should be visible again.");
  87. is(showCallbackArg, testVar,
  88. "The showCallback wasn't called as it should.");
  89. testVar.visible = false;
  90. ok(!testVar.visible,
  91. "The testVar should be invisible after hiding.");
  92. ok(!testVar.expanded,
  93. "The testVar should remember it is collapsed even if it is hidden.");
  94. testVar.visible = true;
  95. ok(testVar.visible,
  96. "The testVar should be visible after reshowing.");
  97. ok(!testVar.expanded,
  98. "The testVar should remember it is collapsed after it is reshown.");
  99. EventUtils.sendMouseEvent({ type: "mousedown" },
  100. testVar.target.querySelector(".name"),
  101. aPanel.panelWin);
  102. ok(testVar.expanded,
  103. "Clicking the testVar name should expand it.");
  104. EventUtils.sendMouseEvent({ type: "mousedown" },
  105. testVar.target.querySelector(".name"),
  106. aPanel.panelWin);
  107. ok(!testVar.expanded,
  108. "Clicking again the testVar name should collapse it.");
  109. EventUtils.sendMouseEvent({ type: "mousedown" },
  110. testVar.target.querySelector(".arrow"),
  111. aPanel.panelWin);
  112. ok(testVar.expanded,
  113. "Clicking the testVar arrow should expand it.");
  114. EventUtils.sendMouseEvent({ type: "mousedown" },
  115. testVar.target.querySelector(".arrow"),
  116. aPanel.panelWin);
  117. ok(!testVar.expanded,
  118. "Clicking again the testVar arrow should collapse it.");
  119. EventUtils.sendMouseEvent({ type: "mousedown" },
  120. testVar.target.querySelector(".title"),
  121. aPanel.panelWin);
  122. ok(testVar.expanded,
  123. "Clicking the testVar title should expand it again.");
  124. testVar.addItem("child", {
  125. value: {
  126. type: "object",
  127. class: "Object"
  128. }
  129. });
  130. let testChild = testVar.get("child");
  131. ok(testChild,
  132. "Should have created a child property.");
  133. ok(testChild.id.includes("child"),
  134. "The newly created property should have the default id set.");
  135. is(testChild.name, "child",
  136. "The newly created property should have the desired name set.");
  137. is(testChild.displayValue, "Object",
  138. "The newly created property should not have a displayed value yet (1).");
  139. is(testChild.displayValueClassName, "token-other",
  140. "The newly created property should not have a displayed value yet (2).");
  141. ok(testChild.target,
  142. "The newly created scope should point to a target node.");
  143. ok(testChild.target.id.includes("child"),
  144. "Should have the correct property id on the element.");
  145. is(testChild.target.querySelector(".name").getAttribute("value"), "child",
  146. "Any new property should have the designated name.");
  147. is(testChild.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0,
  148. "Any new property should have a container with no enumerable child nodes.");
  149. is(testChild.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0,
  150. "Any new property should have a container with no non-enumerable child nodes.");
  151. ok(!testChild.expanded,
  152. "Any new created scope should be initially collapsed.");
  153. ok(testChild.visible,
  154. "Any new created scope should be initially visible.");
  155. EventUtils.sendMouseEvent({ type: "mousedown" },
  156. testChild.target.querySelector(".name"),
  157. aPanel.panelWin);
  158. ok(testChild.expanded,
  159. "Clicking the testChild name should expand it.");
  160. EventUtils.sendMouseEvent({ type: "mousedown" },
  161. testChild.target.querySelector(".name"),
  162. aPanel.panelWin);
  163. ok(!testChild.expanded,
  164. "Clicking again the testChild name should collapse it.");
  165. EventUtils.sendMouseEvent({ type: "mousedown" },
  166. testChild.target.querySelector(".arrow"),
  167. aPanel.panelWin);
  168. ok(testChild.expanded,
  169. "Clicking the testChild arrow should expand it.");
  170. EventUtils.sendMouseEvent({ type: "mousedown" },
  171. testChild.target.querySelector(".arrow"),
  172. aPanel.panelWin);
  173. ok(!testChild.expanded,
  174. "Clicking again the testChild arrow should collapse it.");
  175. EventUtils.sendMouseEvent({ type: "mousedown" },
  176. testChild.target.querySelector(".title"),
  177. aPanel.panelWin);
  178. closeDebuggerAndFinish(aPanel);
  179. });
  180. }