[evolution/wip/mcrha/webkit-jsc-api] test-html-editor-units: Adapt /undo tests and fix found bugs in the new code



commit be8061061a9f0fdd97463dbcd03e1f550555894b
Author: Milan Crha <mcrha redhat com>
Date:   Tue Mar 24 17:56:27 2020 +0100

    test-html-editor-units: Adapt /undo tests and fix found bugs in the new code

 data/webkit/e-editor.js             |  30 +++++++++--
 src/e-util/test-html-editor-units.c | 102 ++++++++++++++++++------------------
 2 files changed, 78 insertions(+), 54 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 3337a965e3..950f5003c8 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -1608,6 +1608,18 @@ EvoEditor.InsertHTML = function(opType, html)
        }
 }
 
+EvoEditor.InsertText = function(opType, text)
+{
+       EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_GROUP, opType);
+       try {
+               document.execCommand("insertText", false, text);
+       } finally {
+               EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_GROUP, opType);
+               EvoEditor.maybeUpdateFormattingState(EvoEditor.FORCE_MAYBE);
+               EvoEditor.EmitContentChanged();
+       }
+}
+
 EvoEditor.applySetBodyAttribute = function(record, isUndo)
 {
        if (isUndo) {
@@ -2480,6 +2492,12 @@ EvoEditor.GetContent = function(flags, cid_uid_prefix)
        try {
                currentElemsArray = EvoEditor.RemoveCurrentElementAttr();
 
+               // For safety, to not export with empty 'style' attributes; these do not need Undo
+               elems = document.querySelectorAll("[style='']");
+               for (ii = 0; ii < elems.length; ii++) {
+                       EvoEditor.removeEmptyStyleAttribute(elems[ii]);
+               }
+
                if ((flags & EvoEditor.E_CONTENT_EDITOR_GET_RAW_BODY_STRIPPED) != 0) {
                        var hidden_elems = [];
 
@@ -3179,6 +3197,7 @@ EvoEditor.AfterInputEvent = function(inputEvent, isWordDelim)
                        EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, opType);
 
                        if (canEmit) {
+                               EvoUndoRedo.GroupTopRecords(2);
                                EvoEditor.maybeUpdateFormattingState(EvoEditor.FORCE_MAYBE);
                                EvoEditor.EmitContentChanged();
                        }
@@ -3289,6 +3308,7 @@ EvoEditor.AfterInputEvent = function(inputEvent, isWordDelim)
                        } finally {
                                if (sz > 1) {
                                        EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_GROUP, "magicSmiley");
+                                       EvoUndoRedo.GroupTopRecords(2);
                                        EvoEditor.maybeUpdateFormattingState(EvoEditor.FORCE_MAYBE);
                                        EvoEditor.EmitContentChanged();
                                }
@@ -4882,10 +4902,14 @@ EvoEditor.InsertContent = function(text, isHTML, quote)
                                        EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, 
"InsertContent::text");
                                }
                        }
-               } else if (EvoEditor.IsBlockNode(content.firstChild)) {
-                       EvoEditor.InsertHTML("InsertContent::text", content.innerHTML);
+               } else if (isHTML) {
+                       if (EvoEditor.IsBlockNode(content.firstChild)) {
+                               EvoEditor.InsertHTML("InsertContent::text", content.innerHTML);
+                       } else {
+                               EvoEditor.InsertHTML("InsertContent::text", content.outerHTML);
+                       }
                } else {
-                       EvoEditor.InsertHTML("InsertContent::text", content.outerHTML);
+                       EvoEditor.InsertText("InsertContent::text", content.innerText);
                }
        } finally {
                EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_GROUP, "InsertContent");
diff --git a/src/e-util/test-html-editor-units.c b/src/e-util/test-html-editor-units.c
index f64d0a0b27..9bc292d269 100644
--- a/src/e-util/test-html-editor-units.c
+++ b/src/e-util/test-html-editor-units.c
@@ -5374,7 +5374,7 @@ test_undo_text_typed (TestFixture *fixture)
                "undo:drop\n"
                "type:xt\n",
                HTML_PREFIX "<div>some text</div>" HTML_SUFFIX,
