browser_dbg_search-basic-04.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 that the selection is dropped for line and token searches, after
  6. * pressing backspace enough times.
  7. */
  8. const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
  9. var gTab, gPanel, gDebugger;
  10. var gEditor, gSources, 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. gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
  23. testLineSearch();
  24. testTokenSearch();
  25. closeDebuggerAndFinish(gPanel);
  26. });
  27. }
  28. function testLineSearch() {
  29. setText(gSearchBox, ":42");
  30. ok(isCaretPos(gPanel, 7),
  31. "The editor caret position appears to be correct (1.1).");
  32. ok(isEditorSel(gPanel, [151, 151]),
  33. "The editor selection appears to be correct (1.1).");
  34. is(gEditor.getSelection(), "",
  35. "The editor selected text appears to be correct (1.1).");
  36. backspaceText(gSearchBox, 1);
  37. ok(isCaretPos(gPanel, 4),
  38. "The editor caret position appears to be correct (1.2).");
  39. ok(isEditorSel(gPanel, [110, 110]),
  40. "The editor selection appears to be correct (1.2).");
  41. is(gEditor.getSelection(), "",
  42. "The editor selected text appears to be correct (1.2).");
  43. backspaceText(gSearchBox, 1);
  44. ok(isCaretPos(gPanel, 4),
  45. "The editor caret position appears to be correct (1.3).");
  46. ok(isEditorSel(gPanel, [110, 110]),
  47. "The editor selection appears to be correct (1.3).");
  48. is(gEditor.getSelection(), "",
  49. "The editor selected text appears to be correct (1.3).");
  50. setText(gSearchBox, ":4");
  51. ok(isCaretPos(gPanel, 4),
  52. "The editor caret position appears to be correct (1.4).");
  53. ok(isEditorSel(gPanel, [110, 110]),
  54. "The editor selection appears to be correct (1.4).");
  55. is(gEditor.getSelection(), "",
  56. "The editor selected text appears to be correct (1.4).");
  57. gSearchBox.select();
  58. backspaceText(gSearchBox, 1);
  59. ok(isCaretPos(gPanel, 4),
  60. "The editor caret position appears to be correct (1.5).");
  61. ok(isEditorSel(gPanel, [110, 110]),
  62. "The editor selection appears to be correct (1.5).");
  63. is(gEditor.getSelection(), "",
  64. "The editor selected text appears to be correct (1.5).");
  65. is(gSearchBox.value, "",
  66. "The searchbox should have been cleared.");
  67. }
  68. function testTokenSearch() {
  69. setText(gSearchBox, "#();");
  70. ok(isCaretPos(gPanel, 5, 16),
  71. "The editor caret position appears to be correct (2.1).");
  72. ok(isEditorSel(gPanel, [145, 148]),
  73. "The editor selection appears to be correct (2.1).");
  74. is(gEditor.getSelection(), "();",
  75. "The editor selected text appears to be correct (2.1).");
  76. backspaceText(gSearchBox, 1);
  77. ok(isCaretPos(gPanel, 4, 21),
  78. "The editor caret position appears to be correct (2.2).");
  79. ok(isEditorSel(gPanel, [128, 130]),
  80. "The editor selection appears to be correct (2.2).");
  81. is(gEditor.getSelection(), "()",
  82. "The editor selected text appears to be correct (2.2).");
  83. backspaceText(gSearchBox, 2);
  84. ok(isCaretPos(gPanel, 4, 20),
  85. "The editor caret position appears to be correct (2.3).");
  86. ok(isEditorSel(gPanel, [129, 129]),
  87. "The editor selection appears to be correct (2.3).");
  88. is(gEditor.getSelection(), "",
  89. "The editor selected text appears to be correct (2.3).");
  90. setText(gSearchBox, "#;");
  91. ok(isCaretPos(gPanel, 5, 16),
  92. "The editor caret position appears to be correct (2.4).");
  93. ok(isEditorSel(gPanel, [147, 148]),
  94. "The editor selection appears to be correct (2.4).");
  95. is(gEditor.getSelection(), ";",
  96. "The editor selected text appears to be correct (2.4).");
  97. gSearchBox.select();
  98. backspaceText(gSearchBox, 1);
  99. ok(isCaretPos(gPanel, 5, 16),
  100. "The editor caret position appears to be correct (2.5).");
  101. ok(isEditorSel(gPanel, [148, 148]),
  102. "The editor selection appears to be correct (2.5).");
  103. is(gEditor.getSelection(), "",
  104. "The editor selected text appears to be correct (2.5).");
  105. is(gSearchBox.value, "",
  106. "The searchbox should have been cleared.");
  107. }
  108. registerCleanupFunction(function () {
  109. gTab = null;
  110. gPanel = null;
  111. gDebugger = null;
  112. gEditor = null;
  113. gSources = null;
  114. gSearchBox = null;
  115. });