2 * Copyright (C) 2009 Gustavo Noronha Silva
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 #include <glib/gstdio.h>
26 #include <webkit/webkit.h>
28 #if GTK_CHECK_VERSION(2, 14, 0)
30 static void test_network_request_create_destroy()
32 WebKitNetworkRequest* request;
35 /* Test creation with URI */
36 request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "uri", "http://debian.org/", NULL));
37 g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
38 message = webkit_network_request_get_message(request);
40 g_object_unref(request);
42 /* Test creation with SoupMessage */
43 message = soup_message_new("GET", "http://debian.org/");
44 request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, NULL));
45 g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
46 g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2);
47 g_object_unref(request);
48 g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1);
49 g_object_unref(message);
51 /* Test creation with both SoupMessage and URI */
52 message = soup_message_new("GET", "http://debian.org/");
53 request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, "uri", "http://gnome.org/", NULL));
54 g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
55 g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2);
56 g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://gnome.org/");
57 g_object_unref(request);
58 g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1);
59 g_object_unref(message);
62 static void test_network_request_properties()
64 WebKitNetworkRequest* request;
68 /* Test URI is set correctly when creating with URI */
69 request = webkit_network_request_new("http://debian.org/");
70 g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
71 g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/");
72 g_object_unref(request);
74 /* Test URI is set correctly when creating with Message */
75 message = soup_message_new("GET", "http://debian.org/");
76 request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, NULL));
77 g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
78 g_object_unref(message);
80 message = webkit_network_request_get_message(request);
81 soupURI = soup_uri_to_string(soup_message_get_uri(message), FALSE);
82 g_assert_cmpstr(soupURI, ==, "http://debian.org/");
85 g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/");
86 g_object_unref(request);
89 int main(int argc, char** argv)
92 gtk_test_init(&argc, &argv, NULL);
94 g_test_bug_base("https://bugs.webkit.org/");
95 g_test_add_func("/webkit/networkrequest/createdestroy", test_network_request_create_destroy);
96 g_test_add_func("/webkit/networkrequest/properties", test_network_request_properties);
101 int main(int argc, char** argv)
103 g_critical("You will need gtk-2.14.0 to run the unit tests. Doing nothing now.");