[evolution/wip/webkit2] Fix the content editor tests



commit 9f800f9b80352dba48df1655d57bc730f571293f
Author: Tomas Popela <tpopela redhat com>
Date:   Thu Jul 14 12:23:48 2016 +0200

    Fix the content editor tests

 e-util/test-html-editor-units.c                    |  104 ++++++++++----------
 .../web-extension/e-editor-dom-functions.c         |   37 +++++--
 .../web-extension/e-editor-web-extension.c         |    4 +-
 3 files changed, 81 insertions(+), 64 deletions(-)
---
diff --git a/e-util/test-html-editor-units.c b/e-util/test-html-editor-units.c
index 7a0e99f..7494f83 100644
--- a/e-util/test-html-editor-units.c
+++ b/e-util/test-html-editor-units.c
@@ -24,10 +24,10 @@
 #include "e-html-editor-private.h"
 #include "test-html-editor-units-utils.h"
 
-#define HTML_PREFIX "<html><head></head><body><p data-evo-paragraph=\"\">"
+#define HTML_PREFIX "<html><head></head><body>"
 #define HTML_PREFIX_PLAIN "<html><head></head><body style=\"font-family: Monospace;\">" \
-       "<p data-evo-paragraph=\"\" style=\"width: 71ch; word-wrap: break-word; word-break: break-word; \">"
-#define HTML_SUFFIX "</p></body></html>"
+       "<p style=\"width: 71ch; word-wrap: break-word; word-break: break-word; \">"
+#define HTML_SUFFIX "</body></html>"
 
 /* The tests do not use the 'user_data' argument, thus the functions avoid them and the typecast is needed. 
*/
 typedef void (* ETestFixtureFunc) (TestFixture *fixture, gconstpointer user_data);
@@ -46,12 +46,12 @@ test_create_editor (TestFixture *fixture)
 static void
 test_style_bold_selection (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
                "type:some bold text\n"
                "seq:hCrcrCSrsc\n"
                "action:bold\n",
-               HTML_PREFIX "some <b>bold</b> text" HTML_SUFFIX,
+               HTML_PREFIX "<p>some <b>bold</b> text</p>" HTML_SUFFIX,
                "some bold text"))
                g_test_fail ();
 }
@@ -59,14 +59,14 @@ test_style_bold_selection (TestFixture *fixture)
 static void
 test_style_bold_typed (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
                "type:some \n"
                "action:bold\n"
                "type:bold\n"
                "action:bold\n"
                "type: text\n",
-               HTML_PREFIX "some <b>bold</b> text" HTML_SUFFIX,
+               HTML_PREFIX "<p>some <b>bold</b> text</p>" HTML_SUFFIX,
                "some bold text"))
                g_test_fail ();
 }
@@ -74,12 +74,12 @@ test_style_bold_typed (TestFixture *fixture)
 static void
 test_style_italic_selection (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
                "type:some italic text\n"
                "seq:hCrcrCSrsc\n"
                "action:italic\n",
-               HTML_PREFIX "some <i>italic</i> text" HTML_SUFFIX,
+               HTML_PREFIX "<p>some <i>italic</i> text</p>" HTML_SUFFIX,
                "some italic text"))
                g_test_fail ();
 }
@@ -87,14 +87,14 @@ test_style_italic_selection (TestFixture *fixture)
 static void
 test_style_italic_typed (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
                "type:some \n"
                "action:italic\n"
                "type:italic\n"
                "action:italic\n"
                "type: text\n",
-               HTML_PREFIX "some <i>italic</i> text" HTML_SUFFIX,
+               HTML_PREFIX "<p>some <i>italic</i> text</p>" HTML_SUFFIX,
                "some italic text"))
                g_test_fail ();
 }
