diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /editor/libeditor/tests/test_textarea_value_not_include_cr.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'editor/libeditor/tests/test_textarea_value_not_include_cr.html')
-rw-r--r-- | editor/libeditor/tests/test_textarea_value_not_include_cr.html | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/editor/libeditor/tests/test_textarea_value_not_include_cr.html b/editor/libeditor/tests/test_textarea_value_not_include_cr.html new file mode 100644 index 0000000000..9319a34139 --- /dev/null +++ b/editor/libeditor/tests/test_textarea_value_not_include_cr.html @@ -0,0 +1,95 @@ +<!DOCTYPE html> +<html> +<head> + <title>Test for HTMLTextAreaElement.value not returning value including CR</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <script src="/tests/SimpleTest/EventUtils.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<p id="display"></p> +<div id="content" style="display: none;"> + +</div> + +<textarea></textarea> + +<script> +SimpleTest.waitForExplicitFinish(); +SimpleTest.waitForFocus(async () => { + /** + * This test should check only the cases with emulating complicated + * key events and using XPCOM methods. If you need to add simple textcases, + * use testing/web-platform/tests/html/semantics/forms/the-textarea-element/value-defaultValue-textContent.html + * instead + */ + let textarea = document.querySelector("textarea"); + textarea.focus(); + // This shouldn't occur because widget handles control characters if they + // receive native key event, but for backward compatibility as XUL platform, + // let's check this. + synthesizeKey("\r"); + is(textarea.value, "\n", "Inputting \\r from keyboard event should be converted to \\n"); + + textarea.value = ""; + await new Promise((resolve, reject) => { + SimpleTest.waitForClipboard( + "ab\ncd\nef", + () => { SpecialPowers.clipboardCopyString("ab\r\ncd\ref"); }, + resolve, + () => { + ok(false, "Clipboard copy failed"); + reject(); + } + ); + }); + synthesizeKey("v", {accelKey: true}); + is(textarea.value, "ab\ncd\nef", "Pasting \\r from clipboard should be converted to \\n"); + + textarea.value = ""; + SpecialPowers.wrap(textarea).editor.insertText("ab\r\ncd\ref"); + is(textarea.value, "ab\ncd\nef", "Inserting \\r with nsIEditor.insertText() should be converted to \\n"); + + textarea.value = ""; + synthesizeCompositionChange( + { "composition": + { "string": "ab\r\ncd\ref", + "clauses": + [ + { "length": 9, "attr": COMPOSITION_ATTR_RAW_CLAUSE } + ] + }, + "caret": { "start": 9, "length": 0 }, + }); + is(textarea.value, "ab\ncd\nef", "Inserting \\r with composition should be converted to \\n"); + + synthesizeComposition({type: "compositioncommitasis"}); + is(textarea.value, "ab\ncd\nef", "Inserting \\r with committing composition should be converted to \\n"); + + // We don't need to test spellchecker features on Android because of unsupported. + if (!navigator.appVersion.includes("Android")) { + ok(true, "Waiting to run spellchecker..."); + let inlineSpellchecker = SpecialPowers.wrap(textarea).editor.getInlineSpellChecker(true); + textarea.value = "abx "; + await new Promise(resolve => { + const { onSpellCheck } = SpecialPowers.ChromeUtils.import( + "resource://testing-common/AsyncSpellCheckTestHelper.jsm" + ); + onSpellCheck(textarea, () => { + SimpleTest.executeSoon(resolve); + }); + }); + let anonymousDivElement = SpecialPowers.wrap(textarea).editor.rootElement; + let misspelledWord = inlineSpellchecker.getMisspelledWord(anonymousDivElement.firstChild, 0); + is(misspelledWord.startOffset, 0, "Misspelled word start should be 0"); + is(misspelledWord.endOffset, 3, "Misspelled word end should be 3"); + inlineSpellchecker.replaceWord(anonymousDivElement.firstChild, 0, "ab\r\ncd\ref"); + is(textarea.value, "ab\ncd\nef ", "Inserting \\r from spellchecker should be converted to \\n"); + } + + SimpleTest.finish(); +}); +</script> +</pre> +</body> +</html> |