Reviewed by Xan Lopez.
authorkov@webkit.org <kov@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Dec 2009 14:35:30 +0000 (14:35 +0000)
committerkov@webkit.org <kov@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Dec 2009 14:35:30 +0000 (14:35 +0000)
        Build the new API test.

        [GTK] REGRESSION: webkit thinks it can render PDFs
        https://bugs.webkit.org/show_bug.cgi?id=32183

        * GNUmakefile.am:

WebCore

        Reviewed by Xan Lopez.

        Turn the MediaPlayer supported types blacklist into a whitelist

        [GTK] REGRESSION: webkit thinks it can render PDFs
        https://bugs.webkit.org/show_bug.cgi?id=32183

        Covered by API test.

        * platform/graphics/gtk/MediaPlayerPrivateGStreamer.cpp:
        (WebCore::mimeTypeCache):

WebKit/gtk

        Reviewed by Xan Lopez.

        New test to make sure we do not regress this feature anymore. All
        test files were created by me.

        [GTK] REGRESSION: webkit thinks it can render PDFs
        https://bugs.webkit.org/show_bug.cgi?id=32183

        * tests/resources/test.html: Added.
        * tests/resources/test.ogg: Added.
        * tests/resources/test.pdf: Added.
        * tests/resources/test.txt: Added.
        * tests/testmimehandling.c: Added.
        (server_callback):
        (idle_quit_loop_cb):
        (mime_type_policy_decision_requested_cb):
        (test_mime_type):
        (test_mime_pdf):
        (test_mime_html):
        (test_mime_text):
        (test_mime_ogg):
        (main):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@51764 268f45cc-cd09-0410-ab3c-d52691b4dbfc

ChangeLog
GNUmakefile.am
WebCore/ChangeLog
WebCore/platform/graphics/gtk/MediaPlayerPrivateGStreamer.cpp
WebKit/gtk/ChangeLog
WebKit/gtk/tests/resources/test.html [new file with mode: 0644]
WebKit/gtk/tests/resources/test.ogg [new file with mode: 0644]
WebKit/gtk/tests/resources/test.pdf [new file with mode: 0644]
WebKit/gtk/tests/resources/test.txt [new file with mode: 0644]
WebKit/gtk/tests/testmimehandling.c [new file with mode: 0644]

index 1127f04..5cf6de8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-12-06  Gustavo Noronha Silva  <gns@gnome.org>
+
+        Reviewed by Xan Lopez.
+
+        Build the new API test.
+
+        [GTK] REGRESSION: webkit thinks it can render PDFs
+        https://bugs.webkit.org/show_bug.cgi?id=32183
+
+        * GNUmakefile.am:
+
 2009-12-05  Vincent Untz <vuntz@gnome.org>
 
         Reviewed by Gustavo Noronha.
index d8fa6ac..d5fc693 100644 (file)
@@ -582,6 +582,7 @@ webkit_tests_ldflags = \
 
 TEST_PROGS += Programs/unittests/testhttpbackend \
        Programs/unittests/testloading \
+       Programs/unittests/testmimehandling \
        Programs/unittests/testnetworkrequest \
        Programs/unittests/testnetworkresponse \
        Programs/unittests/testwebframe \
@@ -607,6 +608,11 @@ Programs_unittests_testloading_CFLAGS = $(webkit_tests_cflags)
 Programs_unittests_testloading_LDADD = $(webkit_tests_ldadd)
 Programs_unittests_testloading_LDFLAGS = $(webkit_tests_ldflags)
 
+Programs_unittests_testmimehandling_SOURCES = WebKit/gtk/tests/testmimehandling.c
+Programs_unittests_testmimehandling_CFLAGS = $(webkit_tests_cflags)
+Programs_unittests_testmimehandling_LDADD = $(webkit_tests_ldadd)
+Programs_unittests_testmimehandling_LDFLAGS = $(webkit_tests_ldflags)
+
 Programs_unittests_testnetworkrequest_SOURCES = WebKit/gtk/tests/testnetworkrequest.c
 Programs_unittests_testnetworkrequest_CFLAGS = $(webkit_tests_cflags)
 Programs_unittests_testnetworkrequest_LDADD = $(webkit_tests_ldadd)
