browser_dbg_search-basic-03.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Tests that searches which cause a popup to be shown properly handle the
  5. * ESCAPE key.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
  8. var gTab, gPanel, gDebugger;
  9. var gSources, gSearchBox;
  10. function test() {
  11. let options = {
  12. source: EXAMPLE_URL + "code_script-switching-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. gSources = gDebugger.DebuggerView.Sources;
  20. gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
  21. // Calling `firstCall` is going to break into the other script
  22. waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6)
  23. .then(performFileSearch)
  24. .then(escapeAndHide)
  25. .then(escapeAndClear)
  26. .then(() => verifySourceAndCaret("-01.js", 1, 1))
  27. .then(performFunctionSearch)
  28. .then(escapeAndHide)
  29. .then(escapeAndClear)
  30. .then(() => verifySourceAndCaret("-01.js", 4, 10))
  31. .then(performGlobalSearch)
  32. .then(escapeAndClear)
  33. .then(() => verifySourceAndCaret("-01.js", 4, 10))
  34. .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
  35. .then(null, aError => {
  36. ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
  37. });
  38. callInTab(gTab, "firstCall");
  39. });
  40. }
  41. function performFileSearch() {
  42. let finished = promise.all([
  43. ensureSourceIs(gPanel, "-02.js"),
  44. ensureCaretAt(gPanel, 6),
  45. once(gDebugger, "popupshown"),
  46. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
  47. waitForSourceShown(gPanel, "-01.js")
  48. ]);
  49. setText(gSearchBox, ".");
  50. return finished.then(() => promise.all([
  51. ensureSourceIs(gPanel, "-01.js"),
  52. ensureCaretAt(gPanel, 1)
  53. ]));
  54. }
  55. function performFunctionSearch() {
  56. let finished = promise.all([
  57. ensureSourceIs(gPanel, "-01.js"),
  58. ensureCaretAt(gPanel, 1),
  59. once(gDebugger, "popupshown"),
  60. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FUNCTION_SEARCH_MATCH_FOUND)
  61. ]);
  62. setText(gSearchBox, "@");
  63. return finished.then(() => promise.all([
  64. ensureSourceIs(gPanel, "-01.js"),
  65. ensureCaretAt(gPanel, 4, 10)
  66. ]));
  67. }
  68. function performGlobalSearch() {
  69. let finished = promise.all([
  70. ensureSourceIs(gPanel, "-01.js"),
  71. ensureCaretAt(gPanel, 4, 10),
  72. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND)
  73. ]);
  74. setText(gSearchBox, "!first");
  75. return finished.then(() => promise.all([
  76. ensureSourceIs(gPanel, "-01.js"),
  77. ensureCaretAt(gPanel, 4, 10)
  78. ]));
  79. }
  80. function escapeAndHide() {
  81. let finished = once(gDebugger, "popuphidden", true);
  82. EventUtils.sendKey("ESCAPE", gDebugger);
  83. return finished;
  84. }
  85. function escapeAndClear() {
  86. EventUtils.sendKey("ESCAPE", gDebugger);
  87. is(gSearchBox.getAttribute("value"), "",
  88. "The searchbox has properly emptied after pressing escape.");
  89. }
  90. function verifySourceAndCaret(aUrl, aLine, aColumn) {
  91. ok(gSources.selectedItem.attachment.label.includes(aUrl),
  92. "The selected item's label appears to be correct.");
  93. ok(gSources.selectedItem.attachment.source.url.includes(aUrl),
  94. "The selected item's value appears to be correct.");
  95. ok(isCaretPos(gPanel, aLine, aColumn),
  96. "The current caret position appears to be correct.");
  97. }
  98. registerCleanupFunction(function () {
  99. gTab = null;
  100. gPanel = null;
  101. gDebugger = null;
  102. gSources = null;
  103. gSearchBox = null;
  104. });