diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-18 14:03:11 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-18 14:03:11 +0200 |
commit | 8d473cf9743f1d30a16a27114e93bd5af5648d23 (patch) | |
tree | cdca40d0353886b3ca52f33a2d7b8f1c0011aafc /Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp | |
parent | 1b914638db989aaa98631a1c1e02c7b2d44805d8 (diff) | |
download | qtwebkit-8d473cf9743f1d30a16a27114e93bd5af5648d23.tar.gz |
Imported WebKit commit 1350e72f7345ced9da2bd9980deeeb5a8d62fab4 (http://svn.webkit.org/repository/webkit/trunk@117578)
Weekly snapshot
Diffstat (limited to 'Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp')
-rw-r--r-- | Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp index ad7ce5b8b..216a5c9f5 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp @@ -22,6 +22,7 @@ #include "TestMain.h" #include <gtk/gtk.h> #include <webkit2/webkit2.h> +#include <wtf/gobject/GRefPtr.h> static void testWebContextDefault(Test* test, gconstpointer) { @@ -29,9 +30,86 @@ static void testWebContextDefault(Test* test, gconstpointer) 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() |