summaryrefslogtreecommitdiffstats
path: root/editor/spellchecker/tests/test_spellcheck_after_pressing_navigation_key.html
blob: 2f0c3bed7d00c14cca7475a3c7fe659985a6096d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!doctype html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1729653
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1729653</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
</head>
<body>
<textarea rows="20" cols="50">That undfgdfg seems OK.</textarea>
<script>
let { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.import(
  "resource://testing-common/AsyncSpellCheckTestHelper.jsm"
);

function waitForTick() {
  return new Promise(resolve => SimpleTest.executeSoon(resolve));
}

function waitForOnSpellCheck(aTextArea) {
  info("Waiting for onSpellCheck...");
  return new Promise(resolve => maybeOnSpellCheck(aTextArea, resolve));
}

/** Test for Bug 1729653 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
  const textarea = document.querySelector("textarea");
  textarea.focus();
  textarea.selectionStart = textarea.selectionEnd = "That undfgdfg".length;
  const editor = SpecialPowers.wrap(textarea).editor;
  const nsISelectionController = SpecialPowers.Ci.nsISelectionController;
  const selection = editor.selectionController.getSelection(nsISelectionController.SELECTION_SPELLCHECK);
  const spellChecker = SpecialPowers.Cu.createSpellChecker();
  spellChecker.InitSpellChecker(editor, false);
  info("Waiting for current dictionary update...");
  await new Promise(resolve => spellChecker.UpdateCurrentDictionary(resolve));
  if (selection.rangeCount === 0) {
    await waitForOnSpellCheck(textarea);
  }
  if (selection.rangeCount == 1) {
    is(
      selection.getRangeAt(0).toString(),
      "undfgdfg",
      "\"undfgdfg\" should be marked as misspelled word at start"
    );
  } else {
    is(selection.rangeCount, 1, "We should have a misspelled word at start");
  }
  synthesizeKey(" ");
  synthesizeKey("KEY_Backspace");
  textarea.addEventListener("keydown", event => {
    event.stopImmediatePropagation();  // This shouldn't block spellchecker to handle it.
  }, {once: true});
  synthesizeKey("KEY_End");
  await waitForTick();
  if (selection.rangeCount === 0) {
    await waitForOnSpellCheck(textarea);
  }
  if (selection.rangeCount == 1) {
    is(
      selection.getRangeAt(0).toString(),
      "undfgdfg",
      "\"undfgdfg\" should be marked as misspelled word at end"
    );
  } else {
    is(selection.rangeCount, 1, "We should have a misspelled word at end");
  }
  SimpleTest.finish();
});
</script>
</body>
</html>