browser_dbg_variables-view-webidl.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 WebIDL attributes in DOM
  6. * objects.
  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(expandGlobalScope)
  25. .then(performTest)
  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 expandGlobalScope() {
  34. let deferred = promise.defer();
  35. let globalScope = gVariables.getScopeAtIndex(2);
  36. is(globalScope.expanded, false,
  37. "The global scope should not be expanded by default.");
  38. gDebugger.once(gDebugger.EVENTS.FETCHED_VARIABLES, deferred.resolve);
  39. EventUtils.sendMouseEvent({ type: "mousedown" },
  40. globalScope.target.querySelector(".name"),
  41. gDebugger);
  42. return deferred.promise;
  43. }
  44. function performTest() {
  45. let deferred = promise.defer();
  46. let globalScope = gVariables.getScopeAtIndex(2);
  47. let buttonVar = globalScope.get("button");
  48. let buttonAsProtoVar = globalScope.get("buttonAsProto");
  49. let documentVar = globalScope.get("document");
  50. is(buttonVar.target.querySelector(".name").getAttribute("value"), "button",
  51. "Should have the right property name for 'button'.");
  52. is(buttonVar.target.querySelector(".value").getAttribute("value"), "<button>",
  53. "Should have the right property value for 'button'.");
  54. ok(buttonVar.target.querySelector(".value").className.includes("token-domnode"),
  55. "Should have the right token class for 'button'.");
  56. is(buttonAsProtoVar.target.querySelector(".name").getAttribute("value"), "buttonAsProto",
  57. "Should have the right property name for 'buttonAsProto'.");
  58. is(buttonAsProtoVar.target.querySelector(".value").getAttribute("value"), "Object",
  59. "Should have the right property value for 'buttonAsProto'.");
  60. ok(buttonAsProtoVar.target.querySelector(".value").className.includes("token-other"),
  61. "Should have the right token class for 'buttonAsProto'.");
  62. is(documentVar.target.querySelector(".name").getAttribute("value"), "document",
  63. "Should have the right property name for 'document'.");
  64. is(documentVar.target.querySelector(".value").getAttribute("value"),
  65. "HTMLDocument \u2192 doc_frame-parameters.html",
  66. "Should have the right property value for 'document'.");
  67. ok(documentVar.target.querySelector(".value").className.includes("token-domnode"),
  68. "Should have the right token class for 'document'.");
  69. is(buttonVar.expanded, false,
  70. "The buttonVar should not be expanded at this point.");
  71. is(buttonAsProtoVar.expanded, false,
  72. "The buttonAsProtoVar should not be expanded at this point.");
  73. is(documentVar.expanded, false,
  74. "The documentVar should not be expanded at this point.");
  75. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 3).then(() => {
  76. is(buttonVar.get("type").target.querySelector(".name").getAttribute("value"), "type",
  77. "Should have the right property name for 'type'.");
  78. is(buttonVar.get("type").target.querySelector(".value").getAttribute("value"), "\"submit\"",
  79. "Should have the right property value for 'type'.");
  80. ok(buttonVar.get("type").target.querySelector(".value").className.includes("token-string"),
  81. "Should have the right token class for 'type'.");
  82. is(buttonVar.get("childNodes").target.querySelector(".name").getAttribute("value"), "childNodes",
  83. "Should have the right property name for 'childNodes'.");
  84. is(buttonVar.get("childNodes").target.querySelector(".value").getAttribute("value"), "NodeList[1]",
  85. "Should have the right property value for 'childNodes'.");
  86. ok(buttonVar.get("childNodes").target.querySelector(".value").className.includes("token-other"),
  87. "Should have the right token class for 'childNodes'.");
  88. is(buttonVar.get("onclick").target.querySelector(".name").getAttribute("value"), "onclick",
  89. "Should have the right property name for 'onclick'.");
  90. is(buttonVar.get("onclick").target.querySelector(".value").getAttribute("value"), "onclick(event)",
  91. "Should have the right property value for 'onclick'.");
  92. ok(buttonVar.get("onclick").target.querySelector(".value").className.includes("token-other"),
  93. "Should have the right token class for 'onclick'.");
  94. is(documentVar.get("title").target.querySelector(".name").getAttribute("value"), "title",
  95. "Should have the right property name for 'title'.");
  96. is(documentVar.get("title").target.querySelector(".value").getAttribute("value"), "\"Debugger test page\"",
  97. "Should have the right property value for 'title'.");
  98. ok(documentVar.get("title").target.querySelector(".value").className.includes("token-string"),
  99. "Should have the right token class for 'title'.");
  100. is(documentVar.get("childNodes").target.querySelector(".name").getAttribute("value"), "childNodes",
  101. "Should have the right property name for 'childNodes'.");
  102. is(documentVar.get("childNodes").target.querySelector(".value").getAttribute("value"), "NodeList[3]",
  103. "Should have the right property value for 'childNodes'.");
  104. ok(documentVar.get("childNodes").target.querySelector(".value").className.includes("token-other"),
  105. "Should have the right token class for 'childNodes'.");
  106. is(documentVar.get("onclick").target.querySelector(".name").getAttribute("value"), "onclick",
  107. "Should have the right property name for 'onclick'.");
  108. is(documentVar.get("onclick").target.querySelector(".value").getAttribute("value"), "null",
  109. "Should have the right property value for 'onclick'.");
  110. ok(documentVar.get("onclick").target.querySelector(".value").className.includes("token-null"),
  111. "Should have the right token class for 'onclick'.");
  112. let buttonProtoVar = buttonVar.get("__proto__");
  113. let buttonAsProtoProtoVar = buttonAsProtoVar.get("__proto__");
  114. let documentProtoVar = documentVar.get("__proto__");
  115. is(buttonProtoVar.target.querySelector(".name").getAttribute("value"), "__proto__",
  116. "Should have the right property name for '__proto__'.");
  117. is(buttonProtoVar.target.querySelector(".value").getAttribute("value"), "HTMLButtonElementPrototype",
  118. "Should have the right property value for '__proto__'.");
  119. ok(buttonProtoVar.target.querySelector(".value").className.includes("token-other"),
  120. "Should have the right token class for '__proto__'.");
  121. is(buttonAsProtoProtoVar.target.querySelector(".name").getAttribute("value"), "__proto__",
  122. "Should have the right property name for '__proto__'.");
  123. is(buttonAsProtoProtoVar.target.querySelector(".value").getAttribute("value"), "<button>",
  124. "Should have the right property value for '__proto__'.");
  125. ok(buttonAsProtoProtoVar.target.querySelector(".value").className.includes("token-domnode"),
  126. "Should have the right token class for '__proto__'.");
  127. is(documentProtoVar.target.querySelector(".name").getAttribute("value"), "__proto__",
  128. "Should have the right property name for '__proto__'.");
  129. is(documentProtoVar.target.querySelector(".value").getAttribute("value"), "HTMLDocumentPrototype",
  130. "Should have the right property value for '__proto__'.");
  131. ok(documentProtoVar.target.querySelector(".value").className.includes("token-other"),
  132. "Should have the right token class for '__proto__'.");
  133. is(buttonProtoVar.expanded, false,
  134. "The buttonProtoVar should not be expanded at this point.");
  135. is(buttonAsProtoProtoVar.expanded, false,
  136. "The buttonAsProtoProtoVar should not be expanded at this point.");
  137. is(documentProtoVar.expanded, false,
  138. "The documentProtoVar should not be expanded at this point.");
  139. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 3).then(() => {
  140. is(buttonAsProtoProtoVar.get("type").target.querySelector(".name").getAttribute("value"), "type",
  141. "Should have the right property name for 'type'.");
  142. is(buttonAsProtoProtoVar.get("type").target.querySelector(".value").getAttribute("value"), "\"submit\"",
  143. "Should have the right property value for 'type'.");
  144. ok(buttonAsProtoProtoVar.get("type").target.querySelector(".value").className.includes("token-string"),
  145. "Should have the right token class for 'type'.");
  146. is(buttonAsProtoProtoVar.get("childNodes").target.querySelector(".name").getAttribute("value"), "childNodes",
  147. "Should have the right property name for 'childNodes'.");
  148. is(buttonAsProtoProtoVar.get("childNodes").target.querySelector(".value").getAttribute("value"), "NodeList[1]",
  149. "Should have the right property value for 'childNodes'.");
  150. ok(buttonAsProtoProtoVar.get("childNodes").target.querySelector(".value").className.includes("token-other"),
  151. "Should have the right token class for 'childNodes'.");
  152. is(buttonAsProtoProtoVar.get("onclick").target.querySelector(".name").getAttribute("value"), "onclick",
  153. "Should have the right property name for 'onclick'.");
  154. is(buttonAsProtoProtoVar.get("onclick").target.querySelector(".value").getAttribute("value"), "onclick(event)",
  155. "Should have the right property value for 'onclick'.");
  156. ok(buttonAsProtoProtoVar.get("onclick").target.querySelector(".value").className.includes("token-other"),
  157. "Should have the right token class for 'onclick'.");
  158. let buttonProtoProtoVar = buttonProtoVar.get("__proto__");
  159. let buttonAsProtoProtoProtoVar = buttonAsProtoProtoVar.get("__proto__");
  160. let documentProtoProtoVar = documentProtoVar.get("__proto__");
  161. is(buttonProtoProtoVar.target.querySelector(".name").getAttribute("value"), "__proto__",
  162. "Should have the right property name for '__proto__'.");
  163. is(buttonProtoProtoVar.target.querySelector(".value").getAttribute("value"), "HTMLElementPrototype",
  164. "Should have the right property value for '__proto__'.");
  165. ok(buttonProtoProtoVar.target.querySelector(".value").className.includes("token-other"),
  166. "Should have the right token class for '__proto__'.");
  167. is(buttonAsProtoProtoProtoVar.target.querySelector(".name").getAttribute("value"), "__proto__",
  168. "Should have the right property name for '__proto__'.");
  169. is(buttonAsProtoProtoProtoVar.target.querySelector(".value").getAttribute("value"), "HTMLButtonElementPrototype",
  170. "Should have the right property value for '__proto__'.");
  171. ok(buttonAsProtoProtoProtoVar.target.querySelector(".value").className.includes("token-other"),
  172. "Should have the right token class for '__proto__'.");
  173. is(documentProtoProtoVar.target.querySelector(".name").getAttribute("value"), "__proto__",
  174. "Should have the right property name for '__proto__'.");
  175. is(documentProtoProtoVar.target.querySelector(".value").getAttribute("value"), "DocumentPrototype",
  176. "Should have the right property value for '__proto__'.");
  177. ok(documentProtoProtoVar.target.querySelector(".value").className.includes("token-other"),
  178. "Should have the right token class for '__proto__'.");
  179. is(buttonAsProtoProtoProtoVar.expanded, false,
  180. "The buttonAsProtoProtoProtoVar should not be expanded at this point.");
  181. is(buttonAsProtoProtoProtoVar.expanded, false,
  182. "The buttonAsProtoProtoProtoVar should not be expanded at this point.");
  183. is(documentProtoProtoVar.expanded, false,
  184. "The documentProtoProtoVar should not be expanded at this point.");
  185. deferred.resolve();
  186. });
  187. // Similarly, expand the 'button.__proto__', 'buttonAsProto.__proto__' and
  188. // 'document.__proto__' variables view nodes.
  189. buttonProtoVar.expand();
  190. buttonAsProtoProtoVar.expand();
  191. documentProtoVar.expand();
  192. is(buttonProtoVar.expanded, true,
  193. "The buttonProtoVar should be immediately marked as expanded.");
  194. is(buttonAsProtoProtoVar.expanded, true,
  195. "The buttonAsProtoProtoVar should be immediately marked as expanded.");
  196. is(documentProtoVar.expanded, true,
  197. "The documentProtoVar should be immediately marked as expanded.");
  198. });
  199. // Expand the 'button', 'buttonAsProto' and 'document' variables view nodes.
  200. // This causes their properties to be retrieved and displayed.
  201. buttonVar.expand();
  202. buttonAsProtoVar.expand();
  203. documentVar.expand();
  204. is(buttonVar.expanded, true,
  205. "The buttonVar should be immediately marked as expanded.");
  206. is(buttonAsProtoVar.expanded, true,
  207. "The buttonAsProtoVar should be immediately marked as expanded.");
  208. is(documentVar.expanded, true,
  209. "The documentVar should be immediately marked as expanded.");
  210. return deferred.promise;
  211. }
  212. registerCleanupFunction(function () {
  213. gTab = null;
  214. gPanel = null;
  215. gDebugger = null;
  216. gVariables = null;
  217. });