browser_dbg_variables-view-04.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 grips are correctly applied to variables.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
  8. function test() {
  9. let options = {
  10. source: TAB_URL,
  11. line: 1
  12. };
  13. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  14. let variables = aPanel.panelWin.DebuggerView.Variables;
  15. let testScope = variables.addScope("test");
  16. let testVar = testScope.addItem("something");
  17. testVar.setGrip(1.618);
  18. is(testVar.target.querySelector(".value").getAttribute("value"), "1.618",
  19. "The grip information for the variable wasn't set correctly (1).");
  20. is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0,
  21. "Setting the grip alone shouldn't add any new tree nodes (1).");
  22. is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0,
  23. "Setting the grip alone shouldn't add any new tree nodes (2).");
  24. testVar.setGrip({
  25. type: "object",
  26. class: "Window"
  27. });
  28. is(testVar.target.querySelector(".value").getAttribute("value"), "Window",
  29. "The grip information for the variable wasn't set correctly (2).");
  30. is(testVar.target.querySelector(".variables-view-element-details.enum").childNodes.length, 0,
  31. "Setting the grip alone shouldn't add any new tree nodes (3).");
  32. is(testVar.target.querySelector(".variables-view-element-details.nonenum").childNodes.length, 0,
  33. "Setting the grip alone shouldn't add any new tree nodes (4).");
  34. testVar.addItems({
  35. helloWorld: {
  36. value: "hello world",
  37. enumerable: true
  38. }
  39. });
  40. is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 1,
  41. "A new detail node should have been added in the variable tree.");
  42. is(testVar.get("helloWorld").target.querySelector(".value").getAttribute("value"), "\"hello world\"",
  43. "The grip information for the variable wasn't set correctly (3).");
  44. testVar.addItems({
  45. helloWorld: {
  46. value: "hello jupiter",
  47. enumerable: true
  48. }
  49. });
  50. is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 1,
  51. "Shouldn't be able to duplicate nodes added in the variable tree.");
  52. is(testVar.get("helloWorld").target.querySelector(".value").getAttribute("value"), "\"hello world\"",
  53. "The grip information for the variable wasn't preserved correctly (4).");
  54. testVar.addItems({
  55. someProp0: {
  56. value: "random string",
  57. enumerable: true
  58. },
  59. someProp1: {
  60. value: "another string",
  61. enumerable: true
  62. }
  63. });
  64. is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 3,
  65. "Two new detail nodes should have been added in the variable tree.");
  66. is(testVar.get("someProp0").target.querySelector(".value").getAttribute("value"), "\"random string\"",
  67. "The grip information for the variable wasn't set correctly (5).");
  68. is(testVar.get("someProp1").target.querySelector(".value").getAttribute("value"), "\"another string\"",
  69. "The grip information for the variable wasn't set correctly (6).");
  70. testVar.addItems({
  71. someProp2: {
  72. value: {
  73. type: "null"
  74. },
  75. enumerable: true
  76. },
  77. someProp3: {
  78. value: {
  79. type: "undefined"
  80. },
  81. enumerable: true
  82. },
  83. someProp4: {
  84. value: {
  85. type: "object",
  86. class: "Object"
  87. },
  88. enumerable: true
  89. }
  90. });
  91. is(testVar.target.querySelector(".variables-view-element-details").childNodes.length, 6,
  92. "Three new detail nodes should have been added in the variable tree.");
  93. is(testVar.get("someProp2").target.querySelector(".value").getAttribute("value"), "null",
  94. "The grip information for the variable wasn't set correctly (7).");
  95. is(testVar.get("someProp3").target.querySelector(".value").getAttribute("value"), "undefined",
  96. "The grip information for the variable wasn't set correctly (8).");
  97. is(testVar.get("someProp4").target.querySelector(".value").getAttribute("value"), "Object",
  98. "The grip information for the variable wasn't set correctly (9).");
  99. let parent = testVar.get("someProp2");
  100. let child = parent.addItem("child", {
  101. value: {
  102. type: "null"
  103. }
  104. });
  105. is(variables.getItemForNode(parent.target), parent,
  106. "VariablesView should have a record of the parent.");
  107. is(variables.getItemForNode(child.target), child,
  108. "VariablesView should have a record of the child.");
  109. is([...parent].length, 1,
  110. "Parent should have one child.");
  111. parent.remove();
  112. is(variables.getItemForNode(parent.target), undefined,
  113. "VariablesView should not have a record of the parent anymore.");
  114. is(parent.target.parentNode, null,
  115. "Parent element should not have a parent.");
  116. is(variables.getItemForNode(child.target), undefined,
  117. "VariablesView should not have a record of the child anymore.");
  118. is(child.target.parentNode, null,
  119. "Child element should not have a parent.");
  120. is([...parent].length, 0,
  121. "Parent should have zero children.");
  122. testScope.remove();
  123. is([...variables].length, 0,
  124. "VariablesView should have been emptied.");
  125. is(ThreadSafeChromeUtils.nondeterministicGetWeakMapKeys(variables._itemsByElement).length,
  126. 0, "VariablesView _itemsByElement map has been emptied.");
  127. is(variables._currHierarchy.size, 0,
  128. "VariablesView _currHierarchy map has been emptied.");
  129. is(variables._list.children.length, 0,
  130. "VariablesView element should have no children.");
  131. closeDebuggerAndFinish(aPanel);
  132. });
  133. }