Bug 1874684 - Part 17: Fix uninitialised variable warnings from clang-tidy. r=allstarschh
[gecko.git] / editor / libeditor / tests / test_textarea_value_not_include_cr.html
blobf687792f8bcf18ae8d490af4615215f49470aec2
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Test for HTMLTextAreaElement.value not returning value including CR</title>
5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
6 <script src="/tests/SimpleTest/EventUtils.js"></script>
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
8 </head>
9 <body>
10 <p id="display"></p>
11 <div id="content" style="display: none;">
13 </div>
15 <textarea></textarea>
17 <script>
18 SimpleTest.waitForExplicitFinish();
19 SimpleTest.waitForFocus(async () => {
20 /**
21 * This test should check only the cases with emulating complicated
22 * key events and using XPCOM methods. If you need to add simple textcases,
23 * use testing/web-platform/tests/html/semantics/forms/the-textarea-element/value-defaultValue-textContent.html
24 * instead
26 let textarea = document.querySelector("textarea");
27 textarea.focus();
28 // This shouldn't occur because widget handles control characters if they
29 // receive native key event, but for backward compatibility as XUL platform,
30 // let's check this.
31 synthesizeKey("\r");
32 is(textarea.value, "\n", "Inputting \\r from keyboard event should be converted to \\n");
34 textarea.value = "";
35 await new Promise((resolve, reject) => {
36 SimpleTest.waitForClipboard(
37 "ab\ncd\nef",
38 () => { SpecialPowers.clipboardCopyString("ab\r\ncd\ref"); },
39 resolve,
40 () => {
41 ok(false, "Clipboard copy failed");
42 reject();
45 });
46 synthesizeKey("v", {accelKey: true});
47 is(textarea.value, "ab\ncd\nef", "Pasting \\r from clipboard should be converted to \\n");
49 textarea.value = "";
50 SpecialPowers.wrap(textarea).editor.insertText("ab\r\ncd\ref");
51 is(textarea.value, "ab\ncd\nef", "Inserting \\r with nsIEditor.insertText() should be converted to \\n");
53 textarea.value = "";
54 synthesizeCompositionChange(
55 { "composition":
56 { "string": "ab\r\ncd\ref",
57 "clauses":
59 { "length": 9, "attr": COMPOSITION_ATTR_RAW_CLAUSE }
62 "caret": { "start": 9, "length": 0 },
63 });
64 is(textarea.value, "ab\ncd\nef", "Inserting \\r with composition should be converted to \\n");
66 synthesizeComposition({type: "compositioncommitasis"});
67 is(textarea.value, "ab\ncd\nef", "Inserting \\r with committing composition should be converted to \\n");
69 // We don't need to test spellchecker features on Android because of unsupported.
70 if (!navigator.appVersion.includes("Android")) {
71 ok(true, "Waiting to run spellchecker...");
72 let inlineSpellchecker = SpecialPowers.wrap(textarea).editor.getInlineSpellChecker(true);
73 textarea.value = "abx ";
74 await new Promise(resolve => {
75 const { onSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
76 "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
78 onSpellCheck(textarea, () => {
79 SimpleTest.executeSoon(resolve);
80 });
81 });
82 let anonymousDivElement = SpecialPowers.wrap(textarea).editor.rootElement;
83 let misspelledWord = inlineSpellchecker.getMisspelledWord(anonymousDivElement.firstChild, 0);
84 is(misspelledWord.startOffset, 0, "Misspelled word start should be 0");
85 is(misspelledWord.endOffset, 3, "Misspelled word end should be 3");
86 inlineSpellchecker.replaceWord(anonymousDivElement.firstChild, 0, "ab\r\ncd\ref");
87 is(textarea.value, "ab\ncd\nef ", "Inserting \\r from spellchecker should be converted to \\n");
90 SimpleTest.finish();
91 });
92 </script>
93 </pre>
94 </body>
95 </html>