browser_dbg_search-global-04.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 global search results trigger MatchFound and NoMatchFound events
  6. * properly, and triggers the expected UI behavior.
  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(() => resumeDebuggerThenCloseAndFinish(gPanel))
  28. .then(null, aError => {
  29. ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
  30. });
  31. callInTab(gTab, "firstCall");
  32. });
  33. }
  34. function firstSearch() {
  35. let deferred = promise.defer();
  36. gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
  37. // Some operations are synchronously dispatched on the main thread,
  38. // to avoid blocking UI, thus giving the impression of faster searching.
  39. executeSoon(() => {
  40. info("Current source url:\n" + getSelectedSourceURL(gSources));
  41. info("Debugger editor text:\n" + gEditor.getText());
  42. ok(isCaretPos(gPanel, 6),
  43. "The editor shouldn't have jumped to a matching line yet.");
  44. ok(getSelectedSourceURL(gSources).includes("-02.js"),
  45. "The current source shouldn't have changed after a global search.");
  46. is(gSources.visibleItems.length, 2,
  47. "Not all the sources are shown after the global search.");
  48. deferred.resolve();
  49. });
  50. });
  51. setText(gSearchBox, "!function");
  52. return deferred.promise;
  53. }
  54. function secondSearch() {
  55. let deferred = promise.defer();
  56. gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_NOT_FOUND, () => {
  57. info("Current source url:\n" + getSelectedSourceURL(gSources));
  58. info("Debugger editor text:\n" + gEditor.getText());
  59. ok(isCaretPos(gPanel, 6),
  60. "The editor shouldn't have jumped to a matching line yet.");
  61. ok(getSelectedSourceURL(gSources).includes("-02.js"),
  62. "The current source shouldn't have changed after a global search.");
  63. is(gSources.visibleItems.length, 2,
  64. "Not all the sources are shown after the global search.");
  65. deferred.resolve();
  66. });
  67. typeText(gSearchBox, "/");
  68. return deferred.promise;
  69. }
  70. registerCleanupFunction(function () {
  71. gTab = null;
  72. gPanel = null;
  73. gDebugger = null;
  74. gEditor = null;
  75. gSources = null;
  76. gSearchView = null;
  77. gSearchBox = null;
  78. });