browser_dbg_search-symbols.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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 if the function searching works properly.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_function-search.html";
  8. var gTab, gPanel, gDebugger;
  9. var gEditor, gSources, gSearchBox, gFilteredFunctions;
  10. function test() {
  11. let options = {
  12. source: EXAMPLE_URL + "code_function-search-01.js",
  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. gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
  22. gFilteredFunctions = gDebugger.DebuggerView.Filtering.FilteredFunctions;
  23. showSource("doc_function-search.html")
  24. .then(htmlSearch)
  25. .then(() => showSource("code_function-search-01.js"))
  26. .then(firstJsSearch)
  27. .then(() => showSource("code_function-search-02.js"))
  28. .then(secondJsSearch)
  29. .then(() => showSource("code_function-search-03.js"))
  30. .then(thirdJsSearch)
  31. .then(saveSearch)
  32. .then(filterSearch)
  33. .then(bogusSearch)
  34. .then(incrementalSearch)
  35. .then(emptySearch)
  36. .then(() => closeDebuggerAndFinish(gPanel))
  37. .then(null, aError => {
  38. ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
  39. });
  40. });
  41. }
  42. function htmlSearch() {
  43. let deferred = promise.defer();
  44. once(gDebugger, "popupshown").then(() => {
  45. writeInfo();
  46. is(gFilteredFunctions.selectedIndex, 0,
  47. "An item should be selected in the filtered functions view (1).");
  48. ok(gFilteredFunctions.selectedItem,
  49. "An item should be selected in the filtered functions view (2).");
  50. if (gSources.selectedItem.attachment.source.url.indexOf(".html") != -1) {
  51. let expectedResults = [
  52. ["inline", ".html", "", 19, 16],
  53. ["arrow", ".html", "", 20, 11],
  54. ["foo", ".html", "", 22, 11],
  55. ["foo2", ".html", "", 23, 11],
  56. ["bar2", ".html", "", 23, 18]
  57. ];
  58. for (let [label, value, description, line, column] of expectedResults) {
  59. let target = gFilteredFunctions.selectedItem.target;
  60. if (label) {
  61. is(target.querySelector(".results-panel-item-label").getAttribute("value"),
  62. gDebugger.SourceUtils.trimUrlLength(label + "()"),
  63. "The correct label (" + label + ") is currently selected.");
  64. } else {
  65. ok(!target.querySelector(".results-panel-item-label"),
  66. "Shouldn't create empty label nodes.");
  67. }
  68. if (value) {
  69. ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").includes(value),
  70. "The correct value (" + value + ") is attached.");
  71. } else {
  72. ok(!target.querySelector(".results-panel-item-label-below"),
  73. "Shouldn't create empty label nodes.");
  74. }
  75. if (description) {
  76. is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description,
  77. "The correct description (" + description + ") is currently shown.");
  78. } else {
  79. ok(!target.querySelector(".results-panel-item-label-before"),
  80. "Shouldn't create empty label nodes.");
  81. }
  82. ok(isCaretPos(gPanel, line, column),
  83. "The editor didn't jump to the correct line.");
  84. EventUtils.sendKey("DOWN", gDebugger);
  85. }
  86. ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]),
  87. "The editor didn't jump to the correct line again.");
  88. deferred.resolve();
  89. } else {
  90. ok(false, "How did you get here? Go away, you.");
  91. }
  92. });
  93. setText(gSearchBox, "@");
  94. return deferred.promise;
  95. }
  96. function firstJsSearch() {
  97. let deferred = promise.defer();
  98. once(gDebugger, "popupshown").then(() => {
  99. writeInfo();
  100. is(gFilteredFunctions.selectedIndex, 0,
  101. "An item should be selected in the filtered functions view (1).");
  102. ok(gFilteredFunctions.selectedItem,
  103. "An item should be selected in the filtered functions view (2).");
  104. if (gSources.selectedItem.attachment.source.url.indexOf("-01.js") != -1) {
  105. let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " ";
  106. let expectedResults = [
  107. ["test", "-01.js", "", 4, 10],
  108. ["anonymousExpression", "-01.js", "test.prototype", 9, 3],
  109. ["namedExpression" + s + "NAME", "-01.js", "test.prototype", 11, 3],
  110. ["a_test", "-01.js", "foo", 22, 3],
  111. ["n_test" + s + "x", "-01.js", "foo", 24, 3],
  112. ["a_test", "-01.js", "foo.sub", 27, 5],
  113. ["n_test" + s + "y", "-01.js", "foo.sub", 29, 5],
  114. ["a_test", "-01.js", "foo.sub.sub", 32, 7],
  115. ["n_test" + s + "z", "-01.js", "foo.sub.sub", 34, 7],
  116. ["test_SAME_NAME", "-01.js", "foo.sub.sub.sub", 37, 9]
  117. ];
  118. for (let [label, value, description, line, column] of expectedResults) {
  119. let target = gFilteredFunctions.selectedItem.target;
  120. if (label) {
  121. is(target.querySelector(".results-panel-item-label").getAttribute("value"),
  122. gDebugger.SourceUtils.trimUrlLength(label + "()"),
  123. "The correct label (" + label + ") is currently selected.");
  124. } else {
  125. ok(!target.querySelector(".results-panel-item-label"),
  126. "Shouldn't create empty label nodes.");
  127. }
  128. if (value) {
  129. ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").includes(value),
  130. "The correct value (" + value + ") is attached.");
  131. } else {
  132. ok(!target.querySelector(".results-panel-item-label-below"),
  133. "Shouldn't create empty label nodes.");
  134. }
  135. if (description) {
  136. is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description,
  137. "The correct description (" + description + ") is currently shown.");
  138. } else {
  139. ok(!target.querySelector(".results-panel-item-label-before"),
  140. "Shouldn't create empty label nodes.");
  141. }
  142. ok(isCaretPos(gPanel, line, column),
  143. "The editor didn't jump to the correct line.");
  144. EventUtils.sendKey("DOWN", gDebugger);
  145. }
  146. ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]),
  147. "The editor didn't jump to the correct line again.");
  148. deferred.resolve();
  149. } else {
  150. ok(false, "How did you get here? Go away, you.");
  151. }
  152. });
  153. setText(gSearchBox, "@");
  154. return deferred.promise;
  155. }
  156. function secondJsSearch() {
  157. let deferred = promise.defer();
  158. once(gDebugger, "popupshown").then(() => {
  159. writeInfo();
  160. is(gFilteredFunctions.selectedIndex, 0,
  161. "An item should be selected in the filtered functions view (1).");
  162. ok(gFilteredFunctions.selectedItem,
  163. "An item should be selected in the filtered functions view (2).");
  164. if (gSources.selectedItem.attachment.source.url.indexOf("-02.js") != -1) {
  165. let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " ";
  166. let expectedResults = [
  167. ["test2", "-02.js", "", 4, 5],
  168. ["test3" + s + "test3_NAME", "-02.js", "", 8, 5],
  169. ["test4_SAME_NAME", "-02.js", "", 11, 5],
  170. ["x" + s + "X", "-02.js", "test.prototype", 14, 1],
  171. ["y" + s + "Y", "-02.js", "test.prototype.sub", 16, 1],
  172. ["z" + s + "Z", "-02.js", "test.prototype.sub.sub", 18, 1],
  173. ["t", "-02.js", "test.prototype.sub.sub.sub", 20, 1],
  174. ["x", "-02.js", "this", 20, 32],
  175. ["y", "-02.js", "this", 20, 41],
  176. ["z", "-02.js", "this", 20, 50]
  177. ];
  178. for (let [label, value, description, line, column] of expectedResults) {
  179. let target = gFilteredFunctions.selectedItem.target;
  180. if (label) {
  181. is(target.querySelector(".results-panel-item-label").getAttribute("value"),
  182. gDebugger.SourceUtils.trimUrlLength(label + "()"),
  183. "The correct label (" + label + ") is currently selected.");
  184. } else {
  185. ok(!target.querySelector(".results-panel-item-label"),
  186. "Shouldn't create empty label nodes.");
  187. }
  188. if (value) {
  189. ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").includes(value),
  190. "The correct value (" + value + ") is attached.");
  191. } else {
  192. ok(!target.querySelector(".results-panel-item-label-below"),
  193. "Shouldn't create empty label nodes.");
  194. }
  195. if (description) {
  196. is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description,
  197. "The correct description (" + description + ") is currently shown.");
  198. } else {
  199. ok(!target.querySelector(".results-panel-item-label-before"),
  200. "Shouldn't create empty label nodes.");
  201. }
  202. ok(isCaretPos(gPanel, line, column),
  203. "The editor didn't jump to the correct line.");
  204. EventUtils.sendKey("DOWN", gDebugger);
  205. }
  206. ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]),
  207. "The editor didn't jump to the correct line again.");
  208. deferred.resolve();
  209. } else {
  210. ok(false, "How did you get here? Go away, you.");
  211. }
  212. });
  213. setText(gSearchBox, "@");
  214. return deferred.promise;
  215. }
  216. function thirdJsSearch() {
  217. let deferred = promise.defer();
  218. once(gDebugger, "popupshown").then(() => {
  219. writeInfo();
  220. is(gFilteredFunctions.selectedIndex, 0,
  221. "An item should be selected in the filtered functions view (1).");
  222. ok(gFilteredFunctions.selectedItem,
  223. "An item should be selected in the filtered functions view (2).");
  224. if (gSources.selectedItem.attachment.source.url.indexOf("-03.js") != -1) {
  225. let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " ";
  226. let expectedResults = [
  227. ["namedEventListener", "-03.js", "", 4, 43],
  228. ["a" + s + "A", "-03.js", "bar", 10, 5],
  229. ["b" + s + "B", "-03.js", "bar.alpha", 15, 5],
  230. ["c" + s + "C", "-03.js", "bar.alpha.beta", 20, 5],
  231. ["d" + s + "D", "-03.js", "this.theta", 25, 5],
  232. ["fun", "-03.js", "", 29, 7],
  233. ["foo", "-03.js", "", 29, 13],
  234. ["bar", "-03.js", "", 29, 19],
  235. ["t_foo", "-03.js", "this", 29, 25],
  236. ["w_bar" + s + "baz", "-03.js", "window", 29, 38]
  237. ];
  238. for (let [label, value, description, line, column] of expectedResults) {
  239. let target = gFilteredFunctions.selectedItem.target;
  240. if (label) {
  241. is(target.querySelector(".results-panel-item-label").getAttribute("value"),
  242. gDebugger.SourceUtils.trimUrlLength(label + "()"),
  243. "The correct label (" + label + ") is currently selected.");
  244. } else {
  245. ok(!target.querySelector(".results-panel-item-label"),
  246. "Shouldn't create empty label nodes.");
  247. }
  248. if (value) {
  249. ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").includes(value),
  250. "The correct value (" + value + ") is attached.");
  251. } else {
  252. ok(!target.querySelector(".results-panel-item-label-below"),
  253. "Shouldn't create empty label nodes.");
  254. }
  255. if (description) {
  256. is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description,
  257. "The correct description (" + description + ") is currently shown.");
  258. } else {
  259. ok(!target.querySelector(".results-panel-item-label-before"),
  260. "Shouldn't create empty label nodes.");
  261. }
  262. ok(isCaretPos(gPanel, line, column),
  263. "The editor didn't jump to the correct line.");
  264. EventUtils.sendKey("DOWN", gDebugger);
  265. }
  266. ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]),
  267. "The editor didn't jump to the correct line again.");
  268. deferred.resolve();
  269. } else {
  270. ok(false, "How did you get here? Go away, you.");
  271. }
  272. });
  273. setText(gSearchBox, "@");
  274. return deferred.promise;
  275. }
  276. function filterSearch() {
  277. let deferred = promise.defer();
  278. once(gDebugger, "popupshown").then(() => {
  279. writeInfo();
  280. is(gFilteredFunctions.selectedIndex, 0,
  281. "An item should be selected in the filtered functions view (1).");
  282. ok(gFilteredFunctions.selectedItem,
  283. "An item should be selected in the filtered functions view (2).");
  284. if (gSources.selectedItem.attachment.source.url.indexOf("-03.js") != -1) {
  285. let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " ";
  286. let expectedResults = [
  287. ["namedEventListener", "-03.js", "", 4, 43],
  288. ["bar", "-03.js", "", 29, 19],
  289. ["w_bar" + s + "baz", "-03.js", "window", 29, 38],
  290. ["anonymousExpression", "-01.js", "test.prototype", 9, 3],
  291. ["namedExpression" + s + "NAME", "-01.js", "test.prototype", 11, 3],
  292. ["arrow", ".html", "", 20, 11],
  293. ["bar2", ".html", "", 23, 18]
  294. ];
  295. for (let [label, value, description, line, column] of expectedResults) {
  296. let target = gFilteredFunctions.selectedItem.target;
  297. if (label) {
  298. is(target.querySelector(".results-panel-item-label").getAttribute("value"),
  299. gDebugger.SourceUtils.trimUrlLength(label + "()"),
  300. "The correct label (" + label + ") is currently selected.");
  301. } else {
  302. ok(!target.querySelector(".results-panel-item-label"),
  303. "Shouldn't create empty label nodes.");
  304. }
  305. if (value) {
  306. ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").includes(value),
  307. "The correct value (" + value + ") is attached.");
  308. } else {
  309. ok(!target.querySelector(".results-panel-item-label-below"),
  310. "Shouldn't create empty label nodes.");
  311. }
  312. if (description) {
  313. is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description,
  314. "The correct description (" + description + ") is currently shown.");
  315. } else {
  316. ok(!target.querySelector(".results-panel-item-label-before"),
  317. "Shouldn't create empty label nodes.");
  318. }
  319. ok(isCaretPos(gPanel, line, column),
  320. "The editor didn't jump to the correct line.");
  321. EventUtils.sendKey("DOWN", gDebugger);
  322. }
  323. ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]),
  324. "The editor didn't jump to the correct line again.");
  325. deferred.resolve();
  326. } else {
  327. ok(false, "How did you get here? Go away, you.");
  328. }
  329. });
  330. setText(gSearchBox, "@r");
  331. return deferred.promise;
  332. }
  333. function bogusSearch() {
  334. let deferred = promise.defer();
  335. once(gDebugger, "popuphidden").then(() => {
  336. ok(true, "Popup was successfully hidden after no matches were found.");
  337. deferred.resolve();
  338. });
  339. setText(gSearchBox, "@bogus");
  340. return deferred.promise;
  341. }
  342. function incrementalSearch() {
  343. let deferred = promise.defer();
  344. once(gDebugger, "popupshown").then(() => {
  345. ok(true, "Popup was successfully shown after some matches were found.");
  346. deferred.resolve();
  347. });
  348. setText(gSearchBox, "@NAME");
  349. return deferred.promise;
  350. }
  351. function emptySearch() {
  352. let deferred = promise.defer();
  353. once(gDebugger, "popuphidden").then(() => {
  354. ok(true, "Popup was successfully hidden when nothing was searched.");
  355. deferred.resolve();
  356. });
  357. clearText(gSearchBox);
  358. return deferred.promise;
  359. }
  360. function showSource(aLabel) {
  361. let deferred = promise.defer();
  362. waitForSourceShown(gPanel, aLabel).then(deferred.resolve);
  363. gSources.selectedItem = e => e.attachment.label == aLabel;
  364. return deferred.promise;
  365. }
  366. function saveSearch() {
  367. let finished = once(gDebugger, "popuphidden");
  368. // Either by pressing RETURN or clicking on an item in the popup,
  369. // the popup should hide and the item should become selected.
  370. let random = Math.random();
  371. if (random >= 0.33) {
  372. EventUtils.sendKey("RETURN", gDebugger);
  373. } else if (random >= 0.66) {
  374. EventUtils.sendKey("RETURN", gDebugger);
  375. } else {
  376. EventUtils.sendMouseEvent({ type: "click" },
  377. gFilteredFunctions.selectedItem.target,
  378. gDebugger);
  379. }
  380. return finished;
  381. }
  382. function writeInfo() {
  383. info("Current source url:\n" + getSelectedSourceURL(gSources));
  384. info("Debugger editor text:\n" + gEditor.getText());
  385. }
  386. registerCleanupFunction(function () {
  387. gTab = null;
  388. gPanel = null;
  389. gDebugger = null;
  390. gEditor = null;
  391. gSources = null;
  392. gSearchBox = null;
  393. gFilteredFunctions = null;
  394. });