browser_dbg_search-global-01.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 functionality of global search (lowercase + upper case, expected
  6. * UI behavior, number of results found etc.)
  7. */
  8. const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
  9. var gTab, gPanel, gDebugger;
  10. var gEditor, gSources, gSearchView, gSearchBox;
  11. function test() {
  12. let options = {
  13. source: EXAMPLE_URL + "code_script-switching-01.js",
  14. line: 1
  15. };
  16. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  17. gTab = aTab;
  18. gPanel = aPanel;
  19. gDebugger = gPanel.panelWin;
  20. gEditor = gDebugger.DebuggerView.editor;
  21. gSources = gDebugger.DebuggerView.Sources;
  22. gSearchView = gDebugger.DebuggerView.GlobalSearch;
  23. gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
  24. waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
  25. .then(firstSearch)
  26. .then(secondSearch)
  27. .then(clearSearch)
  28. .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
  29. .then(null, aError => {
  30. ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
  31. });
  32. callInTab(gTab, "firstCall");
  33. });
  34. }
  35. function firstSearch() {
  36. let deferred = promise.defer();
  37. is(gSearchView.itemCount, 0,
  38. "The global search pane shouldn't have any entries yet.");
  39. is(gSearchView.widget._parent.hidden, true,
  40. "The global search pane shouldn't be visible yet.");
  41. is(gSearchView._splitter.hidden, true,
  42. "The global search pane splitter shouldn't be visible yet.");
  43. gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
  44. // Some operations are synchronously dispatched on the main thread,
  45. // to avoid blocking UI, thus giving the impression of faster searching.
  46. executeSoon(() => {
  47. info("Current source url:\n" + getSelectedSourceURL(gSources));
  48. info("Debugger editor text:\n" + gEditor.getText());
  49. ok(isCaretPos(gPanel, 6),
  50. "The editor shouldn't have jumped to a matching line yet.");
  51. ok(getSelectedSourceURL(gSources).includes("-02.js"),
  52. "The current source shouldn't have changed after a global search.");
  53. is(gSources.visibleItems.length, 2,
  54. "Not all the sources are shown after the global search.");
  55. let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results");
  56. is(sourceResults.length, 2,
  57. "There should be matches found in two sources.");
  58. let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]);
  59. let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]);
  60. is(item0.instance.expanded, true,
  61. "The first source results should automatically be expanded.");
  62. is(item1.instance.expanded, true,
  63. "The second source results should automatically be expanded.");
  64. let searchResult0 = sourceResults[0].querySelectorAll(".dbg-search-result");
  65. let searchResult1 = sourceResults[1].querySelectorAll(".dbg-search-result");
  66. is(searchResult0.length, 1,
  67. "There should be one line result for the first url.");
  68. is(searchResult1.length, 2,
  69. "There should be two line results for the second url.");
  70. let firstLine0 = searchResult0[0];
  71. is(firstLine0.querySelector(".dbg-results-line-number").getAttribute("value"), "1",
  72. "The first result for the first source doesn't have the correct line attached.");
  73. is(firstLine0.querySelectorAll(".dbg-results-line-contents").length, 1,
  74. "The first result for the first source doesn't have the correct number of nodes for a line.");
  75. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string").length, 3,
  76. "The first result for the first source doesn't have the correct number of strings in a line.");
  77. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1,
  78. "The first result for the first source doesn't have the correct number of matches in a line.");
  79. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de",
  80. "The first result for the first source doesn't have the correct match in a line.");
  81. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2,
  82. "The first result for the first source doesn't have the correct number of non-matches in a line.");
  83. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is ",
  84. "The first result for the first source doesn't have the correct non-matches in a line.");
  85. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "dicated to the Public Domain.",
  86. "The first result for the first source doesn't have the correct non-matches in a line.");
  87. let firstLine1 = searchResult1[0];
  88. is(firstLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "1",
  89. "The first result for the second source doesn't have the correct line attached.");
  90. is(firstLine1.querySelectorAll(".dbg-results-line-contents").length, 1,
  91. "The first result for the second source doesn't have the correct number of nodes for a line.");
  92. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string").length, 3,
  93. "The first result for the second source doesn't have the correct number of strings in a line.");
  94. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1,
  95. "The first result for the second source doesn't have the correct number of matches in a line.");
  96. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de",
  97. "The first result for the second source doesn't have the correct match in a line.");
  98. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2,
  99. "The first result for the second source doesn't have the correct number of non-matches in a line.");
  100. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is ",
  101. "The first result for the second source doesn't have the correct non-matches in a line.");
  102. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "dicated to the Public Domain.",
  103. "The first result for the second source doesn't have the correct non-matches in a line.");
  104. let secondLine1 = searchResult1[1];
  105. is(secondLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "6",
  106. "The second result for the second source doesn't have the correct line attached.");
  107. is(secondLine1.querySelectorAll(".dbg-results-line-contents").length, 1,
  108. "The second result for the second source doesn't have the correct number of nodes for a line.");
  109. is(secondLine1.querySelectorAll(".dbg-results-line-contents-string").length, 3,
  110. "The second result for the second source doesn't have the correct number of strings in a line.");
  111. is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1,
  112. "The second result for the second source doesn't have the correct number of matches in a line.");
  113. is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de",
  114. "The second result for the second source doesn't have the correct match in a line.");
  115. is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2,
  116. "The second result for the second source doesn't have the correct number of non-matches in a line.");
  117. is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), " ",
  118. "The second result for the second source doesn't have the correct non-matches in a line.");
  119. is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "bugger;",
  120. "The second result for the second source doesn't have the correct non-matches in a line.");
  121. deferred.resolve();
  122. });
  123. });
  124. setText(gSearchBox, "!de");
  125. return deferred.promise;
  126. }
  127. function secondSearch() {
  128. let deferred = promise.defer();
  129. is(gSearchView.itemCount, 2,
  130. "The global search pane should have some child nodes from the previous search.");
  131. is(gSearchView.widget._parent.hidden, false,
  132. "The global search pane should be visible from the previous search.");
  133. is(gSearchView._splitter.hidden, false,
  134. "The global search pane splitter should be visible from the previous search.");
  135. gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
  136. // Some operations are synchronously dispatched on the main thread,
  137. // to avoid blocking UI, thus giving the impression of faster searching.
  138. executeSoon(() => {
  139. info("Current source url:\n" + getSelectedSourceURL(gSources));
  140. info("Debugger editor text:\n" + gEditor.getText());
  141. ok(isCaretPos(gPanel, 6),
  142. "The editor shouldn't have jumped to a matching line yet.");
  143. ok(getSelectedSourceURL(gSources).includes("-02.js"),
  144. "The current source shouldn't have changed after a global search.");
  145. is(gSources.visibleItems.length, 2,
  146. "Not all the sources are shown after the global search.");
  147. let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results");
  148. is(sourceResults.length, 2,
  149. "There should be matches found in two sources.");
  150. let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]);
  151. let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]);
  152. is(item0.instance.expanded, true,
  153. "The first source results should automatically be expanded.");
  154. is(item1.instance.expanded, true,
  155. "The second source results should automatically be expanded.");
  156. let searchResult0 = sourceResults[0].querySelectorAll(".dbg-search-result");
  157. let searchResult1 = sourceResults[1].querySelectorAll(".dbg-search-result");
  158. is(searchResult0.length, 1,
  159. "There should be one line result for the first url.");
  160. is(searchResult1.length, 1,
  161. "There should be one line result for the second url.");
  162. let firstLine0 = searchResult0[0];
  163. is(firstLine0.querySelector(".dbg-results-line-number").getAttribute("value"), "1",
  164. "The first result for the first source doesn't have the correct line attached.");
  165. is(firstLine0.querySelectorAll(".dbg-results-line-contents").length, 1,
  166. "The first result for the first source doesn't have the correct number of nodes for a line.");
  167. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string").length, 5,
  168. "The first result for the first source doesn't have the correct number of strings in a line.");
  169. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 2,
  170. "The first result for the first source doesn't have the correct number of matches in a line.");
  171. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "ed",
  172. "The first result for the first source doesn't have the correct matches in a line.");
  173. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[1].getAttribute("value"), "ed",
  174. "The first result for the first source doesn't have the correct matches in a line.");
  175. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 3,
  176. "The first result for the first source doesn't have the correct number of non-matches in a line.");
  177. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is d",
  178. "The first result for the first source doesn't have the correct non-matches in a line.");
  179. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "icat",
  180. "The first result for the first source doesn't have the correct non-matches in a line.");
  181. is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[2].getAttribute("value"), " to the Public Domain.",
  182. "The first result for the first source doesn't have the correct non-matches in a line.");
  183. let firstLine1 = searchResult1[0];
  184. is(firstLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "1",
  185. "The first result for the second source doesn't have the correct line attached.");
  186. is(firstLine1.querySelectorAll(".dbg-results-line-contents").length, 1,
  187. "The first result for the second source doesn't have the correct number of nodes for a line.");
  188. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string").length, 5,
  189. "The first result for the second source doesn't have the correct number of strings in a line.");
  190. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 2,
  191. "The first result for the second source doesn't have the correct number of matches in a line.");
  192. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "ed",
  193. "The first result for the second source doesn't have the correct matches in a line.");
  194. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[1].getAttribute("value"), "ed",
  195. "The first result for the second source doesn't have the correct matches in a line.");
  196. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 3,
  197. "The first result for the second source doesn't have the correct number of non-matches in a line.");
  198. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is d",
  199. "The first result for the second source doesn't have the correct non-matches in a line.");
  200. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "icat",
  201. "The first result for the second source doesn't have the correct non-matches in a line.");
  202. is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[2].getAttribute("value"), " to the Public Domain.",
  203. "The first result for the second source doesn't have the correct non-matches in a line.");
  204. deferred.resolve();
  205. });
  206. });
  207. backspaceText(gSearchBox, 2);
  208. typeText(gSearchBox, "ED");
  209. return deferred.promise;
  210. }
  211. function clearSearch() {
  212. gSearchView.clearView();
  213. is(gSearchView.itemCount, 0,
  214. "The global search pane shouldn't have any child nodes after clearing.");
  215. is(gSearchView.widget._parent.hidden, true,
  216. "The global search pane shouldn't be visible after clearing.");
  217. is(gSearchView._splitter.hidden, true,
  218. "The global search pane splitter shouldn't be visible after clearing.");
  219. }
  220. registerCleanupFunction(function () {
  221. gTab = null;
  222. gPanel = null;
  223. gDebugger = null;
  224. gEditor = null;
  225. gSources = null;
  226. gSearchView = null;
  227. gSearchBox = null;
  228. });