browser_dbg_variables-view-frame-parameters-03.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 displays the right variables and
  6. * properties in the global scope 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(expandGlobalScope)
  25. .then(testGlobalScope)
  26. .then(expandWindowVariable)
  27. .then(testWindowVariable)
  28. .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
  29. .then(null, aError => {
  30. ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
  31. });
  32. generateMouseClickInTab(gTab, "content.document.querySelector('button')");
  33. });
  34. }
  35. function expandGlobalScope() {
  36. let deferred = promise.defer();
  37. let globalScope = gVariables.getScopeAtIndex(2);
  38. is(globalScope.expanded, false,
  39. "The global scope should not be expanded by default.");
  40. gDebugger.once(gDebugger.EVENTS.FETCHED_VARIABLES, deferred.resolve);
  41. EventUtils.sendMouseEvent({ type: "mousedown" },
  42. globalScope.target.querySelector(".name"),
  43. gDebugger);
  44. return deferred.promise;
  45. }
  46. function testGlobalScope() {
  47. let globalScope = gVariables.getScopeAtIndex(2);
  48. is(globalScope.expanded, true,
  49. "The global scope should now be expanded.");
  50. is(globalScope.get("InstallTrigger").target.querySelector(".name").getAttribute("value"), "InstallTrigger",
  51. "Should have the right property name for 'InstallTrigger'.");
  52. is(globalScope.get("InstallTrigger").target.querySelector(".value").getAttribute("value"), "InstallTriggerImpl",
  53. "Should have the right property value for 'InstallTrigger'.");
  54. is(globalScope.get("SpecialPowers").target.querySelector(".name").getAttribute("value"), "SpecialPowers",
  55. "Should have the right property name for 'SpecialPowers'.");
  56. is(globalScope.get("SpecialPowers").target.querySelector(".value").getAttribute("value"), "Object",
  57. "Should have the right property value for 'SpecialPowers'.");
  58. is(globalScope.get("window").target.querySelector(".name").getAttribute("value"), "window",
  59. "Should have the right property name for 'window'.");
  60. is(globalScope.get("window").target.querySelector(".value").getAttribute("value"),
  61. "Window \u2192 doc_frame-parameters.html",
  62. "Should have the right property value for 'window'.");
  63. is(globalScope.get("document").target.querySelector(".name").getAttribute("value"), "document",
  64. "Should have the right property name for 'document'.");
  65. is(globalScope.get("document").target.querySelector(".value").getAttribute("value"),
  66. "HTMLDocument \u2192 doc_frame-parameters.html",
  67. "Should have the right property value for 'document'.");
  68. is(globalScope.get("undefined").target.querySelector(".name").getAttribute("value"), "undefined",
  69. "Should have the right property name for 'undefined'.");
  70. is(globalScope.get("undefined").target.querySelector(".value").getAttribute("value"), "undefined",
  71. "Should have the right property value for 'undefined'.");
  72. is(globalScope.get("undefined").target.querySelector(".enum").childNodes.length, 0,
  73. "Should have no child enumerable properties for 'undefined'.");
  74. is(globalScope.get("undefined").target.querySelector(".nonenum").childNodes.length, 0,
  75. "Should have no child non-enumerable properties for 'undefined'.");
  76. }
  77. function expandWindowVariable() {
  78. let deferred = promise.defer();
  79. let windowVar = gVariables.getScopeAtIndex(2).get("window");
  80. is(windowVar.expanded, false,
  81. "The window variable should not be expanded by default.");
  82. gDebugger.once(gDebugger.EVENTS.FETCHED_PROPERTIES, deferred.resolve);
  83. EventUtils.sendMouseEvent({ type: "mousedown" },
  84. windowVar.target.querySelector(".name"),
  85. gDebugger);
  86. return deferred.promise;
  87. }
  88. function testWindowVariable() {
  89. let windowVar = gVariables.getScopeAtIndex(2).get("window");
  90. is(windowVar.expanded, true,
  91. "The window variable should now be expanded.");
  92. is(windowVar.get("InstallTrigger").target.querySelector(".name").getAttribute("value"), "InstallTrigger",
  93. "Should have the right property name for 'InstallTrigger'.");
  94. is(windowVar.get("InstallTrigger").target.querySelector(".value").getAttribute("value"), "InstallTriggerImpl",
  95. "Should have the right property value for 'InstallTrigger'.");
  96. is(windowVar.get("SpecialPowers").target.querySelector(".name").getAttribute("value"), "SpecialPowers",
  97. "Should have the right property name for 'SpecialPowers'.");
  98. is(windowVar.get("SpecialPowers").target.querySelector(".value").getAttribute("value"), "Object",
  99. "Should have the right property value for 'SpecialPowers'.");
  100. is(windowVar.get("window").target.querySelector(".name").getAttribute("value"), "window",
  101. "Should have the right property name for 'window'.");
  102. is(windowVar.get("window").target.querySelector(".value").getAttribute("value"),
  103. "Window \u2192 doc_frame-parameters.html",
  104. "Should have the right property value for 'window'.");
  105. is(windowVar.get("document").target.querySelector(".name").getAttribute("value"), "document",
  106. "Should have the right property name for 'document'.");
  107. is(windowVar.get("document").target.querySelector(".value").getAttribute("value"),
  108. "HTMLDocument \u2192 doc_frame-parameters.html",
  109. "Should have the right property value for 'document'.");
  110. is(windowVar.get("undefined").target.querySelector(".name").getAttribute("value"), "undefined",
  111. "Should have the right property name for 'undefined'.");
  112. is(windowVar.get("undefined").target.querySelector(".value").getAttribute("value"), "undefined",
  113. "Should have the right property value for 'undefined'.");
  114. is(windowVar.get("undefined").target.querySelector(".enum").childNodes.length, 0,
  115. "Should have no child enumerable properties for 'undefined'.");
  116. is(windowVar.get("undefined").target.querySelector(".nonenum").childNodes.length, 0,
  117. "Should have no child non-enumerable properties for 'undefined'.");
  118. }
  119. registerCleanupFunction(function () {
  120. gTab = null;
  121. gPanel = null;
  122. gDebugger = null;
  123. gVariables = null;
  124. });