diff options
Diffstat (limited to 'WebKit/gtk/tests')
| -rw-r--r-- | WebKit/gtk/tests/testatk.c | 240 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testdownload.c | 167 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testhttpbackend.c | 86 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testloading.c | 115 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testnetworkrequest.c | 107 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testwebbackforwardlist.c | 30 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testwebframe.c | 102 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testwebhistoryitem.c | 4 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testwebsettings.c | 81 |
9 files changed, 910 insertions, 22 deletions
diff --git a/WebKit/gtk/tests/testatk.c b/WebKit/gtk/tests/testatk.c new file mode 100644 index 0000000..61eae60 --- /dev/null +++ b/WebKit/gtk/tests/testatk.c @@ -0,0 +1,240 @@ +/* + * Copyright (C) 2009 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 <errno.h> +#include <unistd.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) + +static const char* contents = "<html><body><p>This is a test. This is the second sentence. And this the third.</p></body></html>"; + +static gboolean bail_out(GMainLoop* loop) +{ + if (g_main_loop_is_running(loop)) + g_main_loop_quit(loop); + + return FALSE; +} + +typedef gchar* (*AtkGetTextFunction) (AtkText*, gint, AtkTextBoundary, gint*, gint*); + +static void test_get_text_function(AtkText* text_obj, AtkGetTextFunction fn, AtkTextBoundary boundary, gint offset, const char* text_result, gint start_offset_result, gint end_offset_result) +{ + gint start_offset, end_offset; + char* text; + + text = fn(text_obj, offset, boundary, &start_offset, &end_offset); + g_assert_cmpstr(text, ==, text_result); + g_assert_cmpint(start_offset, ==, start_offset_result); + g_assert_cmpint(end_offset, ==, end_offset_result); + g_free(text); +} + +static void test_webkit_atk_get_text_at_offset(void) +{ + WebKitWebView* webView; + AtkObject *obj; + GMainLoop* loop; + AtkText* text_obj; + char* text; + + webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_object_ref_sink(webView); + webkit_web_view_load_string(webView, contents, NULL, NULL, NULL); + loop = g_main_loop_new(NULL, TRUE); + + g_timeout_add(100, (GSourceFunc)bail_out, loop); + g_main_loop_run(loop); + + /* Get to the inner AtkText object */ + obj = gtk_widget_get_accessible(GTK_WIDGET(webView)); + g_assert(obj); + obj = atk_object_ref_accessible_child(obj, 0); + g_assert(obj); + obj = atk_object_ref_accessible_child(obj, 0); + g_assert(obj); + + text_obj = ATK_TEXT(obj); + g_assert(ATK_IS_TEXT(text_obj)); + + text = atk_text_get_text(text_obj, 0, -1); + g_assert_cmpstr(text, ==, "This is a test. This is the second sentence. And this the third."); + g_free(text); + + /* ATK_TEXT_BOUNDARY_CHAR */ + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_CHAR, + 0, "T", 0, 1); + + test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_CHAR, + 0, "h", 1, 2); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_CHAR, + 0, "", 0, 0); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_CHAR, + 1, "T", 0, 1); + + /* ATK_TEXT_BOUNDARY_WORD_START */ + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_START, + 0, "This ", 0, 5); + + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_START, + 4, "This ", 0, 5); + + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_START, + 10, "test. ", 10, 16); + + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_START, + 58, "third.", 58, 64); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_START, + 5, "This ", 0, 5); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_START, + 7, "This ", 0, 5); + + test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_START, + 0, "is ", 5, 8); + + test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_START, + 4, "is ", 5, 8); + + test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_START, + 3, "is ", 5, 8); + + /* ATK_TEXT_BOUNDARY_WORD_END */ + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, + 0, "This", 0, 4); + + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, + 4, " is", 4, 7); + + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, + 5, " is", 4, 7); + + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, + 9, " test", 9, 14); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_END, + 5, "This", 0, 4); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_END, + 4, "This", 0, 4); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_WORD_END, + 7, " is", 4, 7); + + test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_END, + 5, " a", 7, 9); + + test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_WORD_END, + 4, " a", 7, 9); + + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_WORD_END, + 58, " third", 57, 63); + + /* ATK_TEXT_BOUNDARY_SENTENCE_START */ + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, + 0, "This is a test. ", 0, 16); + + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, + 15, "This is a test. ", 0, 16); + + test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, + 0, "This is the second sentence. ", 16, 45); + + test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, + 15, "This is the second sentence. ", 16, 45); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, + 16, "This is a test. ", 0, 16); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, + 44, "This is a test. ", 0, 16); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_START, + 15, "", 0, 0); + + /* ATK_TEXT_BOUNDARY_SENTENCE_END */ + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, + 0, "This is a test.", 0, 15); + + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, + 15, " This is the second sentence.", 15, 44); + + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, + 16, " This is the second sentence.", 15, 44); + + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, + 17, " This is the second sentence.", 15, 44); + + test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, + 0, " This is the second sentence.", 15, 44); + + test_get_text_function(text_obj, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, + 15, " And this the third.", 44, 64); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, + 16, "This is a test.", 0, 15); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, + 15, "This is a test.", 0, 15); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, + 14, "", 0, 0); + + test_get_text_function(text_obj, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_END, + 44, " This is the second sentence.", 15, 44); + + /* It's trick to test these properly right now, since our a11y + implementation splits different lines in different a11y + items */ + /* ATK_TEXT_BOUNDARY_LINE_START */ + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_START, + 0, "This is a test. This is the second sentence. And this the third.", 0, 64); + + /* ATK_TEXT_BOUNDARY_LINE_END */ + test_get_text_function(text_obj, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END, + 0, "This is a test. This is the second sentence. And this the third.", 0, 64); + + g_object_unref(webView); +} + +int main(int argc, char** argv) +{ + g_thread_init(NULL); + gtk_test_init(&argc, &argv, NULL); + + g_test_bug_base("https://bugs.webkit.org/"); + g_test_add_func("/webkit/atk/get_text_at_offset", test_webkit_atk_get_text_at_offset); + 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 diff --git a/WebKit/gtk/tests/testdownload.c b/WebKit/gtk/tests/testdownload.c new file mode 100644 index 0000000..0d964ed --- /dev/null +++ b/WebKit/gtk/tests/testdownload.c @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2009 Christian Dywan <christian@twotoasts.de> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2,1 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 <errno.h> +#include <unistd.h> +#include <glib/gstdio.h> +#include <webkit/webkit.h> + +#if GTK_CHECK_VERSION(2, 14, 0) + +GMainLoop* loop; +char* temporaryFilename = NULL; + +static void +test_webkit_download_create(void) +{ + WebKitNetworkRequest* request; + WebKitDownload* download; + const gchar* uri = "http://example.com"; + gchar* tmpDir; + + request = webkit_network_request_new(uri); + download = webkit_download_new(request); + g_object_unref(request); + g_assert_cmpstr(webkit_download_get_uri(download), ==, uri); + g_assert(webkit_download_get_network_request(download) == request); + g_assert(g_strrstr(uri, webkit_download_get_suggested_filename(download))); + g_assert(webkit_download_get_status(download) == WEBKIT_DOWNLOAD_STATUS_CREATED); + g_assert(!webkit_download_get_total_size(download)); + g_assert(!webkit_download_get_current_size(download)); + g_assert(!webkit_download_get_progress(download)); + g_assert(!webkit_download_get_elapsed_time(download)); + tmpDir = g_filename_to_uri(g_get_tmp_dir(), NULL, NULL); + webkit_download_set_destination_uri(download, tmpDir); + g_assert_cmpstr(tmpDir, ==, webkit_download_get_destination_uri(download));; + g_free(tmpDir); + g_object_unref(download); +} + +static gboolean +navigation_policy_decision_requested_cb(WebKitWebView* web_view, + WebKitWebFrame* web_frame, + WebKitNetworkRequest* request, + WebKitWebNavigationAction* action, + WebKitWebPolicyDecision* decision, + gpointer data) +{ + webkit_web_policy_decision_download(decision); + return TRUE; +} + +static void +notify_status_cb(GObject* object, GParamSpec* pspec, gpointer data) +{ + WebKitDownload* download = WEBKIT_DOWNLOAD(object); + switch (webkit_download_get_status(download)) { + case WEBKIT_DOWNLOAD_STATUS_FINISHED: + case WEBKIT_DOWNLOAD_STATUS_ERROR: + g_main_loop_quit(loop); + break; + case WEBKIT_DOWNLOAD_STATUS_CANCELLED: + g_assert_not_reached(); + break; + default: + break; + } +} + +static gboolean +download_requested_cb(WebKitWebView* web_view, + WebKitDownload* download, + gboolean* beenThere) +{ + *beenThere = TRUE; + if (temporaryFilename) { + gchar *uri = g_filename_to_uri(temporaryFilename, NULL, NULL); + if (uri) + webkit_download_set_destination_uri(download, uri); + g_free(uri); + } + + g_signal_connect(download, "notify::status", + G_CALLBACK(notify_status_cb), NULL); + + return TRUE; +} + +static void +test_webkit_download_perform(void) +{ + WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + + g_object_ref_sink(G_OBJECT(webView)); + + g_signal_connect(webView, "navigation-policy-decision-requested", + G_CALLBACK(navigation_policy_decision_requested_cb), + NULL); + + gboolean beenThere = FALSE; + g_signal_connect(webView, "download-requested", + G_CALLBACK(download_requested_cb), + &beenThere); + + /* Preparation; FIXME: we should move this code to a test + * utilities file, because we have a very similar one in + * testwebframe.c */ + GError *error = NULL; + int fd = g_file_open_tmp ("webkit-testwebdownload-XXXXXX", + &temporaryFilename, &error); + close(fd); + + if (error) + g_critical("Failed to open a temporary file for writing: %s.", error->message); + + if (g_unlink(temporaryFilename) == -1) + g_critical("Failed to delete the temporary file: %s.", g_strerror(errno)); + + loop = g_main_loop_new(NULL, TRUE); + webkit_web_view_load_uri(webView, "http://gnome.org/"); + g_main_loop_run(loop); + + g_assert_cmpint(beenThere, ==, TRUE); + + g_assert_cmpint(g_file_test(temporaryFilename, G_FILE_TEST_IS_REGULAR), ==, TRUE); + + g_unlink(temporaryFilename); + g_free(temporaryFilename); + g_main_loop_unref(loop); + g_object_unref(webView); +} + +int main(int argc, char** argv) +{ + g_thread_init(NULL); + gtk_test_init(&argc, &argv, NULL); + + g_test_bug_base("https://bugs.webkit.org/"); + g_test_add_func("/webkit/download/create", test_webkit_download_create); + g_test_add_func("/webkit/download/perform", test_webkit_download_perform); + return g_test_run (); +} + +#else + +int main(int argc, char** argv) +{ + g_critical("You will need at least GTK+ 2.14.0 to run the unit tests."); + return 0; +} + +#endif diff --git a/WebKit/gtk/tests/testhttpbackend.c b/WebKit/gtk/tests/testhttpbackend.c new file mode 100644 index 0000000..c061374 --- /dev/null +++ b/WebKit/gtk/tests/testhttpbackend.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2009 Gustavo Noronha Silva + * + * 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 <errno.h> +#include <unistd.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) + +// Not yet public API +SoupMessage* webkit_network_request_get_message(WebKitNetworkRequest* request); + +static gboolean navigation_policy_decision_requested_cb(WebKitWebView* web_view, + WebKitWebFrame* web_frame, + WebKitNetworkRequest* request, + WebKitWebNavigationAction* action, + WebKitWebPolicyDecision* decision, + gpointer data) +{ + SoupMessage* message = webkit_network_request_get_message(request); + + /* 1 -> webkit_network_request_with_core_request + * + * The SoupMessage is created exclusively for the emission of this + * signal. + */ + g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1); + + return FALSE; +} + +static void test_soup_message_lifetime() +{ + WebKitWebView* web_view = WEBKIT_WEB_VIEW(webkit_web_view_new()); + + g_object_ref_sink(web_view); + + g_signal_connect(web_view, "navigation-policy-decision-requested", + G_CALLBACK(navigation_policy_decision_requested_cb), + NULL); + + /* load_uri will trigger the navigation-policy-decision-requested + * signal emission; + */ + webkit_web_view_load_uri(web_view, "http://127.0.0.1/"); + + g_object_unref(web_view); +} + +int main(int argc, char** argv) +{ + g_thread_init(NULL); + gtk_test_init(&argc, &argv, NULL); + + g_test_bug_base("https://bugs.webkit.org/"); + g_test_add_func("/webkit/soupmessage/lifetime", test_soup_message_lifetime); + 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 diff --git a/WebKit/gtk/tests/testloading.c b/WebKit/gtk/tests/testloading.c new file mode 100644 index 0000000..cd5f08e --- /dev/null +++ b/WebKit/gtk/tests/testloading.c @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2009 Gustavo Noronha Silva + * + * 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 <gtk/gtk.h> +#include <webkit/webkit.h> + +#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0) + +static gboolean has_been_provisional = FALSE; +static gboolean has_been_committed = FALSE; +static gboolean has_been_first_visually_non_empty_layout = FALSE; + +static void load_finished_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, gpointer data) +{ + GMainLoop* loop = (GMainLoop*)data; + + g_assert(has_been_provisional); + g_assert(has_been_committed); + g_assert(has_been_first_visually_non_empty_layout); + + g_main_loop_quit(loop); +} + + +static void status_changed_cb(GObject* object, GParamSpec* pspec, gpointer data) +{ + WebKitLoadStatus status = webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(object)); + + switch (status) { + case WEBKIT_LOAD_PROVISIONAL: + g_assert(!has_been_provisional); + g_assert(!has_been_committed); + g_assert(!has_been_first_visually_non_empty_layout); + has_been_provisional = TRUE; + break; + case WEBKIT_LOAD_COMMITTED: + g_assert(has_been_provisional); + g_assert(!has_been_committed); + g_assert(!has_been_first_visually_non_empty_layout); + has_been_committed = TRUE; + break; + case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT: + g_assert(has_been_provisional); + g_assert(has_been_committed); + g_assert(!has_been_first_visually_non_empty_layout); + has_been_first_visually_non_empty_layout = TRUE; + break; + case WEBKIT_LOAD_FINISHED: + g_assert(has_been_provisional); + g_assert(has_been_committed); + g_assert(has_been_first_visually_non_empty_layout); + break; + default: + g_assert_not_reached(); + } +} + +static void test_loading_status() +{ + WebKitWebView* web_view = WEBKIT_WEB_VIEW(webkit_web_view_new()); + GMainLoop* loop = g_main_loop_new(NULL, TRUE); + + g_object_ref_sink(web_view); + + g_assert_cmpint(webkit_web_view_get_load_status(web_view), ==, WEBKIT_LOAD_PROVISIONAL); + + g_object_connect(G_OBJECT(web_view), + "signal::notify::load-status", G_CALLBACK(status_changed_cb), NULL, + "signal::load-finished", G_CALLBACK(load_finished_cb), loop, + NULL); + + /* load_uri will trigger the navigation-policy-decision-requested + * signal emission; + */ + webkit_web_view_load_uri(web_view, "http://gnome.org/"); + + g_main_loop_run(loop); + + g_object_unref(web_view); +} + +int main(int argc, char** argv) +{ + g_thread_init(NULL); + gtk_test_init(&argc, &argv, NULL); + + g_test_bug_base("https://bugs.webkit.org/"); + g_test_add_func("/webkit/loading/status", test_loading_status); + 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 diff --git a/WebKit/gtk/tests/testnetworkrequest.c b/WebKit/gtk/tests/testnetworkrequest.c new file mode 100644 index 0000000..40f8e7f --- /dev/null +++ b/WebKit/gtk/tests/testnetworkrequest.c @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2009 Gustavo Noronha Silva + * + * 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 <errno.h> +#include <unistd.h> +#include <glib.h> +#include <glib/gstdio.h> +#include <gtk/gtk.h> +#include <stdlib.h> +#include <webkit/webkit.h> + +#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0) + +static void test_network_request_create_destroy() +{ + WebKitNetworkRequest* request; + SoupMessage* message; + + /* Test creation with URI */ + request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "uri", "http://debian.org/", NULL)); + g_assert(WEBKIT_IS_NETWORK_REQUEST(request)); + message = webkit_network_request_get_message(request); + g_assert(!message); + g_object_unref(request); + + /* Test creation with SoupMessage */ + message = soup_message_new("GET", "http://debian.org/"); + request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, NULL)); + g_assert(WEBKIT_IS_NETWORK_REQUEST(request)); + g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2); + g_object_unref(request); + g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1); + g_object_unref(message); + + /* Test creation with both SoupMessage and URI */ + message = soup_message_new("GET", "http://debian.org/"); + request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, "uri", "http://gnome.org/", NULL)); + g_assert(WEBKIT_IS_NETWORK_REQUEST(request)); + g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2); + g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://gnome.org/"); + g_object_unref(request); + g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1); + g_object_unref(message); +} + +static void test_network_request_properties() +{ + WebKitNetworkRequest* request; + SoupMessage* message; + gchar* soupURI; + + /* Test URI is set correctly when creating with URI */ + request = webkit_network_request_new("http://debian.org/"); + g_assert(WEBKIT_IS_NETWORK_REQUEST(request)); + g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/"); + g_object_unref(request); + + /* Test URI is set correctly when creating with Message */ + message = soup_message_new("GET", "http://debian.org/"); + request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, NULL)); + g_assert(WEBKIT_IS_NETWORK_REQUEST(request)); + g_object_unref(message); + + message = webkit_network_request_get_message(request); + soupURI = soup_uri_to_string(soup_message_get_uri(message), FALSE); + g_assert_cmpstr(soupURI, ==, "http://debian.org/"); + g_free(soupURI); + + g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/"); + g_object_unref(request); +} + +int main(int argc, char** argv) +{ + g_thread_init(NULL); + gtk_test_init(&argc, &argv, NULL); + + g_test_bug_base("https://bugs.webkit.org/"); + g_test_add_func("/webkit/networkrequest/createdestroy", test_network_request_create_destroy); + g_test_add_func("/webkit/networkrequest/properties", test_network_request_properties); + 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 diff --git a/WebKit/gtk/tests/testwebbackforwardlist.c b/WebKit/gtk/tests/testwebbackforwardlist.c index 8d53c3e..115c079 100644 --- a/WebKit/gtk/tests/testwebbackforwardlist.c +++ b/WebKit/gtk/tests/testwebbackforwardlist.c @@ -47,15 +47,19 @@ static void test_webkit_web_history_item_lifetime(void) /* add test items */ item1 = webkit_web_history_item_new_with_data("http://example.com/1/", "Site 1"); webkit_web_back_forward_list_add_item(backForwardList, item1); + g_object_unref(item1); item2 = webkit_web_history_item_new_with_data("http://example.com/2/", "Site 2"); webkit_web_back_forward_list_add_item(backForwardList, item2); + g_object_unref(item2); item3 = webkit_web_history_item_new_with_data("http://example.com/3/", "Site 3"); webkit_web_back_forward_list_add_item(backForwardList, item3); + g_object_unref(item3); item4 = webkit_web_history_item_new_with_data("http://example.com/4/", "Site 4"); webkit_web_back_forward_list_add_item(backForwardList, item4); + g_object_unref(item4); /* make sure these functions don't add unnecessary ref to the history item */ backItem = webkit_web_back_forward_list_get_back_item(backForwardList); @@ -93,16 +97,12 @@ static void test_webkit_web_history_item_lifetime(void) g_list_free(forwardList); g_list_free(backList); - g_object_unref(item1); - g_object_unref(item2); - g_object_unref(item3); - g_object_unref(item4); - - g_object_ref(backForwardList); - g_object_unref(webView); - + g_assert_cmpint(G_OBJECT(item1)->ref_count, ==, 1); + g_assert_cmpint(G_OBJECT(item2)->ref_count, ==, 1); + g_assert_cmpint(G_OBJECT(item3)->ref_count, ==, 1); + g_assert_cmpint(G_OBJECT(item4)->ref_count, ==, 1); g_assert_cmpint(G_OBJECT(backForwardList)->ref_count, ==, 1); - g_object_unref(backForwardList); + g_object_unref(webView); } static void test_webkit_web_back_forward_list_order(void) @@ -135,18 +135,22 @@ static void test_webkit_web_back_forward_list_order(void) // Add a new items item1 = webkit_web_history_item_new_with_data("http://example.com/1/", "Site 1"); webkit_web_back_forward_list_add_item(webBackForwardList, item1); + g_object_unref(item1); g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, item1)); item2 = webkit_web_history_item_new_with_data("http://example.com/2/", "Site 2"); webkit_web_back_forward_list_add_item(webBackForwardList, item2); + g_object_unref(item2); g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, item2)); item3 = webkit_web_history_item_new_with_data("http://example.com/3/", "Site 3"); webkit_web_back_forward_list_add_item(webBackForwardList, item3); + g_object_unref(item3); g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, item3)); item4 = webkit_web_history_item_new_with_data("http://example.com/4/", "Site 4"); webkit_web_back_forward_list_add_item(webBackForwardList, item4); + g_object_unref(item4); g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, item4)); // check the back list order @@ -187,10 +191,6 @@ static void test_webkit_web_back_forward_list_order(void) g_assert_cmpstr(webkit_web_history_item_get_uri(currentItem), ==, "http://example.com/2/"); g_assert_cmpstr(webkit_web_history_item_get_title(currentItem), ==, "Site 2"); - g_object_unref(item1); - g_object_unref(item2); - g_object_unref(item3); - g_object_unref(item4); g_list_free(forwardList); g_object_unref(webView); } @@ -222,6 +222,7 @@ static void test_webkit_web_back_forward_list_add_item(void) // Add a new item addItem1 = webkit_web_history_item_new_with_data("http://example.com/", "Added site"); webkit_web_back_forward_list_add_item(webBackForwardList, addItem1); + g_object_unref(addItem1); g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, addItem1)); // Check that the added item is the current item. @@ -237,8 +238,8 @@ static void test_webkit_web_back_forward_list_add_item(void) // Add another item. addItem2 = webkit_web_history_item_new_with_data("http://example.com/2/", "Added site 2"); webkit_web_back_forward_list_add_item(webBackForwardList, addItem2); - g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, addItem2)); g_object_unref(addItem2); + g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, addItem2)); // Check that the added item is new current item. currentItem = webkit_web_back_forward_list_get_current_item(webBackForwardList); @@ -262,7 +263,6 @@ static void test_webkit_web_back_forward_list_add_item(void) g_assert(webkit_web_view_can_go_forward(webView)); g_assert(!webkit_web_view_can_go_back(webView)); - g_object_unref(addItem1); g_object_unref(webView); } diff --git a/WebKit/gtk/tests/testwebframe.c b/WebKit/gtk/tests/testwebframe.c index e2da29c..068e2cf 100644 --- a/WebKit/gtk/tests/testwebframe.c +++ b/WebKit/gtk/tests/testwebframe.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2008 Holger Hans Peter Freyther + * Copyright (C) 2009 Collabora Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -17,7 +18,10 @@ * Boston, MA 02110-1301, USA. */ +#include <errno.h> +#include <unistd.h> #include <glib.h> +#include <glib/gstdio.h> #include <gtk/gtk.h> #include <webkit/webkit.h> @@ -25,15 +29,23 @@ static void test_webkit_web_frame_create_destroy(void) { - WebKitWebView* webView; - g_test_bug("21837"); + GtkWidget *webView; + GtkWidget *window; - webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_test_bug("21837"); + webView = webkit_web_view_new(); g_object_ref_sink(webView); g_assert_cmpint(G_OBJECT(webView)->ref_count, ==, 1); - // This crashed with the original version g_object_unref(webView); + + g_test_bug("25042"); + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + webView = webkit_web_view_new(); + gtk_container_add(GTK_CONTAINER(window), webView); + gtk_widget_show(window); + gtk_widget_show(webView); + gtk_widget_destroy(webView); } static void test_webkit_web_frame_lifetime(void) @@ -62,6 +74,87 @@ static void test_webkit_web_frame_lifetime(void) g_object_unref(webFrame); } +static gboolean print_requested_cb(WebKitWebView* webView, WebKitWebFrame* webFrame, GMainLoop* loop) +{ + g_object_set_data(G_OBJECT(webView), "signal-handled", GINT_TO_POINTER(TRUE)); + g_main_loop_quit(loop); + return TRUE; +} + +static void print_timeout(GMainLoop* loop) +{ + if (g_main_loop_is_running(loop)) + g_main_loop_quit(loop); +} + +static void test_webkit_web_frame_printing(void) +{ + WebKitWebView* webView; + + webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_object_ref_sink(webView); + g_assert_cmpint(G_OBJECT(webView)->ref_count, ==, 1); + + webkit_web_view_load_string(webView, + "<html><body><h1>WebKitGTK+!</h1></body></html>", + "text/html", + "utf-8", + "file://"); + + GMainLoop* loop = g_main_loop_new(NULL, TRUE); + + // Does javascript print() work correctly? + g_signal_connect(webView, "print-requested", + G_CALLBACK(print_requested_cb), + loop); + + g_object_set_data(G_OBJECT(webView), "signal-handled", GINT_TO_POINTER(FALSE)); + webkit_web_view_execute_script (webView, "print();"); + + // Give javascriptcore some time to process the print request, but + // prepare a timeout to avoid it running forever in case the signal is + // never emitted. + g_timeout_add(1000, (GSourceFunc)print_timeout, loop); + g_main_loop_run(loop); + + g_assert_cmpint(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(webView), "signal-handled")), ==, TRUE); + + // Does printing directly to a file? + GError *error = NULL; + gchar* temporaryFilename = NULL; + gint fd = g_file_open_tmp ("webkit-testwebframe-XXXXXX", &temporaryFilename, &error); + close(fd); + + if (error) { + g_critical("Failed to open a temporary file for writing: %s.", error->message); + g_error_free(error); + goto cleanup; + } + + // We delete the file, so that we can easily figure out that the + // file got printed; + if (g_unlink(temporaryFilename) == -1) { + g_warning("Failed to delete the temporary file: %s.\nThis may cause the test to be bogus.", g_strerror(errno)); + } + + WebKitWebFrame* webFrame = webkit_web_view_get_main_frame(webView); + GtkPrintOperation* operation = gtk_print_operation_new(); + GtkPrintOperationAction action = GTK_PRINT_OPERATION_ACTION_EXPORT; + GtkPrintOperationResult result; + + gtk_print_operation_set_export_filename(operation, temporaryFilename); + result = webkit_web_frame_print_full (webFrame, operation, action, NULL); + + g_assert_cmpint(result, ==, GTK_PRINT_OPERATION_RESULT_APPLY); + g_assert_cmpint(g_file_test(temporaryFilename, G_FILE_TEST_IS_REGULAR), ==, TRUE); + + g_unlink(temporaryFilename); + g_object_unref(operation); +cleanup: + g_object_unref(webView); + g_free(temporaryFilename); +} + int main(int argc, char** argv) { g_thread_init(NULL); @@ -70,6 +163,7 @@ int main(int argc, char** argv) g_test_bug_base("https://bugs.webkit.org/"); g_test_add_func("/webkit/webview/create_destroy", test_webkit_web_frame_create_destroy); g_test_add_func("/webkit/webframe/lifetime", test_webkit_web_frame_lifetime); + g_test_add_func("/webkit/webview/printing", test_webkit_web_frame_printing); return g_test_run (); } diff --git a/WebKit/gtk/tests/testwebhistoryitem.c b/WebKit/gtk/tests/testwebhistoryitem.c index 6038c647..b940afb 100644 --- a/WebKit/gtk/tests/testwebhistoryitem.c +++ b/WebKit/gtk/tests/testwebhistoryitem.c @@ -31,7 +31,7 @@ static void web_history_item_fixture_setup(WebHistoryItemFixture* fixture, gconstpointer data) { fixture->item = webkit_web_history_item_new_with_data("http://example.com/", "Example1"); - g_assert_cmpint(G_OBJECT(fixture->item)->ref_count, == , 2); + g_assert_cmpint(G_OBJECT(fixture->item)->ref_count, == , 1); g_assert(fixture->item != NULL); } @@ -39,8 +39,6 @@ static void web_history_item_fixture_teardown(WebHistoryItemFixture* fixture, gconstpointer data) { g_assert(fixture->item != NULL); - g_assert_cmpint(G_OBJECT(fixture->item)->ref_count, ==, 2); - g_object_unref(fixture->item); g_assert_cmpint(G_OBJECT(fixture->item)->ref_count, ==, 1); } diff --git a/WebKit/gtk/tests/testwebsettings.c b/WebKit/gtk/tests/testwebsettings.c new file mode 100644 index 0000000..8c77def --- /dev/null +++ b/WebKit/gtk/tests/testwebsettings.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2009 Jan Michael Alonzo + * + * 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 <glib.h> +#include <gtk/gtk.h> +#include <webkit/webkit.h> + +#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0) + +static void test_webkit_web_settings_user_agent(void) +{ + WebKitWebSettings* settings; + GtkWidget* webView; + gchar* defaultUserAgent; + gchar* userAgent; + g_test_bug("17375"); + + webView = webkit_web_view_new(); + g_object_ref_sink(webView); + + settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webView)); + defaultUserAgent = g_strdup(webkit_web_settings_get_user_agent(settings)); + + // test a custom UA string + userAgent = NULL; + g_object_set(G_OBJECT(settings), "user-agent", "testwebsettings/0.1", NULL); + g_object_get(G_OBJECT(settings),"user-agent", &userAgent, NULL); + g_assert_cmpstr(userAgent, ==, "testwebsettings/0.1"); + g_free(userAgent); + + // setting it to NULL or an empty value should give us the default UA string + userAgent = NULL; + g_object_set(G_OBJECT(settings), "user-agent", NULL, NULL); + g_object_get(G_OBJECT(settings),"user-agent", &userAgent, NULL); + g_assert_cmpstr(userAgent, ==, defaultUserAgent); + g_free(userAgent); + + userAgent = NULL; + g_object_set(G_OBJECT(settings), "user-agent", "", NULL); + g_object_get(G_OBJECT(settings),"user-agent", &userAgent, NULL); + g_assert_cmpstr(userAgent, ==, defaultUserAgent); + g_free(userAgent); + + g_free(defaultUserAgent); + g_object_unref(webView); +} + +int main(int argc, char** argv) +{ + g_thread_init(NULL); + gtk_test_init(&argc, &argv, NULL); + + g_test_bug_base("https://bugs.webkit.org/"); + g_test_add_func("/webkit/websettings/user_agent", test_webkit_web_settings_user_agent); + 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 |
