Bug 1397412 - Implement Mochitest for EditorBase::FindBetterInsertionPoint() in plaintext editor. r=ehsan
authorJorg K <jorgk@jorgk.com>
Thu, 07 Sep 2017 12:36:00 -0400
changeset 429117 903bd3c9bfdd2ac36a20f6601b407410508e3f44
parent 429116 78ab7b444a9c125ead34fae6777021d8103571d7
child 429118 84760282660db7bbe97ce7ffb3ed361d6ad02ba3
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1397412
milestone57.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 1397412 - Implement Mochitest for EditorBase::FindBetterInsertionPoint() in plaintext editor. r=ehsan
editor/libeditor/tests/chrome.ini
editor/libeditor/tests/test_bug1397412.xul
--- a/editor/libeditor/tests/chrome.ini
+++ b/editor/libeditor/tests/chrome.ini
@@ -3,13 +3,14 @@ skip-if = os == 'android'
 support-files = green.png
 
 [test_bug489202.xul]
 [test_bug599983.xul]
 [test_bug607584.xul]
 [test_bug616590.xul]
 [test_bug780908.xul]
 [test_bug1386222.xul]
+[test_bug1397412.xul]
 [test_contenteditable_text_input_handling.html]
 [test_htmleditor_keyevent_handling.html]
 [test_texteditor_keyevent_handling.html]
 skip-if = (debug && os=='win') || (os == 'linux') # Bug 1116205, leaks on windows debug, fails delete key on linux
 [test_pasteImgTextarea.xul]
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/tests/test_bug1397412.xul
@@ -0,0 +1,72 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin"
+                 type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+                 type="text/css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1397412
+-->
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        title="Mozilla Bug 1397412" onload="runTest();">
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1397412"
+     target="_blank">Mozilla Bug 1397412</a>
+  <p/>
+  <editor xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+          id="editor"
+          type="content"
+          editortype="textmail"
+          style="width: 400px; height: 200px;"/>
+  <p/>
+  <pre id="test">
+  </pre>
+  </body>
+  <script class="testbody" type="application/javascript">
+  <![CDATA[
+  var Cc = Components.classes;
+  var Ci = Components.interfaces;
+
+function runTest() {
+  var initialHTML1 = "xx<br><br>";
+  var expectedHTML1 = "xx<br>t<br>";
+  var initialHTML2 = "xx<br><br>yy<br>";
+  var expectedHTML2 = "xx<br>t<br>yy<br>";
+  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+     .getInterface(Components.interfaces.nsIWebNavigation)
+     .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
+     .rootTreeItem
+     .QueryInterface(Components.interfaces.nsIDocShell)
+     .appType = Components.interfaces.nsIDocShell.APP_TYPE_EDITOR;
+  var e = document.getElementById("editor");
+  var doc = e.contentDocument;
+  doc.designMode = "on";
+  doc.defaultView.focus();
+  var selection = doc.defaultView.getSelection();
+  var body = doc.body;
+
+  // Test 1.
+  body.innerHTML = initialHTML1;
+  selection.collapse(body, 2);
+  synthesizeKey("t", { code: "KeyT" });
+  var actualHTML = body.innerHTML;
+  is(actualHTML, expectedHTML1, "'t' should be inserted between <br>s");
+
+  // Test 2.
+  body.innerHTML = initialHTML2;
+  selection.collapse(body, 2);
+  synthesizeKey("t", { code: "KeyT" });
+  actualHTML = body.innerHTML;
+  is(actualHTML, expectedHTML2, "'t' should be inserted between <br>s");
+
+  SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+]]>
+</script>
+</window>