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/libeditor/tests/test_nsIEditor_documentCharacterSet.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/libeditor/tests/test_nsIEditor_documentCharacterSet.html')
-rw-r--r-- | editor/libeditor/tests/test_nsIEditor_documentCharacterSet.html | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/editor/libeditor/tests/test_nsIEditor_documentCharacterSet.html b/editor/libeditor/tests/test_nsIEditor_documentCharacterSet.html new file mode 100644 index 0000000000..18f948fdd9 --- /dev/null +++ b/editor/libeditor/tests/test_nsIEditor_documentCharacterSet.html @@ -0,0 +1,113 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html,charset=utf-8"> + <title>Tests of nsIEditor#documentCharacterSet</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> + <script> + SimpleTest.waitForExplicitFinish(); + SimpleTest.waitForFocus(() => { + const originalBody = document.body.innerHTML; + + (function test_with_text_editor() { + for (const test of [ + { + tag: "input", + innerHTML: "<input>", + }, + { + tag: "textarea", + innerHTML: "<textarea></textarea>", + }, + ]) { + document.body.innerHTML = test.innerHTML; + const textControl = document.body.querySelector(test.tag); + const editor = SpecialPowers.wrap(textControl).editor; + try { + editor.documentCharacterSet; + ok(false, `TextEditor::GetDocumentCharacterSet() for <${test.tag}> should throw an exception`); + } catch (e) { + ok(true, `TextEditor::GetDocumentCharacterSet() for <${test.tag}> should throw an exception`); + } + try { + editor.documentCharacterSet = "windows-1252"; + ok(false, `TextEditor::SetDocumentCharacterSet() for <${test.tag}> should throw an exception`); + } catch (e) { + ok(true, `TextEditor::SetDocumentCharacterSet() for <${test.tag}> should throw an exception`); + } + } + })(); + + function getHTMLEditor(win = window) { + const editingSession = SpecialPowers.wrap(win).docShell.editingSession; + if (!editingSession) { + return null; + } + return editingSession.getEditorForWindow(win); + } + + (function test_with_contenteditable() { + document.body.innerHTML = "<div contenteditable><p>abc</p></div>"; + const editor = getHTMLEditor(); + is(editor.documentCharacterSet, "UTF-8", + "HTMLEditor::GetDocumentCharacterSet() should return \"UTF-8\""); + editor.documentCharacterSet = "windows-1252"; + is(document.querySelector("meta[http-equiv]").getAttribute("content"), "text/html,charset=windows-1252", + "HTMLEditor::SetDocumentCharacterSet() should add <meta> element whose \"http-equiv\" attribute has \"windows-1252\""); + is(editor.documentCharacterSet, "windows-1252", + "HTMLEditor::GetDocumentCharacterSet() should return \"windows-1252\" after setting the value"); + editor.documentCharacterSet = "utf-8"; + is(document.querySelector("meta[http-equiv]").getAttribute("content"), "text/html,charset=utf-8", + "HTMLEditor::SetDocumentCharacterSet() should add <meta> element whose \"http-equiv\" attribute has \"utf-8\""); + is(editor.documentCharacterSet, "UTF-8", + "HTMLEditor::GetDocumentCharacterSet() should return \"UTF-8\" after setting the value"); + })(); + + (function test_with_designMode() { + while (document.querySelector("meta")) { + document.querySelector("meta").remove(); + } + document.body.innerHTML = "<iframe></iframe>"; + const editdoc = document.querySelector("iframe").contentDocument; + editdoc.designMode = "on"; + const editor = getHTMLEditor(document.querySelector("iframe").contentWindow); + + editor.documentCharacterSet = "us-ascii"; + const metaWithHttpEquiv = editdoc.getElementsByTagName("meta")[0]; + is(metaWithHttpEquiv.getAttribute("http-equiv"), "Content-Type", + "meta element should have http-equiv"); + is(metaWithHttpEquiv.getAttribute("content"), "text/html;charset=us-ascii", + "charset should be set as us-ascii"); + + const dummyMeta = editdoc.createElement("meta"); + dummyMeta.setAttribute("name", "keywords"); + dummyMeta.setAttribute("content", "test"); + metaWithHttpEquiv.parentNode.insertBefore(dummyMeta, metaWithHttpEquiv); + + editor.documentCharacterSet = "utf-8"; + + is(dummyMeta, editdoc.getElementsByTagName("meta")[0], + "<meta> element shouldn't be touched"); + isnot(dummyMeta.getAttribute("http-equiv"), "Content-Type", + "first meta element shouldn't have http-equiv"); + + is(metaWithHttpEquiv, editdoc.getElementsByTagName("meta")[1], + "The second <meta> element should be reused"); + is(metaWithHttpEquiv.getAttribute("http-equiv"), "Content-Type", + "second meta element should have http-equiv"); + is(metaWithHttpEquiv.getAttribute("content"), "text/html;charset=utf-8", + "charset should be set as utf-8"); + })(); + + document.body.innerHTML = originalBody; + SimpleTest.finish(); + }); + </script> +</head> +<body> +<p id="display"></p> +<div id="content" style="display: none"></div> +<pre id="test"></pre> +</body> +</html> |