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_nsIEditorMailSupport_insertTextWithQuotations.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_nsIEditorMailSupport_insertTextWithQuotations.html')
-rw-r--r-- | editor/libeditor/tests/test_nsIEditorMailSupport_insertTextWithQuotations.html | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/editor/libeditor/tests/test_nsIEditorMailSupport_insertTextWithQuotations.html b/editor/libeditor/tests/test_nsIEditorMailSupport_insertTextWithQuotations.html new file mode 100644 index 0000000000..921e137fa8 --- /dev/null +++ b/editor/libeditor/tests/test_nsIEditorMailSupport_insertTextWithQuotations.html @@ -0,0 +1,104 @@ +<!DOCTYPE> +<html> +<head> + <title>Test for nsIEditorMailSupport.insertTextWithQuotations()</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" href="/tests/SimpleTest/test.css"> +</head> +<body> +<div contenteditable></div> +<iframe srcdoc="<body contenteditable></body>"></iframe> +<script> +"use strict"; + +SimpleTest.waitForExplicitFinish(); +SimpleTest.waitForFocus(async () => { + const iframe = document.querySelector("iframe"); + await new Promise(resolve => { + if (iframe.contentDocument?.readyState == "complete") { + resolve(); + return; + } + iframe.addEventListener("load", resolve, {once: true}); + }); + + function testInDiv() { + const inPlaintextMode = getEditor(window).flags & SpecialPowers.Ci.nsIEditor.eEditorPlaintextMask; + const inReadonlyMode = getEditor(window).flags & SpecialPowers.Ci.nsIEditor.eEditorReadonlyMask; + const editorDescription = `(readonly=${!!inReadonlyMode}, plaintext=${!!inPlaintextMode})`; + const editor = document.querySelector("div[contenteditable]"); + editor.innerHTML = ""; + editor.focus(); + getEditorMailSupport(window).insertTextWithQuotations( + "This is Text\n\n> This is a quote." + ); + is( + editor.innerHTML, + 'This is Text<br><br><span style="white-space: pre-wrap;">> This is a quote.</span><br>', + `The <div contenteditable> should have the expected innerHTML ${editorDescription}` + ); + is( + editor.querySelector("span")?.getAttribute("_moz_quote"), + "true", + `The <span> element in the <div contenteditable> should have _moz_quote="true" ${editorDescription}` + ); + } + + function testInBody() { + const inPlaintextMode = getEditor(iframe.contentWindow).flags & SpecialPowers.Ci.nsIEditor.eEditorPlaintextMask; + const inReadonlyMode = getEditor(iframe.contentWindow).flags & SpecialPowers.Ci.nsIEditor.eEditorReadonlyMask; + const editorDescription = `(readonly=${!!inReadonlyMode}, plaintext=${!!inPlaintextMode})`; + const editor = iframe.contentDocument.body; + editor.innerHTML = ""; + iframe.contentWindow.getSelection().collapse(document.body, 0); + getEditorMailSupport(iframe.contentWindow).insertTextWithQuotations( + "This is Text\n\n> This is a quote." + ); + is( + editor.innerHTML, + 'This is Text<br><br><span style="white-space: pre-wrap; display: block; width: 98vw;">> This is a quote.</span><br>', + `The <body> should have the expected innerHTML ${editorDescription}` + ); + is( + editor.querySelector("span")?.getAttribute("_moz_quote"), + "true", + `The <span> element in the <body> should have _moz_quote="true" ${editorDescription}` + ); + } + + for (const testReadOnly of [false, true]) { + // Even if the HTMLEditor is readonly, XPCOM API should keep working. + if (testReadOnly) { + getEditor(window).flags |= SpecialPowers.Ci.nsIEditor.eEditorReadonlyMask; + getEditor(iframe.contentWindow).flags |= SpecialPowers.Ci.nsIEditor.eEditorReadonlyMask; + } else { + getEditor(window).flags &= ~SpecialPowers.Ci.nsIEditor.eEditorReadonlyMask; + getEditor(iframe.contentWindow).flags &= ~SpecialPowers.Ci.nsIEditor.eEditorReadonlyMask; + } + + getEditor(window).flags &= ~SpecialPowers.Ci.nsIEditor.eEditorPlaintextMask; + getEditor(iframe.contentWindow).flags &= ~SpecialPowers.Ci.nsIEditor.eEditorPlaintextMask; + testInDiv(); + testInBody(); + + getEditor(window).flags |= SpecialPowers.Ci.nsIEditor.eEditorPlaintextMask; + getEditor(iframe.contentWindow).flags |= SpecialPowers.Ci.nsIEditor.eEditorPlaintextMask; + testInDiv(); + testInBody(); + } + + SimpleTest.finish(); +}); + +function getEditor(aWindow) { + const editingSession = SpecialPowers.wrap(aWindow).docShell.editingSession; + return editingSession.getEditorForWindow(aWindow); +} + +function getEditorMailSupport(aWindow) { + return getEditor(aWindow).QueryInterface(SpecialPowers.Ci.nsIEditorMailSupport); +} +</script> +</body> + +</html> |