1/*
2 * Copyright (C) 2009 Gustavo Noronha Silva
3 *
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.
8 *
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.
13 *
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.
18 */
19
20#include "autotoolsconfig.h"
21#include <errno.h>
22#include <unistd.h>
23#include <glib.h>
24#include <glib/gstdio.h>
25#include <gtk/gtk.h>
26#include <stdlib.h>
27#include <webkit/webkit.h>
28
29static void test_network_request_create_destroy()
30{
31    WebKitNetworkRequest* request;
32    SoupMessage* message;
33
34    /* Test creation with URI */
35    request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "uri", "http://debian.org/", NULL));
36    g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
37    message = webkit_network_request_get_message(request);
38    g_assert(!message);
39    g_object_unref(request);
40
41    /* Test creation with SoupMessage */
42    message = soup_message_new("GET", "http://debian.org/");
43    request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, NULL));
44    g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
45    g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2);
46    g_object_unref(request);
47    g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1);
48    g_object_unref(message);
49
50    /* Test creation with both SoupMessage and URI */
51    message = soup_message_new("GET", "http://debian.org/");
52    request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, "uri", "http://gnome.org/", NULL));
53    g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
54    g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2);
55    g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://gnome.org/");
56    g_object_unref(request);
57    g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1);
58    g_object_unref(message);
59}
60
61static void test_network_request_properties()
62{
63    WebKitNetworkRequest* request;
64    SoupMessage* message;
65    gchar* soupURI;
66
67    /* Test URI is set correctly when creating with URI */
68    request = webkit_network_request_new("http://debian.org/");
69    g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
70    g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/");
71    g_object_unref(request);
72
73    /* Test URI is set correctly when creating with Message */
74    message = soup_message_new("GET", "http://debian.org/");
75    request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, NULL));
76    g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
77    g_object_unref(message);
78
79    message = webkit_network_request_get_message(request);
80    soupURI = soup_uri_to_string(soup_message_get_uri(message), FALSE);
81    g_assert_cmpstr(soupURI, ==, "http://debian.org/");
82    g_free(soupURI);
83
84    g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/");
85    g_object_unref(request);
86}
87
88int main(int argc, char** argv)
89{
90    gtk_test_init(&argc, &argv, NULL);
91
92    g_test_bug_base("https://bugs.webkit.org/");
93    g_test_add_func("/webkit/networkrequest/createdestroy", test_network_request_create_destroy);
94    g_test_add_func("/webkit/networkrequest/properties", test_network_request_properties);
95    return g_test_run ();
96}
97