diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /editor/spellchecker/tests/test_nsIEditorSpellCheck_ReplaceWord.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
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..a92c9f2f19 --- /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.importESModule( + "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs" + ); + 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> |