Bug 1347818 - Part 2. Add documentCharacterSet test. r?masayuki
MozReview-Commit-ID: LvUNE7UNpik
--- a/editor/libeditor/tests/mochitest.ini
+++ b/editor/libeditor/tests/mochitest.ini
@@ -230,16 +230,17 @@ skip-if = toolkit == 'android' # bug 131
[test_bug1328023.html]
[test_bug1330796.html]
[test_bug1332876.html]
[test_CF_HTML_clipboard.html]
subsuite = clipboard
[test_composition_event_created_in_chrome.html]
[test_contenteditable_focus.html]
+[test_documentCharacterSet.html]
[test_dom_input_event_on_htmleditor.html]
skip-if = toolkit == 'android' # bug 1054087
[test_dom_input_event_on_texteditor.html]
[test_dragdrop.html]
skip-if = os == 'android'
[test_inline_style_cache.html]
[test_inlineTableEditing.html]
[test_keypress_untrusted_event.html]
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/tests/test_documentCharacterSet.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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>
+
+<iframe></iframe>
+
+<pre id="test">
+
+<script class="testbody" type="application/javascript">
+function getEditor() {
+ const Ci = SpecialPowers.Ci;
+ let editframe = window.frames[0];
+ return SpecialPowers.wrap(editframe)
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIEditingSession)
+ .getEditorForWindow(editframe);
+}
+
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(function() {
+ let editdoc = window.frames[0].document;
+ editdoc.designMode = 'on';
+ let editor = getEditor();
+
+ editor.documentCharacterSet = "us-ascii";
+ let meta = editdoc.getElementsByTagName("meta")[0];
+ is(meta.getAttribute("http-equiv"), "Content-Type",
+ "meta element should have http-equiv");
+ is(meta.getAttribute("content"), "text/html;charset=us-ascii",
+ "charset should be set as us-ascii");
+
+ editor.documentCharacterSet = "utf-8";
+ meta = editdoc.getElementsByTagName("meta")[0];
+ is(meta.getAttribute("http-equiv"), "Content-Type",
+ "meta element should have http-equiv");
+ is(meta.getAttribute("content"), "text/html;charset=utf-8",
+ "charset should be set as utf-8");
+
+ SimpleTest.finish();
+});
+</script>
+</pre>
+</body>
+</html>