Bug 1347818 - Part 2. Add documentCharacterSet test. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 17 Mar 2017 15:24:56 +0900
changeset 348215 fa4734723b879c8ef8c4e9b43d681efd4dfb2175
parent 348214 2e2cc094e6a610a2057f42e294548e1179e1b9a4
child 348216 beff3b520fb38ad07703edbfa3abbbb5a6fc014e
push id31515
push userkwierso@gmail.com
push dateFri, 17 Mar 2017 18:04:10 +0000
treeherdermozilla-central@23a4b7430dd7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1347818
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1347818 - Part 2. Add documentCharacterSet test. r=masayuki MozReview-Commit-ID: LvUNE7UNpik
editor/libeditor/tests/mochitest.ini
editor/libeditor/tests/test_documentCharacterSet.html
--- 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,64 @@
+<!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");
+
+  let dummyMeta = editdoc.createElement("meta");
+  dummyMeta.setAttribute("name", "keywords");
+  dummyMeta.setAttribute("content", "test");
+  meta.parentNode.insertBefore(dummyMeta, meta);
+
+  editor.documentCharacterSet = "utf-8";
+
+  meta = editdoc.getElementsByTagName("meta")[0];
+  isnot(meta.getAttribute("http-equiv"), "Content-Type",
+     "first meta element shouldn't have http-equiv");
+
+  meta = editdoc.getElementsByTagName("meta")[1];
+  is(meta.getAttribute("http-equiv"), "Content-Type",
+     "second 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>