• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 Jan Michael Alonzo
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 <glib.h>
21 #include <gtk/gtk.h>
22 #include <webkit/webkit.h>
23 
24 #if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0)
25 
test_webkit_web_settings_user_agent(void)26 static void test_webkit_web_settings_user_agent(void)
27 {
28     WebKitWebSettings* settings;
29     GtkWidget* webView;
30     gchar* defaultUserAgent;
31     gchar* userAgent;
32     g_test_bug("17375");
33 
34     webView = webkit_web_view_new();
35     g_object_ref_sink(webView);
36 
37     settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webView));
38     defaultUserAgent = g_strdup(webkit_web_settings_get_user_agent(settings));
39 
40     // test a custom UA string
41     userAgent = NULL;
42     g_object_set(G_OBJECT(settings), "user-agent", "testwebsettings/0.1", NULL);
43     g_object_get(G_OBJECT(settings),"user-agent", &userAgent, NULL);
44     g_assert_cmpstr(userAgent, ==, "testwebsettings/0.1");
45     g_free(userAgent);
46 
47     // setting it to NULL or an empty value should give us the default UA string
48     userAgent = NULL;
49     g_object_set(G_OBJECT(settings), "user-agent", NULL, NULL);
50     g_object_get(G_OBJECT(settings),"user-agent", &userAgent, NULL);
51     g_assert_cmpstr(userAgent, ==, defaultUserAgent);
52     g_free(userAgent);
53 
54     userAgent = NULL;
55     g_object_set(G_OBJECT(settings), "user-agent", "", NULL);
56     g_object_get(G_OBJECT(settings),"user-agent", &userAgent, NULL);
57     g_assert_cmpstr(userAgent, ==, defaultUserAgent);
58     g_free(userAgent);
59 
60     g_free(defaultUserAgent);
61     g_object_unref(webView);
62 }
63 
main(int argc,char ** argv)64 int main(int argc, char** argv)
65 {
66     g_thread_init(NULL);
67     gtk_test_init(&argc, &argv, NULL);
68 
69     g_test_bug_base("https://bugs.webkit.org/");
70     g_test_add_func("/webkit/websettings/user_agent", test_webkit_web_settings_user_agent);
71     return g_test_run ();
72 }
73 
74 #else
main(int argc,char ** argv)75 int main(int argc, char** argv)
76 {
77     g_critical("You will need at least glib-2.16.0 and gtk-2.14.0 to run the unit tests. Doing nothing now.");
78     return 0;
79 }
80 
81 #endif
82