index 3446641..5977881 100644 (file)
@@ -1,3 +1,17 @@
+2009-12-07  Gustavo Noronha Silva  <gns@gnome.org>
+
+        Reviewed by Xan Lopez.
+
+        Turn the MediaPlayer supported types blacklist into a whitelist
+
+        [GTK] REGRESSION: webkit thinks it can render PDFs
+        https://bugs.webkit.org/show_bug.cgi?id=32183
+
+        Covered by API test.
+
+        * platform/graphics/gtk/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::mimeTypeCache):
+
 2009-12-07  Joanmarie Diggs  <joanmarie.diggs@gmail.com>
 
         Reviewed by Xan Lopez.
index d30c942..195026d 100644 (file)
@@ -758,19 +758,16 @@ static HashSet<String> mimeTypeCache()
 
     if (!typeListInitialized) {
         // These subtypes are already beeing supported by WebKit itself
-        HashSet<String> ignoredApplicationSubtypes;
-        ignoredApplicationSubtypes.add(String("javascript"));
-        ignoredApplicationSubtypes.add(String("ecmascript"));
-        ignoredApplicationSubtypes.add(String("x-javascript"));
-        ignoredApplicationSubtypes.add(String("xml"));
-        ignoredApplicationSubtypes.add(String("xhtml+xml"));
-        ignoredApplicationSubtypes.add(String("rss+xml"));
-        ignoredApplicationSubtypes.add(String("atom+xml"));
-        ignoredApplicationSubtypes.add(String("x-ftp-directory"));
-        ignoredApplicationSubtypes.add(String("x-java-applet"));
-        ignoredApplicationSubtypes.add(String("x-java-bean"));
-        ignoredApplicationSubtypes.add(String("x-java-vm"));
-        ignoredApplicationSubtypes.add(String("x-shockwave-flash"));
+        HashSet<String> handledApplicationSubtypes;
+        handledApplicationSubtypes.add(String("x-id3v2"));
+        handledApplicationSubtypes.add(String("x-id3v1"));
+        handledApplicationSubtypes.add(String("x-apetag"));
+        handledApplicationSubtypes.add(String("ogg"));
+        handledApplicationSubtypes.add(String("x-3gp"));
+        handledApplicationSubtypes.add(String("vnd.rn-realmedia"));
+        handledApplicationSubtypes.add(String("x-pn-realaudio"));
+        handledApplicationSubtypes.add(String("sdp"));
+        handledApplicationSubtypes.add(String("smil"));
 
         GList* factories = gst_type_find_factory_get_list();
         for (GList* iterator = factories; iterator; iterator = iterator->next) {
@@ -843,7 +840,7 @@ static HashSet<String> mimeTypeCache()
                     if (g_str_equal(mimetype[0], "audio")
                         || g_str_equal(mimetype[0], "video")
                         || (g_str_equal(mimetype[0], "application")
-                            && !ignoredApplicationSubtypes.contains(String(mimetype[1]))))
+                            && handledApplicationSubtypes.contains(String(mimetype[1]))))
                         cache.add(String(name));
 
                     g_strfreev(mimetype);
index 77cde53..68340d0 100644 (file)
@@ -1,3 +1,28 @@
+2009-12-06  Gustavo Noronha Silva  <gns@gnome.org>
+
+        Reviewed by Xan Lopez.
+
+        New test to make sure we do not regress this feature anymore. All
+        test files were created by me.
+
+        [GTK] REGRESSION: webkit thinks it can render PDFs
+        https://bugs.webkit.org/show_bug.cgi?id=32183
+
+        * tests/resources/test.html: Added.
+        * tests/resources/test.ogg: Added.
+        * tests/resources/test.pdf: Added.
+        * tests/resources/test.txt: Added.
+        * tests/testmimehandling.c: Added.
+        (server_callback):
+        (idle_quit_loop_cb):
+        (mime_type_policy_decision_requested_cb):
+        (test_mime_type):
+        (test_mime_pdf):
+        (test_mime_html):
+        (test_mime_text):
+        (test_mime_ogg):
+        (main):
+
 2009-12-05  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
 
         Reviewed by Xan Lopez.
