browser_dbg_search-global-03.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 are cleared on location changes, and
  6. * the expected UI behaviors are triggered.
  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(performTest)
  27. .then(() => closeDebuggerAndFinish(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. is(gSearchView.itemCount, 0,
  37. "The global search pane shouldn't have any entries yet.");
  38. is(gSearchView.widget._parent.hidden, true,
  39. "The global search pane shouldn't be visible yet.");
  40. is(gSearchView._splitter.hidden, true,
  41. "The global search pane splitter shouldn't be visible yet.");
  42. gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
  43. // Some operations are synchronously dispatched on the main thread,
  44. // to avoid blocking UI, thus giving the impression of faster searching.
  45. executeSoon(() => {
  46. info("Current source url:\n" + getSelectedSourceURL(gSources));
  47. info("Debugger editor text:\n" + gEditor.getText());
  48. ok(isCaretPos(gPanel, 6),
  49. "The editor shouldn't have jumped to a matching line yet.");
  50. ok(getSelectedSourceURL(gSources).includes("-02.js"),
  51. "The current source shouldn't have changed after a global search.");
  52. is(gSources.visibleItems.length, 2,
  53. "Not all the sources are shown after the global search.");
  54. deferred.resolve();
  55. });
  56. });
  57. setText(gSearchBox, "!function");
  58. return deferred.promise;
  59. }
  60. function performTest() {
  61. let deferred = promise.defer();
  62. is(gSearchView.itemCount, 2,
  63. "The global search pane should have some entries from the previous search.");
  64. is(gSearchView.widget._parent.hidden, false,
  65. "The global search pane should be visible from the previous search.");
  66. is(gSearchView._splitter.hidden, false,
  67. "The global search pane splitter should be visible from the previous search.");
  68. reloadActiveTab(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(() => {
  69. info("Current source url:\n" + getSelectedSourceURL(gSources));
  70. info("Debugger editor text:\n" + gEditor.getText());
  71. is(gSearchView.itemCount, 0,
  72. "The global search pane shouldn't have any entries after a page navigation.");
  73. is(gSearchView.widget._parent.hidden, true,
  74. "The global search pane shouldn't be visible after a page navigation.");
  75. is(gSearchView._splitter.hidden, true,
  76. "The global search pane splitter shouldn't be visible after a page navigation.");
  77. deferred.resolve();
  78. });
  79. return deferred.promise;
  80. }
  81. registerCleanupFunction(function () {
  82. gTab = null;
  83. gPanel = null;
  84. gDebugger = null;
  85. gEditor = null;
  86. gSources = null;
  87. gSearchView = null;
  88. gSearchBox = null;
  89. });