2010-02-23 Arno Renevier <arno@renevier.net>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Feb 2010 22:43:23 +0000 (22:43 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Feb 2010 22:43:23 +0000 (22:43 +0000)
        Reviewed by Gustavo Noronha Silva.

        [Gtk]: testwebview does not work when called with absolute path
        https://bugs.webkit.org/show_bug.cgi?id=34940

        When testwebview is called as absolute path, chdir to executable
        directory before searching resource files.

        * GNUmakefile.am:

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

ChangeLog
GNUmakefile.am
WebKit/gtk/tests/test_utils.c [new file with mode: 0644]
WebKit/gtk/tests/test_utils.h [new file with mode: 0644]
WebKit/gtk/tests/testmimehandling.c
WebKit/gtk/tests/testwebview.c

index 2ede05a..65c71bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-02-23  Arno Renevier  <arno@renevier.net>
+
+        Reviewed by Gustavo Noronha Silva.
+
+        [Gtk]: testwebview does not work when called with absolute path
+        https://bugs.webkit.org/show_bug.cgi?id=34940
+
+        When testwebview is called as absolute path, chdir to executable
+        directory before searching resource files.
+
+        * GNUmakefile.am:
+
 2010-02-23  Leandro Pereira  <leandro@profusion.mobi>
 
         Reviewed by Gustavo Noronha Silva.
index 5f6af48..854a1b0 100644 (file)
@@ -596,7 +596,7 @@ 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_SOURCES = WebKit/gtk/tests/testmimehandling.c WebKit/gtk/tests/test_utils.c
 Programs_unittests_testmimehandling_CFLAGS = $(webkit_tests_cflags)
 Programs_unittests_testmimehandling_LDADD = $(webkit_tests_ldadd)
 Programs_unittests_testmimehandling_LDFLAGS = $(webkit_tests_ldflags)
@@ -654,7 +654,7 @@ Programs_unittests_testwebdatasource_SOURCES = WebKit/gtk/tests/testwebdatasourc
 Programs_unittests_testwebdatasource_CFLAGS = $(webkit_tests_cflags)
 Programs_unittests_testwebdatasource_LDADD = $(webkit_tests_ldadd)
 
-Programs_unittests_testwebview_SOURCES = WebKit/gtk/tests/testwebview.c
+Programs_unittests_testwebview_SOURCES = WebKit/gtk/tests/testwebview.c WebKit/gtk/tests/test_utils.c
 Programs_unittests_testwebview_CFLAGS = $(webkit_tests_cflags)
 Programs_unittests_testwebview_LDADD = $(webkit_tests_ldadd)
 Programs_unittests_testwebview_LDFLAGS = $(webkit_tests_ldflags)
diff --git a/WebKit/gtk/tests/test_utils.c b/WebKit/gtk/tests/test_utils.c
new file mode 100644 (file)
index 0000000..646fd25
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2010 Arno Renevier
+ *
+ * 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 "test_utils.h"
+
+#include <glib.h>
+#include <glib/gstdio.h>
+
+int testutils_relative_chdir(const gchar* target_filename, const gchar* executable_path)
+{
+    if (g_path_is_absolute(executable_path)) {
+        if (g_chdir(g_path_get_dirname(executable_path))) {
+            return -1;
+        }
+    }
+
+    while (!g_file_test(target_filename, G_FILE_TEST_EXISTS)) {
+        gchar *path_name;
+        if (g_chdir("..")) {
+            return -1;
+        }
+        g_assert(!g_str_equal((path_name = g_get_current_dir()), "/"));
+        g_free(path_name);
+    }
+
+    gchar* dirname = g_path_get_dirname(target_filename);
+    if (g_chdir(dirname)) {
+        g_free(dirname);
+        return -1;
+    }
+
+    g_free(dirname);
+    return 0;
+}
diff --git a/WebKit/gtk/tests/test_utils.h b/WebKit/gtk/tests/test_utils.h
new file mode 100644 (file)
index 0000000..e761f74
--- /dev/null
@@ -0,0 +1,3 @@
+#include <glib.h>
+
+int testutils_relative_chdir(const gchar*, const gchar*);
index e6e8d45..2ab0257 100644 (file)
@@ -18,6 +18,8 @@
  * Boston, MA 02110-1301, USA.
  */
 
+#include "test_utils.h"
+
 #include <glib.h>
 #include <glib/gstdio.h>
 #include <libsoup/soup.h>
@@ -182,16 +184,7 @@ int main(int argc, char** argv)
     gtk_test_init(&argc, &argv, NULL);
 
     /* Hopefully make test independent of the path it's called from. */
-    while (!g_file_test ("WebKit/gtk/tests/resources/test.html", G_FILE_TEST_EXISTS)) {
-        gchar *path_name;
-
-        g_chdir("..");
-
-        g_assert(!g_str_equal((path_name = g_get_current_dir()), "/"));
-        g_free(path_name);
-    }
-
-    g_chdir("WebKit/gtk/tests/resources/");
+    testutils_relative_chdir("WebKit/gtk/tests/resources/test.html", argv[0]);
 
     server = soup_server_new(SOUP_SERVER_PORT, 0, NULL);
     soup_server_run_async(server);
index 34b6867..ceac8a0 100644 (file)
@@ -18,6 +18,8 @@
  * Boston, MA 02110-1301, USA.
  */
 
+#include "test_utils.h"
+
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>
@@ -233,16 +235,7 @@ int main(int argc, char** argv)
     gtk_test_init(&argc, &argv, NULL);
 
     /* Hopefully make test independent of the path it's called from. */
-    while (!g_file_test ("WebKit/gtk/tests/resources/test.html", G_FILE_TEST_EXISTS)) {
-        gchar *path_name;
-
-        g_chdir("..");
-
-        g_assert(!g_str_equal((path_name = g_get_current_dir()), "/"));
-        g_free(path_name);
-    }
-
-    g_chdir("WebKit/gtk/tests/resources/");
+    testutils_relative_chdir("WebKit/gtk/tests/resources/test.html", argv[0]);
 
     server = soup_server_new(SOUP_SERVER_PORT, 0, NULL);
     soup_server_run_async(server);