@@ -102,12 +102,12 @@ test_style_italic_typed (TestFixture *fixture)
 static void
 test_style_underline_selection (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
                "type:some underline text\n"
                "seq:hCrcrCSrsc\n"
                "action:underline\n",
-               HTML_PREFIX "some <u>underline</u> text" HTML_SUFFIX,
+               HTML_PREFIX "<p>some <u>underline</u> text</p>" HTML_SUFFIX,
                "some underline text"))
                g_test_fail ();
 }
@@ -115,14 +115,14 @@ test_style_underline_selection (TestFixture *fixture)
 static void
 test_style_underline_typed (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
                "type:some \n"
                "action:underline\n"
                "type:underline\n"
                "action:underline\n"
                "type: text\n",
-               HTML_PREFIX "some <u>underline</u> text" HTML_SUFFIX,
+               HTML_PREFIX "<p>some <u>underline</u> text</p>" HTML_SUFFIX,
                "some underline text"))
                g_test_fail ();
 }
@@ -130,12 +130,12 @@ test_style_underline_typed (TestFixture *fixture)
 static void
 test_style_monospace_selection (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
                "type:some monospace text\n"
                "seq:hCrcrCSrsc\n"
                "action:monospaced\n",
-               HTML_PREFIX "some <font face=\"monospace\" size=\"3\">monospace</font> text" HTML_SUFFIX,
+               HTML_PREFIX "<p>some <font face=\"monospace\" size=\"3\">monospace</font> text</p>" 
HTML_SUFFIX,
                "some monospace text"))
                g_test_fail ();
 }
@@ -143,14 +143,14 @@ test_style_monospace_selection (TestFixture *fixture)
 static void
 test_style_monospace_typed (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
                "type:some \n"
                "action:monospaced\n"
                "type:monospace\n"
                "action:monospaced\n"
                "type: text\n",
-               HTML_PREFIX "some <font face=\"monospace\" size=\"3\">monospace</font> text" HTML_SUFFIX,
+               HTML_PREFIX "<p>some <font face=\"monospace\" size=\"3\">monospace</font> text</p>" 
HTML_SUFFIX,
                "some monospace text"))
                g_test_fail ();
 }
@@ -158,7 +158,7 @@ test_style_monospace_typed (TestFixture *fixture)
 static void
 test_undo_text_typed (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
                "type:some te\n"
                "undo:save\n"   /* 1 */
@@ -173,7 +173,7 @@ test_undo_text_typed (TestFixture *fixture)
                "undo:undo:2\n"
                "undo:drop\n"
                "type:xt\n",
-               HTML_PREFIX "some text" HTML_SUFFIX,
+               HTML_PREFIX "<p>some text</p>" HTML_SUFFIX,
                "some text"))
                g_test_fail ();
 }
