Bug 1385905 - part1: Add automated test to check if editor won't create mozBR element when typing Enter before invisible <br> element r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 01 Aug 2017 18:07:08 +0900
changeset 619634 c1c999362e53e3a697e3de440dcb877b22f7a8b4
parent 619442 fec8d72590053c3ad72cd3492d389213dfabc2ff
child 619635 a5603dc9da770566e23acb0ef6b7c085d02a7a8b
push id71752
push usermasayuki@d-toybox.com
push dateWed, 02 Aug 2017 10:33:24 +0000
reviewersm_kato
bugs1385905
milestone56.0a1
Bug 1385905 - part1: Add automated test to check if editor won't create mozBR element when typing Enter before invisible <br> element r?m_kato MozReview-Commit-ID: AcHnK2LbTs1
editor/libeditor/tests/mochitest.ini
editor/libeditor/tests/test_bug1385905.html
--- a/editor/libeditor/tests/mochitest.ini
+++ b/editor/libeditor/tests/mochitest.ini
@@ -242,16 +242,17 @@ skip-if = toolkit == 'android' # bug 131
 [test_bug1328023.html]
 [test_bug1330796.html]
 [test_bug1332876.html]
 [test_bug1352799.html]
 [test_bug1355792.html]
 [test_bug1358025.html]
 [test_bug1361008.html]
 [test_bug1368544.html]
+[test_bug1385905.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
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/tests/test_bug1385905.html
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi=id=1385905
+-->
+<html>
+<head>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1385905">Mozilla Bug 1385905</a>
+<div id="display"></div>
+<div id="editor" contenteditable style="padding: 5px;"><div>contents</div></div>
+<pre id="test">
+</pre>
+
+<script class="testbody" type="application/javascript">
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(() => {
+  SpecialPowers.pushPrefEnv({"set": [["editor.use_div_for_default_newlines", true]]}, () => {
+    function ensureNoMozBR() {
+      for (let br of document.querySelectorAll("#editor > div > br")) {
+        isnot(br.getAttribute("type"), "_moz",
+              "mozBR shouldn't be used with this test");
+      }
+    }
+    var editor = document.getElementById("editor");
+    // Click the left blank area of the first line to set cursor to the start of "contents".
+    synthesizeMouse(editor, 3, 10, {});
+    synthesizeKey("KEY_Enter", { code: "Enter" });
+    is(editor.innerHTML, "<div><br></div><div>contents</div>",
+       "Typing Enter at start of the <div> element should split the <div> element");
+    synthesizeKey("KEY_ArrowUp", { code: "ArrowUp" });
+    synthesizeKey("x", { code: "KeyX" });
+    is(editor.innerHTML, "<div>x<br></div><div>contents</div>",
+       "Typing 'x' at the empty <div> element should just insert 'x' into the <div> element");
+    ensureNoMozBR();
+    synthesizeKey("KEY_Enter", { code: "Enter" });
+    is(editor.innerHTML, "<div>x</div><div><br></div><div>contents</div>",
+       "Typing Enter next to 'x' in the first <div> element should split the <div> element and inserts <br> element to a new <div> element");
+    ensureNoMozBR();
+    synthesizeKey("KEY_Enter", { code: "Enter" });
+    is(editor.innerHTML, "<div>x</div><div><br></div><div><br></div><div>contents</div>",
+       "Typing Enter in the empty <div> should split the <div> element and inserts <br> element to a new <div> element");
+    ensureNoMozBR();
+    SimpleTest.finish();
+  });
+});
+</script>
+</body>
+</html>