<!DOCTYPE HTML><html><head><metahttp-equiv="Content-Type"content="text/html,charset=utf-8"><title>Tests of nsIEditor#documentCharacterSet</title><scriptsrc="/tests/SimpleTest/SimpleTest.js"></script><linkrel="stylesheet"href="/tests/SimpleTest/test.css"/><script>SimpleTest.waitForExplicitFinish();SimpleTest.waitForFocus(()=>{constoriginalBody=document.body.innerHTML;(functiontest_with_text_editor(){for(consttestof[{tag:"input",innerHTML:"<input>",},{tag:"textarea",innerHTML:"<textarea></textarea>",},]){document.body.innerHTML=test.innerHTML;consttextControl=document.body.querySelector(test.tag);consteditor=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`);}}})();functiongetHTMLEditor(win=window){consteditingSession=SpecialPowers.wrap(win).docShell.editingSession;if(!editingSession){returnnull;}returneditingSession.getEditorForWindow(win);}(functiontest_with_contenteditable(){document.body.innerHTML="<div contenteditable><p>abc</p></div>";consteditor=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");})();(functiontest_with_designMode(){while(document.querySelector("meta")){document.querySelector("meta").remove();}document.body.innerHTML="<iframe></iframe>";consteditdoc=document.querySelector("iframe").contentDocument;editdoc.designMode="on";consteditor=getHTMLEditor(document.querySelector("iframe").contentWindow);editor.documentCharacterSet="us-ascii";constmetaWithHttpEquiv=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");constdummyMeta=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><pid="display"></p><divid="content"style="display: none"></div><preid="test"></pre></body></html>