browser_dbg_search-global-06.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 hidden when they're supposed to
  6. * (after a focus lost, or when ESCAPE is pressed).
  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(doSearch)
  26. .then(testFocusLost)
  27. .then(doSearch)
  28. .then(testEscape)
  29. .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
  30. .then(null, aError => {
  31. ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
  32. });
  33. callInTab(gTab, "firstCall");
  34. });
  35. }
  36. function doSearch() {
  37. let deferred = promise.defer();
  38. is(gSearchView.itemCount, 0,
  39. "The global search pane shouldn't have any entries yet.");
  40. is(gSearchView.widget._parent.hidden, true,
  41. "The global search pane shouldn't be visible yet.");
  42. is(gSearchView._splitter.hidden, true,
  43. "The global search pane splitter shouldn't be visible yet.");
  44. gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
  45. // Some operations are synchronously dispatched on the main thread,
  46. // to avoid blocking UI, thus giving the impression of faster searching.
  47. executeSoon(() => {
  48. info("Current source url:\n" + getSelectedSourceURL(gSources));
  49. info("Debugger editor text:\n" + gEditor.getText());
  50. ok(isCaretPos(gPanel, 6),
  51. "The editor shouldn't have jumped to a matching line yet.");
  52. ok(getSelectedSourceURL(gSources).includes("-02.js"),
  53. "The current source shouldn't have changed after a global search.");
  54. is(gSources.visibleItems.length, 2,
  55. "Not all the sources are shown after the global search.");
  56. deferred.resolve();
  57. });
  58. });
  59. setText(gSearchBox, "!a");
  60. return deferred.promise;
  61. }
  62. function testFocusLost() {
  63. is(gSearchView.itemCount, 2,
  64. "The global search pane should have some entries from the previous search.");
  65. is(gSearchView.widget._parent.hidden, false,
  66. "The global search pane should be visible from the previous search.");
  67. is(gSearchView._splitter.hidden, false,
  68. "The global search pane splitter should be visible from the previous search.");
  69. gDebugger.DebuggerView.editor.focus();
  70. info("Current source url:\n" + getSelectedSourceURL(gSources));
  71. info("Debugger editor text:\n" + gEditor.getText());
  72. is(gSearchView.itemCount, 0,
  73. "The global search pane shouldn't have any child nodes after clearing.");
  74. is(gSearchView.widget._parent.hidden, true,
  75. "The global search pane shouldn't be visible after clearing.");
  76. is(gSearchView._splitter.hidden, true,
  77. "The global search pane splitter shouldn't be visible after clearing.");
  78. }
  79. function testEscape() {
  80. is(gSearchView.itemCount, 2,
  81. "The global search pane should have some entries from the previous search.");
  82. is(gSearchView.widget._parent.hidden, false,
  83. "The global search pane should be visible from the previous search.");
  84. is(gSearchView._splitter.hidden, false,
  85. "The global search pane splitter should be visible from the previous search.");
  86. gSearchBox.focus();
  87. EventUtils.sendKey("ESCAPE", gDebugger);
  88. is(gSearchView.itemCount, 0,
  89. "The global search pane shouldn't have any child nodes after clearing.");
  90. is(gSearchView.widget._parent.hidden, true,
  91. "The global search pane shouldn't be visible after clearing.");
  92. is(gSearchView._splitter.hidden, true,
  93. "The global search pane splitter shouldn't be visible after clearing.");
  94. }
  95. registerCleanupFunction(function () {
  96. gTab = null;
  97. gPanel = null;
  98. gDebugger = null;
  99. gEditor = null;
  100. gSources = null;
  101. gSearchView = null;
  102. gSearchBox = null;
  103. });