browser_dbg_variables-view-frame-parameters-01.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 displays the properties
  6. * of objects when debugger is paused.
  7. */
  8. const TAB_URL = EXAMPLE_URL + "doc_frame-parameters.html";
  9. var gTab, gPanel, gDebugger;
  10. var gVariables;
  11. function test() {
  12. // Debug test slaves are a bit slow at this test.
  13. requestLongerTimeout(2);
  14. let options = {
  15. source: TAB_URL,
  16. line: 1
  17. };
  18. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  19. gTab = aTab;
  20. gPanel = aPanel;
  21. gDebugger = gPanel.panelWin;
  22. gVariables = gDebugger.DebuggerView.Variables;
  23. waitForCaretAndScopes(gPanel, 24)
  24. .then(initialChecks)
  25. .then(testExpandVariables)
  26. .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
  27. .then(null, aError => {
  28. ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
  29. });
  30. generateMouseClickInTab(gTab, "content.document.querySelector('button')");
  31. });
  32. }
  33. function initialChecks() {
  34. let scopeNodes = gDebugger.document.querySelectorAll(".variables-view-scope");
  35. is(scopeNodes.length, 3,
  36. "There should be 3 scopes available.");
  37. ok(scopeNodes[0].querySelector(".name").getAttribute("value").includes("[test]"),
  38. "The local scope should be properly identified.");
  39. ok(scopeNodes[1].querySelector(".name").getAttribute("value").includes("Block"),
  40. "The global lexical scope should be properly identified.");
  41. ok(scopeNodes[2].querySelector(".name").getAttribute("value").includes("[Window]"),
  42. "The global scope should be properly identified.");
  43. is(gVariables.getScopeAtIndex(0).target, scopeNodes[0],
  44. "getScopeAtIndex(0) didn't return the expected scope.");
  45. is(gVariables.getScopeAtIndex(1).target, scopeNodes[1],
  46. "getScopeAtIndex(1) didn't return the expected scope.");
  47. is(gVariables.getScopeAtIndex(2).target, scopeNodes[2],
  48. "getScopeAtIndex(2) didn't return the expected scope.");
  49. is(gVariables.getItemForNode(scopeNodes[0]).target, scopeNodes[0],
  50. "getItemForNode([0]) didn't return the expected scope.");
  51. is(gVariables.getItemForNode(scopeNodes[1]).target, scopeNodes[1],
  52. "getItemForNode([1]) didn't return the expected scope.");
  53. is(gVariables.getItemForNode(scopeNodes[2]).target, scopeNodes[2],
  54. "getItemForNode([2]) didn't return the expected scope.");
  55. is(gVariables.getItemForNode(scopeNodes[0]).expanded, true,
  56. "The local scope should be expanded by default.");
  57. is(gVariables.getItemForNode(scopeNodes[1]).expanded, false,
  58. "The global lexical scope should not be collapsed by default.");
  59. is(gVariables.getItemForNode(scopeNodes[2]).expanded, false,
  60. "The global scope should not be collapsed by default.");
  61. }
  62. function testExpandVariables() {
  63. let deferred = promise.defer();
  64. let localScope = gVariables.getScopeAtIndex(0);
  65. let localEnums = localScope.target.querySelector(".variables-view-element-details.enum").childNodes;
  66. let thisVar = gVariables.getItemForNode(localEnums[0]);
  67. let argsVar = gVariables.getItemForNode(localEnums[8]);
  68. let cVar = gVariables.getItemForNode(localEnums[10]);
  69. is(thisVar.target.querySelector(".name").getAttribute("value"), "this",
  70. "Should have the right property name for 'this'.");
  71. is(argsVar.target.querySelector(".name").getAttribute("value"), "arguments",
  72. "Should have the right property name for 'arguments'.");
  73. is(cVar.target.querySelector(".name").getAttribute("value"), "c",
  74. "Should have the right property name for 'c'.");
  75. is(thisVar.expanded, false,
  76. "The thisVar should not be expanded at this point.");
  77. is(argsVar.expanded, false,
  78. "The argsVar should not be expanded at this point.");
  79. is(cVar.expanded, false,
  80. "The cVar should not be expanded at this point.");
  81. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 3).then(() => {
  82. is(thisVar.get("window").target.querySelector(".name").getAttribute("value"), "window",
  83. "Should have the right property name for 'window'.");
  84. is(thisVar.get("window").target.querySelector(".value").getAttribute("value"),
  85. "Window \u2192 doc_frame-parameters.html",
  86. "Should have the right property value for 'window'.");
  87. ok(thisVar.get("window").target.querySelector(".value").className.includes("token-other"),
  88. "Should have the right token class for 'window'.");
  89. is(thisVar.get("document").target.querySelector(".name").getAttribute("value"), "document",
  90. "Should have the right property name for 'document'.");
  91. is(thisVar.get("document").target.querySelector(".value").getAttribute("value"),
  92. "HTMLDocument \u2192 doc_frame-parameters.html",
  93. "Should have the right property value for 'document'.");
  94. ok(thisVar.get("document").target.querySelector(".value").className.includes("token-domnode"),
  95. "Should have the right token class for 'document'.");
  96. let argsProps = argsVar.target.querySelectorAll(".variables-view-property");
  97. is(argsProps.length, 8,
  98. "The 'arguments' variable should contain 5 enumerable and 3 non-enumerable properties");
  99. is(argsProps[0].querySelector(".name").getAttribute("value"), "0",
  100. "Should have the right property name for '0'.");
  101. is(argsProps[0].querySelector(".value").getAttribute("value"), "Object",
  102. "Should have the right property value for '0'.");
  103. ok(argsProps[0].querySelector(".value").className.includes("token-other"),
  104. "Should have the right token class for '0'.");
  105. is(argsProps[1].querySelector(".name").getAttribute("value"), "1",
  106. "Should have the right property name for '1'.");
  107. is(argsProps[1].querySelector(".value").getAttribute("value"), "\"beta\"",
  108. "Should have the right property value for '1'.");
  109. ok(argsProps[1].querySelector(".value").className.includes("token-string"),
  110. "Should have the right token class for '1'.");
  111. is(argsProps[2].querySelector(".name").getAttribute("value"), "2",
  112. "Should have the right property name for '2'.");
  113. is(argsProps[2].querySelector(".value").getAttribute("value"), "3",
  114. "Should have the right property name for '2'.");
  115. ok(argsProps[2].querySelector(".value").className.includes("token-number"),
  116. "Should have the right token class for '2'.");
  117. is(argsProps[3].querySelector(".name").getAttribute("value"), "3",
  118. "Should have the right property name for '3'.");
  119. is(argsProps[3].querySelector(".value").getAttribute("value"), "false",
  120. "Should have the right property value for '3'.");
  121. ok(argsProps[3].querySelector(".value").className.includes("token-boolean"),
  122. "Should have the right token class for '3'.");
  123. is(argsProps[4].querySelector(".name").getAttribute("value"), "4",
  124. "Should have the right property name for '4'.");
  125. is(argsProps[4].querySelector(".value").getAttribute("value"), "null",
  126. "Should have the right property name for '4'.");
  127. ok(argsProps[4].querySelector(".value").className.includes("token-null"),
  128. "Should have the right token class for '4'.");
  129. is(gVariables.getItemForNode(argsProps[0]).target,
  130. argsVar.target.querySelectorAll(".variables-view-property")[0],
  131. "getItemForNode([0]) didn't return the expected property.");
  132. is(gVariables.getItemForNode(argsProps[1]).target,
  133. argsVar.target.querySelectorAll(".variables-view-property")[1],
  134. "getItemForNode([1]) didn't return the expected property.");
  135. is(gVariables.getItemForNode(argsProps[2]).target,
  136. argsVar.target.querySelectorAll(".variables-view-property")[2],
  137. "getItemForNode([2]) didn't return the expected property.");
  138. is(argsVar.find(argsProps[0]).target,
  139. argsVar.target.querySelectorAll(".variables-view-property")[0],
  140. "find([0]) didn't return the expected property.");
  141. is(argsVar.find(argsProps[1]).target,
  142. argsVar.target.querySelectorAll(".variables-view-property")[1],
  143. "find([1]) didn't return the expected property.");
  144. is(argsVar.find(argsProps[2]).target,
  145. argsVar.target.querySelectorAll(".variables-view-property")[2],
  146. "find([2]) didn't return the expected property.");
  147. let cProps = cVar.target.querySelectorAll(".variables-view-property");
  148. is(cProps.length, 7,
  149. "The 'c' variable should contain 6 enumerable and 1 non-enumerable properties");
  150. is(cProps[0].querySelector(".name").getAttribute("value"), "a",
  151. "Should have the right property name for 'a'.");
  152. is(cProps[0].querySelector(".value").getAttribute("value"), "1",
  153. "Should have the right property value for 'a'.");
  154. ok(cProps[0].querySelector(".value").className.includes("token-number"),
  155. "Should have the right token class for 'a'.");
  156. is(cProps[1].querySelector(".name").getAttribute("value"), "b",
  157. "Should have the right property name for 'b'.");
  158. is(cProps[1].querySelector(".value").getAttribute("value"), "\"beta\"",
  159. "Should have the right property value for 'b'.");
  160. ok(cProps[1].querySelector(".value").className.includes("token-string"),
  161. "Should have the right token class for 'b'.");
  162. is(cProps[2].querySelector(".name").getAttribute("value"), "c",
  163. "Should have the right property name for 'c'.");
  164. is(cProps[2].querySelector(".value").getAttribute("value"), "3",
  165. "Should have the right property value for 'c'.");
  166. ok(cProps[2].querySelector(".value").className.includes("token-number"),
  167. "Should have the right token class for 'c'.");
  168. is(cProps[3].querySelector(".name").getAttribute("value"), "d",
  169. "Should have the right property name for 'd'.");
  170. is(cProps[3].querySelector(".value").getAttribute("value"), "false",
  171. "Should have the right property value for 'd'.");
  172. ok(cProps[3].querySelector(".value").className.includes("token-boolean"),
  173. "Should have the right token class for 'd'.");
  174. is(cProps[4].querySelector(".name").getAttribute("value"), "e",
  175. "Should have the right property name for 'e'.");
  176. is(cProps[4].querySelector(".value").getAttribute("value"), "null",
  177. "Should have the right property value for 'e'.");
  178. ok(cProps[4].querySelector(".value").className.includes("token-null"),
  179. "Should have the right token class for 'e'.");
  180. is(cProps[5].querySelector(".name").getAttribute("value"), "f",
  181. "Should have the right property name for 'f'.");
  182. is(cProps[5].querySelector(".value").getAttribute("value"), "undefined",
  183. "Should have the right property value for 'f'.");
  184. ok(cProps[5].querySelector(".value").className.includes("token-undefined"),
  185. "Should have the right token class for 'f'.");
  186. is(gVariables.getItemForNode(cProps[0]).target,
  187. cVar.target.querySelectorAll(".variables-view-property")[0],
  188. "getItemForNode([0]) didn't return the expected property.");
  189. is(gVariables.getItemForNode(cProps[1]).target,
  190. cVar.target.querySelectorAll(".variables-view-property")[1],
  191. "getItemForNode([1]) didn't return the expected property.");
  192. is(gVariables.getItemForNode(cProps[2]).target,
  193. cVar.target.querySelectorAll(".variables-view-property")[2],
  194. "getItemForNode([2]) didn't return the expected property.");
  195. is(cVar.find(cProps[0]).target,
  196. cVar.target.querySelectorAll(".variables-view-property")[0],
  197. "find([0]) didn't return the expected property.");
  198. is(cVar.find(cProps[1]).target,
  199. cVar.target.querySelectorAll(".variables-view-property")[1],
  200. "find([1]) didn't return the expected property.");
  201. is(cVar.find(cProps[2]).target,
  202. cVar.target.querySelectorAll(".variables-view-property")[2],
  203. "find([2]) didn't return the expected property.");
  204. });
  205. // Expand the 'this', 'arguments' and 'c' variables view nodes. This causes
  206. // their properties to be retrieved and displayed.
  207. thisVar.expand();
  208. argsVar.expand();
  209. cVar.expand();
  210. is(thisVar.expanded, true,
  211. "The thisVar should be immediately marked as expanded.");
  212. is(argsVar.expanded, true,
  213. "The argsVar should be immediately marked as expanded.");
  214. is(cVar.expanded, true,
  215. "The cVar should be immediately marked as expanded.");
  216. }
  217. registerCleanupFunction(function () {
  218. gTab = null;
  219. gPanel = null;
  220. gDebugger = null;
  221. gVariables = null;
  222. });