diff options
Diffstat (limited to 'WebKit/gtk/tests')
| -rw-r--r-- | WebKit/gtk/tests/testatk.c | 100 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testdownload.c | 43 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testloading.c | 209 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testmimehandling.c | 30 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testwebdatasource.c | 49 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testwebresource.c | 29 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testwebview.c | 29 | ||||
| -rw-r--r-- | WebKit/gtk/tests/testwindow.c | 12 |
8 files changed, 410 insertions, 91 deletions
diff --git a/WebKit/gtk/tests/testatk.c b/WebKit/gtk/tests/testatk.c index c5f4db3..7db274a 100644 --- a/WebKit/gtk/tests/testatk.c +++ b/WebKit/gtk/tests/testatk.c @@ -34,6 +34,10 @@ static const char* contentsInTextarea = "<html><body><textarea cols='80'>This is 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 const char* contentsInParagraphAndBodySimple = "<html><body><p>This is a test.</p>Hello world.</body></html>"; + +static const char* contentsInParagraphAndBodyModerate = "<html><body><p>This is a test.</p>Hello world.<br /><font color='#00cc00'>This sentence is green.</font><br />This one is not.</body></html>"; + static gboolean bail_out(GMainLoop* loop) { if (g_main_loop_is_running(loop)) @@ -221,8 +225,6 @@ static void test_webkit_atk_get_text_at_offset_forms(void) 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)); @@ -254,8 +256,6 @@ static void test_webkit_atk_get_text_at_offset(void) 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)); @@ -287,8 +287,6 @@ static void test_webkit_atk_get_text_at_offset_newlines(void) 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)); @@ -364,6 +362,94 @@ static void test_webkit_atk_get_text_at_offset_text_input(void) g_object_unref(webView); } +static void testWebkitAtkGetTextInParagraphAndBodySimple(void) +{ + WebKitWebView* webView; + AtkObject* obj; + AtkObject* obj1; + AtkObject* obj2; + GMainLoop* loop; + AtkText* textObj1; + AtkText* textObj2; + + 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, contentsInParagraphAndBodySimple, 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); + obj1 = atk_object_ref_accessible_child(obj, 0); + g_assert(obj1); + obj2 = atk_object_ref_accessible_child(obj, 1); + g_assert(obj2); + + textObj1 = ATK_TEXT(obj1); + g_assert(ATK_IS_TEXT(textObj1)); + textObj2 = ATK_TEXT(obj2); + g_assert(ATK_IS_TEXT(textObj2)); + + char *text = atk_text_get_text(textObj1, 0, -1); + g_assert_cmpstr(text, ==, "This is a test."); + + text = atk_text_get_text(textObj2, 0, 12); + g_assert_cmpstr(text, ==, "Hello world."); + + g_object_unref(obj1); + g_object_unref(obj2); + g_object_unref(webView); +} + +static void testWebkitAtkGetTextInParagraphAndBodyModerate(void) +{ + WebKitWebView* webView; + AtkObject* obj; + AtkObject* obj1; + AtkObject* obj2; + GMainLoop* loop; + AtkText* textObj1; + AtkText* textObj2; + + 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, contentsInParagraphAndBodyModerate, 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); + obj1 = atk_object_ref_accessible_child(obj, 0); + g_assert(obj1); + obj2 = atk_object_ref_accessible_child(obj, 1); + g_assert(obj2); + + textObj1 = ATK_TEXT(obj1); + g_assert(ATK_IS_TEXT(textObj1)); + textObj2 = ATK_TEXT(obj2); + g_assert(ATK_IS_TEXT(textObj2)); + + char *text = atk_text_get_text(textObj1, 0, -1); + g_assert_cmpstr(text, ==, "This is a test."); + + text = atk_text_get_text(textObj2, 0, 53); + g_assert_cmpstr(text, ==, "Hello world.\nThis sentence is green.\nThis one is not."); + + g_object_unref(obj1); + g_object_unref(obj2); + g_object_unref(webView); +} + int main(int argc, char** argv) { g_thread_init(NULL); @@ -375,6 +461,8 @@ int main(int argc, char** argv) 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); + g_test_add_func("/webkit/atk/getTextInParagraphAndBodySimple", testWebkitAtkGetTextInParagraphAndBodySimple); + g_test_add_func("/webkit/atk/getTextInParagraphAndBodyModerate", testWebkitAtkGetTextInParagraphAndBodyModerate); return g_test_run (); } diff --git a/WebKit/gtk/tests/testdownload.c b/WebKit/gtk/tests/testdownload.c index 0d964ed..05c3a8d 100644 --- a/WebKit/gtk/tests/testdownload.c +++ b/WebKit/gtk/tests/testdownload.c @@ -26,6 +26,7 @@ GMainLoop* loop; char* temporaryFilename = NULL; +WebKitDownload* theDownload = NULL; static void test_webkit_download_create(void) @@ -87,6 +88,7 @@ download_requested_cb(WebKitWebView* web_view, WebKitDownload* download, gboolean* beenThere) { + theDownload = download; *beenThere = TRUE; if (temporaryFilename) { gchar *uri = g_filename_to_uri(temporaryFilename, NULL, NULL); @@ -101,8 +103,19 @@ download_requested_cb(WebKitWebView* web_view, return TRUE; } +static gboolean +set_filename(gchar* filename) +{ + gchar *uri = g_filename_to_uri(filename, NULL, NULL); + webkit_download_set_destination_uri(theDownload, uri); + g_free(uri); + temporaryFilename = filename; + webkit_download_start(theDownload); + return FALSE; +} + static void -test_webkit_download_perform(void) +test_webkit_download_perform(gboolean asynch) { WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); @@ -121,16 +134,23 @@ test_webkit_download_perform(void) * 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); + gchar* filename; + int fd = g_file_open_tmp("webkit-testwebdownload-XXXXXX", &filename, &error); close(fd); if (error) g_critical("Failed to open a temporary file for writing: %s.", error->message); - if (g_unlink(temporaryFilename) == -1) + if (g_unlink(filename) == -1) g_critical("Failed to delete the temporary file: %s.", g_strerror(errno)); + if (asynch) + g_idle_add((GSourceFunc)set_filename, filename); + else + temporaryFilename = filename; + + theDownload = NULL; + loop = g_main_loop_new(NULL, TRUE); webkit_web_view_load_uri(webView, "http://gnome.org/"); g_main_loop_run(loop); @@ -145,6 +165,18 @@ test_webkit_download_perform(void) g_object_unref(webView); } +static void +test_webkit_download_synch(void) +{ + test_webkit_download_perform(FALSE); +} + +static void +test_webkit_download_asynch(void) +{ + test_webkit_download_perform(TRUE); +} + int main(int argc, char** argv) { g_thread_init(NULL); @@ -152,7 +184,8 @@ int main(int argc, char** argv) 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); + g_test_add_func("/webkit/download/synch", test_webkit_download_synch); + g_test_add_func("/webkit/download/asynch", test_webkit_download_asynch); return g_test_run (); } diff --git a/WebKit/gtk/tests/testloading.c b/WebKit/gtk/tests/testloading.c index c1f0fac..fd9a05c 100644 --- a/WebKit/gtk/tests/testloading.c +++ b/WebKit/gtk/tests/testloading.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Gustavo Noronha Silva + * Copyright (C) 2009, 2010 Gustavo Noronha Silva * Copyright (C) 2009 Igalia S.L. * * This library is free software; you can redistribute it and/or @@ -19,10 +19,45 @@ */ #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) +/* This string has to be rather big because of the cancelled test - it + * looks like soup refuses to send or receive a too small chunk */ +#define HTML_STRING "<html><body>Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!</body></html>" + +SoupURI* 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, "/test_loading_status") || g_str_equal(path, "/test_loading_status2")) + soup_message_body_append(msg->response_body, SOUP_MEMORY_STATIC, HTML_STRING, strlen(HTML_STRING)); + else if (g_str_equal(path, "/test_load_error")) { + soup_message_set_status(msg, SOUP_STATUS_CANT_CONNECT); + } else if (g_str_equal(path, "/test_loading_cancelled")) { + soup_message_headers_set_encoding(msg->response_headers, SOUP_ENCODING_CHUNKED); + soup_message_body_append(msg->response_body, SOUP_MEMORY_STATIC, HTML_STRING, strlen(HTML_STRING)); + soup_server_unpause_message(server, msg); + return; + } + + soup_message_body_complete(msg->response_body); +} + typedef struct { WebKitWebView* webView; GMainLoop *loop; @@ -53,6 +88,18 @@ static void web_loading_fixture_teardown(WebLoadingFixture* fixture, gconstpoint g_main_loop_unref(fixture->loop); } +static char* get_uri_for_path(const char* path) +{ + SoupURI* uri; + char* uri_string; + + uri = soup_uri_new_with_base(base_uri, path); + uri_string = soup_uri_to_string(uri, FALSE); + soup_uri_free (uri); + + return uri_string; +} + static void load_finished_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, WebLoadingFixture* fixture) { g_assert(fixture->has_been_provisional); @@ -98,6 +145,8 @@ static void status_changed_cb(GObject* object, GParamSpec* pspec, WebLoadingFixt static void test_loading_status(WebLoadingFixture* fixture, gconstpointer data) { + char* uri_string; + g_assert_cmpint(webkit_web_view_get_load_status(fixture->webView), ==, WEBKIT_LOAD_PROVISIONAL); g_object_connect(G_OBJECT(fixture->webView), @@ -105,10 +154,13 @@ static void test_loading_status(WebLoadingFixture* fixture, gconstpointer data) "signal::load-finished", G_CALLBACK(load_finished_cb), fixture, NULL); + uri_string = get_uri_for_path("/test_loading_status"); + /* load_uri will trigger the navigation-policy-decision-requested * signal emission; */ - webkit_web_view_load_uri(fixture->webView, "http://gnome.org/"); + webkit_web_view_load_uri(fixture->webView, uri_string); + g_free(uri_string); g_main_loop_run(fixture->loop); } @@ -119,23 +171,24 @@ static void load_error_status_changed_cb(GObject* object, GParamSpec* pspec, Web switch(status) { case WEBKIT_LOAD_PROVISIONAL: - /* We are going to go through here twice, so don't assert - * anything */ + g_assert(!fixture->has_been_provisional); fixture->has_been_provisional = TRUE; break; + case WEBKIT_LOAD_COMMITTED: + g_assert(!fixture->has_been_committed); + fixture->has_been_committed = 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; + g_main_loop_quit(fixture->loop); break; default: break; @@ -153,13 +206,24 @@ static gboolean load_error_cb(WebKitWebView* webView, WebKitWebFrame* frame, con static void test_loading_error(WebLoadingFixture* fixture, gconstpointer data) { + char* uri_string; + 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/"); + uri_string = get_uri_for_path("/test_load_error"); + webkit_web_view_load_uri(fixture->webView, uri_string); + g_free(uri_string); + g_main_loop_run(fixture->loop); + + g_assert(fixture->has_been_provisional); + g_assert(!fixture->has_been_committed); + g_assert(fixture->has_been_load_error); + g_assert(fixture->has_been_failed); + g_assert(!fixture->has_been_finished); } /* Cancelled load */ @@ -211,20 +275,142 @@ static void load_cancelled_status_changed_cb(GObject* object, GParamSpec* pspec, static void test_loading_cancelled(WebLoadingFixture* fixture, gconstpointer data) { + char* uri_string; + g_test_bug("29644"); 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); - webkit_web_view_load_uri(fixture->webView, "http://google.com/"); + uri_string = get_uri_for_path("/test_loading_cancelled"); + webkit_web_view_load_uri(fixture->webView, uri_string); + g_free(uri_string); + g_main_loop_run(fixture->loop); } +static void load_goback_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); + fixture->has_been_provisional = TRUE; + break; + case WEBKIT_LOAD_COMMITTED: + g_assert(fixture->has_been_provisional); + fixture->has_been_committed = TRUE; + break; + case WEBKIT_LOAD_FAILED: + g_assert_not_reached(); + break; + case WEBKIT_LOAD_FINISHED: + g_assert(fixture->has_been_provisional); + g_assert(fixture->has_been_committed); + fixture->has_been_finished = TRUE; + g_main_loop_quit(fixture->loop); + break; + default: + break; + } +} + +static void load_wentback_status_changed_cb(GObject* object, GParamSpec* pspec, WebLoadingFixture* fixture) +{ + WebKitLoadStatus status = webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(object)); + char* uri_string; + char* uri_string2; + + uri_string = get_uri_for_path("/test_loading_status"); + uri_string2 = get_uri_for_path("/test_loading_status2"); + + switch(status) { + case WEBKIT_LOAD_PROVISIONAL: + g_assert_cmpstr(webkit_web_view_get_uri(fixture->webView), ==, uri_string2); + break; + case WEBKIT_LOAD_COMMITTED: + g_assert_cmpstr(webkit_web_view_get_uri(fixture->webView), ==, uri_string); + break; + case WEBKIT_LOAD_FAILED: + g_assert_not_reached(); + break; + case WEBKIT_LOAD_FINISHED: + g_assert_cmpstr(webkit_web_view_get_uri(fixture->webView), ==, uri_string); + g_main_loop_quit(fixture->loop); + break; + default: + break; + } + + g_free(uri_string); + g_free(uri_string2); +} + +static void load_error_test(WebKitWebView* webview, WebKitWebFrame* frame, const char* uri, GError* error) +{ + g_debug("Error: %s", error->message); +} + +static void test_loading_goback(WebLoadingFixture* fixture, gconstpointer data) +{ + char* uri_string; + + g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_goback_status_changed_cb), fixture); + + g_signal_connect(fixture->webView, "load-error", G_CALLBACK(load_error_test), fixture); + + uri_string = get_uri_for_path("/test_loading_status"); + webkit_web_view_load_uri(fixture->webView, uri_string); + g_free(uri_string); + + g_main_loop_run(fixture->loop); + + 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; + + uri_string = get_uri_for_path("/test_loading_status2"); + webkit_web_view_load_uri(fixture->webView, uri_string); + g_free(uri_string); + + g_main_loop_run(fixture->loop); + + g_signal_handlers_disconnect_by_func(fixture->webView, load_goback_status_changed_cb, fixture); + + 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; + + g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_wentback_status_changed_cb), fixture); + webkit_web_view_go_back(fixture->webView); + + g_main_loop_run(fixture->loop); + + g_signal_handlers_disconnect_by_func(fixture->webView, load_wentback_status_changed_cb, fixture); +} + int main(int argc, char** argv) { + SoupServer* server; + 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); + + base_uri = soup_uri_new("http://127.0.0.1/"); + soup_uri_set_port(base_uri, soup_server_get_port(server)); + g_test_bug_base("https://bugs.webkit.org/"); g_test_add("/webkit/loading/status", WebLoadingFixture, NULL, @@ -241,6 +427,11 @@ int main(int argc, char** argv) web_loading_fixture_setup, test_loading_cancelled, web_loading_fixture_teardown); + g_test_add("/webkit/loading/goback", + WebLoadingFixture, NULL, + web_loading_fixture_setup, + test_loading_goback, + web_loading_fixture_teardown); return g_test_run(); } diff --git a/WebKit/gtk/tests/testmimehandling.c b/WebKit/gtk/tests/testmimehandling.c index e68dcdf..bfe3148 100644 --- a/WebKit/gtk/tests/testmimehandling.c +++ b/WebKit/gtk/tests/testmimehandling.c @@ -23,6 +23,7 @@ #include <libsoup/soup.h> #include <string.h> #include <webkit/webkit.h> +#include <unistd.h> #if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0) @@ -87,10 +88,11 @@ server_callback(SoupServer *server, SoupMessage *msg, soup_message_body_complete(msg->response_body); } -static gboolean idle_quit_loop_cb(gpointer data) +static void idle_quit_loop_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data) { - g_main_loop_quit(loop); - return FALSE; + if (webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FINISHED || + webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FAILED) + g_main_loop_quit(loop); } static gboolean mime_type_policy_decision_requested_cb(WebKitWebView* view, WebKitWebFrame* frame, @@ -138,7 +140,7 @@ static void test_mime_type(const char* name) loop = g_main_loop_new(NULL, TRUE); g_object_connect(G_OBJECT(view), - "signal::load-finished", idle_quit_loop_cb, NULL, + "signal::notify::load-status", idle_quit_loop_cb, NULL, "signal::mime-type-policy-decision-requested", mime_type_policy_decision_requested_cb, g_strdup(name), NULL); @@ -175,22 +177,20 @@ 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); + while (!g_file_test ("WebKit/gtk/tests/resources/test.html", G_FILE_TEST_EXISTS)) { + char path_name[PATH_MAX]; + + g_chdir(".."); + + g_assert(!g_str_equal(getcwd(path_name, PATH_MAX), "/")); + } + + g_chdir("WebKit/gtk/tests/resources/"); server = soup_server_new(SOUP_SERVER_PORT, 0, NULL); soup_server_run_async(server); diff --git a/WebKit/gtk/tests/testwebdatasource.c b/WebKit/gtk/tests/testwebdatasource.c index fe5c62f..5c0568e 100644 --- a/WebKit/gtk/tests/testwebdatasource.c +++ b/WebKit/gtk/tests/testwebdatasource.c @@ -55,35 +55,45 @@ static void test_webkit_web_data_source_get_initial_request() g_object_unref(view); } -static void load_finished_unreachable_cb(WebKitWebView* view, WebKitWebFrame* frame, GMainLoop* loop) +static void notify_load_status_unreachable_cb(WebKitWebView* view, GParamSpec* pspec, GMainLoop* loop) { + WebKitLoadStatus status = webkit_web_view_get_load_status (view); + WebKitWebFrame* frame = webkit_web_view_get_main_frame(view); + + if (status != WEBKIT_LOAD_FINISHED) + return; + 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); + WebKitWebDataSource* datasource = webkit_web_frame_get_data_source(frame); 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)) - g_main_loop_quit(loop); + g_main_loop_quit(loop); } -static void load_finished_cb(WebKitWebView* view, WebKitWebFrame* frame, GMainLoop* loop) +static void notify_load_status_cb(WebKitWebView* view, GParamSpec* pspec, GMainLoop* loop) { + WebKitLoadStatus status = webkit_web_view_get_load_status (view); + WebKitWebFrame* frame = webkit_web_view_get_main_frame(view); + WebKitWebDataSource* dataSource = webkit_web_frame_get_data_source(frame); + + if (status == WEBKIT_LOAD_COMMITTED) { + g_assert(webkit_web_data_source_is_loading(dataSource)); + return; + } + else if (status != WEBKIT_LOAD_FINISHED) + return; + 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); @@ -102,21 +112,13 @@ static void load_finished_cb(WebKitWebView* view, WebKitWebFrame* frame, GMainLo /* 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)); + g_main_loop_quit(loop); } static gboolean wait_timer_fired(GMainLoop* loop) { waitTimer = 0; - if (g_main_loop_is_running(loop)) - g_main_loop_quit(loop); + g_main_loop_quit(loop); return FALSE; } @@ -129,8 +131,7 @@ static void test_webkit_web_data_source() 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); + g_signal_connect(view, "notify::load-status", G_CALLBACK(notify_load_status_cb), loop); webkit_web_view_load_uri(view, "http://webkit.org"); if (!waitTimer) @@ -148,7 +149,7 @@ static void test_webkit_web_data_source_unreachable_uri() 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); + g_signal_connect(view, "notify::load-status", G_CALLBACK(notify_load_status_unreachable_cb), loop); webkit_web_view_load_uri(view, "http://this.host.does.not.exist/doireallyexist.html"); if (!waitTimer) diff --git a/WebKit/gtk/tests/testwebresource.c b/WebKit/gtk/tests/testwebresource.c index b9cd40b..81457a4 100644 --- a/WebKit/gtk/tests/testwebresource.c +++ b/WebKit/gtk/tests/testwebresource.c @@ -163,14 +163,16 @@ static void resource_request_starting_cb(WebKitWebView* web_view, WebKitWebFrame } } -static void load_finished_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, gpointer data) +static void notify_load_status_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data) { - gboolean* been_there = data; - *been_there = TRUE; + if (webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FINISHED) { + gboolean* been_there = data; + *been_there = TRUE; - g_assert_cmpstr(webkit_web_view_get_uri(web_view), ==, "about:blank"); + g_assert_cmpstr(webkit_web_view_get_uri(web_view), ==, "about:blank"); - g_main_loop_quit(loop); + g_main_loop_quit(loop); + } } static void test_web_resource_loading() @@ -189,8 +191,8 @@ static void test_web_resource_loading() G_CALLBACK(resource_request_starting_cb), &been_to_resource_request_starting); - g_signal_connect(web_view, "load-finished", - G_CALLBACK(load_finished_cb), + g_signal_connect(web_view, "notify::load-status", + G_CALLBACK(notify_load_status_cb), &been_to_load_finished); webkit_web_view_load_uri(web_view, base_uri); @@ -220,9 +222,10 @@ static void resource_request_starting_sub_cb(WebKitWebView* web_view, WebKitWebF sub_resource = g_object_ref(web_resource); } -static void load_finished_sub_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, gpointer data) +static void notify_load_status_sub_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data) { - g_main_loop_quit(loop); + if (webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FINISHED) + g_main_loop_quit(loop); } static gboolean idle_quit_loop_cb(gpointer data) @@ -249,8 +252,8 @@ static void test_web_resource_sub_resource_loading() G_CALLBACK(resource_request_starting_sub_cb), NULL); - g_signal_connect(web_view, "load-finished", - G_CALLBACK(load_finished_sub_cb), + g_signal_connect(web_view, "notify::load-status", + G_CALLBACK(notify_load_status_sub_cb), NULL); webkit_web_view_load_uri(web_view, uri); @@ -271,8 +274,10 @@ static void test_web_resource_sub_resource_loading() g_object_unref(main_resource); sub_resources = webkit_web_data_source_get_subresources(data_source); + // Expected resources: javascripts.js, favicon.ico g_assert(sub_resources); - g_assert(!sub_resources->next); + g_assert(sub_resources->next); + g_assert(!sub_resources->next->next); g_assert(WEBKIT_WEB_RESOURCE(sub_resources->data) == sub_resource); diff --git a/WebKit/gtk/tests/testwebview.c b/WebKit/gtk/tests/testwebview.c index e0921c0..7482747 100644 --- a/WebKit/gtk/tests/testwebview.c +++ b/WebKit/gtk/tests/testwebview.c @@ -63,10 +63,11 @@ server_callback(SoupServer* server, SoupMessage* msg, soup_message_body_complete(msg->response_body); } -static gboolean idle_quit_loop_cb(gpointer data) +static void idle_quit_loop_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data) { - g_main_loop_quit(loop); - return FALSE; + if (webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FINISHED || + webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FAILED) + g_main_loop_quit(loop); } static void icon_uri_changed_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data) @@ -105,7 +106,7 @@ static void test_webkit_web_view_icon_uri() loop = g_main_loop_new(NULL, TRUE); g_object_connect(G_OBJECT(view), - "signal::load-finished", idle_quit_loop_cb, NULL, + "signal::notify::progress", 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); @@ -124,22 +125,20 @@ 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); + while (!g_file_test ("WebKit/gtk/tests/resources/test.html", G_FILE_TEST_EXISTS)) { + char path_name[PATH_MAX]; + + g_chdir(".."); + + g_assert(!g_str_equal(getcwd(path_name, PATH_MAX), "/")); + } + + g_chdir("WebKit/gtk/tests/resources/"); server = soup_server_new(SOUP_SERVER_PORT, 0, NULL); soup_server_run_async(server); diff --git a/WebKit/gtk/tests/testwindow.c b/WebKit/gtk/tests/testwindow.c index 41ff323..106f934 100644 --- a/WebKit/gtk/tests/testwindow.c +++ b/WebKit/gtk/tests/testwindow.c @@ -22,11 +22,13 @@ #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) +static void notify_load_status_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data) { - GMainLoop* loop = (GMainLoop*)data; + if (webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FINISHED) { + GMainLoop* loop = (GMainLoop*)data; - g_main_loop_quit(loop); + g_main_loop_quit(loop); + } } static void test_webkit_window_scrollbar_policy(void) @@ -47,8 +49,8 @@ static void test_webkit_window_scrollbar_policy(void) webView = webkit_web_view_new(); g_object_ref_sink(webView); - g_signal_connect(webView, "load-finished", - G_CALLBACK(load_finished_cb), loop); + g_signal_connect(webView, "notify::load-status", + G_CALLBACK(notify_load_status_cb), loop); gtk_container_add(GTK_CONTAINER(scrolledWindow), webView); |