diff --git a/WebKit/gtk/tests/resources/test.html b/WebKit/gtk/tests/resources/test.html
new file mode 100644 (file)
index 0000000..98f7d4f
--- /dev/null
@@ -0,0 +1,6 @@
+<html>
+<head><title>test</title></head>
+<body>test</body>
+</html>></head>
+<body>test</body>
+</html>
diff --git a/WebKit/gtk/tests/resources/test.ogg b/WebKit/gtk/tests/resources/test.ogg
new file mode 100644 (file)
index 0000000..7f3a3b9
Binary files /dev/null and b/WebKit/gtk/tests/resources/test.ogg differ
diff --git a/WebKit/gtk/tests/resources/test.pdf b/WebKit/gtk/tests/resources/test.pdf
new file mode 100644 (file)
index 0000000..2424c19
Binary files /dev/null and b/WebKit/gtk/tests/resources/test.pdf differ
diff --git a/WebKit/gtk/tests/resources/test.txt b/WebKit/gtk/tests/resources/test.txt
new file mode 100644 (file)
index 0000000..9daeafb
--- /dev/null
@@ -0,0 +1 @@
+test
diff --git a/WebKit/gtk/tests/testmimehandling.c b/WebKit/gtk/tests/testmimehandling.c
new file mode 100644 (file)
index 0000000..3613162
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2009 Jan Michael Alonzo
+ * Copyright (C) 2009 Gustavo Noronha Silva
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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 <glib.h>
+#include <glib/gstdio.h>
+#include <libsoup/soup.h>
+#include <string.h>
+#include <webkit/webkit.h>
+
+#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0)
+
+GMainLoop* loop;
+SoupSession *session;
+char* base_uri;
+
+/* For real request testing */
+static void
+server_callback(SoupServer *server, SoupMessage *msg,
+                 const char *path, GHashTable *query,
+                 SoupClientContext *context, gpointer data)
+{
+    if (msg->method != SOUP_METHOD_GET) {
+        soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
+        return;
+    }
+
+    soup_message_set_status(msg, SOUP_STATUS_OK);
+
+    /* PDF */
+    if (g_str_equal(path, "/pdf")) {
+        char* contents;
+        gsize length;
+        GError* error = NULL;
+
+        g_file_get_contents("test.pdf", &contents, &length, &error);
+        g_assert(!error);
+
+        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
+    } else if (g_str_equal(path, "/html")) {
+        char* contents;
+        gsize length;
+        GError* error = NULL;
+
+        g_file_get_contents("test.html", &contents, &length, &error);
+        g_assert(!error);
+
+        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
+    } else if (g_str_equal(path, "/text")) {
+        char* contents;
+        gsize length;
+        GError* error = NULL;
+
+        g_file_get_contents("test.txt", &contents, &length, &error);
+        g_assert(!error);
+
+        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
+    } else if (g_str_equal(path, "/ogg")) {
+        char* contents;
+        gsize length;
+        GError* error = NULL;
+
+        g_file_get_contents("test.ogg", &contents, &length, &error);
+        g_assert(!error);
+
+        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
+    }
+
+    soup_message_body_complete(msg->response_body);
+}
+
+static gboolean idle_quit_loop_cb(gpointer data)
+{
+    g_main_loop_quit(loop);
+    return FALSE;
+}
+
+static gboolean mime_type_policy_decision_requested_cb(WebKitWebView* view, WebKitWebFrame* frame,
+                                                       WebKitNetworkRequest* request, const char* mime_type,
+                                                       WebKitWebPolicyDecision* decision, gpointer data)
+{
+    char* type = (char*)data;
+
+    if (g_str_equal(type, "pdf")) {
+        g_assert_cmpstr(mime_type, ==, "application/pdf");
+        g_assert(!webkit_web_view_can_show_mime_type(view, mime_type));
+    } else if (g_str_equal(type, "html")) {
+        g_assert_cmpstr(mime_type, ==, "text/html");
+        g_assert(webkit_web_view_can_show_mime_type(view, mime_type));
+    } else if (g_str_equal(type, "text")) {
+        g_assert_cmpstr(mime_type, ==, "text/plain");
+        g_assert(webkit_web_view_can_show_mime_type(view, mime_type));
+    } else if (g_str_equal(type, "ogg")) {
+        g_assert_cmpstr(mime_type, ==, "audio/ogg");
+        g_assert(webkit_web_view_can_show_mime_type(view, mime_type));
+    }
+
+    g_free(type);
+
+    return FALSE;
+}
+
+static void test_mime_type(const char* name)
+{
+    WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new());
+    g_object_ref_sink(G_OBJECT(view));
+
+    loop = g_main_loop_new(NULL, TRUE);
+
+    g_object_connect(G_OBJECT(view),
+                     "signal::load-finished", idle_quit_loop_cb, NULL,
+                     "signal::mime-type-policy-decision-requested", mime_type_policy_decision_requested_cb, g_strdup(name),
+                     NULL);
+
+    char* effective_uri = g_strdup_printf("%s%s", base_uri, name);
+    webkit_web_view_load_uri(view, effective_uri);
+    g_free(effective_uri);
+
+    g_main_loop_run(loop);
+
+    g_object_unref(view);
+}
+
+static void test_mime_pdf()
+{
+    test_mime_type("pdf");
+}
+
+static void test_mime_html()
+{
+    test_mime_type("html");
+}
+
+static void test_mime_text()
+{
+    test_mime_type("text");
+}
+
+static void test_mime_ogg()
+{
+    test_mime_type("pdf");
+}
+
+int main(int argc, char** argv)
+{
+    SoupServer* server;
+    SoupURI* soup_uri;
+    char* test_dir;
+    char* resources_dir;
+
+    g_thread_init(NULL);
+    gtk_test_init(&argc, &argv, NULL);
+
+    /* Hopefully make test independent of the path it's called from. */
+    test_dir = g_path_get_dirname(argv[0]);
+    resources_dir = g_build_path(G_DIR_SEPARATOR_S, test_dir,
+                                 "..", "..", "..", "..",
+                                 "WebKit", "gtk", "tests", "resources",
+                                 NULL);
+    g_free(test_dir);
+
+    g_chdir(resources_dir);
+    g_free(resources_dir);
+
+    server = soup_server_new(SOUP_SERVER_PORT, 0, NULL);
+    soup_server_run_async(server);
+
+    soup_server_add_handler(server, NULL, server_callback, NULL, NULL);
+
+    soup_uri = soup_uri_new("http://127.0.0.1/");
+    soup_uri_set_port(soup_uri, soup_server_get_port(server));
+
+    base_uri = soup_uri_to_string(soup_uri, FALSE);
+    soup_uri_free(soup_uri);
+
+    g_test_bug_base("https://bugs.webkit.org/");
+    g_test_add_func("/webkit/mime/PDF", test_mime_pdf);
+    g_test_add_func("/webkit/mime/HTML", test_mime_html);
+    g_test_add_func("/webkit/mime/TEXT", test_mime_text);
+    g_test_add_func("/webkit/mime/OGG", test_mime_ogg);
+
+    return g_test_run();
+}
+
+#else
+int main(int argc, char** argv)
+{
+    g_critical("You will need at least glib-2.16.0 and gtk-2.14.0 to run the unit tests. Doing nothing now.");
+    return 0;
+}
+
+#endif