summaryrefslogtreecommitdiffstats
path: root/WebKit/gtk/tests/testloading.c
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/gtk/tests/testloading.c')
-rw-r--r--WebKit/gtk/tests/testloading.c209
1 files changed, 200 insertions, 9 deletions
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();
}