2010-06-08 Xan Lopez <xlopez@igalia.com>
authorxan@webkit.org <xan@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Jun 2010 14:42:59 +0000 (14:42 +0000)
committerxan@webkit.org <xan@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Jun 2010 14:42:59 +0000 (14:42 +0000)
        Reviewed by Gustavo Noronha.

        [GTK] Unit testing for WebKitDOMNode hierarchy walk
        https://bugs.webkit.org/show_bug.cgi?id=40171

        Add DOM node test to the build system.

        * GNUmakefile.am:

WebKit/gtk:

2010-06-08  Xan Lopez  <xlopez@igalia.com>

        Reviewed by Gustavo Noronha.

        [GTK] Unit testing for WebKitDOMNode hierarchy walk
        https://bugs.webkit.org/show_bug.cgi?id=40171

        Add some DOM node unit testing.

        * tests/testdomnode.c: Added.
        (finish_loading):
        (dom_node_fixture_setup):
        (dom_node_fixture_teardown):
        (test_dom_node_hierarchy_navigation):
        (main):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@60842 268f45cc-cd09-0410-ab3c-d52691b4dbfc

ChangeLog
GNUmakefile.am
WebKit/gtk/ChangeLog
WebKit/gtk/tests/testdomnode.c [new file with mode: 0644]

index ef17c28..1dc092c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-06-08  Xan Lopez  <xlopez@igalia.com>
+
+        Reviewed by Gustavo Noronha.
+
+        [GTK] Unit testing for WebKitDOMNode hierarchy walk
+        https://bugs.webkit.org/show_bug.cgi?id=40171
+
+        Add DOM node test to the build system.
+
+        * GNUmakefile.am:
+
 2010-06-02  Sterling Swigart  <sswigart@google.com>
 
         Reviewed by David Levin.
index bb96036..1168782 100644 (file)
@@ -644,6 +644,7 @@ webkit_tests_ldflags = \
 TEST_PROGS += \
        Programs/unittests/testdomdocument \
        Programs/unittests/testdomdomwindow \
+       Programs/unittests/testdomnode \
        Programs/unittests/testhttpbackend \
        Programs/unittests/testloading \
        Programs/unittests/testglobals \
@@ -676,6 +677,11 @@ Programs_unittests_testdomdomwindow_CFLAGS = $(webkit_tests_cflags)
 Programs_unittests_testdomdomwindow_LDADD = $(webkit_tests_ldadd)
 Programs_unittests_testdomdomwindow_LDFLAGS = $(webkit_tests_ldflags)
 
+Programs_unittests_testdomnode_SOURCES = WebKit/gtk/tests/testdomnode.c
+Programs_unittests_testdomnode_CFLAGS = $(webkit_tests_cflags)
+Programs_unittests_testdomnode_LDADD = $(webkit_tests_ldadd)
+Programs_unittests_testdomnode_LDFLAGS = $(webkit_tests_ldflags)
+
 Programs_unittests_testhttpbackend_SOURCES = WebKit/gtk/tests/testhttpbackend.c
 Programs_unittests_testhttpbackend_CFLAGS = $(webkit_tests_cflags)
 Programs_unittests_testhttpbackend_LDADD = $(webkit_tests_ldadd)
index 0b7f1fd..f7f4c8f 100644 (file)
@@ -1,3 +1,19 @@
+2010-06-08  Xan Lopez  <xlopez@igalia.com>
+
+        Reviewed by Gustavo Noronha.
+
+        [GTK] Unit testing for WebKitDOMNode hierarchy walk
+        https://bugs.webkit.org/show_bug.cgi?id=40171
+
+        Add some DOM node unit testing.
+
+        * tests/testdomnode.c: Added.
+        (finish_loading):
+        (dom_node_fixture_setup):
+        (dom_node_fixture_teardown):
+        (test_dom_node_hierarchy_navigation):
+        (main):
+
 2010-06-08  Antonio Gomes  <tonikitoo@webkit.org>
 
         Reviewed by Ojan Vafai and Darin Adler.