@@ -181,9 +181,8 @@ test_undo_text_typed (TestFixture *fixture)
 static void
 test_justify_selection (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
-               "seq:n\n" /* new line, to be able to use HTML_PREFIX macro */
                "type:center\\n\n"
                "type:right\\n\n"
                "type:left\\n\n"
@@ -193,40 +192,43 @@ test_justify_selection (TestFixture *fixture)
                "action:justify-right\n"
                "seq:d\n"
                "action:justify-left\n",
-               HTML_PREFIX "<br></p>"
-                       "<p data-evo-paragraph=\"\" style=\"text-align: center\">center</p>"
-                       "<p data-evo-paragraph=\"\" style=\"text-align: right\">right</p>"
-                       "<p data-evo-paragraph=\"\">left</p><p data-evo-paragraph=\"\"><br>"
+               HTML_PREFIX
+                       "<p style=\"text-align: center\">center</p>"
+                       "<p style=\"text-align: right\">right</p>"
+                       "<p>left</p><p><br></p>"
                HTML_SUFFIX,
-               "\ncenter\nright\nleft\n"))
+               "                                center\n"
+               "                                                                  right\n"
+               "left\n"))
                g_test_fail ();
 }
 
 static void
 test_justify_typed (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
-               "seq:n\n" /* new line, to be able to use HTML_PREFIX macro */
                "action:justify-center\n"
                "type:center\\n\n"
                "action:justify-right\n"
                "type:right\\n\n"
                "action:justify-left\n"
                "type:left\\n\n",
-               HTML_PREFIX "<br></p>"
-                       "<p data-evo-paragraph=\"\" style=\"text-align: center\">center</p>"
-                       "<p data-evo-paragraph=\"\" style=\"text-align: right\">right</p>"
-                       "<p data-evo-paragraph=\"\">left</p><p data-evo-paragraph=\"\"><br>"
+               HTML_PREFIX
+                       "<p style=\"text-align: center\">center</p>"
+                       "<p style=\"text-align: right\">right</p>"
+                       "<p>left</p><p><br></p>"
                HTML_SUFFIX,
-               "\ncenter\nright\nleft\n"))
+               "                                center\n"
+               "                                                                  right\n"
+               "left\n"))
                g_test_fail ();
 }
 
 static void
 test_indent_selection (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
                "type:level 0\\n\n"
                "type:level 1\\n\n"
@@ -242,12 +244,12 @@ test_indent_selection (TestFixture *fixture)
                "action:indent\n" /* just to try whether the unindent will work too */
                "action:unindent\n",
                HTML_PREFIX
-                       "level 0</p>"
+                       "<p>level 0</p>"
                        "<div style=\"margin-left: 3ch;\">"
-                               "<p data-evo-paragraph=\"\">level 1</p>"
-                               "<div style=\"margin-left: 3ch;\"><p data-evo-paragraph=\"\">level 
2</p></div>"
-                               "<p data-evo-paragraph=\"\">level 1</p>"
-                       "</div><p data-evo-paragraph=\"\"><br>"
+                               "<p>level 1</p>"
+                               "<div style=\"margin-left: 3ch;\"><p>level 2</p></div>"
+                               "<p>level 1</p>"
+                       "</div><p><br></p>"
                HTML_SUFFIX,
                "level 0\n"
                "    level 1\n"
@@ -259,7 +261,7 @@ test_indent_selection (TestFixture *fixture)
 static void
 test_indent_typed (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
                "type:level 0\\n\n"
                "action:indent\n"
@@ -270,12 +272,12 @@ test_indent_typed (TestFixture *fixture)
                "type:level 1\\n\n"
                "action:unindent\n",
                HTML_PREFIX
-                       "level 0</p>"
+                       "<p>level 0</p>"
                        "<div style=\"margin-left: 3ch;\">"
-                               "<p data-evo-paragraph=\"\">level 1</p>"
-                               "<div style=\"margin-left: 3ch;\"><p data-evo-paragraph=\"\">level 
2</p></div>"
-                               "<p data-evo-paragraph=\"\">level 1</p>"
-                       "</div><p data-evo-paragraph=\"\"><br>"
+                               "<p>level 1</p>"
+                               "<div style=\"margin-left: 3ch;\"><p>level 2</p></div>"
+                               "<p>level 1</p>"
+                       "</div><p><br></p>"
                HTML_SUFFIX,
                "level 0\n"
                "    level 1\n"
@@ -287,12 +289,12 @@ test_indent_typed (TestFixture *fixture)
 static void
 test_font_size_selection (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
                "type:some monospace text\n"
                "seq:hCrcrCSrsc\n"
                "action:monospaced\n",
-               HTML_PREFIX "some <font face=\"monospace\" size=\"3\">monospace</font> text" HTML_SUFFIX,
+               HTML_PREFIX "<p>some <font face=\"monospace\" size=\"3\">monospace</font> text</p>" 
HTML_SUFFIX,
                "some monospace text"))
                g_test_fail ();
 }
