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 <errno.h> 21 #include <unistd.h> 22 #include <glib.h> 23 #include <glib/gstdio.h> 24 #include <gtk/gtk.h> 25 #include <webkit/webkit.h> 26 27 #if GTK_CHECK_VERSION(2, 14, 0) 28 29 // Not yet public API 30 SoupMessage* webkit_network_request_get_message(WebKitNetworkRequest* request); 31 32 static gboolean navigation_policy_decision_requested_cb(WebKitWebView* web_view, 33 WebKitWebFrame* web_frame, 34 WebKitNetworkRequest* request, 35 WebKitWebNavigationAction* action, 36 WebKitWebPolicyDecision* decision, 37 gpointer data) 38 { 39 SoupMessage* message = webkit_network_request_get_message(request); 40 41 /* 1 -> webkit_network_request_with_core_request 42 * 43 * The SoupMessage is created exclusively for the emission of this 44 * signal. 45 */ 46 g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1); 47 48 return FALSE; 49 } 50 51 static void test_soup_message_lifetime() 52 { 53 WebKitWebView* web_view = WEBKIT_WEB_VIEW(webkit_web_view_new()); 54 55 g_object_ref_sink(web_view); 56 57 g_signal_connect(web_view, "navigation-policy-decision-requested", 58 G_CALLBACK(navigation_policy_decision_requested_cb), 59 NULL); 60 61 /* load_uri will trigger the navigation-policy-decision-requested 62 * signal emission; 63 */ 64 webkit_web_view_load_uri(web_view, "http://127.0.0.1/"); 65 66 g_object_unref(web_view); 67 } 68 69 int main(int argc, char** argv) 70 { 71 g_thread_init(NULL); 72 gtk_test_init(&argc, &argv, NULL); 73 74 g_test_bug_base("https://bugs.webkit.org/"); 75 g_test_add_func("/webkit/soupmessage/lifetime", test_soup_message_lifetime); 76 return g_test_run (); 77 } 78 79 #else 80 int main(int argc, char** argv) 81 { 82 g_critical("You will need gtk-2.14.0 to run the unit tests. Doing nothing now."); 83 return 0; 84 } 85 86 #endif 87