1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*
* Copyright (C) 2011 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2,1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "TestMain.h"
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>
#include <wtf/gobject/GRefPtr.h>
static void testWebContextDefault(Test* test, gconstpointer)
{
// Check there's a single instance of the default web context.
g_assert(webkit_web_context_get_default() == webkit_web_context_get_default());
}
class PluginsTest: public Test {
public:
MAKE_GLIB_TEST_FIXTURE(PluginsTest);
PluginsTest()
: m_context(webkit_web_context_get_default())
, m_mainLoop(g_main_loop_new(0, TRUE))
, m_plugins(0)
{
webkit_web_context_set_additional_plugins_directory(m_context, WEBKIT_TEST_PLUGIN_DIR);
}
~PluginsTest()
{
g_main_loop_unref(m_mainLoop);
g_list_free_full(m_plugins, g_object_unref);
}
static void getPluginsAsyncReadyCallback(GObject*, GAsyncResult* result, PluginsTest* test)
{
test->m_plugins = webkit_web_context_get_plugins_finish(test->m_context, result, 0);
g_main_loop_quit(test->m_mainLoop);
}
GList* getPlugins()
{
g_list_free_full(m_plugins, g_object_unref);
webkit_web_context_get_plugins(m_context, 0, reinterpret_cast<GAsyncReadyCallback>(getPluginsAsyncReadyCallback), this);
g_main_loop_run(m_mainLoop);
return m_plugins;
}
WebKitWebContext* m_context;
GMainLoop* m_mainLoop;
GList* m_plugins;
};
static void testWebContextGetPlugins(PluginsTest* test, gconstpointer)
{
GList* plugins = test->getPlugins();
g_assert(plugins);
GRefPtr<WebKitPlugin> testPlugin;
for (GList* item = plugins; item; item = g_list_next(item)) {
WebKitPlugin* plugin = WEBKIT_PLUGIN(item->data);
test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(plugin));
if (!g_strcmp0(webkit_plugin_get_name(plugin), "WebKit Test PlugIn")) {
testPlugin = plugin;
break;
}
}
g_assert(WEBKIT_IS_PLUGIN(testPlugin.get()));
GOwnPtr<char> pluginPath(g_build_filename(WEBKIT_TEST_PLUGIN_DIR, "libtestnetscapeplugin.so", NULL));
g_assert_cmpstr(webkit_plugin_get_path(testPlugin.get()), ==, pluginPath.get());
g_assert_cmpstr(webkit_plugin_get_description(testPlugin.get()), ==, "Simple Netscape® plug-in that handles test content for WebKit");
GList* mimeInfoList = webkit_plugin_get_mime_info_list(testPlugin.get());
g_assert(mimeInfoList);
g_assert_cmpuint(g_list_length(mimeInfoList), ==, 2);
WebKitMimeInfo* mimeInfo = static_cast<WebKitMimeInfo*>(mimeInfoList->data);
g_assert_cmpstr(webkit_mime_info_get_mime_type(mimeInfo), ==, "image/png");
g_assert_cmpstr(webkit_mime_info_get_description(mimeInfo), ==, "png image");
const gchar* const* extensions = webkit_mime_info_get_extensions(mimeInfo);
g_assert(extensions);
g_assert_cmpstr(extensions[0], ==, "png");
mimeInfoList = g_list_next(mimeInfoList);
mimeInfo = static_cast<WebKitMimeInfo*>(mimeInfoList->data);
g_assert_cmpstr(webkit_mime_info_get_mime_type(mimeInfo), ==, "application/x-webkit-test-netscape");
g_assert_cmpstr(webkit_mime_info_get_description(mimeInfo), ==, "test netscape content");
extensions = webkit_mime_info_get_extensions(mimeInfo);
g_assert(extensions);
g_assert_cmpstr(extensions[0], ==, "testnetscape");
}
void beforeAll()
{
Test::add("WebKitWebContext", "default-context", testWebContextDefault);
PluginsTest::add("WebKitWebContext", "get-plugins", testWebContextGetPlugins);
}
void afterAll()
{
}
|