diff options
Diffstat (limited to 'WebKit/gtk/tests')
| -rw-r--r-- | WebKit/gtk/tests/testatk.c | 2 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testhittestresult.c | 152 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testkeyevents.c | 186 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testloading.c | 217 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testnetworkresponse.c | 108 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testwebdatasource.c | 184 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testwebresource.c | 332 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testwindow.c | 128 |
8 files changed, 1270 insertions, 39 deletions
diff --git a/WebKit/gtk/tests/testatk.c b/WebKit/gtk/tests/testatk.c index 61eae60..3910347 100644 --- a/WebKit/gtk/tests/testatk.c +++ b/WebKit/gtk/tests/testatk.c @@ -60,6 +60,8 @@ static void test_webkit_atk_get_text_at_offset(void) 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, contents, NULL, NULL, NULL); loop = g_main_loop_new(NULL, TRUE); diff --git a/WebKit/gtk/tests/testhittestresult.c b/WebKit/gtk/tests/testhittestresult.c new file mode 100644 index 0000000..defda7a --- /dev/null +++ b/WebKit/gtk/tests/testhittestresult.c @@ -0,0 +1,152 @@ +/* + * 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 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) + +typedef struct { + char* data; + guint flag; +} TestInfo; + +static GMainLoop* loop; + +typedef struct { + WebKitWebView* webView; + TestInfo* info; +} HitTestResultFixture; + +TestInfo* +test_info_new(const char* data, guint flag) +{ + TestInfo* info; + + info = g_slice_new(TestInfo); + info->data = g_strdup(data); + info->flag = flag; + + return info; +} + +void +test_info_destroy(TestInfo* info) +{ + g_free(info->data); + g_slice_free(TestInfo, info); +} + +static void hit_test_result_fixture_setup(HitTestResultFixture* fixture, gconstpointer data) +{ + fixture->webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_object_ref_sink(fixture->webView); + loop = g_main_loop_new(NULL, TRUE); + fixture->info = (TestInfo*)data; +} + +static void hit_test_result_fixture_teardown(HitTestResultFixture* fixture, gconstpointer data) +{ + g_object_unref(fixture->webView); + g_main_loop_unref(loop); + test_info_destroy(fixture->info); +} + +static void +load_status_cb(WebKitWebView* webView, + GParamSpec* spec, + gpointer data) +{ + WebKitLoadStatus status = webkit_web_view_get_load_status(webView); + TestInfo* info = (TestInfo*)data; + + if (status == WEBKIT_LOAD_FINISHED) { + WebKitHitTestResult* result; + guint context; + GdkEventButton event; + event.type = GDK_BUTTON_PRESS; + /* Close enough to 0,0 */ + event.x = 5; + event.y = 5; + + result = webkit_web_view_get_hit_test_result(webView, &event); + g_assert(result); + g_object_get(result, "context", &context, NULL); + g_assert(context & info->flag); + g_object_unref(result); + g_main_loop_quit(loop); + } +} + +static void +test_webkit_hit_test_result(HitTestResultFixture* fixture, gconstpointer data) +{ + TestInfo* info = (TestInfo*)data; + GtkAllocation allocation = { 0, 0, 50, 50 }; + + webkit_web_view_load_string(fixture->webView, + info->data, + "text/html", + "utf-8", + "file://"); + gtk_widget_size_allocate(GTK_WIDGET(fixture->webView), &allocation); + g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_status_cb), info); + g_main_loop_run(loop); +} + +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("/webkit/hittestresult/document", HitTestResultFixture, + test_info_new("<html><body><h1>WebKitGTK+!</h1></body></html>", + WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT), + hit_test_result_fixture_setup, test_webkit_hit_test_result, hit_test_result_fixture_teardown); + /* We hardcode all elements to be at 0,0 so that we know where to + * generate the button events */ + g_test_add("/webkit/hittestresult/image", HitTestResultFixture, + test_info_new("<html><body><img style='position:absolute; left:0; top:0'src='0xdeadbeef' width=50 height=50></img></body></html>", + WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE), + hit_test_result_fixture_setup, test_webkit_hit_test_result, hit_test_result_fixture_teardown); + g_test_add("/webkit/hittestresult/editable", HitTestResultFixture, + test_info_new("<html><body><input style='position:absolute; left:0; top:0' size='35'></input>></body></html>", + WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE), + hit_test_result_fixture_setup, test_webkit_hit_test_result, hit_test_result_fixture_teardown); + g_test_add("/webkit/hittestresult/link", HitTestResultFixture, + test_info_new("<html><body><a style='position:absolute; left:0; top:0' href='http://www.example.com'>HELLO WORLD</a></body></html>", + WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK), + hit_test_result_fixture_setup, test_webkit_hit_test_result, hit_test_result_fixture_teardown); + + 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/testkeyevents.c b/WebKit/gtk/tests/testkeyevents.c new file mode 100644 index 0000000..ee7728c --- /dev/null +++ b/WebKit/gtk/tests/testkeyevents.c @@ -0,0 +1,186 @@ +/* + * Copyright (C) 2009 Martin Robinson + * + * 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 <string.h> +#include <glib/gstdio.h> +#include <webkit/webkit.h> + +#if GTK_CHECK_VERSION(2, 14, 0) + +typedef struct { + char* page; + gboolean shouldBeHandled; +} TestInfo; + +typedef struct { + GtkWidget* window; + WebKitWebView* webView; + GMainLoop* loop; + TestInfo* info; +} KeyEventFixture; + +TestInfo* +test_info_new(const char* page, gboolean shouldBeHandled) +{ + TestInfo* info; + + info = g_slice_new(TestInfo); + info->page = g_strdup(page); + info->shouldBeHandled = shouldBeHandled; + + return info; +} + +void +test_info_destroy(TestInfo* info) +{ + g_free(info->page); + g_slice_free(TestInfo, info); +} + +static void key_event_fixture_setup(KeyEventFixture* fixture, gconstpointer data) +{ + fixture->loop = g_main_loop_new(NULL, TRUE); + + fixture->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + fixture->webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + + gtk_container_add(GTK_CONTAINER(fixture->window), GTK_WIDGET(fixture->webView)); +} + +static void key_event_fixture_teardown(KeyEventFixture* fixture, gconstpointer data) +{ + gtk_widget_destroy(fixture->window); + g_main_loop_unref(fixture->loop); + test_info_destroy(fixture->info); +} + +static gboolean key_press_event_cb(WebKitWebView* webView, GdkEvent* event, gpointer data) +{ + KeyEventFixture* fixture = (KeyEventFixture*)data; + gboolean handled = GTK_WIDGET_GET_CLASS(fixture->webView)->key_press_event(GTK_WIDGET(fixture->webView), &event->key); + g_assert_cmpint(handled, ==, fixture->info->shouldBeHandled); + + return FALSE; +} + + +static gboolean key_release_event_cb(WebKitWebView* webView, GdkEvent* event, gpointer data) +{ + // WebCore never seems to mark keyup events as handled. + KeyEventFixture* fixture = (KeyEventFixture*)data; + gboolean handled = GTK_WIDGET_GET_CLASS(fixture->webView)->key_press_event(GTK_WIDGET(fixture->webView), &event->key); + g_assert(!handled); + + g_main_loop_quit(fixture->loop); + + return FALSE; +} + +static void load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data) +{ + KeyEventFixture* fixture = (KeyEventFixture*)data; + WebKitLoadStatus status = webkit_web_view_get_load_status(webView); + if (status == WEBKIT_LOAD_FINISHED) { + gtk_test_widget_send_key(GTK_WIDGET(fixture->webView), + gdk_unicode_to_keyval('a'), 0); + } + +} + +gboolean map_event_cb(GtkWidget *widget, GdkEvent* event, gpointer data) +{ + gtk_widget_grab_focus(widget); + KeyEventFixture* fixture = (KeyEventFixture*)data; + + g_signal_connect(fixture->webView, "key-press-event", + G_CALLBACK(key_press_event_cb), fixture); + g_signal_connect(fixture->webView, "key-release-event", + G_CALLBACK(key_release_event_cb), fixture); + + g_signal_connect(fixture->webView, "notify::load-status", + G_CALLBACK(load_status_cb), fixture); + + webkit_web_view_load_string(fixture->webView, fixture->info->page, + "text/html", "utf-8", "file://"); + + return FALSE; +} + +static void test_keypress(KeyEventFixture* fixture, gconstpointer data) +{ + fixture->info = (TestInfo*)data; + + g_signal_connect(fixture->window, "map-event", + G_CALLBACK(map_event_cb), fixture); + + gtk_widget_show(fixture->window); + gtk_widget_show(GTK_WIDGET(fixture->webView)); + gtk_window_present(GTK_WINDOW(fixture->window)); + + g_main_loop_run(fixture->loop); + +} + +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("/webkit/keyevent/textfield", KeyEventFixture, + test_info_new("<html><body><input id=\"in\" type=\"text\">" + "<script>document.getElementById('in').focus();" + "</script></body></html>", TRUE), + key_event_fixture_setup, + test_keypress, + key_event_fixture_teardown); + + g_test_add("/webkit/keyevent/buttons", KeyEventFixture, + test_info_new("<html><body><input id=\"in\" type=\"button\">" + "<script>document.getElementById('in').focus();" + "</script></body></html>", FALSE), + key_event_fixture_setup, + test_keypress, + key_event_fixture_teardown); + + g_test_add("/webkit/keyevent/link", KeyEventFixture, + test_info_new("<html><body><a href=\"http://www.gnome.org\" id=\"in\">" + "LINKY MCLINKERSON</a><script>" + "document.getElementById('in').focus();</script>" + "</body></html>", FALSE), + key_event_fixture_setup, + test_keypress, + key_event_fixture_teardown); + + 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/testloading.c b/WebKit/gtk/tests/testloading.c index cd5f08e..c1f0fac 100644 --- a/WebKit/gtk/tests/testloading.c +++ b/WebKit/gtk/tests/testloading.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Gustavo Noronha Silva + * 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 @@ -22,77 +23,201 @@ #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; +typedef struct { + WebKitWebView* webView; + GMainLoop *loop; + gboolean has_been_provisional; + gboolean has_been_committed; + gboolean has_been_first_visually_non_empty_layout; + gboolean has_been_finished; + gboolean has_been_failed; + gboolean has_been_load_error; +} WebLoadingFixture; + +static void web_loading_fixture_setup(WebLoadingFixture* fixture, gconstpointer data) +{ + fixture->webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + fixture->loop = g_main_loop_new(NULL, TRUE); + g_object_ref_sink(fixture->webView); + fixture->has_been_provisional = FALSE; + fixture->has_been_committed = FALSE; + fixture->has_been_first_visually_non_empty_layout = FALSE; + fixture->has_been_finished = FALSE; + fixture->has_been_failed = FALSE; + fixture->has_been_load_error = FALSE; +} -static void load_finished_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, gpointer data) +static void web_loading_fixture_teardown(WebLoadingFixture* fixture, gconstpointer data) { - GMainLoop* loop = (GMainLoop*)data; + g_object_unref(fixture->webView); + g_main_loop_unref(fixture->loop); +} - g_assert(has_been_provisional); - g_assert(has_been_committed); - g_assert(has_been_first_visually_non_empty_layout); +static void load_finished_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, WebLoadingFixture* fixture) +{ + g_assert(fixture->has_been_provisional); + g_assert(fixture->has_been_committed); + g_assert(fixture->has_been_first_visually_non_empty_layout); - g_main_loop_quit(loop); + g_main_loop_quit(fixture->loop); } -static void status_changed_cb(GObject* object, GParamSpec* pspec, gpointer data) +static void status_changed_cb(GObject* object, GParamSpec* pspec, WebLoadingFixture* fixture) { 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; + g_assert(!fixture->has_been_provisional); + g_assert(!fixture->has_been_committed); + g_assert(!fixture->has_been_first_visually_non_empty_layout); + fixture->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; + g_assert(fixture->has_been_provisional); + g_assert(!fixture->has_been_committed); + g_assert(!fixture->has_been_first_visually_non_empty_layout); + fixture->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; + g_assert(fixture->has_been_provisional); + g_assert(fixture->has_been_committed); + g_assert(!fixture->has_been_first_visually_non_empty_layout); + fixture->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); + g_assert(fixture->has_been_provisional); + g_assert(fixture->has_been_committed); + g_assert(fixture->has_been_first_visually_non_empty_layout); break; default: g_assert_not_reached(); } } -static void test_loading_status() +static void test_loading_status(WebLoadingFixture* fixture, gconstpointer data) { - WebKitWebView* web_view = WEBKIT_WEB_VIEW(webkit_web_view_new()); - GMainLoop* loop = g_main_loop_new(NULL, TRUE); + g_assert_cmpint(webkit_web_view_get_load_status(fixture->webView), ==, WEBKIT_LOAD_PROVISIONAL); - 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, + g_object_connect(G_OBJECT(fixture->webView), + "signal::notify::load-status", G_CALLBACK(status_changed_cb), fixture, + "signal::load-finished", G_CALLBACK(load_finished_cb), fixture, NULL); /* load_uri will trigger the navigation-policy-decision-requested * signal emission; */ - webkit_web_view_load_uri(web_view, "http://gnome.org/"); + webkit_web_view_load_uri(fixture->webView, "http://gnome.org/"); + + g_main_loop_run(fixture->loop); +} + +static void load_error_status_changed_cb(GObject* object, GParamSpec* pspec, WebLoadingFixture* fixture) +{ + WebKitLoadStatus status = webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(object)); + + switch(status) { + case WEBKIT_LOAD_PROVISIONAL: + /* We are going to go through here twice, so don't assert + * anything */ + fixture->has_been_provisional = TRUE; + break; + case WEBKIT_LOAD_FINISHED: + g_assert(fixture->has_been_provisional); + g_assert(fixture->has_been_load_error); + g_assert(fixture->has_been_failed); + /* We are checking that only one FINISHED is received in the + whole cycle, so assert it's FALSE */ + g_assert(!fixture->has_been_finished); + fixture->has_been_finished = TRUE; + g_main_loop_quit(fixture->loop); + break; + case WEBKIT_LOAD_FAILED: + g_assert(!fixture->has_been_failed); + fixture->has_been_failed = TRUE; + break; + default: + break; + } +} + +static gboolean load_error_cb(WebKitWebView* webView, WebKitWebFrame* frame, const char* uri, GError *error, WebLoadingFixture* fixture) +{ + g_assert(fixture->has_been_provisional); + g_assert(!fixture->has_been_load_error); + fixture->has_been_load_error = TRUE; + + return FALSE; +} + +static void test_loading_error(WebLoadingFixture* fixture, gconstpointer data) +{ + g_test_bug("28842"); + + g_signal_connect(fixture->webView, "load-error", G_CALLBACK(load_error_cb), fixture); + g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_error_status_changed_cb), fixture); + + webkit_web_view_load_uri(fixture->webView, "http://snoetuhsetuhseoutoeutc.com/"); + g_main_loop_run(fixture->loop); +} + +/* Cancelled load */ + +static gboolean load_cancelled_cb(WebKitWebView* webView, WebKitWebFrame* frame, const char* uri, GError *error, WebLoadingFixture* fixture) +{ + g_assert(fixture->has_been_provisional); + g_assert(fixture->has_been_failed); + g_assert(!fixture->has_been_load_error); + g_assert(error->code == WEBKIT_NETWORK_ERROR_CANCELLED); + fixture->has_been_load_error = TRUE; + + return TRUE; +} + +static gboolean stop_load (gpointer data) +{ + webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(data)); + return FALSE; +} + +static void load_cancelled_status_changed_cb(GObject* object, GParamSpec* pspec, WebLoadingFixture* fixture) +{ + WebKitLoadStatus status = webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(object)); + + switch(status) { + case WEBKIT_LOAD_PROVISIONAL: + g_assert(!fixture->has_been_provisional); + g_assert(!fixture->has_been_failed); + fixture->has_been_provisional = TRUE; + break; + case WEBKIT_LOAD_COMMITTED: + g_idle_add (stop_load, object); + break; + case WEBKIT_LOAD_FAILED: + g_assert(fixture->has_been_provisional); + g_assert(!fixture->has_been_failed); + g_assert(!fixture->has_been_load_error); + fixture->has_been_failed = TRUE; + g_main_loop_quit(fixture->loop); + break; + case WEBKIT_LOAD_FINISHED: + g_assert_not_reached(); + break; + default: + break; + } +} + +static void test_loading_cancelled(WebLoadingFixture* fixture, gconstpointer data) +{ + g_test_bug("29644"); - g_main_loop_run(loop); + g_signal_connect(fixture->webView, "load-error", G_CALLBACK(load_cancelled_cb), fixture); + g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_cancelled_status_changed_cb), fixture); - g_object_unref(web_view); + webkit_web_view_load_uri(fixture->webView, "http://google.com/"); + g_main_loop_run(fixture->loop); } int main(int argc, char** argv) @@ -101,7 +226,21 @@ int main(int argc, char** argv) gtk_test_init(&argc, &argv, NULL); g_test_bug_base("https://bugs.webkit.org/"); - g_test_add_func("/webkit/loading/status", test_loading_status); + g_test_add("/webkit/loading/status", + WebLoadingFixture, NULL, + web_loading_fixture_setup, + test_loading_status, + web_loading_fixture_teardown); + g_test_add("/webkit/loading/error", + WebLoadingFixture, NULL, + web_loading_fixture_setup, + test_loading_error, + web_loading_fixture_teardown); + g_test_add("/webkit/loading/cancelled", + WebLoadingFixture, NULL, + web_loading_fixture_setup, + test_loading_cancelled, + web_loading_fixture_teardown); return g_test_run(); } diff --git a/WebKit/gtk/tests/testnetworkresponse.c b/WebKit/gtk/tests/testnetworkresponse.c new file mode 100644 index 0000000..9050c04 --- /dev/null +++ b/WebKit/gtk/tests/testnetworkresponse.c @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2009 Gustavo Noronha Silva + * 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 <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_response_create_destroy() +{ + WebKitNetworkResponse* response; + SoupMessage* message; + + /* Test creation with URI */ + response = WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "uri", "http://debian.org/", NULL)); + g_assert(WEBKIT_IS_NETWORK_RESPONSE(response)); + message = webkit_network_response_get_message(response); + g_assert(!message); + g_object_unref(response); + + /* Test creation with SoupMessage */ + message = soup_message_new("GET", "http://debian.org/"); + response = WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "message", message, NULL)); + g_assert(WEBKIT_IS_NETWORK_RESPONSE(response)); + g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2); + g_object_unref(response); + 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/"); + response = WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "message", message, "uri", "http://gnome.org/", NULL)); + g_assert(WEBKIT_IS_NETWORK_RESPONSE(response)); + g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2); + g_assert_cmpstr(webkit_network_response_get_uri(response), ==, "http://gnome.org/"); + g_object_unref(response); + g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1); + g_object_unref(message); +} + +static void test_network_response_properties() +{ + WebKitNetworkResponse* response; + SoupMessage* message; + gchar* soupURI; + + /* Test URI is set correctly when creating with URI */ + response = webkit_network_response_new("http://debian.org/"); + g_assert(WEBKIT_IS_NETWORK_RESPONSE(response)); + g_assert_cmpstr(webkit_network_response_get_uri(response), ==, "http://debian.org/"); + g_object_unref(response); + + /* Test URI is set correctly when creating with Message */ + message = soup_message_new("GET", "http://debian.org/"); + response = WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "message", message, NULL)); + g_assert(WEBKIT_IS_NETWORK_RESPONSE(response)); + g_object_unref(message); + + message = webkit_network_response_get_message(response); + 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_response_get_uri(response), ==, "http://debian.org/"); + g_object_unref(response); +} + +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/networkresponse/createdestroy", test_network_response_create_destroy); + g_test_add_func("/webkit/networkresponse/properties", test_network_response_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/testwebdatasource.c b/WebKit/gtk/tests/testwebdatasource.c new file mode 100644 index 0000000..de2430f --- /dev/null +++ b/WebKit/gtk/tests/testwebdatasource.c @@ -0,0 +1,184 @@ +/* + * 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 const gshort defaultTimeout = 10; +guint waitTimer; +gboolean shouldWait; + +typedef struct { + WebKitWebView* webView; + WebKitWebFrame* mainFrame; +} WebDataSourceFixture; + +static void test_webkit_web_data_source_get_initial_request() +{ + WebKitWebView* view; + WebKitWebFrame* frame; + WebKitWebDataSource* dataSource; + WebKitNetworkRequest* initialRequest; + + view = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_object_ref_sink(view); + frame = webkit_web_view_get_main_frame(view); + + WebKitNetworkRequest* request = webkit_network_request_new("http://www.google.com"); + webkit_web_frame_load_request(frame, request); + g_object_unref(request); + + dataSource = webkit_web_frame_get_provisional_data_source(frame); + g_assert(dataSource); + initialRequest = webkit_web_data_source_get_initial_request(dataSource); + g_assert_cmpstr(webkit_network_request_get_uri(initialRequest), ==, "http://www.google.com/"); + + g_object_unref(view); +} + +static void load_finished_unreachable_cb(WebKitWebView* view, WebKitWebFrame* frame, GMainLoop* loop) +{ + if (waitTimer) { + g_source_remove(waitTimer); + waitTimer = 0; + } + + WebKitWebDataSource* datasource; + frame = webkit_web_view_get_main_frame(view); + datasource = webkit_web_frame_get_data_source(frame); + + g_assert_cmpstr("http://localhost/doireallyexist.html", ==, + webkit_web_data_source_get_unreachable_uri(datasource)); + + if (g_main_loop_is_running(loop)) + g_main_loop_quit(loop); +} + +static void load_finished_cb(WebKitWebView* view, WebKitWebFrame* frame, GMainLoop* loop) +{ + if (waitTimer) { + g_source_remove(waitTimer); + waitTimer = 0; + } + + WebKitWebDataSource* dataSource; + frame = webkit_web_view_get_main_frame(view); + dataSource = webkit_web_frame_get_data_source(frame); + + /* Test get_request */ + g_test_message("Testing webkit_web_data_source_get_request"); + WebKitNetworkRequest* request = webkit_web_data_source_get_request(dataSource); + g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://webkit.org/"); + + /* Test get_main_resource */ + g_test_message("Testing webkit_web_data_source_get_main_resource"); + WebKitWebResource* resource = webkit_web_data_source_get_main_resource(dataSource); + g_assert_cmpstr("text/html", ==, webkit_web_resource_get_mime_type(resource)); + g_assert_cmpstr("http://webkit.org/", ==, webkit_web_resource_get_uri(resource)); + + /* Test get_data. We just test if data has certain size for the mean time */ + g_test_message("Testing webkit_web_data_source_get_data has certain size"); + GString* data = webkit_web_data_source_get_data(dataSource); + g_assert(data->len > 100); + + /* FIXME: Add test for get_encoding */ + + if (g_main_loop_is_running(loop)) + g_main_loop_quit(loop); +} + +static void load_committed_cb(WebKitWebView* view, WebKitWebFrame* frame) +{ + WebKitWebDataSource* dataSource = webkit_web_frame_get_data_source(frame); + g_assert(webkit_web_data_source_is_loading(dataSource)); +} + +static gboolean wait_timer_fired(GMainLoop* loop) +{ + waitTimer = 0; + if (g_main_loop_is_running(loop)) + g_main_loop_quit(loop); + + return FALSE; +} + +static void test_webkit_web_data_source() +{ + WebKitWebView* view; + GMainLoop* loop; + + view = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_object_ref_sink(view); + loop = g_main_loop_new(NULL, TRUE); + g_signal_connect(view, "load-committed", G_CALLBACK(load_committed_cb), loop); + g_signal_connect(view, "load-finished", G_CALLBACK(load_finished_cb), loop); + webkit_web_view_load_uri(view, "http://webkit.org"); + + if (!waitTimer) + waitTimer = g_timeout_add_seconds(defaultTimeout, (GSourceFunc)wait_timer_fired, loop); + + g_main_loop_run(loop); + g_object_unref(view); +} + +static void test_webkit_web_data_source_unreachable_uri() +{ + WebKitWebView* view; + GMainLoop* loop; + + view = WEBKIT_WEB_VIEW(webkit_web_view_new()); + 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"); + + if (!waitTimer) + waitTimer = g_timeout_add_seconds(defaultTimeout, (GSourceFunc)wait_timer_fired, loop); + + g_main_loop_run(loop); + g_object_unref(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_bug("24758"); + g_test_add_func("/webkit/webdatasource/get_initial_request", + test_webkit_web_data_source_get_initial_request); + g_test_add_func("/webkit/webdatasource/api", + test_webkit_web_data_source); + g_test_add_func("/webkit/webdatasource/unreachable_uri", + test_webkit_web_data_source_unreachable_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 diff --git a/WebKit/gtk/tests/testwebresource.c b/WebKit/gtk/tests/testwebresource.c new file mode 100644 index 0000000..b9cd40b --- /dev/null +++ b/WebKit/gtk/tests/testwebresource.c @@ -0,0 +1,332 @@ +/* + * 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 <libsoup/soup.h> +#include <string.h> +#include <webkit/webkit.h> + +#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0) + +#define INDEX_HTML "<html></html>" +#define MAIN_HTML "<html><head><script language=\"javascript\" src=\"/javascript.js\"></script></head><body><h1>hah</h1></html>" +#define JAVASCRIPT "function blah () { var a = 1; }" + +GMainLoop* loop; +SoupSession *session; +char *base_uri; +WebKitWebResource* main_resource; +WebKitWebResource* sub_resource; + +typedef struct { + WebKitWebResource* webResource; + WebKitWebView* webView; +} WebResourceFixture; + +/* 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); + + /* Redirect */ + if (g_str_equal (path, "/")) { + soup_message_set_status (msg, SOUP_STATUS_MOVED_PERMANENTLY); + + soup_message_headers_append (msg->response_headers, + "Location", "/index.html"); + } else if (g_str_equal (path, "/index.html")) { + soup_message_body_append (msg->response_body, + SOUP_MEMORY_COPY, + INDEX_HTML, + strlen (INDEX_HTML)); + } else if (g_str_equal (path, "/main.html")) { + soup_message_body_append (msg->response_body, + SOUP_MEMORY_COPY, + MAIN_HTML, + strlen (MAIN_HTML)); + } else if (g_str_equal (path, "/javascript.js")) { + soup_message_body_append (msg->response_body, + SOUP_MEMORY_COPY, + JAVASCRIPT, + strlen (JAVASCRIPT)); + } + + + soup_message_body_complete (msg->response_body); +} + +static void web_resource_fixture_setup(WebResourceFixture* fixture, gconstpointer data) +{ + fixture->webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_object_ref_sink(fixture->webView); + const gchar* webData = "<html></html>"; + fixture->webResource = webkit_web_resource_new(webData, strlen(webData), "http://example.com/", "text/html", "utf8", "Example.com"); + g_assert(fixture->webResource); +} + +static void web_resource_fixture_teardown(WebResourceFixture* fixture, gconstpointer data) +{ + g_assert(fixture->webResource); + g_object_unref(fixture->webResource); + g_object_unref(fixture->webView); +} + +static void test_webkit_web_resource_get_url(WebResourceFixture* fixture, gconstpointer data) +{ + gchar* url; + g_object_get(G_OBJECT(fixture->webResource), "uri", &url, NULL); + g_assert_cmpstr(url, ==, "http://example.com/"); + g_assert_cmpstr(webkit_web_resource_get_uri(fixture->webResource) ,==,"http://example.com/"); + g_free(url); +} + +static void test_webkit_web_resource_get_data(WebResourceFixture* fixture, gconstpointer data) +{ + GString* charData = webkit_web_resource_get_data(fixture->webResource); + g_assert_cmpstr(charData->str, ==, "<html></html>"); +} + +static void test_webkit_web_resource_get_mime_type(WebResourceFixture* fixture, gconstpointer data) +{ + gchar* mime_type; + g_object_get(G_OBJECT(fixture->webResource), "mime-type", &mime_type, NULL); + g_assert_cmpstr(mime_type, ==, "text/html"); + g_assert_cmpstr(webkit_web_resource_get_mime_type(fixture->webResource),==,"text/html"); + g_free(mime_type); +} + +static void test_webkit_web_resource_get_encoding(WebResourceFixture* fixture, gconstpointer data) +{ + gchar* text_encoding; + g_object_get(G_OBJECT(fixture->webResource), "encoding", &text_encoding, NULL); + g_assert_cmpstr(text_encoding, ==, "utf8"); + g_assert_cmpstr(webkit_web_resource_get_encoding(fixture->webResource),==,"utf8"); + g_free(text_encoding); +} + +static void test_webkit_web_resource_get_frame_name(WebResourceFixture* fixture, gconstpointer data) +{ + gchar* frame_name; + g_object_get(G_OBJECT(fixture->webResource), "frame-name", &frame_name, NULL); + g_assert_cmpstr(frame_name, ==, "Example.com"); + g_assert_cmpstr(webkit_web_resource_get_frame_name(fixture->webResource),==,"Example.com"); + g_free(frame_name); +} + +static void resource_request_starting_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, WebKitWebResource* web_resource, WebKitNetworkRequest* request, WebKitNetworkResponse* response, gpointer data) +{ + gint* been_there = data; + *been_there = *been_there + 1; + + if (*been_there == 1) { + g_assert(!main_resource); + main_resource = g_object_ref(web_resource); + + g_assert_cmpstr(webkit_web_resource_get_uri(web_resource), ==, base_uri); + + /* This should be a redirect, so the response must be NULL */ + g_assert(!response); + } else if (*been_there == 2) { + char* uri = g_strdup_printf("%sindex.html", base_uri); + + g_assert_cmpstr(webkit_web_resource_get_uri(web_resource), ==, uri); + + /* Cancel the request. */ + webkit_network_request_set_uri(request, "about:blank"); + + g_free(uri); + } +} + +static void load_finished_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, gpointer data) +{ + gboolean* been_there = data; + *been_there = TRUE; + + g_assert_cmpstr(webkit_web_view_get_uri(web_view), ==, "about:blank"); + + g_main_loop_quit(loop); +} + +static void test_web_resource_loading() +{ + WebKitWebView* web_view = WEBKIT_WEB_VIEW(webkit_web_view_new()); + gint been_to_resource_request_starting = 0; + gboolean been_to_load_finished = FALSE; + WebKitWebFrame* web_frame; + WebKitWebDataSource* data_source; + + loop = g_main_loop_new(NULL, TRUE); + + g_object_ref_sink(web_view); + + g_signal_connect(web_view, "resource-request-starting", + G_CALLBACK(resource_request_starting_cb), + &been_to_resource_request_starting); + + g_signal_connect(web_view, "load-finished", + G_CALLBACK(load_finished_cb), + &been_to_load_finished); + + webkit_web_view_load_uri(web_view, base_uri); + + /* We won't get finished immediately, because of the redirect */ + g_main_loop_run(loop); + + web_frame = webkit_web_view_get_main_frame(web_view); + data_source = webkit_web_frame_get_data_source(web_frame); + + g_assert(main_resource); + g_assert(webkit_web_data_source_get_main_resource(data_source) == main_resource); + g_object_unref(main_resource); + + g_assert_cmpint(been_to_resource_request_starting, ==, 2); + g_assert_cmpint(been_to_load_finished, ==, TRUE); + + g_object_unref(web_view); + g_main_loop_unref(loop); +} + +static void resource_request_starting_sub_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, WebKitWebResource* web_resource, WebKitNetworkRequest* request, WebKitNetworkResponse* response, gpointer data) +{ + if (!main_resource) + main_resource = g_object_ref(web_resource); + else + sub_resource = g_object_ref(web_resource); +} + +static void load_finished_sub_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, gpointer data) +{ + g_main_loop_quit(loop); +} + +static gboolean idle_quit_loop_cb(gpointer data) +{ + g_main_loop_quit(loop); + return FALSE; +} + +static void test_web_resource_sub_resource_loading() +{ + WebKitWebView* web_view = WEBKIT_WEB_VIEW(webkit_web_view_new()); + WebKitWebFrame* web_frame; + WebKitWebDataSource* data_source; + GList* sub_resources; + char* uri = g_strdup_printf("%smain.html", base_uri); + + main_resource = NULL; + + loop = g_main_loop_new(NULL, TRUE); + + g_object_ref_sink(web_view); + + g_signal_connect(web_view, "resource-request-starting", + G_CALLBACK(resource_request_starting_sub_cb), + NULL); + + g_signal_connect(web_view, "load-finished", + G_CALLBACK(load_finished_sub_cb), + NULL); + + webkit_web_view_load_uri(web_view, uri); + + g_main_loop_run(loop); + + /* The main resource should be loaded; now let's wait for the sub-resource to load */ + g_idle_add(idle_quit_loop_cb, NULL); + g_main_loop_run(loop); + + g_assert(main_resource && sub_resource); + g_assert(main_resource != sub_resource); + + web_frame = webkit_web_view_get_main_frame(web_view); + data_source = webkit_web_frame_get_data_source(web_frame); + + g_assert(webkit_web_data_source_get_main_resource(data_source) == main_resource); + g_object_unref(main_resource); + + sub_resources = webkit_web_data_source_get_subresources(data_source); + g_assert(sub_resources); + g_assert(!sub_resources->next); + + g_assert(WEBKIT_WEB_RESOURCE(sub_resources->data) == sub_resource); + + g_object_unref(web_view); + g_main_loop_unref(loop); +} + +int main(int argc, char** argv) +{ + SoupServer* server; + SoupURI* soup_uri; + + g_thread_init(NULL); + gtk_test_init(&argc, &argv, NULL); + + 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("/webkit/webresource/get_url", + WebResourceFixture, 0, web_resource_fixture_setup, + test_webkit_web_resource_get_url, web_resource_fixture_teardown); + g_test_add("/webkit/webresource/get_mime_type", + WebResourceFixture, 0, web_resource_fixture_setup, + test_webkit_web_resource_get_mime_type, web_resource_fixture_teardown); + g_test_add("/webkit/webresource/get_text_encoding_name", + WebResourceFixture, 0, web_resource_fixture_setup, + test_webkit_web_resource_get_encoding, web_resource_fixture_teardown); + g_test_add("/webkit/webresource/get_frame_name", + WebResourceFixture, 0, web_resource_fixture_setup, + test_webkit_web_resource_get_frame_name, web_resource_fixture_teardown); + g_test_add("/webkit/webresource/get_data", + WebResourceFixture, 0, web_resource_fixture_setup, + test_webkit_web_resource_get_data, web_resource_fixture_teardown); + + g_test_add_func("/webkit/webresource/loading", test_web_resource_loading); + g_test_add_func("/webkit/webresource/sub_resource_loading", test_web_resource_sub_resource_loading); + + 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/testwindow.c b/WebKit/gtk/tests/testwindow.c new file mode 100644 index 0000000..41ff323 --- /dev/null +++ b/WebKit/gtk/tests/testwindow.c @@ -0,0 +1,128 @@ +/* + * 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 <gtk/gtk.h> +#include <webkit/webkit.h> + +#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0) + +static void load_finished_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, gpointer data) +{ + GMainLoop* loop = (GMainLoop*)data; + + g_main_loop_quit(loop); +} + +static void test_webkit_window_scrollbar_policy(void) +{ + GMainLoop* loop; + GtkWidget* scrolledWindow; + GtkWidget* webView; + WebKitWebFrame* mainFrame; + GtkPolicyType horizontalPolicy; + GtkPolicyType verticalPolicy; + + loop = g_main_loop_new(NULL, TRUE); + + scrolledWindow = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + + webView = webkit_web_view_new(); + g_object_ref_sink(webView); + + g_signal_connect(webView, "load-finished", + G_CALLBACK(load_finished_cb), loop); + + gtk_container_add(GTK_CONTAINER(scrolledWindow), webView); + + mainFrame = webkit_web_view_get_main_frame(WEBKIT_WEB_VIEW(webView)); + + /* Test we correctly apply policy for not having scrollbars; This + * case is special, because we turn the policy from NEVER to + * AUTOMATIC, since we cannot easily represent the same thing + * using GtkScrolledWindow */ + webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView), + "<html><body>WebKit!</body><script>document.getElementsByTagName('body')[0].style.overflow = 'hidden';</script></html>", + "file://"); + + g_main_loop_run(loop); + + gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(scrolledWindow), + &horizontalPolicy, &verticalPolicy); + + g_assert(horizontalPolicy == GTK_POLICY_AUTOMATIC); + g_assert(verticalPolicy == GTK_POLICY_AUTOMATIC); + + g_assert(GTK_POLICY_NEVER == webkit_web_frame_get_horizontal_scrollbar_policy(mainFrame)); + g_assert(GTK_POLICY_NEVER == webkit_web_frame_get_vertical_scrollbar_policy(mainFrame)); + + /* Test we correctly apply policy for always having scrollbars */ + webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView), + "<html><body>WebKit!</body><script>document.getElementsByTagName('body')[0].style.overflow = 'scroll';</script></html>", + "file://"); + + g_main_loop_run(loop); + + gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(scrolledWindow), + &horizontalPolicy, &verticalPolicy); + + g_assert(horizontalPolicy == GTK_POLICY_ALWAYS); + g_assert(verticalPolicy == GTK_POLICY_ALWAYS); + + g_assert(horizontalPolicy == webkit_web_frame_get_horizontal_scrollbar_policy(mainFrame)); + g_assert(verticalPolicy == webkit_web_frame_get_vertical_scrollbar_policy(mainFrame)); + + /* Test we correctly apply policy for having scrollbars when needed */ + webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView), + "<html><body>WebKit!</body><script>document.getElementsByTagName('body')[0].style.overflow = 'auto';</script></html>", + "file://"); + + g_main_loop_run(loop); + + gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(scrolledWindow), + &horizontalPolicy, &verticalPolicy); + + g_assert(horizontalPolicy == GTK_POLICY_AUTOMATIC); + g_assert(verticalPolicy == GTK_POLICY_AUTOMATIC); + + g_assert(horizontalPolicy == webkit_web_frame_get_horizontal_scrollbar_policy(mainFrame)); + g_assert(verticalPolicy == webkit_web_frame_get_vertical_scrollbar_policy(mainFrame)); + + 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/window/scrollbar_policy", test_webkit_window_scrollbar_policy); + 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 |
