[evolution/wip/mcrha/webkit-jsc-api] test-html-editor: Adapt some unit tests to changes from other unit tests



commit 025d6e1eb6eacf23219bbabe46a8da194dc6b720
Author: Milan Crha <mcrha redhat com>
Date:   Mon Apr 6 20:04:21 2020 +0200

    test-html-editor: Adapt some unit tests to changes from other unit tests

 data/webkit/e-editor.js                     | 23 ++++++--
 src/e-util/test-html-editor-units-bugs.c    |  7 ++-
 src/e-util/test-html-editor-units.c         | 82 ++++++++++++++++++++---------
 src/modules/webkit-editor/e-webkit-editor.c |  2 -
 4 files changed, 82 insertions(+), 32 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index b029c7767e..ec489fa0bf 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -2907,7 +2907,7 @@ EvoEditor.requoteNodeParagraph = function(node)
        }
 
        if (!node || node.tagName == "BODY")
-               return;
+               return null;
 
        EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "requote", node, node,
                EvoEditor.CLAIM_CONTENT_FLAG_SAVE_HTML);
@@ -3096,7 +3096,7 @@ EvoEditor.removeEmptyElements = function(tagName)
 
                didRemove++;
 
-               EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "removeEmptyElem::" + tagName, node, 
node,
+               EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, "removeEmptyElem::" + tagName, 
node.parentElement, node.parentElement,
                        EvoEditor.CLAIM_CONTENT_FLAG_SAVE_HTML | 
EvoEditor.CLAIM_CONTENT_FLAG_USE_PARENT_BLOCK_NODE);
                try {
                        node.remove();
@@ -3154,10 +3154,24 @@ EvoEditor.beforeInputCb = function(inputEvent)
                                didRemove++;
 
                        if (didRemove) {
-                               EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, inputEvent.inputType 
+ "::selDeletion", selection.anchorNode, selection.focusNode,
+                               EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, inputEvent.inputType 
+ "::selDeletion", selection.anchorNode.parentElement, selection.focusNode.parentElement,
                                        EvoEditor.CLAIM_CONTENT_FLAG_SAVE_HTML | 
EvoEditor.CLAIM_CONTENT_FLAG_USE_PARENT_BLOCK_NODE);
                                try {
+                                       var anchorBlockquote = EvoEditor.getParentElement("BLOCKQUOTE", 
selection.anchorNode, true);
+                                       var blockquote = EvoEditor.getParentElement("BLOCKQUOTE", 
selection.focusNode, true);
+
                                        selection.deleteFromDocument();
+
+                                       if (blockquote && anchorBlockquote === blockquote && 
blockquote.lastElementChild &&
+                                           (blockquote.lastElementChild.tagName == "DIV" || 
blockquote.lastElementChild.tagName == "PRE") &&
+                                           (!blockquote.lastElementChild.childNodes.length || 
(blockquote.lastElementChild.childNodes.length == 1 &&
+                                            blockquote.lastElementChild.childNodes[0].nodeType == 
blockquote.TEXT_NODE && !blockquote.lastElementChild.childNodes[0].nodeValue))) {
+                                               // keep at least one empty DIV/PRE, when it's at the end of 
the BLOCKQUOTE
+                                               
blockquote.lastElementChild.append(document.createElement("BR"));
+
+                                               if 
(EvoEditor.requoteNodeParagraph(blockquote.lastElementChild.firstElementChild))
+                                                    didRemove++;
+                                       }
                                } finally {
                                        EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_CUSTOM, 
inputEvent.inputType + "::selDeletion");
                                }
@@ -4521,7 +4535,8 @@ EvoEditor.replaceSelectionWord = function(opType, expandWord, replacement)
 
                        /* Insert the word on current location. */
                        range.insertNode(fragment);
