browser_dbg_searchbox-help-popup-02.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * Make sure that the searchbox popup isn't displayed when there's some text
  6. * already present.
  7. */
  8. const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
  9. var gTab, gPanel, gDebugger;
  10. var gEditor, gSearchBox, gSearchBoxPanel;
  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. gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
  22. gSearchBoxPanel = gDebugger.DebuggerView.Filtering._searchboxHelpPanel;
  23. once(gSearchBoxPanel, "popupshown").then(() => {
  24. ok(false, "Damn it, this shouldn't have happened.");
  25. });
  26. waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
  27. .then(tryShowPopup)
  28. .then(focusEditor)
  29. .then(testFocusLost)
  30. .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
  31. .then(null, aError => {
  32. ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
  33. });
  34. callInTab(gTab, "firstCall");
  35. });
  36. }
  37. function tryShowPopup() {
  38. setText(gSearchBox, "#call()");
  39. ok(isCaretPos(gPanel, 4, 22),
  40. "The editor caret position appears to be correct.");
  41. ok(isEditorSel(gPanel, [125, 131]),
  42. "The editor selection appears to be correct.");
  43. is(gEditor.getSelection(), "Call()",
  44. "The editor selected text appears to be correct.");
  45. is(gSearchBoxPanel.state, "closed",
  46. "The search box panel shouldn't be visible yet.");
  47. EventUtils.sendMouseEvent({ type: "click" }, gSearchBox, gDebugger);
  48. }
  49. function focusEditor() {
  50. let deferred = promise.defer();
  51. // Focusing the editor takes a tick to update the caret and selection.
  52. gEditor.focus();
  53. executeSoon(deferred.resolve);
  54. return deferred.promise;
  55. }
  56. function testFocusLost() {
  57. ok(isCaretPos(gPanel, 4, 22),
  58. "The editor caret position appears to be correct after gaining focus.");
  59. ok(isEditorSel(gPanel, [125, 131]),
  60. "The editor selection appears to be correct after gaining focus.");
  61. is(gEditor.getSelection(), "Call()",
  62. "The editor selected text appears to be correct after gaining focus.");
  63. is(gSearchBoxPanel.state, "closed",
  64. "The search box panel should still not be visible.");
  65. }
  66. registerCleanupFunction(function () {
  67. gTab = null;
  68. gPanel = null;
  69. gDebugger = null;
  70. gEditor = null;
  71. gSearchBox = null;
  72. gSearchBoxPanel = null;
  73. });