diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /editor/spellchecker/tests/test_nsIEditorSpellCheck_ReplaceWord.html | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'editor/spellchecker/tests/test_nsIEditorSpellCheck_ReplaceWord.html')
-rw-r--r-- | editor/spellchecker/tests/test_nsIEditorSpellCheck_ReplaceWord.html | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/editor/spellchecker/tests/test_nsIEditorSpellCheck_ReplaceWord.html b/editor/spellchecker/tests/test_nsIEditorSpellCheck_ReplaceWord.html new file mode 100644 index 0000000000..6088b97e3e --- /dev/null +++ b/editor/spellchecker/tests/test_nsIEditorSpellCheck_ReplaceWord.html @@ -0,0 +1,64 @@ +<!DOCTYPE html> +<html> +<head> + <title>Test for nsIEditorSpellCheck.ReplaceWord()</title> + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> +</head> +<body> +<div contenteditable spellcheck="true" lang="en-US"></div> +<script> +"use strict"; + +SimpleTest.waitForExplicitFinish(); +SimpleTest.waitForFocus(async () => { + const { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.import( + "resource://testing-common/AsyncSpellCheckTestHelper.jsm" + ); + const editor = document.querySelector("div[contenteditable]"); + async function replaceWord(aMisspelledWord, aCorrectWord, aReplaceAll) { + const editorObj = SpecialPowers.wrap(window).docShell.editingSession.getEditorForWindow(window); + const inlineSpellChecker = editorObj.getInlineSpellChecker(true); + await new Promise(resolve => maybeOnSpellCheck(editor, resolve)); + const editorSpellCheck = inlineSpellChecker.spellChecker; + editorObj.beginTransaction(); + try { + editorSpellCheck.ReplaceWord(aMisspelledWord, aCorrectWord, aReplaceAll); + } catch (e) { + ok(false, `Unexpected exception: ${e.message}`); + } + editorObj.endTransaction(); + editorSpellCheck.GetNextMisspelledWord(); + } + + async function testReplaceAllMisspelledWords(aCorrectWord) { + editor.innerHTML = "<p>def abc def<br>abc def abc</p><p>abc def abc<br>def abc def</p>"; + editor.focus(); + editor.getBoundingClientRect(); + await replaceWord("abc", aCorrectWord, true); + is( + editor.innerHTML, + `<p>def ${aCorrectWord} def<br>${aCorrectWord} def ${aCorrectWord}</p><p>${aCorrectWord} def ${aCorrectWord}<br>def ${aCorrectWord} def</p>`, + `nsIEditorSpellCheck.ReplaceWord(..., true) should replace all misspelled words with ${ + (() => { + if (aCorrectWord.length > "abc".length) { + return "longer"; + } + return aCorrectWord.length < "abc".length ? "shorter" : "same length" + })() + } correct word` + ); + editor.blur(); + editor.getBoundingClientRect(); + } + await testReplaceAllMisspelledWords("ABC"); + await testReplaceAllMisspelledWords("ABC!"); + await testReplaceAllMisspelledWords("AB"); + + // TODO: Add tests for not all replacing cases. + + SimpleTest.finish(); +}); +</script> +</body> +</html> |