-               "some text"))
+               "some text\n"))
                g_test_fail ();
 }
 
@@ -5389,7 +5389,7 @@ test_undo_text_forward_delete (TestFixture *fixture)
                "undo:redo\n"
                "undo:undo\n",
                HTML_PREFIX "<div>some text to delete</div>" HTML_SUFFIX,
-               "some text to delete"))
+               "some text to delete\n"))
                g_test_fail ();
 }
 
@@ -5404,7 +5404,7 @@ test_undo_text_backward_delete (TestFixture *fixture)
                "undo:redo\n"
                "undo:undo\n",
                HTML_PREFIX "<div>some text to delete</div>" HTML_SUFFIX,
-               "some text to delete"))
+               "some text to delete\n"))
                g_test_fail ();
 }
 
@@ -5418,7 +5418,7 @@ test_undo_text_cut (TestFixture *fixture)
                "action:cut\n"
                "undo:undo\n",
                NULL,
-               "some text to delete"))
+               "some text to delete\n"))
                g_test_fail ();
 }
 
@@ -5433,104 +5433,104 @@ test_undo_style (TestFixture *fixture)
                "action:bold\n"
                "type:bold\n"
                "undo:save\n" /* 2 */
-               "undo:undo:5\n"
+               "undo:undo:4\n"
                "undo:test:2\n"
-               "undo:redo:5\n"
+               "undo:redo:4\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:5\n"
+               "undo:undo:4\n"
                "type:bold\n"
                "seq:CSlsc\n"
                "action:bold\n"
                "undo:save\n" /* 2 */
-               "undo:undo:5\n"
+               "undo:undo:2\n"
                "undo:test:2\n"
-               "undo:redo:5\n"
+               "undo:redo:2\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:5\n"
+               "undo:undo:2\n"
 
                "action:italic\n"
                "type:italic\n"
                "undo:save\n" /* 2 */
-               "undo:undo:7\n"
+               "undo:undo:6\n"
                "undo:test:2\n"
-               "undo:redo:7\n"
+               "undo:redo:6\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:7\n"
+               "undo:undo:6\n"
                "type:italic\n"
                "seq:CSlsc\n"
                "action:italic\n"
                "undo:save\n" /* 2 */
-               "undo:undo:7\n"
+               "undo:undo:2\n"
                "undo:test:2\n"
-               "undo:redo:7\n"
+               "undo:redo:2\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:7\n"
+               "undo:undo:2\n"
 
                "action:underline\n"
                "type:underline\n"
                "undo:save\n" /* 2 */
-               "undo:undo:10\n"
+               "undo:undo:9\n"
                "undo:test:2\n"
-               "undo:redo:10\n"
+               "undo:redo:9\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:10\n"
+               "undo:undo:9\n"
                "type:underline\n"
                "seq:CSlsc\n"
                "action:underline\n"
                "undo:save\n" /* 2 */
-               "undo:undo:10\n"
+               "undo:undo:2\n"
                "undo:test:2\n"
-               "undo:redo:10\n"
+               "undo:redo:2\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:10\n"
+               "undo:undo:2\n"
 
                "action:strikethrough\n"
                "type:strikethrough\n"
                "undo:save\n" /* 2 */
-               "undo:undo:14\n"
+               "undo:undo:13\n"
                "undo:test:2\n"
-               "undo:redo:14\n"
+               "undo:redo:13\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:14\n"
+               "undo:undo:13\n"
                "type:strikethrough\n"
                "seq:CSlsc\n"
                "action:strikethrough\n"
                "undo:save\n" /* 2 */
-               "undo:undo:14\n"
+               "undo:undo:2\n"
                "undo:test:2\n"
-               "undo:redo:14\n"
+               "undo:redo:2\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:14\n"
+               "undo:undo:2\n"
 
                "font-name:monospace\n"
                "type:monospaced\n"
                "undo:save\n" /* 2 */
-               "undo:undo:11\n"
+               "undo:undo:10\n"
                "undo:test:2\n"
