summaryrefslogtreecommitdiff
path: root/Source/WebKit/gtk/tests
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit/gtk/tests')
-rw-r--r--Source/WebKit/gtk/tests/testcopyandpaste.c3
-rw-r--r--Source/WebKit/gtk/tests/testkeyevents.c2
-rw-r--r--Source/WebKit/gtk/tests/testwebplugindatabase.c4
-rw-r--r--Source/WebKit/gtk/tests/testwebview.c118
4 files changed, 123 insertions, 4 deletions
diff --git a/Source/WebKit/gtk/tests/testcopyandpaste.c b/Source/WebKit/gtk/tests/testcopyandpaste.c
index 6d1b48080..7d8dd8f0d 100644
--- a/Source/WebKit/gtk/tests/testcopyandpaste.c
+++ b/Source/WebKit/gtk/tests/testcopyandpaste.c
@@ -111,7 +111,6 @@ static void load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer da
gboolean map_event_cb(GtkWidget *widget, GdkEvent* event, gpointer data)
{
- gtk_widget_grab_focus(widget);
CopyAndPasteFixture* fixture = (CopyAndPasteFixture*)data;
webkit_web_view_load_string(fixture->webView, fixture->info->page,
"text/html", "utf-8", "file://");
@@ -137,6 +136,8 @@ static void test_copy_and_paste(CopyAndPasteFixture* fixture, gconstpointer data
static CopyAndPasteFixture* currentFixture;
static JSValueRef runPasteTestCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
+ gtk_widget_grab_focus(GTK_WIDGET(currentFixture->webView));
+
// Simulate a paste keyboard sequence.
GdkEvent* event = gdk_event_new(GDK_KEY_PRESS);
event->key.keyval = gdk_unicode_to_keyval('v');
diff --git a/Source/WebKit/gtk/tests/testkeyevents.c b/Source/WebKit/gtk/tests/testkeyevents.c
index cf33d4abe..b55b4bcaf 100644
--- a/Source/WebKit/gtk/tests/testkeyevents.c
+++ b/Source/WebKit/gtk/tests/testkeyevents.c
@@ -118,7 +118,6 @@ static void test_keypress_events_load_status_cb(WebKitWebView* webView, GParamSp
gboolean map_event_cb(GtkWidget *widget, GdkEvent* event, gpointer data)
{
- gtk_widget_grab_focus(widget);
KeyEventFixture* fixture = (KeyEventFixture*)data;
webkit_web_view_load_string(fixture->webView, fixture->info->page,
"text/html", "utf-8", "file://");
@@ -131,6 +130,7 @@ static void setup_keyevent_test(KeyEventFixture* fixture, gconstpointer data, GC
g_signal_connect(fixture->window, "map-event",
G_CALLBACK(map_event_cb), fixture);
+ gtk_widget_grab_focus(GTK_WIDGET(fixture->webView));
gtk_widget_show(fixture->window);
gtk_widget_show(GTK_WIDGET(fixture->webView));
gtk_window_present(GTK_WINDOW(fixture->window));
diff --git a/Source/WebKit/gtk/tests/testwebplugindatabase.c b/Source/WebKit/gtk/tests/testwebplugindatabase.c
index db2529f3a..f5e23d08a 100644
--- a/Source/WebKit/gtk/tests/testwebplugindatabase.c
+++ b/Source/WebKit/gtk/tests/testwebplugindatabase.c
@@ -44,7 +44,7 @@ static void test_webkit_web_plugin_database_get_plugins()
for (p = pluginList; p; p = p->next) {
WebKitWebPlugin* plugin = (WebKitWebPlugin*)p->data;
if (!g_strcmp0(webkit_web_plugin_get_name(plugin), "WebKit Test PlugIn") &&
- !g_strcmp0(webkit_web_plugin_get_description(plugin), "Simple Netscape plug-in that handles test content for WebKit")) {
+ !g_strcmp0(webkit_web_plugin_get_description(plugin), "Simple Netscape® plug-in that handles test content for WebKit")) {
found = TRUE;
enabled = webkit_web_plugin_get_enabled(plugin);
webkit_web_plugin_set_enabled(plugin, FALSE);
@@ -60,7 +60,7 @@ static void test_webkit_web_plugin_database_get_plugins()
for (p = pluginList; p; p = p->next) {
WebKitWebPlugin* plugin = (WebKitWebPlugin*)p->data;
if (!g_strcmp0(webkit_web_plugin_get_name(plugin), "WebKit Test PlugIn") &&
- !g_strcmp0(webkit_web_plugin_get_description(plugin), "Simple Netscape plug-in that handles test content for WebKit"))
+ !g_strcmp0(webkit_web_plugin_get_description(plugin), "Simple Netscape® plug-in that handles test content for WebKit"))
enabled = webkit_web_plugin_get_enabled(plugin);
}
webkit_web_plugin_database_plugins_list_free(pluginList);
diff --git a/Source/WebKit/gtk/tests/testwebview.c b/Source/WebKit/gtk/tests/testwebview.c
index 41cf308f6..ab3bd5576 100644
--- a/Source/WebKit/gtk/tests/testwebview.c
+++ b/Source/WebKit/gtk/tests/testwebview.c
@@ -382,6 +382,121 @@ static void test_webkit_web_view_in_offscreen_window_does_not_crash()
g_main_loop_unref(loop);
}
+static void test_webkit_web_view_does_not_steal_focus()
+{
+ loop = g_main_loop_new(NULL, TRUE);
+
+ GtkWidget *window = gtk_offscreen_window_new();
+ GtkWidget *webView = webkit_web_view_new();
+ GtkWidget *entry = gtk_entry_new();
+ GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+
+ gtk_container_add(GTK_CONTAINER(box), webView);
+ gtk_container_add(GTK_CONTAINER(box), entry);
+ gtk_container_add(GTK_CONTAINER(window), box);
+ gtk_widget_show_all(window);
+
+ gtk_widget_grab_focus(entry);
+ g_assert(gtk_widget_is_focus(entry));
+
+ g_signal_connect(webView, "notify::load-status", G_CALLBACK(idle_quit_loop_cb), NULL);
+ webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView),
+ "<html><body>"
+ " <input id=\"entry\" type=\"text\"/>"
+ " <script>"
+ " document.getElementById(\"entry\").focus();"
+ " </script>"
+ "</body></html>", "file://");
+
+ g_main_loop_run(loop);
+
+ g_assert(gtk_widget_is_focus(entry));
+
+ gtk_widget_destroy(window);
+ g_main_loop_unref(loop);
+}
+
+static gboolean emitKeyStroke(WebKitWebView* webView)
+{
+ GdkEvent* pressEvent = gdk_event_new(GDK_KEY_PRESS);
+ pressEvent->key.keyval = GDK_KEY_f;
+ GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(webView));
+ pressEvent->key.window = window;
+ g_object_ref(pressEvent->key.window);
+
+ GdkDeviceManager* manager = gdk_display_get_device_manager(gdk_window_get_display(window));
+ gdk_event_set_device(pressEvent, gdk_device_manager_get_client_pointer(manager));
+
+ // When synthesizing an event, an invalid hardware_keycode value
+ // can cause it to be badly processed by Gtk+.
+ GdkKeymapKey* keys;
+ gint n_keys;
+ if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), GDK_KEY_f, &keys, &n_keys)) {
+ pressEvent->key.hardware_keycode = keys[0].keycode;
+ g_free(keys);
+ }
+
+ GdkEvent* releaseEvent = gdk_event_copy(pressEvent);
+ gtk_main_do_event(pressEvent);
+ gdk_event_free(pressEvent);
+ releaseEvent->key.type = GDK_KEY_RELEASE;
+ gtk_main_do_event(releaseEvent);
+ gdk_event_free(releaseEvent);
+
+ return FALSE;
+}
+
+static gboolean entering_fullscreen_cb(WebKitWebView* webView, GObject* element, gboolean blocked)
+{
+ if (blocked)
+ g_main_loop_quit(loop);
+ else
+ g_timeout_add(200, (GSourceFunc) emitKeyStroke, webView);
+ return blocked;
+}
+
+static gboolean leaving_fullscreen_cb(WebKitWebView* webView, GObject* element, gpointer data)
+{
+ g_main_loop_quit(loop);
+ return FALSE;
+}
+
+static void test_webkit_web_view_fullscreen(gconstpointer blocked)
+{
+ GtkWidget* window;
+ GtkWidget* web_view;
+ WebKitWebSettings *settings;
+
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ web_view = webkit_web_view_new();
+
+ settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(web_view));
+ g_object_set(settings, "enable-fullscreen", TRUE, NULL);
+ webkit_web_view_set_settings(WEBKIT_WEB_VIEW(web_view), settings);
+
+ gtk_container_add(GTK_CONTAINER(window), web_view);
+
+ gtk_widget_show_all(window);
+
+ loop = g_main_loop_new(NULL, TRUE);
+
+ g_signal_connect(web_view, "entering-fullscreen", G_CALLBACK(entering_fullscreen_cb), (gpointer) blocked);
+ g_signal_connect(web_view, "leaving-fullscreen", G_CALLBACK(leaving_fullscreen_cb), NULL);
+
+ webkit_web_view_load_string(WEBKIT_WEB_VIEW(web_view), "<html><body>"
+ "<script>"
+ "var eventName = 'keypress';"
+ "document.addEventListener(eventName, function () {"
+ " document.documentElement.webkitRequestFullScreen();"
+ "}, false);"
+ "</script></body></html>", NULL, NULL, NULL);
+
+ g_timeout_add(100, (GSourceFunc) emitKeyStroke, WEBKIT_WEB_VIEW(web_view));
+ g_main_loop_run(loop);
+
+ gtk_widget_destroy(window);
+}
+
int main(int argc, char** argv)
{
SoupServer* server;
@@ -410,6 +525,9 @@ int main(int argc, char** argv)
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);
g_test_add_func("/webkit/webview/webview-in-offscreen-window-does-not-crash", test_webkit_web_view_in_offscreen_window_does_not_crash);
+ g_test_add_func("/webkit/webview/webview-does-not-steal-focus", test_webkit_web_view_does_not_steal_focus);
+ g_test_add_data_func("/webkit/webview/fullscreen", GINT_TO_POINTER(FALSE), test_webkit_web_view_fullscreen);
+ g_test_add_data_func("/webkit/webview/fullscreen-blocked", GINT_TO_POINTER(TRUE), test_webkit_web_view_fullscreen);
return g_test_run ();
}