initial import
[vuplus_webkit] / Source / WebKit / gtk / tests / testwebplugindatabase.c
1 /*
2  * Copyright (C) 2010 Igalia S.L.
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 <glib.h>
22 #include <glib/gstdio.h>
23 #include <gtk/gtk.h>
24 #include <webkit/webkit.h>
25
26 #if GTK_CHECK_VERSION(2, 14, 0)
27
28 /* This function is not public, so we need an extern declaration */
29 extern void webkit_web_settings_add_extra_plugin_directory(WebKitWebView* view, const gchar* directory);
30
31 static void test_webkit_web_plugin_database_get_plugins()
32 {
33     WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new());
34     WebKitWebPluginDatabase* database;
35     GSList* pluginList, *p;
36     gboolean found = FALSE;
37     gboolean enabled = FALSE;
38
39     webkit_web_settings_add_extra_plugin_directory(view, TEST_PLUGIN_DIR);
40     g_object_ref_sink(G_OBJECT(view));
41
42     database = webkit_get_web_plugin_database();
43     pluginList = webkit_web_plugin_database_get_plugins(database);
44     for (p = pluginList; p; p = p->next) {
45         WebKitWebPlugin* plugin = (WebKitWebPlugin*)p->data;
46         if (!g_strcmp0(webkit_web_plugin_get_name(plugin), "WebKit Test PlugIn") &&
47             !g_strcmp0(webkit_web_plugin_get_description(plugin), "Simple Netscape plug-in that handles test content for WebKit")) {
48             found = TRUE;
49             enabled = webkit_web_plugin_get_enabled(plugin);
50             webkit_web_plugin_set_enabled(plugin, FALSE);
51         }
52     }
53     webkit_web_plugin_database_plugins_list_free(pluginList);
54     g_assert(found);
55     g_assert(enabled);
56
57     webkit_web_plugin_database_refresh(database);
58     pluginList = webkit_web_plugin_database_get_plugins(database);
59
60     for (p = pluginList; p; p = p->next) {
61         WebKitWebPlugin* plugin = (WebKitWebPlugin*)p->data;
62         if (!g_strcmp0(webkit_web_plugin_get_name(plugin), "WebKit Test PlugIn") &&
63             !g_strcmp0(webkit_web_plugin_get_description(plugin), "Simple Netscape plug-in that handles test content for WebKit"))
64             enabled = webkit_web_plugin_get_enabled(plugin);
65     }
66     webkit_web_plugin_database_plugins_list_free(pluginList);
67     g_assert(!enabled);
68
69     g_object_unref(view);
70 }
71
72 int main(int argc, char** argv)
73 {
74     g_thread_init(NULL);
75     gtk_test_init(&argc, &argv, NULL);
76
77     g_test_bug_base("https://bugs.webkit.org/");
78     g_test_add_func("/webkit/webplugindatabase/getplugins", test_webkit_web_plugin_database_get_plugins);
79     return g_test_run ();
80 }
81
82 #else
83 int main(int argc, char** argv)
84 {
85     g_critical("You will need at least gtk-2.14.0 to run the unit tests. Doing nothing now.");
86     return 0;
87 }
88
89 #endif