-                       document.getSelection().modify("move", "forward", "word");
+
+                       document.getSelection().setPosition(text, replacement ? replacement.length : 0);
                }
        } finally {
                EvoUndoRedo.StopRecord(EvoUndoRedo.RECORD_KIND_EVENT, opType);
diff --git a/src/e-util/test-html-editor-units-bugs.c b/src/e-util/test-html-editor-units-bugs.c
index 47254aa35d..aff33738d1 100644
--- a/src/e-util/test-html-editor-units-bugs.c
+++ b/src/e-util/test-html-editor-units-bugs.c
@@ -55,8 +55,11 @@ test_bug_726548 (TestFixture *fixture)
        success = test_utils_html_equal (fixture, text, expected_plain);
 
        if (!success) {
-               g_warning ("%s: clipboard Plain text \n---%s---\n does not match expected Plain\n---%s---",
-                       G_STRFUNC, text, expected_plain);
+               if (test_utils_get_keep_going ())
+                       g_printerr ("%s: clipboard Plain text \n---%s---\n does not match expected 
Plain\n---%s---", G_STRFUNC, text, expected_plain);
+               else
+                       g_warning ("%s: clipboard Plain text \n---%s---\n does not match expected 
Plain\n---%s---", G_STRFUNC, text, expected_plain);
+
                g_free (text);
                g_test_fail ();
        } else {
diff --git a/src/e-util/test-html-editor-units.c b/src/e-util/test-html-editor-units.c
index 9bc292d269..5adaf9039a 100644
--- a/src/e-util/test-html-editor-units.c
+++ b/src/e-util/test-html-editor-units.c
@@ -1058,7 +1058,7 @@ test_list_indent_same (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:d\n"
+               "seq:dh\n"
                "action:unindent\n"
                "action:style-preformat\n",
                !is_html ? NULL :
@@ -1210,7 +1210,7 @@ test_list_indent_same (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:uuuSds\n"
+               "seq:uuuhSdes\n"
                "action:unindent\n"
                "action:style-preformat\n",
                !is_html ? NULL :
@@ -1285,7 +1285,7 @@ test_list_indent_same (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:duSds\n"
+               "seq:duhSdes\n"
                "action:unindent\n"
                "action:style-preformat\n",
                !is_html ? NULL :
@@ -1362,7 +1362,7 @@ test_list_indent_same (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:dSus\n"
+               "seq:dhSues\n"
                "action:unindent\n"
                "action:style-preformat\n",
                !is_html ? NULL :
@@ -1478,7 +1478,7 @@ test_list_indent_same (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:uuuSddds\n"
+               "seq:uuuhSdddes\n"
                "action:unindent\n"
                "action:style-preformat\n",
                !is_html ? NULL :
@@ -1644,7 +1644,7 @@ test_list_indent_same (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:d\n"
+               "seq:dh\n"
                "action:unindent\n"
                "action:style-preformat\n",
                !is_html ? NULL :
@@ -1729,7 +1729,7 @@ test_list_indent_same (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:dd\n"
+               "seq:ddh\n"
                "action:unindent\n"
                "action:style-preformat\n",
                !is_html ? NULL :
@@ -1812,7 +1812,7 @@ test_list_indent_same (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:uuuSds\n"
+               "seq:uuuhSdes\n"
                "action:unindent\n"
                "action:style-preformat\n",
                !is_html ? NULL :
@@ -1895,7 +1895,7 @@ test_list_indent_same (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:duSds\n"
+               "seq:duhSdes\n"
                "action:unindent\n"
                "action:style-preformat\n",
                !is_html ? NULL :
@@ -1980,7 +1980,7 @@ test_list_indent_same (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:dSus\n"
+               "seq:deSuhs\n"
                "action:unindent\n"
                "action:style-preformat\n",
                !is_html ? NULL :
@@ -2302,7 +2302,7 @@ test_list_indent_different (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:uuuSds\n"
+               "seq:uuuhSdes\n"
                "action:indent\n"
                "action:style-list-number\n",
                !is_html ? NULL :
@@ -2367,7 +2367,7 @@ test_list_indent_different (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:duSds\n"
+               "seq:duhSdes\n"
                "action:indent\n"
                "action:style-list-alpha\n",
                !is_html ? NULL :
@@ -2434,7 +2434,7 @@ test_list_indent_different (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:dSus\n"
+               "seq:deSuhs\n"
                "action:indent\n"
                "action:style-list-roman\n",
                !is_html ? NULL :
@@ -2749,7 +2749,7 @@ test_list_indent_different (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:uuuSds\n"
+               "seq:uuuhSdes\n"
                "action:indent\n"
                "action:style-list-bullet\n",
                !is_html ? NULL :
@@ -2822,7 +2822,7 @@ test_list_indent_different (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:duSds\n"
+               "seq:duhSdes\n"
                "action:indent\n"
                "action:style-list-alpha\n",
                !is_html ? NULL :
@@ -2897,7 +2897,7 @@ test_list_indent_different (TestFixture *fixture,
 
        if (!test_utils_run_simple_test (fixture,
                "undo:save\n" /* 1 */
-               "seq:dSus\n"
+               "seq:deSuhs\n"
                "action:indent\n"
                "action:style-list-roman\n",
                !is_html ? NULL :
@@ -4412,7 +4412,7 @@ test_paste_quoted_singleline_html2plain (TestFixture *fixture)
                        "<div>" QUOTE_SPAN (QUOTE_CHR) "some bold text</div>"
                "</blockquote>"
                "<div style=\"width: 71ch;\">text after</div>" HTML_SUFFIX,
-               "text before\n"
+               "text before \n"
                "> some bold text\n"
                "text after\n"))
                g_test_fail ();
@@ -4452,7 +4452,7 @@ test_paste_quoted_singleline_plain2plain (TestFixture *fixture)
                HTML_PREFIX "<div style=\"width: 71ch;\">text before </div>"
                "<blockquote type=\"cite\"><div>" QUOTE_SPAN (QUOTE_CHR) "some plain text</div></blockquote>"
                "<div style=\"width: 71ch;\">text after</div>" HTML_SUFFIX,
-               "text before\n"
+               "text before \n"
                "> some plain text\n"
                "text after\n"))
                g_test_fail ();
@@ -4498,7 +4498,7 @@ test_paste_quoted_multiline_html2plain (TestFixture *fixture)
                QUOTE_SPAN (QUOTE_CHR) "italic text<br>"
                QUOTE_SPAN (QUOTE_CHR) "underline text</div></blockquote>"
                "<div style=\"width: 71ch;\">text after</div>" HTML_SUFFIX,
-               "text before\n"
+               "text before \n"
                "> bold text\n"
                "> italic text\n"
                "> underline text\n"
@@ -4548,7 +4548,7 @@ test_paste_quoted_multiline_plain2plain (TestFixture *fixture)
                "<div>" QUOTE_SPAN (QUOTE_CHR) "line 2</div>"
                "<div>" QUOTE_SPAN (QUOTE_CHR) "line 3</div></blockquote>"
                "<div style=\"width: 71ch;\">text after</div>" HTML_SUFFIX,
-               "text before\n"
+               "text before \n"
                "> line 1\n"
                "> line 2\n"
                "> line 3\n"
@@ -4781,8 +4781,8 @@ test_cite_longline (TestFixture *fixture)
                "</blockquote><br>after quote" HTML_SUFFIX,
                "> This is the first paragraph of a quoted text which has some long text\n"
                "> to test. It has the second sentence as well.\n"
-               "> This is the second paragraph of a quoted text which has some long text\n"
-               "> to test. It has the second sentence as well.\n"
+               "> This is the second paragraph of a quoted text which has some long\n"
+               "> text to test. It has the second sentence as well.\n"
                "> This is the third paragraph of a quoted text which has some long text\n"
                "> to test. It has the second sentence as well.\n"
                "\nafter quote")) {
@@ -4841,6 +4841,40 @@ test_cite_reply_html_to_plain (TestFixture *fixture)
                return;
        }
 
+       if (!test_utils_run_simple_test (fixture,
+               "",
+               HTML_PREFIX "<div style=\"width: 71ch;\">On Today, User wrote:</div>"
+               "<blockquote type=\"cite\">"
+               "<pre>" QUOTE_SPAN (QUOTE_CHR) "line 1</pre>"
+               "<pre>" QUOTE_SPAN (QUOTE_CHR) "line 2</pre>"
+               "<pre>" QUOTE_SPAN (QUOTE_CHR) "<br></pre></blockquote>" HTML_SUFFIX,
+               "On Today, User wrote:\n"
+               "> line 1\n"
+               "> line 2\n"
+               "> \n")) {
+               g_test_fail ();
+               return;
+       }
+
+       if (!test_utils_process_commands (fixture,
+               "mode:html\n")) {
+               g_test_fail ();
+               return;
+       }
+
+       test_utils_insert_content (fixture,
+               "<div>line 1</div>"
+               "<div>line 2</div><br>"
+               "<span class=\"-x-evo-to-body\" data-credits=\"On Today, User wrote:\"></span>"
+               "<span class=\"-x-evo-cite-body\"></span>",
+               E_CONTENT_EDITOR_INSERT_REPLACE_ALL | E_CONTENT_EDITOR_INSERT_TEXT_HTML);
+
+       if (!test_utils_process_commands (fixture,
+               "mode:plain\n")) {
+               g_test_fail ();
+               return;
+       }
+
        if (!test_utils_run_simple_test (fixture,
                "",
                HTML_PREFIX "<div style=\"width: 71ch;\">On Today, User wrote:</div>"
@@ -5803,8 +5837,8 @@ test_delete_after_quoted (TestFixture *fixture)
                "seq:dddb\n",
                HTML_PREFIX "<div style=\"width: 71ch;\">On Thu, 2016-09-15 at 08:08 -0400, user wrote:</div>"
                "<blockquote type=\"cite\">"
-               "<div>" QUOTE_SPAN (QUOTE_CHR) "a</div>"
-               "<div>" QUOTE_SPAN (QUOTE_CHR) "b</div>"
+               "<pre>" QUOTE_SPAN (QUOTE_CHR) "a</pre>"
+               "<pre>" QUOTE_SPAN (QUOTE_CHR) "b</pre>"
                "</blockquote>"
                HTML_SUFFIX,
                "On Thu, 2016-09-15 at 08:08 -0400, user wrote:\n"
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 713bf1b0d6..af1da34344 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -2807,8 +2807,6 @@ webkit_editor_replace_all (EContentEditor *editor,
        wk_editor->priv->performing_replace_all = TRUE;
        wk_editor->priv->replaced_count = 0;
 
-       webkit_web_view_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor), 
"MoveToBeginningOfDocumentAndModifySelection");
-
        e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
                "EvoUndoRedo.StartRecord(EvoUndoRedo.RECORD_KIND_GROUP, %s);", "ReplaceAll");
 


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