/* * 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 #include #include 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(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 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 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(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(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() { }