editor/spellchecker/tests/test_spellcheck_after_pressing_navigation_key.html
author Andy Leiserson <aleiserson@mozilla.com>
Sat, 19 Jul 2025 16:44:54 +0000 (6 hours ago)
changeset 797257 246e16bb06c941d6f64d807d43c807bfba04ae86
parent 671986 58c769d5be44e325f145235d5b7732224b6fcb96
permissions -rw-r--r--
Bug 1976958 - Update wgpu to b83c9cf (2025-07-10) r=webgpu-reviewers,supply-chain-reviewers,teoxoy Differential Revision: https://phabricator.services.mozilla.com/D257047
<!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.importESModule(
  "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
);

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>