browser_dbg_search-basic-01.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 basic search functionality (find token and jump to line).
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
  8. var gTab, gPanel, gDebugger;
  9. var gEditor, gSources, gFiltering, gSearchBox;
  10. function test() {
  11. let options = {
  12. source: TAB_URL,
  13. line: 1
  14. };
  15. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  16. gTab = aTab;
  17. gPanel = aPanel;
  18. gDebugger = gPanel.panelWin;
  19. gEditor = gDebugger.DebuggerView.editor;
  20. gSources = gDebugger.DebuggerView.Sources;
  21. gFiltering = gDebugger.DebuggerView.Filtering;
  22. gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
  23. performTest();
  24. });
  25. }
  26. function performTest() {
  27. // Make sure that the search box becomes focused when pressing ctrl+f - Bug 1211038
  28. gEditor.focus();
  29. synthesizeKeyFromKeyTag(gDebugger.document.getElementById("tokenSearchKey"));
  30. let focusedEl = Services.focus.focusedElement;
  31. focusedEl = focusedEl.ownerDocument.getBindingParent(focusedEl) || focusedEl;
  32. is(focusedEl, gDebugger.document.getElementById("searchbox"), "Searchbox is focused");
  33. setText(gSearchBox, "#html");
  34. EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }, gDebugger);
  35. is(gFiltering.searchData.toSource(), '["#", ["", "html"]]',
  36. "The searchbox data wasn't parsed correctly.");
  37. ok(isCaretPos(gPanel, 35, 7),
  38. "The editor didn't jump to the correct line.");
  39. EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }, gDebugger);
  40. is(gFiltering.searchData.toSource(), '["#", ["", "html"]]',
  41. "The searchbox data wasn't parsed correctly.");
  42. ok(isCaretPos(gPanel, 5, 6),
  43. "The editor didn't jump to the correct line.");
  44. EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }, gDebugger);
  45. is(gFiltering.searchData.toSource(), '["#", ["", "html"]]',
  46. "The searchbox data wasn't parsed correctly.");
  47. ok(isCaretPos(gPanel, 3, 15),
  48. "The editor didn't jump to the correct line.");
  49. setText(gSearchBox, ":12");
  50. is(gFiltering.searchData.toSource(), '[":", ["", 12]]',
  51. "The searchbox data wasn't parsed correctly.");
  52. ok(isCaretPos(gPanel, 12),
  53. "The editor didn't jump to the correct line.");
  54. EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger);
  55. is(gFiltering.searchData.toSource(), '[":", ["", 13]]',
  56. "The searchbox data wasn't parsed correctly.");
  57. ok(isCaretPos(gPanel, 13),
  58. "The editor didn't jump to the correct line after Meta+G.");
  59. EventUtils.synthesizeKey("n", { ctrlKey: true }, gDebugger);
  60. is(gFiltering.searchData.toSource(), '[":", ["", 14]]',
  61. "The searchbox data wasn't parsed correctly.");
  62. ok(isCaretPos(gPanel, 14),
  63. "The editor didn't jump to the correct line after Ctrl+N.");
  64. EventUtils.synthesizeKey("G", { metaKey: true, shiftKey: true }, gDebugger);
  65. is(gFiltering.searchData.toSource(), '[":", ["", 13]]',
  66. "The searchbox data wasn't parsed correctly.");
  67. ok(isCaretPos(gPanel, 13),
  68. "The editor didn't jump to the correct line after Meta+Shift+G.");
  69. EventUtils.synthesizeKey("p", { ctrlKey: true }, gDebugger);
  70. is(gFiltering.searchData.toSource(), '[":", ["", 12]]',
  71. "The searchbox data wasn't parsed correctly.");
  72. ok(isCaretPos(gPanel, 12),
  73. "The editor didn't jump to the correct line after Ctrl+P.");
  74. for (let i = 0; i < 100; i++) {
  75. EventUtils.sendKey("DOWN", gDebugger);
  76. }
  77. is(gFiltering.searchData.toSource(), '[":", ["", 36]]',
  78. "The searchbox data wasn't parsed correctly.");
  79. ok(isCaretPos(gPanel, 36),
  80. "The editor didn't jump to the correct line after multiple DOWN keys.");
  81. for (let i = 0; i < 100; i++) {
  82. EventUtils.sendKey("UP", gDebugger);
  83. }
  84. is(gFiltering.searchData.toSource(), '[":", ["", 1]]',
  85. "The searchbox data wasn't parsed correctly.");
  86. ok(isCaretPos(gPanel, 1),
  87. "The editor didn't jump to the correct line after multiple UP keys.");
  88. let token = "debugger";
  89. setText(gSearchBox, "#" + token);
  90. is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
  91. "The searchbox data wasn't parsed correctly.");
  92. ok(isCaretPos(gPanel, 8, 12 + token.length),
  93. "The editor didn't jump to the correct token (1).");
  94. EventUtils.sendKey("DOWN", gDebugger);
  95. is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
  96. "The searchbox data wasn't parsed correctly.");
  97. ok(isCaretPos(gPanel, 14, 9 + token.length),
  98. "The editor didn't jump to the correct token (2).");
  99. EventUtils.sendKey("DOWN", gDebugger);
  100. is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
  101. "The searchbox data wasn't parsed correctly.");
  102. ok(isCaretPos(gPanel, 18, 15 + token.length),
  103. "The editor didn't jump to the correct token (3).");
  104. EventUtils.sendKey("RETURN", gDebugger);
  105. is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
  106. "The searchbox data wasn't parsed correctly.");
  107. ok(isCaretPos(gPanel, 26, 11 + token.length),
  108. "The editor didn't jump to the correct token (4).");
  109. EventUtils.sendKey("RETURN", gDebugger);
  110. is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
  111. "The searchbox data wasn't parsed correctly.");
  112. ok(isCaretPos(gPanel, 8, 12 + token.length),
  113. "The editor didn't jump to the correct token (5).");
  114. EventUtils.sendKey("UP", gDebugger);
  115. is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
  116. "The searchbox data wasn't parsed correctly.");
  117. ok(isCaretPos(gPanel, 26, 11 + token.length),
  118. "The editor didn't jump to the correct token (6).");
  119. setText(gSearchBox, ":bogus#" + token + ";");
  120. is(gFiltering.searchData.toSource(), '["#", [":bogus", "debugger;"]]',
  121. "The searchbox data wasn't parsed correctly.");
  122. ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
  123. "The editor didn't jump to the correct token (7).");
  124. setText(gSearchBox, ":13#" + token + ";");
  125. is(gFiltering.searchData.toSource(), '["#", [":13", "debugger;"]]',
  126. "The searchbox data wasn't parsed correctly.");
  127. ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
  128. "The editor didn't jump to the correct token (8).");
  129. setText(gSearchBox, ":#" + token + ";");
  130. is(gFiltering.searchData.toSource(), '["#", [":", "debugger;"]]',
  131. "The searchbox data wasn't parsed correctly.");
  132. ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
  133. "The editor didn't jump to the correct token (9).");
  134. setText(gSearchBox, "::#" + token + ";");
  135. is(gFiltering.searchData.toSource(), '["#", ["::", "debugger;"]]',
  136. "The searchbox data wasn't parsed correctly.");
  137. ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
  138. "The editor didn't jump to the correct token (10).");
  139. setText(gSearchBox, ":::#" + token + ";");
  140. is(gFiltering.searchData.toSource(), '["#", [":::", "debugger;"]]',
  141. "The searchbox data wasn't parsed correctly.");
  142. ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
  143. "The editor didn't jump to the correct token (11).");
  144. setText(gSearchBox, "#" + token + ";" + ":bogus");
  145. is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:bogus"]]',
  146. "The searchbox data wasn't parsed correctly.");
  147. ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
  148. "The editor didn't jump to the correct token (12).");
  149. setText(gSearchBox, "#" + token + ";" + ":13");
  150. is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:13"]]',
  151. "The searchbox data wasn't parsed correctly.");
  152. ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
  153. "The editor didn't jump to the correct token (13).");
  154. setText(gSearchBox, "#" + token + ";" + ":");
  155. is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:"]]',
  156. "The searchbox data wasn't parsed correctly.");
  157. ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
  158. "The editor didn't jump to the correct token (14).");
  159. setText(gSearchBox, "#" + token + ";" + "::");
  160. is(gFiltering.searchData.toSource(), '["#", ["", "debugger;::"]]',
  161. "The searchbox data wasn't parsed correctly.");
  162. ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
  163. "The editor didn't jump to the correct token (15).");
  164. setText(gSearchBox, "#" + token + ";" + ":::");
  165. is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:::"]]',
  166. "The searchbox data wasn't parsed correctly.");
  167. ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
  168. "The editor didn't jump to the correct token (16).");
  169. setText(gSearchBox, ":i am not a number");
  170. is(gFiltering.searchData.toSource(), '[":", ["", 0]]',
  171. "The searchbox data wasn't parsed correctly.");
  172. ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
  173. "The editor didn't remain at the correct token (17).");
  174. setText(gSearchBox, "#__i do not exist__");
  175. is(gFiltering.searchData.toSource(), '["#", ["", "__i do not exist__"]]',
  176. "The searchbox data wasn't parsed correctly.");
  177. ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
  178. "The editor didn't remain at the correct token (18).");
  179. setText(gSearchBox, "#" + token);
  180. is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
  181. "The searchbox data wasn't parsed correctly.");
  182. ok(isCaretPos(gPanel, 8, 12 + token.length),
  183. "The editor didn't jump to the correct token (19).");
  184. clearText(gSearchBox);
  185. is(gFiltering.searchData.toSource(), '["", [""]]',
  186. "The searchbox data wasn't parsed correctly.");
  187. EventUtils.sendKey("RETURN", gDebugger);
  188. is(gFiltering.searchData.toSource(), '["", [""]]',
  189. "The searchbox data wasn't parsed correctly.");
  190. ok(isCaretPos(gPanel, 8, 12 + token.length),
  191. "The editor shouldn't jump to another token (20).");
  192. EventUtils.sendKey("RETURN", gDebugger);
  193. is(gFiltering.searchData.toSource(), '["", [""]]',
  194. "The searchbox data wasn't parsed correctly.");
  195. ok(isCaretPos(gPanel, 8, 12 + token.length),
  196. "The editor shouldn't jump to another token (21).");
  197. setText(gSearchBox, ":1:2:3:a:b:c:::12");
  198. is(gFiltering.searchData.toSource(), '[":", [":1:2:3:a:b:c::", 12]]',
  199. "The searchbox data wasn't parsed correctly.");
  200. ok(isCaretPos(gPanel, 12),
  201. "The editor didn't jump to the correct line (22).");
  202. setText(gSearchBox, "#don't#find#me#instead#find#" + token);
  203. is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
  204. "The searchbox data wasn't parsed correctly.");
  205. ok(isCaretPos(gPanel, 8, 12 + token.length),
  206. "The editor didn't jump to the correct token (23).");
  207. EventUtils.sendKey("DOWN", gDebugger);
  208. is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
  209. "The searchbox data wasn't parsed correctly.");
  210. ok(isCaretPos(gPanel, 14, 9 + token.length),
  211. "The editor didn't jump to the correct token (24).");
  212. EventUtils.sendKey("DOWN", gDebugger);
  213. is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
  214. "The searchbox data wasn't parsed correctly.");
  215. ok(isCaretPos(gPanel, 18, 15 + token.length),
  216. "The editor didn't jump to the correct token (25).");
  217. EventUtils.sendKey("RETURN", gDebugger);
  218. is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
  219. "The searchbox data wasn't parsed correctly.");
  220. ok(isCaretPos(gPanel, 26, 11 + token.length),
  221. "The editor didn't jump to the correct token (26).");
  222. EventUtils.sendKey("RETURN", gDebugger);
  223. is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
  224. "The searchbox data wasn't parsed correctly.");
  225. ok(isCaretPos(gPanel, 8, 12 + token.length),
  226. "The editor didn't jump to the correct token (27).");
  227. EventUtils.sendKey("UP", gDebugger);
  228. is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
  229. "The searchbox data wasn't parsed correctly.");
  230. ok(isCaretPos(gPanel, 26, 11 + token.length),
  231. "The editor didn't jump to the correct token (28).");
  232. clearText(gSearchBox);
  233. is(gFiltering.searchData.toSource(), '["", [""]]',
  234. "The searchbox data wasn't parsed correctly.");
  235. ok(isCaretPos(gPanel, 26, 11 + token.length),
  236. "The editor didn't remain at the correct token (29).");
  237. is(gSources.visibleItems.length, 1,
  238. "Not all the sources are shown after the search (30).");
  239. gEditor.focus();
  240. gEditor.setSelection.apply(gEditor, gEditor.getPosition(1, 5));
  241. ok(isCaretPos(gPanel, 1, 6),
  242. "The editor caret position didn't update after selecting some text.");
  243. EventUtils.synthesizeKey("F", { accelKey: true });
  244. is(gFiltering.searchData.toSource(), '["#", ["", "!-- "]]',
  245. "The searchbox data wasn't parsed correctly.");
  246. is(gSearchBox.value, "#!-- ",
  247. "The search field has the right initial value (1).");
  248. gEditor.focus();
  249. gEditor.setSelection.apply(gEditor, gEditor.getPosition(415, 418));
  250. ok(isCaretPos(gPanel, 21, 30),
  251. "The editor caret position didn't update after selecting some number.");
  252. EventUtils.synthesizeKey("L", { accelKey: true });
  253. is(gFiltering.searchData.toSource(), '[":", ["", 100]]',
  254. "The searchbox data wasn't parsed correctly.");
  255. is(gSearchBox.value, ":100",
  256. "The search field has the right initial value (2).");
  257. closeDebuggerAndFinish(gPanel);
  258. }
  259. registerCleanupFunction(function () {
  260. gTab = null;
  261. gPanel = null;
  262. gDebugger = null;
  263. gEditor = null;
  264. gSources = null;
  265. gFiltering = null;
  266. gSearchBox = null;
  267. });