diff --git a/WebKit/gtk/tests/testdomnode.c b/WebKit/gtk/tests/testdomnode.c
new file mode 100644 (file)
index 0000000..1050587
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2010 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "test_utils.h"
+
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <gtk/gtk.h>
+#include <webkit/webkit.h>
+
+#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0)
+
+#define HTML_DOCUMENT_HIERARCHY_NAVIGATION "<html><head><title>This is the title</title></head><body><p>1</p><p>2</p><p>3</p></body></html>"
+
+typedef struct {
+    GtkWidget* webView;
+    GMainLoop* loop;
+} DomNodeFixture;
+
+static gboolean finish_loading(DomNodeFixture* fixture)
+{
+    if (g_main_loop_is_running(fixture->loop))
+        g_main_loop_quit(fixture->loop);
+
+    return FALSE;
+}
+
+static void dom_node_fixture_setup(DomNodeFixture* fixture, gconstpointer data)
+{
+    fixture->loop = g_main_loop_new(NULL, TRUE);
+    fixture->webView = webkit_web_view_new();
+    g_object_ref_sink(fixture->webView);
+
+    if (data != NULL)
+        webkit_web_view_load_string(WEBKIT_WEB_VIEW(fixture->webView), (const char*)data, NULL, NULL, NULL);
+
+    g_idle_add((GSourceFunc)finish_loading, fixture);
+    g_main_loop_run(fixture->loop);
+}
+
+static void dom_node_fixture_teardown(DomNodeFixture* fixture, gconstpointer data)
+{
+    g_object_unref(fixture->webView);
+    g_main_loop_unref(fixture->loop);
+}
+
+static void test_dom_node_hierarchy_navigation(DomNodeFixture* fixture, gconstpointer data)
+{
+    WebKitDOMDocument* document;
+    WebKitDOMHTMLHeadElement* head;
+    WebKitDOMHTMLBodyElement* body;
+    WebKitDOMNodeList* list;
+    WebKitDOMNode* ptr;
+    gulong i, length;
+
+    document = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(fixture->webView));
+    g_assert(document);
+    g_assert(WEBKIT_DOM_IS_DOCUMENT(document));
+    head = webkit_dom_document_get_head(document);
+    g_assert(head);
+    g_assert(WEBKIT_DOM_IS_HTML_HEAD_ELEMENT(head));
+
+    /* Title, head's child */
+    g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(head)));
+    list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(head));
+    g_assert_cmpint(webkit_dom_node_list_get_length(list), ==, 1);
+    ptr = webkit_dom_node_list_item(list, 0);
+    g_assert(ptr);
+    g_assert(WEBKIT_DOM_IS_HTML_TITLE_ELEMENT(ptr));
+
+    /* Body, Head sibling */
+    ptr = webkit_dom_node_get_next_sibling(WEBKIT_DOM_NODE(head));
+    g_assert(ptr);
+    body = WEBKIT_DOM_HTML_BODY_ELEMENT(ptr);
+    g_assert(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(body));
+
+    /* There is no third sibling */
+    ptr = webkit_dom_node_get_next_sibling(ptr);
+    g_assert(ptr == NULL);
+
+    /* Body's previous sibling is Head */
+    ptr = webkit_dom_node_get_previous_sibling(WEBKIT_DOM_NODE(body));
+    g_assert(ptr);
+    g_assert(WEBKIT_DOM_IS_HTML_HEAD_ELEMENT(ptr));
+
+    /* Body has 3 children */
+    g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(body)));
+    list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(body));
+    length = webkit_dom_node_list_get_length(list);
+    g_assert_cmpint(length, ==, 3);
+
+    /* The three of them are P tags */
+    for (i = 0; i < length; i++) {
+        ptr = webkit_dom_node_list_item(list, i);
+        g_assert(ptr);
+        g_assert(WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT(ptr));
+    }
+
+    /* Go backwards */
+    for (i = 0; ptr; ptr = webkit_dom_node_get_previous_sibling(ptr), i++)
+        /* Nothing */;
+
+    g_assert_cmpint(i, ==, 3);
+}
+
+int main(int argc, char** argv)
+{
+    if (!g_thread_supported())
+        g_thread_init(NULL);
+
+    gtk_test_init(&argc, &argv, NULL);
+
+    g_test_bug_base("https://bugs.webkit.org/");
+
+    g_test_add("/webkit/domnode/test_hierarchy_navigation",
+               DomNodeFixture, HTML_DOCUMENT_HIERARCHY_NAVIGATION,
+               dom_node_fixture_setup,
+               test_dom_node_hierarchy_navigation,
+               dom_node_fixture_teardown);
+
+    return g_test_run();
+}
+
+#else
+int main(int argc, char** argv)
+{
+    g_critical("You will need at least glib-2.16.0 and gtk-2.14.0 to run the unit tests. Doing nothing now.");
+    return 0;
+}
+
+#endif