-               "undo:redo:11\n"
+               "undo:redo:10\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:11\n"
+               "undo:undo:10\n"
                "type:monospaced\n"
                "seq:CSlsc\n"
                "font-name:monospace\n"
                "undo:save\n" /* 2 */
-               "undo:undo:11\n"
+               "undo:undo:2\n"
                "undo:test:2\n"
-               "undo:redo:11\n"
+               "undo:redo:2\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:11\n",
+               "undo:undo:2\n",
                HTML_PREFIX "<div>The first paragraph text</div><div><br></div>" HTML_SUFFIX,
-               "The first paragraph text\n"))
+               "The first paragraph text\n\n"))
                g_test_fail ();
 }
 
@@ -5595,15 +5595,15 @@ test_undo_justify (TestFixture *fixture)
                "seq:CSlsc\n"
                "action:justify-right\n"
                "undo:save\n" /* 2 */
-               "undo:undo:6\n"
+               "undo:undo:2\n"
                "undo:test:2\n"
-               "undo:redo:6\n"
+               "undo:redo:2\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:6\n",
+               "undo:undo:2\n",
 
                HTML_PREFIX "<div>The first paragraph text</div><div><br></div>" HTML_SUFFIX,
-               "The first paragraph text\n"))
+               "The first paragraph text\n\n"))
                g_test_fail ();
 }
 
@@ -5628,12 +5628,12 @@ test_undo_indent (TestFixture *fixture)
                "seq:CSlsc\n"
                "action:indent\n"
                "undo:save\n" /* 2 */
-               "undo:undo:5\n"
+               "undo:undo:2\n"
                "undo:test:2\n"
-               "undo:redo:5\n"
+               "undo:redo:2\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:5\n"
+               "undo:undo:2\n"
 
                "type:text\n"
                "undo:save\n" /* 2 */
@@ -5652,7 +5652,7 @@ test_undo_indent (TestFixture *fixture)
                "undo:undo:3\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:4\n"
+               "undo:undo:1\n"
                "undo:test\n"
 
                "type:level 1\\n\n"
@@ -5684,15 +5684,15 @@ test_undo_indent (TestFixture *fixture)
                "undo:drop:2\n" /* drop the save 3 and 2 */
 
                "undo:save\n" /* 2 */
-               "undo:undo:30\n" /* 6x action:indent, 24x type "level X\\n" */
+               "undo:undo:18\n" /* 6x action:indent, 3x type "level X\\n" (= 4 undo steps) */
                "undo:test:2\n"
-               "undo:redo:30\n"
+               "undo:redo:18\n"
                "undo:test\n"
                "undo:drop\n" /* drop the save 2 */
-               "undo:undo:30\n",
+               "undo:undo:18\n",
 
                HTML_PREFIX "<div>The first paragraph text</div><div><br></div>" HTML_SUFFIX,
-               "The first paragraph text\n"))
+               "The first paragraph text\n\n"))
                g_test_fail ();
 }
 
@@ -5710,11 +5710,11 @@ test_undo_link_paste_html (TestFixture *fixture)
                "undo:save\n" /* 2 */
                "undo:undo:2\n"
                "undo:test:2\n"
-               "undo:undo:5\n"
-               "undo:redo:7\n"
+               "undo:undo:2\n"
+               "undo:redo:4\n"
                "undo:test\n",
                HTML_PREFIX "<div>URL:</div><div><a 
href=\"http://www.gnome.org\";>http://www.gnome.org</a></div><div><br></div>" HTML_SUFFIX,
-               "URL:\nhttp://www.gnome.org\n";))
+               "URL:\nhttp://www.gnome.org\n\n";))
                g_test_fail ();
 }
 
@@ -5738,7 +5738,7 @@ test_undo_link_paste_plain (TestFixture *fixture)
                HTML_PREFIX "<div style=\"width: 71ch;\">URL:</div>"
                "<div style=\"width: 71ch;\"><a href=\"http://www.gnome.org\";>http://www.gnome.org</a></div>"
                "<div style=\"width: 71ch;\"><br></div>" HTML_SUFFIX,
-               "URL:\nhttp://www.gnome.org\n";))
+               "URL:\nhttp://www.gnome.org\n\n";))
                g_test_fail ();
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]