@@ -300,14 +302,14 @@ test_font_size_selection (TestFixture *fixture)
 static void
 test_font_size_typed (TestFixture *fixture)
 {
-       if (!test_utils_run_simple_test (fixture,
+       if (!test_utils_run_simple_test (fixture,
                "mode:html\n"
                "type:some \n"
                "action:monospaced\n"
                "type:monospace\n"
                "action:monospaced\n"
                "type: text\n",
-               HTML_PREFIX "some <font face=\"monospace\" size=\"3\">monospace</font> text" HTML_SUFFIX,
+               HTML_PREFIX "<p>some <font face=\"monospace\" size=\"3\">monospace</font> text</p>" 
HTML_SUFFIX,
                "some monospace text"))
                g_test_fail ();
 }
diff --git a/modules/webkit-editor/web-extension/e-editor-dom-functions.c 
b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
index 27eaaf2..d340567 100644
--- a/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -7014,6 +7014,7 @@ remove_base_attributes (WebKitDOMElement *element)
 static void
 remove_evolution_attributes (WebKitDOMElement *element)
 {
+       webkit_dom_element_remove_attribute (element, "data-evo-paragraph");
        webkit_dom_element_remove_attribute (element, "data-converted");
        webkit_dom_element_remove_attribute (element, "data-edit-as-new");
        webkit_dom_element_remove_attribute (element, "data-evo-draft");
@@ -7428,23 +7429,23 @@ process_node_to_html_for_exporting (EEditorPage *editor_page,
        remove_evolution_attributes (WEBKIT_DOM_ELEMENT (source));
 
        /* Aligned elements */
-       list = webkit_dom_element_query_selector_all (WEBKIT_DOM_ELEMENT (source), 
"[class^=\"-x-evo-align\"]", NULL);
+       list = webkit_dom_element_query_selector_all (WEBKIT_DOM_ELEMENT (source), 
"[class*=\"-x-evo-align\"]", NULL);
        length = webkit_dom_node_list_get_length (list);
 
        for (ii = 0; ii < length; ii++) {
                gchar *class = NULL;
-               const gchar *align_type;
                WebKitDOMNode *node;
+               gboolean center = FALSE;
 
                node = webkit_dom_node_list_item (list, ii);
                class = webkit_dom_element_get_class_name (WEBKIT_DOM_ELEMENT (node));
-               align_type = class + 13;
-               if (!g_str_has_prefix (align_type, "left")) {
+               center = g_strrstr (class, "center") != NULL;
+               if (center || g_strrstr (class, "right")) {
                        if (WEBKIT_DOM_IS_HTML_LI_ELEMENT (node))
                                webkit_dom_element_set_attribute (
                                        WEBKIT_DOM_ELEMENT (node),
                                        "style",
-                                       g_str_has_prefix (align_type, "center") ?
+                                       center ?
                                                "list-style-position: inside; text-align: center" :
                                                "list-style-position: inside; text-align: right",
                                        NULL);
@@ -7452,7 +7453,7 @@ process_node_to_html_for_exporting (EEditorPage *editor_page,
                                webkit_dom_element_set_attribute (
                                        WEBKIT_DOM_ELEMENT (node),
                                        "style",
-                                       g_str_has_prefix (align_type + 13, "center") ?
+                                       center ?
                                                "text-align: center" :
                                                "text-align: right",
                                        NULL);
@@ -7597,13 +7598,14 @@ process_node_to_html_for_exporting (EEditorPage *editor_page,
        g_object_unref (collection);
 
        list = webkit_dom_element_query_selector_all (
-               WEBKIT_DOM_ELEMENT (source), ".-x-evo-paragraph", NULL);
+               WEBKIT_DOM_ELEMENT (source), "p[data-evo-paragraph]", NULL);
        length = webkit_dom_node_list_get_length (list);
        for (ii = 0; ii < length; ii++) {
                WebKitDOMNode *node;
 
                node = webkit_dom_node_list_item (list, ii);
-               element_remove_class (WEBKIT_DOM_ELEMENT (node), "-x-evo-paragraph");
+               remove_evolution_attributes (WEBKIT_DOM_ELEMENT (node));
+               remove_base_attributes (WEBKIT_DOM_ELEMENT (node));
                g_object_unref (node);
        }
        g_object_unref (list);
@@ -8172,9 +8174,9 @@ e_editor_dom_process_content_to_plain_text_for_exporting (EEditorPage *editor_pa
                                WebKitDOMNode *next_item =
                                        webkit_dom_node_get_next_sibling (item);
 
-                               if (WEBKIT_DOM_IS_HTML_LI_ELEMENT (item)) {
+                               if (WEBKIT_DOM_IS_HTML_LI_ELEMENT (item))
                                        e_editor_dom_wrap_paragraph (editor_page, WEBKIT_DOM_ELEMENT (item));
-                               }
+
                                item = next_item;
                        }
                } else if (!webkit_dom_element_query_selector (WEBKIT_DOM_ELEMENT (paragraph), 
".-x-evo-wrap-br,.-x-evo-quoted", NULL)) {
@@ -8211,6 +8213,11 @@ e_editor_dom_process_content_to_plain_text_for_exporting (EEditorPage *editor_pa
        }
 
        process_node_to_plain_text_for_exporting (editor_page, source, plain_text);
+       /* Truncate the extra new line on the end of generated text as the
+        * check inside the previous function is based on whether the processed
+        * node is BODY or not, but in this case the content is wrapped in DIV. */
+       if (remove_last_new_line)
+               g_string_truncate (plain_text, plain_text->len - 1);
 
        e_editor_dom_selection_restore (editor_page);
 
@@ -8528,6 +8535,8 @@ adapt_to_editor_dom_changes (WebKitDOMDocument *document)
 
                node = webkit_dom_html_collection_item (collection, ii);
                element = webkit_dom_document_create_element (document, "p", NULL);
+               webkit_dom_element_set_attribute (element, "data-evo-paragraph", "", NULL);
+
                webkit_dom_node_insert_before (
                        webkit_dom_node_get_parent_node (node),
                        WEBKIT_DOM_NODE (element),
@@ -13510,7 +13519,7 @@ wrap_lines (EEditorPage *editor_page,
                                newline = strstr (text_content, "\n");
                        }
                        g_free (text_content);
-               } else {
+               } else if (WEBKIT_DOM_IS_ELEMENT (node)) {
                        if (e_editor_dom_is_selection_position_node (node)) {
                                if (line_length == 0) {
                                        WebKitDOMNode *tmp_node;
@@ -13607,6 +13616,12 @@ wrap_lines (EEditorPage *editor_page,
                                }
                        }
                        goto next_node;
+               } else {
+                       WebKitDOMNode *sibling;
+
+                       sibling = webkit_dom_node_get_next_sibling (node);
+                       node = sibling;
+                       continue;
                }
 
                /* If length of this node + what we already have is still less
diff --git a/modules/webkit-editor/web-extension/e-editor-web-extension.c 
b/modules/webkit-editor/web-extension/e-editor-web-extension.c
index e25cf58..60ace08 100644
--- a/modules/webkit-editor/web-extension/e-editor-web-extension.c
+++ b/modules/webkit-editor/web-extension/e-editor-web-extension.c
@@ -658,7 +658,7 @@ handle_method_call (GDBusConnection *connection,
        if (g_strcmp0 (interface_name, E_WEBKIT_EDITOR_WEB_EXTENSION_INTERFACE) != 0)
                return;
 
-       if (g_strcmp0 (method_name, "TestHtmlEqual") == 0) {
+       if (g_strcmp0 (method_name, "TestHTMLEqual") == 0) {
                gboolean equal = FALSE;
                const gchar *html1 = NULL, *html2 = NULL;
 
@@ -2267,7 +2267,7 @@ handle_method_call (GDBusConnection *connection,
 
                g_dbus_method_invocation_return_value (invocation, NULL);
        } else {
-               g_warning ("UNKNOWN METHOD '%s:i'", method_name);
+               g_warning ("UNKNOWN METHOD '%s'", method_name);
        }
 
        return;


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