2010-04-29 Xan Lopez <xlopez@igalia.com>
authorxan@webkit.org <xan@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Apr 2010 13:50:07 +0000 (13:50 +0000)
committerxan@webkit.org <xan@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Apr 2010 13:50:07 +0000 (13:50 +0000)
        Reviewed by Gustavo Noronha.

        [GTK] GObject DOM bindings
        https://bugs.webkit.org/show_bug.cgi?id=33590

        Add WebKitDOMDocument tests to the build.

        * GNUmakefile.am:

WebKit/gtk:

2010-04-29  Xan Lopez  <xlopez@igalia.com>

        Reviewed by Gustavo Noronha.

        [GTK] GObject DOM bindings
        https://bugs.webkit.org/show_bug.cgi?id=33590

        Move WebKitDOMDocument unit tests to their own file.

        * tests/testdomdocument.c: Added.
        (finish_loading):
        (dom_document_fixture_setup):
        (dom_document_fixture_teardown):
        (test_dom_document_title):
        (main):
        * tests/testwebview.c:

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

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

index 581ec5a42b64d54bca3a9fd0c5d8cffd609c640c..d1dec5e97af4983c7057062804f515cad68caf68 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-04-29  Xan Lopez  <xlopez@igalia.com>
+
+        Reviewed by Gustavo Noronha.
+
+        [GTK] GObject DOM bindings
+        https://bugs.webkit.org/show_bug.cgi?id=33590
+
+        Add WebKitDOMDocument tests to the build.
+
+        * GNUmakefile.am:
+
 2010-04-28  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Mark Rowe.
index 368220d7cf6502d80f73cd649505f0a5fd6fc499..699a5ff07405b53edb3824479637b3910802c0f4 100644 (file)
@@ -622,7 +622,9 @@ webkit_tests_ldflags = \
        -no-install \
        -no-fast-install
 
-TEST_PROGS += Programs/unittests/testhttpbackend \
+TEST_PROGS += \
+       Programs/unittests/testdomdocument \
+       Programs/unittests/testhttpbackend \
        Programs/unittests/testloading \
        Programs/unittests/testglobals \
        Programs/unittests/testmimehandling \
@@ -643,6 +645,11 @@ TEST_PROGS += Programs/unittests/testhttpbackend \
        Programs/unittests/testkeyevents
 
 # Add additional tests here
+Programs_unittests_testdomdocument_SOURCES = WebKit/gtk/tests/testdomdocument.c
+Programs_unittests_testdomdocument_CFLAGS = $(webkit_tests_cflags)
+Programs_unittests_testdomdocument_LDADD = $(webkit_tests_ldadd)
+Programs_unittests_testdomdocument_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 53ee006120ea0d1f1a559b8ae84cd4cf25643dba..450ae67331872bb48ebc5d8202a92838ffef288f 100644 (file)
@@ -1,3 +1,20 @@
+2010-04-29  Xan Lopez  <xlopez@igalia.com>
+
+        Reviewed by Gustavo Noronha.
+
+        [GTK] GObject DOM bindings
+        https://bugs.webkit.org/show_bug.cgi?id=33590
+
+        Move WebKitDOMDocument unit tests to their own file.
+
+        * tests/testdomdocument.c: Added.
+        (finish_loading):
+        (dom_document_fixture_setup):
+        (dom_document_fixture_teardown):
+        (test_dom_document_title):
+        (main):
+        * tests/testwebview.c:
+
 2010-04-29  Xan Lopez  <xlopez@igalia.com>
 
         Reviewed by Gustavo Noronha.
diff --git a/WebKit/gtk/tests/testdomdocument.c b/WebKit/gtk/tests/testdomdocument.c
new file mode 100644 (file)
index 0000000..5d10bad
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * 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_TITLE "<html><head><title>This is the title</title></head><body></body></html>"
+
+typedef struct {
+    GtkWidget* webView;
+    GMainLoop* loop;
+} DomDocumentFixture;
+
+static gboolean finish_loading(DomDocumentFixture* fixture)
+{
+    if (g_main_loop_is_running(fixture->loop))
+        g_main_loop_quit(fixture->loop);
+
+    return FALSE;
+}
+
+static void dom_document_fixture_setup(DomDocumentFixture* 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_document_fixture_teardown(DomDocumentFixture* fixture, gconstpointer data)
+{
+    g_object_unref(fixture->webView);
+    g_main_loop_unref(fixture->loop);
+}
+
+static void test_dom_document_title(DomDocumentFixture* fixture, gconstpointer data)
+{
+    g_assert(fixture);
+    WebKitWebView* view = (WebKitWebView*)fixture->webView;
+    g_assert(view);
+    WebKitDOMDocument* document = webkit_web_view_get_dom_document(view);
+    g_assert(document);
+    gchar* title = webkit_dom_document_get_title(document);
+    g_assert(title);
+    g_assert_cmpstr(title, ==, "This is the title");
+    g_free(title);
+    webkit_dom_document_set_title(document, (gchar*)"This is the second title");
+    title = webkit_dom_document_get_title(document);
+    g_assert(title);
+    g_assert_cmpstr(title, ==, "This is the second title");
+    g_free(title);
+}
+
+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/domdocument/test_title",
+               DomDocumentFixture, HTML_DOCUMENT_TITLE,
+               dom_document_fixture_setup,
+               test_dom_document_title,
+               dom_document_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
index 71bc8be3bb49c0aafe62d7fa178700a936a82cc9..36511d7e3072031c2323a7ec8c747d5d77a36141 100644 (file)
@@ -336,41 +336,6 @@ static void test_webkit_web_view_window_features()
     gtk_widget_destroy(window);
 }    
 
-static void test_webkit_web_view_document()
-{
-    GtkWidget* window;
-    GtkWidget* web_view;
-    gchar* title;
-    WebKitDOMDocument* document;
-    
-    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-    web_view = webkit_web_view_new();
-    
-    gtk_container_add(GTK_CONTAINER(window), web_view);
-    gtk_widget_show_all(window);
-
-    loop = g_main_loop_new(NULL, TRUE);
-
-    g_signal_connect(window, "map-event",
-                     G_CALLBACK(map_event_cb), loop);
-    g_main_loop_run(loop);
-
-    document = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view));
-    g_assert(document);
-    webkit_dom_document_set_title(document, (gchar*)"First title");
-    title = webkit_dom_document_get_title(document);
-    g_assert(title);
-    g_assert_cmpstr(title, ==, "First title");
-    g_free(title);
-    webkit_dom_document_set_title(document, (gchar*)"Title changed by DOM bindings");
-    title = webkit_dom_document_get_title(document);
-    g_assert(title);
-    g_assert_cmpstr(title, ==, "Title changed by DOM bindings");
-    g_free(title);
-    
-    gtk_widget_destroy(window);
-}    
-
 int main(int argc, char** argv)
 {
     SoupServer* server;
@@ -399,7 +364,6 @@ int main(int argc, char** argv)
     g_test_add_func("/webkit/webview/destroy", test_webkit_web_view_destroy);
     g_test_add_func("/webkit/webview/grab_focus", test_webkit_web_view_grab_focus);
     g_test_add_func("/webkit/webview/window-features", test_webkit_web_view_window_features);
-    g_test_add_func("/webkit/webview/document", test_webkit_web_view_document);
 
     return g_test_run ();
 }