diff options
Diffstat (limited to 'WebKit/gtk/tests')
-rw-r--r-- | WebKit/gtk/tests/resources/blank.ico | bin | 0 -> 198 bytes | |||
-rw-r--r-- | WebKit/gtk/tests/resources/test.html | 6 | ||||
-rw-r--r-- | WebKit/gtk/tests/resources/test.ogg | bin | 0 -> 30131 bytes | |||
-rw-r--r-- | WebKit/gtk/tests/resources/test.pdf | bin | 0 -> 7421 bytes | |||
-rw-r--r-- | WebKit/gtk/tests/resources/test.txt | 1 | ||||
-rw-r--r-- | WebKit/gtk/tests/testatk.c | 108 | ||||
-rw-r--r-- | WebKit/gtk/tests/testmimehandling.c | 222 | ||||
-rw-r--r-- | WebKit/gtk/tests/testwebdatasource.c | 4 | ||||
-rw-r--r-- | WebKit/gtk/tests/testwebframe.c | 9 | ||||
-rw-r--r-- | WebKit/gtk/tests/testwebview.c | 168 |
10 files changed, 516 insertions, 2 deletions
diff --git a/WebKit/gtk/tests/resources/blank.ico b/WebKit/gtk/tests/resources/blank.ico Binary files differnew file mode 100644 index 0000000..ea848b9 --- /dev/null +++ b/WebKit/gtk/tests/resources/blank.ico diff --git a/WebKit/gtk/tests/resources/test.html b/WebKit/gtk/tests/resources/test.html new file mode 100644 index 0000000..98f7d4f --- /dev/null +++ b/WebKit/gtk/tests/resources/test.html @@ -0,0 +1,6 @@ +<html> +<head><title>test</title></head> +<body>test</body> +</html>></head> +<body>test</body> +</html> diff --git a/WebKit/gtk/tests/resources/test.ogg b/WebKit/gtk/tests/resources/test.ogg Binary files differnew file mode 100644 index 0000000..7f3a3b9 --- /dev/null +++ b/WebKit/gtk/tests/resources/test.ogg diff --git a/WebKit/gtk/tests/resources/test.pdf b/WebKit/gtk/tests/resources/test.pdf Binary files differnew file mode 100644 index 0000000..2424c19 --- /dev/null +++ b/WebKit/gtk/tests/resources/test.pdf diff --git a/WebKit/gtk/tests/resources/test.txt b/WebKit/gtk/tests/resources/test.txt new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/WebKit/gtk/tests/resources/test.txt @@ -0,0 +1 @@ +test diff --git a/WebKit/gtk/tests/testatk.c b/WebKit/gtk/tests/testatk.c index e47898b..c5f4db3 100644 --- a/WebKit/gtk/tests/testatk.c +++ b/WebKit/gtk/tests/testatk.c @@ -28,6 +28,12 @@ static const char* contents = "<html><body><p>This is a test. This is the second sentence. And this the third.</p></body></html>"; +static const char* contentsWithNewlines = "<html><body><p>This is a test. \n\nThis\n is the second sentence. And this the third.</p></body></html>"; + +static const char* contentsInTextarea = "<html><body><textarea cols='80'>This is a test. This is the second sentence. And this the third.</textarea></body></html>"; + +static const char* contentsInTextInput = "<html><body><input type='text' size='80' value='This is a test. This is the second sentence. And this the third.'/></body></html>"; + static gboolean bail_out(GMainLoop* loop) { if (g_main_loop_is_running(loop)) @@ -259,6 +265,105 @@ static void test_webkit_atk_get_text_at_offset(void) g_object_unref(webView); } +static void test_webkit_atk_get_text_at_offset_newlines(void) +{ + WebKitWebView* webView; + AtkObject* obj; + GMainLoop* loop; + AtkText* text_obj; + + webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_object_ref_sink(webView); + GtkAllocation alloc = { 0, 0, 800, 600 }; + gtk_widget_size_allocate(GTK_WIDGET(webView), &alloc); + webkit_web_view_load_string(webView, contentsWithNewlines, 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)); + + run_get_text_tests(text_obj); + + g_object_unref(webView); +} + +static void test_webkit_atk_get_text_at_offset_textarea(void) +{ + WebKitWebView* webView; + AtkObject* obj; + GMainLoop* loop; + AtkText* text_obj; + + webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_object_ref_sink(webView); + GtkAllocation alloc = { 0, 0, 800, 600 }; + gtk_widget_size_allocate(GTK_WIDGET(webView), &alloc); + webkit_web_view_load_string(webView, contentsInTextarea, 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)); + + run_get_text_tests(text_obj); + + g_object_unref(webView); +} + +static void test_webkit_atk_get_text_at_offset_text_input(void) +{ + WebKitWebView* webView; + AtkObject* obj; + GMainLoop* loop; + AtkText* text_obj; + + webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_object_ref_sink(webView); + GtkAllocation alloc = { 0, 0, 800, 600 }; + gtk_widget_size_allocate(GTK_WIDGET(webView), &alloc); + webkit_web_view_load_string(webView, contentsInTextInput, 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)); + + run_get_text_tests(text_obj); + + g_object_unref(webView); +} + int main(int argc, char** argv) { g_thread_init(NULL); @@ -267,6 +372,9 @@ int main(int argc, char** argv) 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); g_test_add_func("/webkit/atk/get_text_at_offset_forms", test_webkit_atk_get_text_at_offset_forms); + g_test_add_func("/webkit/atk/get_text_at_offset_newlines", test_webkit_atk_get_text_at_offset_newlines); + g_test_add_func("/webkit/atk/get_text_at_offset_textarea", test_webkit_atk_get_text_at_offset_textarea); + g_test_add_func("/webkit/atk/get_text_at_offset_text_input", test_webkit_atk_get_text_at_offset_text_input); return g_test_run (); } diff --git a/WebKit/gtk/tests/testmimehandling.c b/WebKit/gtk/tests/testmimehandling.c new file mode 100644 index 0000000..e68dcdf --- /dev/null +++ b/WebKit/gtk/tests/testmimehandling.c @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2009 Jan Michael Alonzo + * 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 <glib.h> +#include <glib/gstdio.h> +#include <libsoup/soup.h> +#include <string.h> +#include <webkit/webkit.h> + +#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0) + +GMainLoop* loop; +SoupSession *session; +char* base_uri; + +/* For real request testing */ +static void +server_callback(SoupServer *server, SoupMessage *msg, + const char *path, GHashTable *query, + SoupClientContext *context, gpointer data) +{ + if (msg->method != SOUP_METHOD_GET) { + soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED); + return; + } + + soup_message_set_status(msg, SOUP_STATUS_OK); + + /* PDF */ + if (g_str_equal(path, "/pdf")) { + char* contents; + gsize length; + GError* error = NULL; + + g_file_get_contents("test.pdf", &contents, &length, &error); + g_assert(!error); + + soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length); + } else if (g_str_equal(path, "/html")) { + char* contents; + gsize length; + GError* error = NULL; + + g_file_get_contents("test.html", &contents, &length, &error); + g_assert(!error); + + soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length); + } else if (g_str_equal(path, "/text")) { + char* contents; + gsize length; + GError* error = NULL; + + soup_message_headers_append(msg->response_headers, "Content-Disposition", "attachment; filename=test.txt"); + + g_file_get_contents("test.txt", &contents, &length, &error); + g_assert(!error); + + soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length); + } else if (g_str_equal(path, "/ogg")) { + char* contents; + gsize length; + GError* error = NULL; + + g_file_get_contents("test.ogg", &contents, &length, &error); + g_assert(!error); + + soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length); + } + + soup_message_body_complete(msg->response_body); +} + +static gboolean idle_quit_loop_cb(gpointer data) +{ + g_main_loop_quit(loop); + return FALSE; +} + +static gboolean mime_type_policy_decision_requested_cb(WebKitWebView* view, WebKitWebFrame* frame, + WebKitNetworkRequest* request, const char* mime_type, + WebKitWebPolicyDecision* decision, gpointer data) +{ + char* type = (char*)data; + + if (g_str_equal(type, "pdf")) { + g_assert_cmpstr(mime_type, ==, "application/pdf"); + g_assert(!webkit_web_view_can_show_mime_type(view, mime_type)); + } else if (g_str_equal(type, "html")) { + g_assert_cmpstr(mime_type, ==, "text/html"); + g_assert(webkit_web_view_can_show_mime_type(view, mime_type)); + } else if (g_str_equal(type, "text")) { + WebKitNetworkResponse* response = webkit_web_frame_get_network_response(frame); + SoupMessage* message = webkit_network_response_get_message(response); + char* disposition; + + g_assert(message); + soup_message_headers_get_content_disposition(message->response_headers, + &disposition, NULL); + g_object_unref(response); + + g_assert_cmpstr(disposition, ==, "attachment"); + g_free(disposition); + + g_assert_cmpstr(mime_type, ==, "text/plain"); + g_assert(webkit_web_view_can_show_mime_type(view, mime_type)); + } else if (g_str_equal(type, "ogg")) { + g_assert_cmpstr(mime_type, ==, "audio/ogg"); + g_assert(webkit_web_view_can_show_mime_type(view, mime_type)); + } + + g_free(type); + + return FALSE; +} + +static void test_mime_type(const char* name) +{ + WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_object_ref_sink(G_OBJECT(view)); + + loop = g_main_loop_new(NULL, TRUE); + + g_object_connect(G_OBJECT(view), + "signal::load-finished", idle_quit_loop_cb, NULL, + "signal::mime-type-policy-decision-requested", mime_type_policy_decision_requested_cb, g_strdup(name), + NULL); + + char* effective_uri = g_strdup_printf("%s%s", base_uri, name); + webkit_web_view_load_uri(view, effective_uri); + g_free(effective_uri); + + g_main_loop_run(loop); + + g_object_unref(view); +} + +static void test_mime_pdf() +{ + test_mime_type("pdf"); +} + +static void test_mime_html() +{ + test_mime_type("html"); +} + +static void test_mime_text() +{ + test_mime_type("text"); +} + +static void test_mime_ogg() +{ + test_mime_type("pdf"); +} + +int main(int argc, char** argv) +{ + SoupServer* server; + SoupURI* soup_uri; + char* test_dir; + char* resources_dir; + + g_thread_init(NULL); + gtk_test_init(&argc, &argv, NULL); + + /* Hopefully make test independent of the path it's called from. */ + test_dir = g_path_get_dirname(argv[0]); + resources_dir = g_build_path(G_DIR_SEPARATOR_S, test_dir, + "..", "..", "..", "..", + "WebKit", "gtk", "tests", "resources", + NULL); + g_free(test_dir); + + g_chdir(resources_dir); + g_free(resources_dir); + + server = soup_server_new(SOUP_SERVER_PORT, 0, NULL); + soup_server_run_async(server); + + soup_server_add_handler(server, NULL, server_callback, NULL, NULL); + + soup_uri = soup_uri_new("http://127.0.0.1/"); + soup_uri_set_port(soup_uri, soup_server_get_port(server)); + + base_uri = soup_uri_to_string(soup_uri, FALSE); + soup_uri_free(soup_uri); + + g_test_bug_base("https://bugs.webkit.org/"); + g_test_add_func("/webkit/mime/PDF", test_mime_pdf); + g_test_add_func("/webkit/mime/HTML", test_mime_html); + g_test_add_func("/webkit/mime/TEXT", test_mime_text); + g_test_add_func("/webkit/mime/OGG", test_mime_ogg); + + 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/testwebdatasource.c b/WebKit/gtk/tests/testwebdatasource.c index de2430f..fe5c62f 100644 --- a/WebKit/gtk/tests/testwebdatasource.c +++ b/WebKit/gtk/tests/testwebdatasource.c @@ -66,7 +66,7 @@ static void load_finished_unreachable_cb(WebKitWebView* view, WebKitWebFrame* fr frame = webkit_web_view_get_main_frame(view); datasource = webkit_web_frame_get_data_source(frame); - g_assert_cmpstr("http://localhost/doireallyexist.html", ==, + g_assert_cmpstr("http://this.host.does.not.exist/doireallyexist.html", ==, webkit_web_data_source_get_unreachable_uri(datasource)); if (g_main_loop_is_running(loop)) @@ -149,7 +149,7 @@ static void test_webkit_web_data_source_unreachable_uri() g_object_ref_sink(view); loop = g_main_loop_new(NULL, TRUE); g_signal_connect(view, "load-finished", G_CALLBACK(load_finished_unreachable_cb), loop); - webkit_web_view_load_uri(view, "http://localhost/doireallyexist.html"); + webkit_web_view_load_uri(view, "http://this.host.does.not.exist/doireallyexist.html"); if (!waitTimer) waitTimer = g_timeout_add_seconds(defaultTimeout, (GSourceFunc)wait_timer_fired, loop); diff --git a/WebKit/gtk/tests/testwebframe.c b/WebKit/gtk/tests/testwebframe.c index 068e2cf..620c9c9 100644 --- a/WebKit/gtk/tests/testwebframe.c +++ b/WebKit/gtk/tests/testwebframe.c @@ -155,6 +155,14 @@ cleanup: g_free(temporaryFilename); } +static void test_webkit_web_frame_response() +{ + WebKitWebFrame* frame = g_object_new(WEBKIT_TYPE_WEB_FRAME, NULL); + WebKitNetworkResponse* response = webkit_web_frame_get_network_response(frame); + g_assert(!response); + g_object_unref(frame); +} + int main(int argc, char** argv) { g_thread_init(NULL); @@ -164,6 +172,7 @@ int main(int argc, char** argv) 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); + g_test_add_func("/webkit/webview/response", test_webkit_web_frame_response); return g_test_run (); } diff --git a/WebKit/gtk/tests/testwebview.c b/WebKit/gtk/tests/testwebview.c new file mode 100644 index 0000000..e0921c0 --- /dev/null +++ b/WebKit/gtk/tests/testwebview.c @@ -0,0 +1,168 @@ +/* + * 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 + * 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 <string.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) + +GMainLoop* loop; +SoupSession *session; +char* base_uri; + +/* For real request testing */ +static void +server_callback(SoupServer* server, SoupMessage* msg, + const char* path, GHashTable* query, + SoupClientContext* context, gpointer data) +{ + if (msg->method != SOUP_METHOD_GET) { + soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED); + return; + } + + soup_message_set_status(msg, SOUP_STATUS_OK); + + if (g_str_equal(path, "/favicon.ico")) { + char* contents; + gsize length; + GError* error = NULL; + + g_file_get_contents("blank.ico", &contents, &length, &error); + g_assert(!error); + + soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length); + } else { + char* contents = g_strdup("<html><body>test</body></html>"); + soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, strlen(contents)); + } + + soup_message_body_complete(msg->response_body); +} + +static gboolean idle_quit_loop_cb(gpointer data) +{ + g_main_loop_quit(loop); + return FALSE; +} + +static void icon_uri_changed_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data) +{ + gboolean* been_here = (gboolean*)data; + char* expected_uri; + + g_assert_cmpstr(g_param_spec_get_name(pspec), ==, "icon-uri"); + + expected_uri = g_strdup_printf("%sfavicon.ico", base_uri); + g_assert_cmpstr(webkit_web_view_get_icon_uri(web_view), ==, expected_uri); + g_free(expected_uri); + + *been_here = TRUE; +} + +static void icon_loaded_cb(WebKitWebView* web_view, char* icon_uri, gpointer data) +{ + gboolean* been_here = (gboolean*)data; + char* expected_uri = g_strdup_printf("%sfavicon.ico", base_uri); + g_assert_cmpstr(icon_uri, ==, expected_uri); + g_free(expected_uri); + + g_assert_cmpstr(icon_uri, ==, webkit_web_view_get_icon_uri(web_view)); + + *been_here = TRUE; +} + +static void test_webkit_web_view_icon_uri() +{ + gboolean been_to_uri_changed = FALSE; + gboolean been_to_icon_loaded = FALSE; + WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_object_ref_sink(G_OBJECT(view)); + + loop = g_main_loop_new(NULL, TRUE); + + g_object_connect(G_OBJECT(view), + "signal::load-finished", idle_quit_loop_cb, NULL, + "signal::notify::icon-uri", icon_uri_changed_cb, &been_to_uri_changed, + "signal::icon-loaded", icon_loaded_cb, &been_to_icon_loaded, + NULL); + + webkit_web_view_load_uri(view, base_uri); + + g_main_loop_run(loop); + + g_assert(been_to_uri_changed); + g_assert(been_to_icon_loaded); + + g_object_unref(view); +} + +int main(int argc, char** argv) +{ + SoupServer* server; + SoupURI* soup_uri; + char* test_dir; + char* resources_dir; + + g_thread_init(NULL); + gtk_test_init(&argc, &argv, NULL); + + /* Hopefully make test independent of the path it's called from. */ + test_dir = g_path_get_dirname(argv[0]); + resources_dir = g_build_path(G_DIR_SEPARATOR_S, test_dir, + "..", "..", "..", "..", + "WebKit", "gtk", "tests", "resources", + NULL); + g_free(test_dir); + + g_chdir(resources_dir); + g_free(resources_dir); + + server = soup_server_new(SOUP_SERVER_PORT, 0, NULL); + soup_server_run_async(server); + + soup_server_add_handler(server, NULL, server_callback, NULL, NULL); + + soup_uri = soup_uri_new("http://127.0.0.1/"); + soup_uri_set_port(soup_uri, soup_server_get_port(server)); + + base_uri = soup_uri_to_string(soup_uri, FALSE); + soup_uri_free(soup_uri); + + g_test_bug_base("https://bugs.webkit.org/"); + g_test_add_func("/webkit/webview/icon-uri", test_webkit_web_view_icon_uri); + + 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 |