summaryrefslogtreecommitdiffstats
path: root/WebKit/gtk/tests
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/gtk/tests')
-rw-r--r--WebKit/gtk/tests/test_utils.c50
-rw-r--r--WebKit/gtk/tests/test_utils.h3
-rw-r--r--WebKit/gtk/tests/testatk.c31
-rw-r--r--WebKit/gtk/tests/testatkroles.c383
-rw-r--r--WebKit/gtk/tests/testglobals.c66
-rw-r--r--WebKit/gtk/tests/testkeyevents.c290
-rw-r--r--WebKit/gtk/tests/testmimehandling.c13
-rw-r--r--WebKit/gtk/tests/testwebbackforwardlist.c49
-rw-r--r--WebKit/gtk/tests/testwebview.c132
9 files changed, 957 insertions, 60 deletions
diff --git a/WebKit/gtk/tests/test_utils.c b/WebKit/gtk/tests/test_utils.c
new file mode 100644
index 0000000..646fd25
--- /dev/null
+++ b/WebKit/gtk/tests/test_utils.c
@@ -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
index 0000000..e761f74
--- /dev/null
+++ b/WebKit/gtk/tests/test_utils.h
@@ -0,0 +1,3 @@
+#include <glib.h>
+
+int testutils_relative_chdir(const gchar*, const gchar*);
diff --git a/WebKit/gtk/tests/testatk.c b/WebKit/gtk/tests/testatk.c
index 7db274a..1f1ab0c 100644
--- a/WebKit/gtk/tests/testatk.c
+++ b/WebKit/gtk/tests/testatk.c
@@ -38,6 +38,8 @@ static const char* contentsInParagraphAndBodySimple = "<html><body><p>This is a
static const char* contentsInParagraphAndBodyModerate = "<html><body><p>This is a test.</p>Hello world.<br /><font color='#00cc00'>This sentence is green.</font><br />This one is not.</body></html>";
+static const char* contentsInTable = "<html><body><table><tr><td>foo</td><td>bar</td></tr></table></body></html>";
+
static gboolean bail_out(GMainLoop* loop)
{
if (g_main_loop_is_running(loop))
@@ -450,6 +452,34 @@ static void testWebkitAtkGetTextInParagraphAndBodyModerate(void)
g_object_unref(webView);
}
+static void testWebkitAtkGetTextInTable(void)
+{
+ WebKitWebView* webView;
+ AtkObject* obj;
+ GMainLoop* loop;
+
+ webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
+ g_object_ref_sink(webView);
+ GtkAllocation alloc = { 0, 0, 800, 600 };
+ gtk_widget_size_allocate(GTK_WIDGET(webView), &alloc);
+ webkit_web_view_load_string(webView, contentsInTable, NULL, NULL, NULL);
+ loop = g_main_loop_new(NULL, TRUE);
+
+ g_timeout_add(100, (GSourceFunc)bail_out, loop);
+ g_main_loop_run(loop);
+
+ obj = gtk_widget_get_accessible(GTK_WIDGET(webView));
+ g_assert(obj);
+ obj = atk_object_ref_accessible_child(obj, 0);
+ g_assert(obj);
+
+ /* Tables should not implement AtkText */
+ g_assert(G_TYPE_INSTANCE_GET_INTERFACE(obj, ATK_TYPE_TEXT, AtkTextIface) == NULL);
+
+ g_object_unref(obj);
+ g_object_unref(webView);
+}
+
int main(int argc, char** argv)
{
g_thread_init(NULL);
@@ -463,6 +493,7 @@ int main(int argc, char** argv)
g_test_add_func("/webkit/atk/get_text_at_offset_text_input", test_webkit_atk_get_text_at_offset_text_input);
g_test_add_func("/webkit/atk/getTextInParagraphAndBodySimple", testWebkitAtkGetTextInParagraphAndBodySimple);
g_test_add_func("/webkit/atk/getTextInParagraphAndBodyModerate", testWebkitAtkGetTextInParagraphAndBodyModerate);
+ g_test_add_func("/webkit/atk/getTextInTable", testWebkitAtkGetTextInTable);
return g_test_run ();
}
diff --git a/WebKit/gtk/tests/testatkroles.c b/WebKit/gtk/tests/testatkroles.c
new file mode 100644
index 0000000..d3ade6e
--- /dev/null
+++ b/WebKit/gtk/tests/testatkroles.c
@@ -0,0 +1,383 @@
+/*
+ * Copyright © 2010 Joanmarie Diggs
+ * Copyright © 2010 Igalia S.L.
+ *
+ * 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 <gtk/gtk.h>
+#include <webkit/webkit.h>
+
+#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0)
+
+/* Non form roles */
+#define HTML_DOCUMENT_FRAME "<html><body>This is a test.</body></html>"
+#define HTML_HEADING "<html><body><h1>1</h1><h2>2</h2><h3>3</h3><h4>4</h4><h5>5</h5><h6>6</h6></body></html>"
+#define HTML_IMAGE "<html><body><img src='foobar.png' alt='This is a test.'/></body></html>"
+#define HTML_LINK_TEXT "<html><body><a href='foobar.html'>This is a test.</a></body></html>"
+#define HTML_LIST "<html><body><ul><li>1</li><li>2</li></ul><ol><li>1</li><li>2</li></ol></body></html>"
+#define HTML_PARAGRAPH "<html><body><p>This is a test.</p></body></html>"
+#define HTML_SECTION "<html><body><div>This is a test.</div></body></html>"
+#define HTML_TABLE "<html><body><table border='1'><tr><td>This is</td><td>a test.</td></tr></table></body></html>"
+/* Form roles */
+#define HTML_FORM "<html><body><form>This is a test.</form></body></html>"
+#define HTML_CHECK_BOX "<html><body><input type='checkbox' />This is a test.</body></html>"
+#define HTML_LABELED_ENTRY "<html><body><label for='foo'>Name:</label><input type='text' id='foo' /></body></html>"
+#define HTML_LISTBOX "<html><body><select size='3'><option>one</option><option>two</option><option>three</option></select></body></html>"
+#define HTML_PASSWORD_TEXT "<html><body><input type='password' /></body></html>"
+#define HTML_PUSH_BUTTON "<html><body><input type='submit' value='ok' />This is a test.</body></html>"
+#define HTML_RADIO_BUTTON "<html><body><input type='radio' />This is a test.</body></html>"
+
+typedef struct {
+ AtkObject* documentFrame;
+ AtkObject* obj;
+ AtkRole role;
+ GtkWidget* webView;
+ GtkAllocation alloc;
+ GMainLoop* loop;
+} AtkRolesFixture;
+
+static gboolean finish_loading(AtkRolesFixture* fixture)
+{
+ if (g_main_loop_is_running(fixture->loop))
+ g_main_loop_quit(fixture->loop);
+
+ fixture->documentFrame = gtk_widget_get_accessible(fixture->webView);
+ g_assert(fixture->documentFrame);
+
+ return FALSE;
+}
+
+static void atk_roles_fixture_setup(AtkRolesFixture* fixture, gconstpointer data)
+{
+ fixture->loop = g_main_loop_new(NULL, TRUE);
+ fixture->alloc = (GtkAllocation) { 0, 0, 800, 600 };
+ fixture->webView = webkit_web_view_new();
+ g_object_ref_sink(fixture->webView);
+
+ gtk_widget_size_allocate(fixture->webView, &fixture->alloc);
+
+ if (data != NULL)
+ webkit_web_view_load_string(WEBKIT_WEB_VIEW (fixture->webView), (const char*) data, NULL, NULL, NULL);
+
+ g_idle_add((GSourceFunc) finish_loading, fixture);
+ g_main_loop_run(fixture->loop);
+}
+
+static void atk_roles_fixture_teardown(AtkRolesFixture* fixture, gconstpointer data)
+{
+ g_object_unref(fixture->webView);
+ g_main_loop_unref(fixture->loop);
+}
+
+static void get_child_and_test_role(AtkObject* obj, gint pos, AtkRole role)
+{
+ AtkObject* child;
+ AtkRole child_role;
+
+ child = atk_object_ref_accessible_child(obj, pos);
+ g_assert(child);
+ child_role = atk_object_get_role(child);
+ g_assert(child_role == role);
+
+ g_object_unref(child);
+}
+
+static void test_webkit_atk_get_role_document_frame(AtkRolesFixture* fixture, gconstpointer data)
+{
+ fixture->role = atk_object_get_role(fixture->documentFrame);
+ g_assert(fixture->role == ATK_ROLE_DOCUMENT_FRAME);
+}
+
+static void test_webkit_atk_get_role_heading(AtkRolesFixture* fixture, gconstpointer data)
+{
+ get_child_and_test_role(fixture->documentFrame, 0, ATK_ROLE_HEADING);
+ get_child_and_test_role(fixture->documentFrame, 1, ATK_ROLE_HEADING);
+ get_child_and_test_role(fixture->documentFrame, 2, ATK_ROLE_HEADING);
+ get_child_and_test_role(fixture->documentFrame, 3, ATK_ROLE_HEADING);
+ get_child_and_test_role(fixture->documentFrame, 4, ATK_ROLE_HEADING);
+ get_child_and_test_role(fixture->documentFrame, 5, ATK_ROLE_HEADING);
+}
+
+static void test_webkit_atk_get_role_image(AtkRolesFixture* fixture, gconstpointer data)
+{
+ // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
+ fixture->obj = atk_object_ref_accessible_child(fixture->documentFrame, 0);
+ g_assert(fixture->obj);
+
+ get_child_and_test_role(fixture->obj, 0, ATK_ROLE_IMAGE);
+
+ g_object_unref(fixture->obj);
+}
+
+static void test_webkit_atk_get_role_link(AtkRolesFixture* fixture, gconstpointer data)
+{
+ // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
+ fixture->obj = atk_object_ref_accessible_child(fixture->documentFrame, 0);
+ g_assert(fixture->obj);
+
+ get_child_and_test_role(fixture->obj, 0, ATK_ROLE_LINK);
+
+ g_object_unref(fixture->obj);
+}
+
+static void test_webkit_atk_get_role_list_and_item(AtkRolesFixture* fixture, gconstpointer data)
+{
+ AtkObject* listObj;
+
+ listObj = atk_object_ref_accessible_child(fixture->documentFrame, 0);
+ g_assert(listObj);
+ fixture->role = atk_object_get_role(listObj);
+ g_assert(fixture->role == ATK_ROLE_LIST);
+
+ get_child_and_test_role(listObj, 0, ATK_ROLE_LIST_ITEM);
+ get_child_and_test_role(listObj, 1, ATK_ROLE_LIST_ITEM);
+ g_object_unref(listObj);
+
+ listObj = atk_object_ref_accessible_child(fixture->documentFrame, 1);
+ g_assert(listObj);
+ fixture->role = atk_object_get_role(listObj);
+ g_assert(fixture->role == ATK_ROLE_LIST);
+
+ get_child_and_test_role(listObj, 0, ATK_ROLE_LIST_ITEM);
+ get_child_and_test_role(listObj, 1, ATK_ROLE_LIST_ITEM);
+ g_object_unref(listObj);
+}
+
+static void test_webkit_atk_get_role_paragraph(AtkRolesFixture* fixture, gconstpointer data)
+{
+ get_child_and_test_role(fixture->documentFrame, 0, ATK_ROLE_PARAGRAPH);
+}
+
+static void test_webkit_atk_get_role_section(AtkRolesFixture* fixture, gconstpointer data)
+{
+ get_child_and_test_role(fixture->documentFrame, 0, ATK_ROLE_SECTION);
+}
+
+// Does not yet test table cells because of bug 30895.
+static void test_webkit_atk_get_role_table(AtkRolesFixture* fixture, gconstpointer data)
+{
+ get_child_and_test_role(fixture->documentFrame, 0, ATK_ROLE_TABLE);
+}
+
+/* Form roles */
+static void test_webkit_atk_get_role_form(AtkRolesFixture *fixture, gconstpointer data)
+{
+ get_child_and_test_role(fixture->documentFrame, 0, ATK_ROLE_FORM);
+}
+
+static void test_webkit_atk_get_role_check_box(AtkRolesFixture* fixture, gconstpointer data)
+{
+ // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
+ fixture->obj = atk_object_ref_accessible_child(fixture->documentFrame, 0);
+ g_assert(fixture->obj);
+
+ get_child_and_test_role(fixture->obj, 0, ATK_ROLE_CHECK_BOX);
+
+ g_object_unref(fixture->obj);
+}
+
+static void test_webkit_atk_get_role_entry(AtkRolesFixture* fixture, gconstpointer data)
+{
+ // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
+ fixture->obj = atk_object_ref_accessible_child(fixture->documentFrame, 0);
+ g_assert(fixture->obj);
+
+ get_child_and_test_role(fixture->obj, 1, ATK_ROLE_ENTRY);
+
+ g_object_unref(fixture->obj);
+}
+
+static void test_webkit_atk_get_role_label(AtkRolesFixture* fixture, gconstpointer data)
+{
+ // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
+ fixture->obj = atk_object_ref_accessible_child(fixture->documentFrame, 0);
+ g_assert(fixture->obj);
+
+ get_child_and_test_role(fixture->obj, 0, ATK_ROLE_LABEL);
+
+ g_object_unref(fixture->obj);
+}
+
+static void test_webkit_atk_get_role_listbox(AtkRolesFixture* fixture, gconstpointer data)
+{
+ AtkObject* listboxObj;
+ // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
+ fixture->obj = atk_object_ref_accessible_child(fixture->documentFrame, 0);
+ g_assert(fixture->obj);
+
+ listboxObj = atk_object_ref_accessible_child(fixture->obj, 0);
+ g_assert(listboxObj);
+ fixture->role = atk_object_get_role(listboxObj);
+ g_assert(fixture->role == ATK_ROLE_LIST);
+
+ get_child_and_test_role(listboxObj, 0, ATK_ROLE_LIST_ITEM);
+ get_child_and_test_role(listboxObj, 1, ATK_ROLE_LIST_ITEM);
+ get_child_and_test_role(listboxObj, 2, ATK_ROLE_LIST_ITEM);
+
+ g_object_unref(fixture->obj);
+ g_object_unref(listboxObj);
+}
+
+static void test_webkit_atk_get_role_password_text(AtkRolesFixture* fixture, gconstpointer data)
+{
+ // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
+ fixture->obj = atk_object_ref_accessible_child(fixture->documentFrame, 0);
+ g_assert(fixture->obj);
+
+ get_child_and_test_role(fixture->obj, 0, ATK_ROLE_PASSWORD_TEXT);
+
+ g_object_unref(fixture->obj);
+}
+
+static void test_webkit_atk_get_role_push_button(AtkRolesFixture* fixture, gconstpointer data)
+{
+ // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
+ fixture->obj = atk_object_ref_accessible_child(fixture->documentFrame, 0);
+ g_assert(fixture->obj);
+
+ get_child_and_test_role(fixture->obj, 0, ATK_ROLE_PUSH_BUTTON);
+
+ g_object_unref(fixture->obj);
+}
+
+static void test_webkit_atk_get_role_radio_button(AtkRolesFixture* fixture, gconstpointer data)
+{
+ // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
+ fixture->obj = atk_object_ref_accessible_child(fixture->documentFrame, 0);
+ g_assert(fixture->obj);
+
+ get_child_and_test_role(fixture->obj, 0, ATK_ROLE_RADIO_BUTTON);
+
+ g_object_unref(fixture->obj);
+}
+
+int main(int argc, char** argv)
+{
+ g_thread_init(NULL);
+ gtk_test_init(&argc, &argv, NULL);
+
+ g_test_bug_base("https://bugs.webkit.org/");
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_document_frame",
+ AtkRolesFixture, HTML_DOCUMENT_FRAME,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_document_frame,
+ atk_roles_fixture_teardown);
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_heading",
+ AtkRolesFixture, HTML_HEADING,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_heading,
+ atk_roles_fixture_teardown);
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_image",
+ AtkRolesFixture, HTML_IMAGE,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_image,
+ atk_roles_fixture_teardown);
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_link",
+ AtkRolesFixture, HTML_LINK_TEXT,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_link,
+ atk_roles_fixture_teardown);
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_list_and_item",
+ AtkRolesFixture, HTML_LIST,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_list_and_item,
+ atk_roles_fixture_teardown);
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_paragraph",
+ AtkRolesFixture, HTML_PARAGRAPH,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_paragraph,
+ atk_roles_fixture_teardown);
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_section",
+ AtkRolesFixture, HTML_SECTION,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_section,
+ atk_roles_fixture_teardown);
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_table",
+ AtkRolesFixture, HTML_TABLE,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_table,
+ atk_roles_fixture_teardown);
+
+ /* Form roles */
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_form",
+ AtkRolesFixture, HTML_FORM,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_form,
+ atk_roles_fixture_teardown);
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_check_box",
+ AtkRolesFixture, HTML_CHECK_BOX,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_check_box,
+ atk_roles_fixture_teardown);
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_entry",
+ AtkRolesFixture, HTML_LABELED_ENTRY,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_entry,
+ atk_roles_fixture_teardown);
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_label",
+ AtkRolesFixture, HTML_LABELED_ENTRY,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_label,
+ atk_roles_fixture_teardown);
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_listbox",
+ AtkRolesFixture, HTML_LISTBOX,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_listbox,
+ atk_roles_fixture_teardown);
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_password_text",
+ AtkRolesFixture, HTML_PASSWORD_TEXT,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_password_text,
+ atk_roles_fixture_teardown);
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_push_button",
+ AtkRolesFixture, HTML_PUSH_BUTTON,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_push_button,
+ atk_roles_fixture_teardown);
+
+ g_test_add("/webkit/atk/test_webkit_atk_get_role_radio_button",
+ AtkRolesFixture, HTML_RADIO_BUTTON,
+ atk_roles_fixture_setup,
+ test_webkit_atk_get_role_radio_button,
+ atk_roles_fixture_teardown);
+
+ 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
diff --git a/WebKit/gtk/tests/testglobals.c b/WebKit/gtk/tests/testglobals.c
new file mode 100644
index 0000000..e53edf4
--- /dev/null
+++ b/WebKit/gtk/tests/testglobals.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2010 Collabora Ltd.
+ *
+ * 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 <gtk/gtk.h>
+#include <libsoup/soup.h>
+#include <webkit/webkit.h>
+
+#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0)
+
+// Make sure the session is initialized properly when webkit_get_default_session() is called.
+static void test_globals_default_session()
+{
+ g_test_bug("36754");
+
+ SoupSession* session = webkit_get_default_session();
+ soup_session_remove_feature_by_type(session, WEBKIT_TYPE_SOUP_AUTH_DIALOG);
+
+ // This makes sure our initialization ran.
+ g_assert(soup_session_get_feature(session, SOUP_TYPE_CONTENT_DECODER) != NULL);
+
+ // Creating a WebView should make sure the session is
+ // initialized, and not mess with our changes.
+ WebKitWebView* web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
+ g_object_ref_sink(web_view);
+ g_object_unref(web_view);
+
+ // These makes sure our modification was kept.
+ g_assert(soup_session_get_feature(session, SOUP_TYPE_CONTENT_DECODER) != NULL);
+ g_assert(soup_session_get_feature(session, WEBKIT_TYPE_SOUP_AUTH_DIALOG) == NULL);
+}
+
+int main(int argc, char** argv)
+{
+ g_thread_init(NULL);
+ gtk_test_init(&argc, &argv, NULL);
+
+ g_test_bug_base("https://bugs.webkit.org/");
+ g_test_add_func("/webkit/globals/default_session",
+ test_globals_default_session);
+ 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
diff --git a/WebKit/gtk/tests/testkeyevents.c b/WebKit/gtk/tests/testkeyevents.c
index ee7728c..b41a032 100644
--- a/WebKit/gtk/tests/testkeyevents.c
+++ b/WebKit/gtk/tests/testkeyevents.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 Martin Robinson
+ * Copyright (C) 2009, 2010 Martin Robinson <mrobinson@webkit.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -22,12 +22,16 @@
#include <string.h>
#include <glib/gstdio.h>
#include <webkit/webkit.h>
+#include <JavaScriptCore/JSStringRef.h>
+#include <JavaScriptCore/JSContextRef.h>
+
#if GTK_CHECK_VERSION(2, 14, 0)
typedef struct {
- char* page;
- gboolean shouldBeHandled;
+ char* page;
+ char* text;
+ gboolean shouldBeHandled;
} TestInfo;
typedef struct {
@@ -45,6 +49,7 @@ test_info_new(const char* page, gboolean shouldBeHandled)
info = g_slice_new(TestInfo);
info->page = g_strdup(page);
info->shouldBeHandled = shouldBeHandled;
+ info->text = 0;
return info;
}
@@ -53,6 +58,7 @@ void
test_info_destroy(TestInfo* info)
{
g_free(info->page);
+ g_free(info->text);
g_slice_free(TestInfo, info);
}
@@ -82,7 +88,6 @@ static gboolean key_press_event_cb(WebKitWebView* webView, GdkEvent* event, gpoi
return FALSE;
}
-
static gboolean key_release_event_cb(WebKitWebView* webView, GdkEvent* event, gpointer data)
{
// WebCore never seems to mark keyup events as handled.
@@ -95,13 +100,18 @@ static gboolean key_release_event_cb(WebKitWebView* webView, GdkEvent* event, gp
return FALSE;
}
-static void load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
+static void test_keypress_events_load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
{
KeyEventFixture* fixture = (KeyEventFixture*)data;
WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
if (status == WEBKIT_LOAD_FINISHED) {
- gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
- gdk_unicode_to_keyval('a'), 0);
+ g_signal_connect(fixture->webView, "key-press-event",
+ G_CALLBACK(key_press_event_cb), fixture);
+ g_signal_connect(fixture->webView, "key-release-event",
+ G_CALLBACK(key_release_event_cb), fixture);
+ if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
+ gdk_unicode_to_keyval('a'), 0))
+ g_assert_not_reached();
}
}
@@ -110,25 +120,14 @@ gboolean map_event_cb(GtkWidget *widget, GdkEvent* event, gpointer data)
{
gtk_widget_grab_focus(widget);
KeyEventFixture* fixture = (KeyEventFixture*)data;
-
- g_signal_connect(fixture->webView, "key-press-event",
- G_CALLBACK(key_press_event_cb), fixture);
- g_signal_connect(fixture->webView, "key-release-event",
- G_CALLBACK(key_release_event_cb), fixture);
-
- g_signal_connect(fixture->webView, "notify::load-status",
- G_CALLBACK(load_status_cb), fixture);
-
webkit_web_view_load_string(fixture->webView, fixture->info->page,
"text/html", "utf-8", "file://");
-
return FALSE;
}
-static void test_keypress(KeyEventFixture* fixture, gconstpointer data)
+static void setup_keyevent_test(KeyEventFixture* fixture, gconstpointer data, GCallback load_event_callback)
{
fixture->info = (TestInfo*)data;
-
g_signal_connect(fixture->window, "map-event",
G_CALLBACK(map_event_cb), fixture);
@@ -136,10 +135,172 @@ static void test_keypress(KeyEventFixture* fixture, gconstpointer data)
gtk_widget_show(GTK_WIDGET(fixture->webView));
gtk_window_present(GTK_WINDOW(fixture->window));
+ g_signal_connect(fixture->webView, "notify::load-status",
+ load_event_callback, fixture);
+
g_main_loop_run(fixture->loop);
+}
+
+static void test_keypress_events(KeyEventFixture* fixture, gconstpointer data)
+{
+ setup_keyevent_test(fixture, data, G_CALLBACK(test_keypress_events_load_status_cb));
+}
+
+static gboolean element_text_equal_to(JSContextRef context, const gchar* text)
+{
+ JSStringRef scriptString = JSStringCreateWithUTF8CString(
+ "window.document.getElementById(\"in\").value;");
+ JSValueRef value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0);
+ JSStringRelease(scriptString);
+
+ // If the value isn't a string, the element is probably a div
+ // so grab the innerText instead.
+ if (!JSValueIsString(context, value)) {
+ JSStringRef scriptString = JSStringCreateWithUTF8CString(
+ "window.document.getElementById(\"in\").innerText;");
+ value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0);
+ JSStringRelease(scriptString);
+ }
+
+ g_assert(JSValueIsString(context, value));
+ JSStringRef inputString = JSValueToStringCopy(context, value, 0);
+ g_assert(inputString);
+
+ gint size = JSStringGetMaximumUTF8CStringSize(inputString);
+ gchar* cString = g_malloc(size);
+ JSStringGetUTF8CString(inputString, cString, size);
+ JSStringRelease(inputString);
+
+ gboolean result = g_utf8_collate(cString, text) == 0;
+ g_free(cString);
+ return result;
+}
+
+static void test_ime_load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
+{
+ KeyEventFixture* fixture = (KeyEventFixture*)data;
+ WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
+ if (status != WEBKIT_LOAD_FINISHED)
+ return;
+
+ JSGlobalContextRef context = webkit_web_frame_get_global_context(
+ webkit_web_view_get_main_frame(webView));
+ g_assert(context);
+
+ GtkIMContext* imContext = 0;
+ g_object_get(webView, "im-context", &imContext, NULL);
+ g_assert(imContext);
+
+ // Test that commits that happen outside of key events
+ // change the text field immediately. This closely replicates
+ // the behavior of SCIM.
+ g_assert(element_text_equal_to(context, ""));
+ g_signal_emit_by_name(imContext, "commit", "a");
+ g_assert(element_text_equal_to(context, "a"));
+ g_signal_emit_by_name(imContext, "commit", "b");
+ g_assert(element_text_equal_to(context, "ab"));
+ g_signal_emit_by_name(imContext, "commit", "c");
+ g_assert(element_text_equal_to(context, "abc"));
+
+ g_object_unref(imContext);
+ g_main_loop_quit(fixture->loop);
+}
+
+static void test_ime(KeyEventFixture* fixture, gconstpointer data)
+{
+ setup_keyevent_test(fixture, data, G_CALLBACK(test_ime_load_status_cb));
+}
+
+static gboolean verify_contents(gpointer data)
+{
+ KeyEventFixture* fixture = (KeyEventFixture*)data;
+ JSGlobalContextRef context = webkit_web_frame_get_global_context(
+ webkit_web_view_get_main_frame(fixture->webView));
+ g_assert(context);
+
+ g_assert(element_text_equal_to(context, fixture->info->text));
+ g_main_loop_quit(fixture->loop);
+ return FALSE;
+}
+
+static void test_blocking_load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
+{
+ KeyEventFixture* fixture = (KeyEventFixture*)data;
+ WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
+ if (status != WEBKIT_LOAD_FINISHED)
+ return;
+
+ // The first keypress event should not modify the field.
+ fixture->info->text = g_strdup("bc");
+ if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
+ gdk_unicode_to_keyval('a'), 0))
+ g_assert_not_reached();
+ if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
+ gdk_unicode_to_keyval('b'), 0))
+ g_assert_not_reached();
+ if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
+ gdk_unicode_to_keyval('c'), 0))
+ g_assert_not_reached();
+
+ g_idle_add(verify_contents, fixture);
+}
+
+static void test_blocking(KeyEventFixture* fixture, gconstpointer data)
+{
+ setup_keyevent_test(fixture, data, G_CALLBACK(test_blocking_load_status_cb));
+}
+#if defined(GDK_WINDOWING_X11) && GTK_CHECK_VERSION(2, 16, 0)
+static void test_xim_load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
+{
+ KeyEventFixture* fixture = (KeyEventFixture*)data;
+ WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
+ if (status != WEBKIT_LOAD_FINISHED)
+ return;
+
+ GtkIMContext* imContext = 0;
+ g_object_get(webView, "im-context", &imContext, NULL);
+ g_assert(imContext);
+
+ gchar* originalId = g_strdup(gtk_im_multicontext_get_context_id(GTK_IM_MULTICONTEXT(imContext)));
+ gtk_im_multicontext_set_context_id(GTK_IM_MULTICONTEXT(imContext), "xim");
+
+ // Test that commits that happen outside of key events
+ // change the text field immediately. This closely replicates
+ // the behavior of SCIM.
+ fixture->info->text = g_strdup("debian");
+ if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
+ gdk_unicode_to_keyval('d'), 0))
+ g_assert_not_reached();
+ if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
+ gdk_unicode_to_keyval('e'), 0))
+ g_assert_not_reached();
+ if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
+ gdk_unicode_to_keyval('b'), 0))
+ g_assert_not_reached();
+ if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
+ gdk_unicode_to_keyval('i'), 0))
+ g_assert_not_reached();
+ if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
+ gdk_unicode_to_keyval('a'), 0))
+ g_assert_not_reached();
+ if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
+ gdk_unicode_to_keyval('n'), 0))
+ g_assert_not_reached();
+
+ gtk_im_multicontext_set_context_id(GTK_IM_MULTICONTEXT(imContext), originalId);
+ g_free(originalId);
+ g_object_unref(imContext);
+
+ g_idle_add(verify_contents, fixture);
}
+static void test_xim(KeyEventFixture* fixture, gconstpointer data)
+{
+ setup_keyevent_test(fixture, data, G_CALLBACK(test_xim_load_status_cb));
+}
+#endif
+
int main(int argc, char** argv)
{
g_thread_init(NULL);
@@ -147,30 +308,85 @@ int main(int argc, char** argv)
g_test_bug_base("https://bugs.webkit.org/");
- g_test_add("/webkit/keyevent/textfield", KeyEventFixture,
- test_info_new("<html><body><input id=\"in\" type=\"text\">"
- "<script>document.getElementById('in').focus();"
- "</script></body></html>", TRUE),
+
+ // We'll test input on a slew of different node types. Key events to
+ // text inputs and editable divs should be marked as handled. Key events
+ // to buttons and links should not.
+ const char* textinput_html = "<html><body><input id=\"in\" type=\"text\">"
+ "<script>document.getElementById('in').focus();</script></body></html>";
+ const char* button_html = "<html><body><input id=\"in\" type=\"button\">"
+ "<script>document.getElementById('in').focus();</script></body></html>";
+ const char* link_html = "<html><body><a href=\"http://www.gnome.org\" id=\"in\">"
+ "LINKY MCLINKERSON</a><script>document.getElementById('in').focus();</script>"
+ "</body></html>";
+ const char* div_html = "<html><body><div id=\"in\" contenteditable=\"true\">"
+ "<script>document.getElementById('in').focus();</script></body></html>";
+
+ // These are similar to the blocks above, but they should block the first
+ // keypress modifying the editable node.
+ const char* textinput_html_blocking = "<html><body>"
+ "<input id=\"in\" type=\"text\" "
+ "onkeypress=\"if (first) {event.preventDefault();first=false;}\">"
+ "<script>first = true;\ndocument.getElementById('in').focus();</script>\n"
+ "</script></body></html>";
+ const char* div_html_blocking = "<html><body>"
+ "<div id=\"in\" contenteditable=\"true\" "
+ "onkeypress=\"if (first) {event.preventDefault();first=false;}\">"
+ "<script>first = true; document.getElementById('in').focus();</script>\n"
+ "</script></body></html>";
+
+ g_test_add("/webkit/keyevents/event-textinput", KeyEventFixture,
+ test_info_new(textinput_html, TRUE),
key_event_fixture_setup,
- test_keypress,
+ test_keypress_events,
key_event_fixture_teardown);
-
- g_test_add("/webkit/keyevent/buttons", KeyEventFixture,
- test_info_new("<html><body><input id=\"in\" type=\"button\">"
- "<script>document.getElementById('in').focus();"
- "</script></body></html>", FALSE),
+ g_test_add("/webkit/keyevents/event-buttons", KeyEventFixture,
+ test_info_new(button_html, FALSE),
key_event_fixture_setup,
- test_keypress,
+ test_keypress_events,
key_event_fixture_teardown);
-
- g_test_add("/webkit/keyevent/link", KeyEventFixture,
- test_info_new("<html><body><a href=\"http://www.gnome.org\" id=\"in\">"
- "LINKY MCLINKERSON</a><script>"
- "document.getElementById('in').focus();</script>"
- "</body></html>", FALSE),
+ g_test_add("/webkit/keyevents/event-link", KeyEventFixture,
+ test_info_new(link_html, FALSE),
key_event_fixture_setup,
- test_keypress,
+ test_keypress_events,
key_event_fixture_teardown);
+ g_test_add("/webkit/keyevent/event-div", KeyEventFixture,
+ test_info_new(div_html, TRUE),
+ key_event_fixture_setup,
+ test_keypress_events,
+ key_event_fixture_teardown);
+ g_test_add("/webkit/keyevent/ime-textinput", KeyEventFixture,
+ test_info_new(textinput_html, TRUE),
+ key_event_fixture_setup,
+ test_ime,
+ key_event_fixture_teardown);
+ g_test_add("/webkit/keyevent/ime-div", KeyEventFixture,
+ test_info_new(div_html, TRUE),
+ key_event_fixture_setup,
+ test_ime,
+ key_event_fixture_teardown);
+ g_test_add("/webkit/keyevent/block-textinput", KeyEventFixture,
+ test_info_new(textinput_html_blocking, TRUE),
+ key_event_fixture_setup,
+ test_blocking,
+ key_event_fixture_teardown);
+ g_test_add("/webkit/keyevent/block-div", KeyEventFixture,
+ test_info_new(div_html_blocking, TRUE),
+ key_event_fixture_setup,
+ test_blocking,
+ key_event_fixture_teardown);
+#if defined(GDK_WINDOWING_X11) && GTK_CHECK_VERSION(2, 16, 0)
+ g_test_add("/webkit/keyevent/xim-textinput", KeyEventFixture,
+ test_info_new(textinput_html, TRUE),
+ key_event_fixture_setup,
+ test_xim,
+ key_event_fixture_teardown);
+ g_test_add("/webkit/keyevent/xim-div", KeyEventFixture,
+ test_info_new(div_html, TRUE),
+ key_event_fixture_setup,
+ test_xim,
+ key_event_fixture_teardown);
+#endif
return g_test_run();
}
diff --git a/WebKit/gtk/tests/testmimehandling.c b/WebKit/gtk/tests/testmimehandling.c
index e6e8d45..2ab0257 100644
--- a/WebKit/gtk/tests/testmimehandling.c
+++ b/WebKit/gtk/tests/testmimehandling.c
@@ -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);
diff --git a/WebKit/gtk/tests/testwebbackforwardlist.c b/WebKit/gtk/tests/testwebbackforwardlist.c
index 115c079..2109840 100644
--- a/WebKit/gtk/tests/testwebbackforwardlist.c
+++ b/WebKit/gtk/tests/testwebbackforwardlist.c
@@ -266,6 +266,54 @@ static void test_webkit_web_back_forward_list_add_item(void)
g_object_unref(webView);
}
+static void test_webkit_web_back_forward_list_clear(void)
+{
+ WebKitWebView* webView;
+ WebKitWebBackForwardList* webBackForwardList;
+ WebKitWebHistoryItem* addItem;
+ g_test_bug("36173");
+
+ webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
+ g_object_ref_sink(webView);
+
+ webBackForwardList = webkit_web_view_get_back_forward_list(webView);
+ g_assert(webBackForwardList);
+
+ // Check that there is no item.
+ g_assert_cmpint(webkit_web_back_forward_list_get_forward_length(webBackForwardList), ==, 0);
+ g_assert_cmpint(webkit_web_back_forward_list_get_back_length(webBackForwardList), ==, 0);
+ g_assert(!webkit_web_back_forward_list_get_current_item(webBackForwardList));
+ g_assert(!webkit_web_view_can_go_forward(webView));
+ g_assert(!webkit_web_view_can_go_back(webView));
+
+ // Check that clearing the empty list does not modify counters
+ webkit_web_back_forward_list_clear(webBackForwardList);
+ g_assert_cmpint(webkit_web_back_forward_list_get_forward_length(webBackForwardList), ==, 0);
+ g_assert_cmpint(webkit_web_back_forward_list_get_back_length(webBackForwardList), ==, 0);
+ g_assert(!webkit_web_back_forward_list_get_current_item(webBackForwardList));
+ g_assert(!webkit_web_view_can_go_forward(webView));
+ g_assert(!webkit_web_view_can_go_back(webView));
+
+ // Add a new item
+ addItem = webkit_web_history_item_new_with_data("http://example.com/", "Added site");
+ webkit_web_back_forward_list_add_item(webBackForwardList, addItem);
+ g_object_unref(addItem);
+ g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, addItem));
+
+ // Check that after clearing the list the added item is no longer in the list
+ webkit_web_back_forward_list_clear(webBackForwardList);
+ g_assert(!webkit_web_back_forward_list_contains_item(webBackForwardList, addItem));
+
+ // Check that after clearing it, the list is empty
+ g_assert_cmpint(webkit_web_back_forward_list_get_forward_length(webBackForwardList), ==, 0);
+ g_assert_cmpint(webkit_web_back_forward_list_get_back_length(webBackForwardList), ==, 0);
+ g_assert(!webkit_web_back_forward_list_get_current_item(webBackForwardList));
+ g_assert(!webkit_web_view_can_go_forward(webView));
+ g_assert(!webkit_web_view_can_go_back(webView));
+
+ g_object_unref(webView);
+}
+
int main(int argc, char** argv)
{
g_thread_init(NULL);
@@ -275,6 +323,7 @@ int main(int argc, char** argv)
g_test_add_func("/webkit/webbackforwardlist/add_item", test_webkit_web_back_forward_list_add_item);
g_test_add_func("/webkit/webbackforwardlist/list_order", test_webkit_web_back_forward_list_order);
g_test_add_func("/webkit/webhistoryitem/lifetime", test_webkit_web_history_item_lifetime);
+ g_test_add_func("/webkit/webbackforwardlist/clear", test_webkit_web_back_forward_list_clear);
return g_test_run ();
}
diff --git a/WebKit/gtk/tests/testwebview.c b/WebKit/gtk/tests/testwebview.c
index 34b6867..36511d7 100644
--- a/WebKit/gtk/tests/testwebview.c
+++ b/WebKit/gtk/tests/testwebview.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2008 Holger Hans Peter Freyther
- * Copyright (C) 2009 Collabora Ltd.
+ * Copyright (C) 2009, 2010 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -18,6 +18,8 @@
* Boston, MA 02110-1301, USA.
*/
+#include "test_utils.h"
+
#include <errno.h>
#include <unistd.h>
#include <string.h>
@@ -56,10 +58,10 @@ server_callback(SoupServer* server, SoupMessage* msg,
soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
} else if (g_str_equal(path, "/bigdiv.html")) {
- char* contents = g_strdup("<html><body><div style=\"background-color: green; height: 1200px;\"></div></body></html>");
+ char* contents = g_strdup("<html><body><a id=\"link\" href=\"http://abc.def\">test</a><div style=\"background-color: green; height: 1200px;\"></div></body></html>");
soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, strlen(contents));
} else if (g_str_equal(path, "/iframe.html")) {
- char* contents = g_strdup("<html><body><div style=\"background-color: green; height: 50px;\"></div><iframe src=\"bigdiv.html\"></iframe></body></html>");
+ char* contents = g_strdup("<html><body id=\"some-content\"><div style=\"background-color: green; height: 50px;\"></div><iframe src=\"bigdiv.html\"></iframe></body></html>");
soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, strlen(contents));
} else {
char* contents = g_strdup("<html><body>test</body></html>");
@@ -135,6 +137,61 @@ static gboolean map_event_cb(GtkWidget *widget, GdkEvent* event, gpointer data)
return FALSE;
}
+static void test_webkit_web_view_grab_focus()
+{
+ char* uri = g_strconcat(base_uri, "iframe.html", NULL);
+ GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP);
+ GtkWidget* scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+ WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new());
+ GtkAdjustment* adjustment;
+
+ gtk_window_set_default_size(GTK_WINDOW(window), 400, 200);
+
+ gtk_container_add(GTK_CONTAINER(window), scrolled_window);
+ gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(view));
+
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+ loop = g_main_loop_new(NULL, TRUE);
+
+ g_signal_connect(view, "notify::progress", G_CALLBACK (idle_quit_loop_cb), NULL);
+
+ /* Wait for window to show up */
+ gtk_widget_show_all(window);
+ g_signal_connect(window, "map-event",
+ G_CALLBACK(map_event_cb), loop);
+ g_main_loop_run(loop);
+
+ /* Load a page with a big div that will cause scrollbars to appear */
+ webkit_web_view_load_uri(view, uri);
+ g_main_loop_run(loop);
+
+ adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolled_window));
+ g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), ==, 0.0);
+
+ /* Since webkit_web_view_execute_script does not return a value,
+ it is impossible to know if an inner document has focus after
+ a node of it was focused via .focus() method.
+ The code below is an workaround: if the node has focus, a scroll
+ action is performed and afterward it is checked if the adjustment
+ has to be different from 0.
+ */
+ char script[] = "var innerDoc = document.defaultView.frames[0].document; \
+ innerDoc.getElementById(\"link\").focus(); \
+ if (innerDoc.hasFocus()) \
+ window.scrollBy(0, 100);";
+
+ /* Focus an element using JavaScript */
+ webkit_web_view_execute_script(view, script);
+
+ /* Make sure the ScrolledWindow noticed the scroll */
+ g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), !=, 0.0);
+
+ g_free(uri);
+ gtk_widget_destroy(window);
+}
+
static void do_test_webkit_web_view_adjustments(gboolean with_page_cache)
{
char* effective_uri = g_strconcat(base_uri, "bigdiv.html", NULL);
@@ -224,6 +281,61 @@ static void test_webkit_web_view_adjustments()
do_test_webkit_web_view_adjustments(TRUE);
}
+gboolean delayed_destroy(gpointer data)
+{
+ gtk_widget_destroy(GTK_WIDGET(data));
+ g_main_loop_quit(loop);
+ return FALSE;
+}
+
+static void test_webkit_web_view_destroy()
+{
+ GtkWidget* window;
+ GtkWidget* web_view;
+
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ web_view = webkit_web_view_new();
+
+ gtk_container_add(GTK_CONTAINER(window), web_view);
+
+ gtk_widget_show_all(window);
+
+ loop = g_main_loop_new(NULL, TRUE);
+
+ g_signal_connect(window, "map-event",
+ G_CALLBACK(map_event_cb), loop);
+ g_main_loop_run(loop);
+
+ g_idle_add(delayed_destroy, web_view);
+ g_main_loop_run(loop);
+
+ gtk_widget_destroy(window);
+}
+
+static void test_webkit_web_view_window_features()
+{
+ GtkWidget* window;
+ GtkWidget* web_view;
+
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ web_view = webkit_web_view_new();
+
+ gtk_container_add(GTK_CONTAINER(window), web_view);
+
+ gtk_widget_show_all(window);
+
+ loop = g_main_loop_new(NULL, TRUE);
+
+ g_signal_connect(window, "map-event",
+ G_CALLBACK(map_event_cb), loop);
+ g_main_loop_run(loop);
+
+ /* Bug #36144 */
+ g_object_set(G_OBJECT(web_view), "window-features", NULL, NULL);
+
+ gtk_widget_destroy(window);
+}
+
int main(int argc, char** argv)
{
SoupServer* server;
@@ -233,16 +345,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);
@@ -258,6 +361,9 @@ int main(int argc, char** argv)
g_test_bug_base("https://bugs.webkit.org/");
g_test_add_func("/webkit/webview/icon-uri", test_webkit_web_view_icon_uri);
g_test_add_func("/webkit/webview/adjustments", test_webkit_web_view_adjustments);
+ g_test_add_func("/webkit/webview/destroy", test_webkit_web_view_destroy);
+ g_test_add_func("/webkit/webview/grab_focus", test_webkit_web_view_grab_focus);
+ g_test_add_func("/webkit/webview/window-features", test_webkit_web_view_window_features);
return g_test_run ();
}