browser_dbg_watch-expressions-01.js 8.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. * Bug 727429: Test the debugger watch expressions.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_watch-expressions.html";
  8. function test() {
  9. // Debug test slaves are a bit slow at this test.
  10. requestLongerTimeout(2);
  11. let gTab, gPanel, gDebugger;
  12. let gEditor, gWatch, gVariables;
  13. let options = {
  14. source: TAB_URL,
  15. line: 1
  16. };
  17. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  18. gTab = aTab;
  19. gPanel = aPanel;
  20. gDebugger = gPanel.panelWin;
  21. gEditor = gDebugger.DebuggerView.editor;
  22. gWatch = gDebugger.DebuggerView.WatchExpressions;
  23. gVariables = gDebugger.DebuggerView.Variables;
  24. gDebugger.DebuggerView.toggleInstrumentsPane({ visible: true, animated: false });
  25. performTest();
  26. closeDebuggerAndFinish(gPanel);
  27. });
  28. function performTest() {
  29. is(gWatch.getAllStrings().length, 0,
  30. "There should initially be no watch expressions.");
  31. addAndCheckExpressions(1, 0, "a");
  32. addAndCheckExpressions(2, 0, "b");
  33. addAndCheckExpressions(3, 0, "c");
  34. removeAndCheckExpression(2, 1, "a");
  35. removeAndCheckExpression(1, 0, "a");
  36. addAndCheckExpressions(2, 0, "", true);
  37. gEditor.focus();
  38. is(gWatch.getAllStrings().length, 1,
  39. "Empty watch expressions are automatically removed.");
  40. addAndCheckExpressions(2, 0, "a", true);
  41. gEditor.focus();
  42. is(gWatch.getAllStrings().length, 1,
  43. "Duplicate watch expressions are automatically removed.");
  44. addAndCheckExpressions(2, 0, "a\t", true);
  45. addAndCheckExpressions(2, 0, "a\r", true);
  46. addAndCheckExpressions(2, 0, "a\n", true);
  47. gEditor.focus();
  48. is(gWatch.getAllStrings().length, 1,
  49. "Duplicate watch expressions are automatically removed.");
  50. addAndCheckExpressions(2, 0, "\ta", true);
  51. addAndCheckExpressions(2, 0, "\ra", true);
  52. addAndCheckExpressions(2, 0, "\na", true);
  53. gEditor.focus();
  54. is(gWatch.getAllStrings().length, 1,
  55. "Duplicate watch expressions are automatically removed.");
  56. addAndCheckCustomExpression(2, 0, "bazΩΩka");
  57. addAndCheckCustomExpression(3, 0, "bambøøcha");
  58. EventUtils.sendMouseEvent({ type: "click" },
  59. gWatch.getItemAtIndex(0).attachment.view.closeNode,
  60. gDebugger);
  61. is(gWatch.getAllStrings().length, 2,
  62. "Watch expressions are removed when the close button is pressed.");
  63. is(gWatch.getAllStrings()[0], "bazΩΩka",
  64. "The expression at index " + 0 + " should be correct (1).");
  65. is(gWatch.getAllStrings()[1], "a",
  66. "The expression at index " + 1 + " should be correct (2).");
  67. EventUtils.sendMouseEvent({ type: "click" },
  68. gWatch.getItemAtIndex(0).attachment.view.closeNode,
  69. gDebugger);
  70. is(gWatch.getAllStrings().length, 1,
  71. "Watch expressions are removed when the close button is pressed.");
  72. is(gWatch.getAllStrings()[0], "a",
  73. "The expression at index " + 0 + " should be correct (3).");
  74. EventUtils.sendMouseEvent({ type: "click" },
  75. gWatch.getItemAtIndex(0).attachment.view.closeNode,
  76. gDebugger);
  77. is(gWatch.getAllStrings().length, 0,
  78. "Watch expressions are removed when the close button is pressed.");
  79. EventUtils.sendMouseEvent({ type: "click" },
  80. gWatch.widget._parent,
  81. gDebugger);
  82. is(gWatch.getAllStrings().length, 1,
  83. "Watch expressions are added when the view container is pressed.");
  84. }
  85. function addAndCheckCustomExpression(aTotal, aIndex, aString, noBlur) {
  86. addAndCheckExpressions(aTotal, aIndex, "", true);
  87. EventUtils.sendString(aString, gDebugger);
  88. gEditor.focus();
  89. let element = gWatch.getItemAtIndex(aIndex).target;
  90. is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, "",
  91. "The initial expression at index " + aIndex + " should be correct (1).");
  92. is(gWatch.getItemForElement(element).attachment.initialExpression, "",
  93. "The initial expression at index " + aIndex + " should be correct (2).");
  94. is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString,
  95. "The expression at index " + aIndex + " should be correct (1).");
  96. is(gWatch.getItemForElement(element).attachment.currentExpression, aString,
  97. "The expression at index " + aIndex + " should be correct (2).");
  98. is(gWatch.getString(aIndex), aString,
  99. "The expression at index " + aIndex + " should be correct (3).");
  100. is(gWatch.getAllStrings()[aIndex], aString,
  101. "The expression at index " + aIndex + " should be correct (4).");
  102. }
  103. function addAndCheckExpressions(aTotal, aIndex, aString, noBlur) {
  104. gWatch.addExpression(aString);
  105. is(gWatch.getAllStrings().length, aTotal,
  106. "There should be " + aTotal + " watch expressions available (1).");
  107. is(gWatch.itemCount, aTotal,
  108. "There should be " + aTotal + " watch expressions available (2).");
  109. ok(gWatch.getItemAtIndex(aIndex),
  110. "The expression at index " + aIndex + " should be available.");
  111. is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString,
  112. "The expression at index " + aIndex + " should have an initial expression.");
  113. let element = gWatch.getItemAtIndex(aIndex).target;
  114. ok(element,
  115. "There should be a new expression item in the view.");
  116. ok(gWatch.getItemForElement(element),
  117. "The watch expression item should be accessible.");
  118. is(gWatch.getItemForElement(element), gWatch.getItemAtIndex(aIndex),
  119. "The correct watch expression item was accessed.");
  120. ok(gWatch.widget.getItemAtIndex(aIndex) instanceof XULElement,
  121. "The correct watch expression element was accessed (1).");
  122. is(element, gWatch.widget.getItemAtIndex(aIndex),
  123. "The correct watch expression element was accessed (2).");
  124. is(gWatch.getItemForElement(element).attachment.view.arrowNode.hidden, false,
  125. "The arrow node should be visible.");
  126. is(gWatch.getItemForElement(element).attachment.view.closeNode.hidden, false,
  127. "The close button should be visible.");
  128. is(gWatch.getItemForElement(element).attachment.view.inputNode.getAttribute("focused"), "true",
  129. "The textbox input should be focused.");
  130. is(gVariables.parentNode.scrollTop, 0,
  131. "The variables view should be scrolled to top");
  132. is(gWatch.items[0], gWatch.getItemAtIndex(aIndex),
  133. "The correct watch expression was added to the cache (1).");
  134. is(gWatch.items[0], gWatch.getItemForElement(element),
  135. "The correct watch expression was added to the cache (2).");
  136. if (!noBlur) {
  137. gEditor.focus();
  138. is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString,
  139. "The initial expression at index " + aIndex + " should be correct (1).");
  140. is(gWatch.getItemForElement(element).attachment.initialExpression, aString,
  141. "The initial expression at index " + aIndex + " should be correct (2).");
  142. is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString,
  143. "The expression at index " + aIndex + " should be correct (1).");
  144. is(gWatch.getItemForElement(element).attachment.currentExpression, aString,
  145. "The expression at index " + aIndex + " should be correct (2).");
  146. is(gWatch.getString(aIndex), aString,
  147. "The expression at index " + aIndex + " should be correct (3).");
  148. is(gWatch.getAllStrings()[aIndex], aString,
  149. "The expression at index " + aIndex + " should be correct (4).");
  150. }
  151. }
  152. function removeAndCheckExpression(aTotal, aIndex, aString) {
  153. gWatch.removeAt(aIndex);
  154. is(gWatch.getAllStrings().length, aTotal,
  155. "There should be " + aTotal + " watch expressions available (1).");
  156. is(gWatch.itemCount, aTotal,
  157. "There should be " + aTotal + " watch expressions available (2).");
  158. ok(gWatch.getItemAtIndex(aIndex),
  159. "The expression at index " + aIndex + " should still be available.");
  160. is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString,
  161. "The expression at index " + aIndex + " should still have an initial expression.");
  162. let element = gWatch.getItemAtIndex(aIndex).target;
  163. is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString,
  164. "The initial expression at index " + aIndex + " should be correct (1).");
  165. is(gWatch.getItemForElement(element).attachment.initialExpression, aString,
  166. "The initial expression at index " + aIndex + " should be correct (2).");
  167. is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString,
  168. "The expression at index " + aIndex + " should be correct (1).");
  169. is(gWatch.getItemForElement(element).attachment.currentExpression, aString,
  170. "The expression at index " + aIndex + " should be correct (2).");
  171. is(gWatch.getString(aIndex), aString,
  172. "The expression at index " + aIndex + " should be correct (3).");
  173. is(gWatch.getAllStrings()[aIndex], aString,
  174. "The expression at index " + aIndex + " should be correct (4).");
  175. }
  176. }