summaryrefslogtreecommitdiffstats
path: root/WebKit/gtk/tests/testwindow.c
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2009-10-08 17:19:54 +0100
committerSteve Block <steveblock@google.com>2009-10-20 00:41:58 +0100
commit231d4e3152a9c27a73b6ac7badbe6be673aa3ddf (patch)
treea6c7e2d6cd7bfa7011cc39abbb436142d7a4a7c8 /WebKit/gtk/tests/testwindow.c
parente196732677050bd463301566a68a643b6d14b907 (diff)
downloadexternal_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.zip
external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.tar.gz
external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.tar.bz2
Merge webkit.org at R49305 : Automatic merge by git.
Change-Id: I8968561bc1bfd72b8923b7118d3728579c6dbcc7
Diffstat (limited to 'WebKit/gtk/tests/testwindow.c')
-rw-r--r--WebKit/gtk/tests/testwindow.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/WebKit/gtk/tests/testwindow.c b/WebKit/gtk/tests/testwindow.c
new file mode 100644
index 0000000..41ff323
--- /dev/null
+++ b/WebKit/gtk/tests/testwindow.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2009 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 <webkit/webkit.h>
+
+#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0)
+
+static void load_finished_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, gpointer data)
+{
+ GMainLoop* loop = (GMainLoop*)data;
+
+ g_main_loop_quit(loop);
+}
+
+static void test_webkit_window_scrollbar_policy(void)
+{
+ GMainLoop* loop;
+ GtkWidget* scrolledWindow;
+ GtkWidget* webView;
+ WebKitWebFrame* mainFrame;
+ GtkPolicyType horizontalPolicy;
+ GtkPolicyType verticalPolicy;
+
+ loop = g_main_loop_new(NULL, TRUE);
+
+ scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+ webView = webkit_web_view_new();
+ g_object_ref_sink(webView);
+
+ g_signal_connect(webView, "load-finished",
+ G_CALLBACK(load_finished_cb), loop);
+
+ gtk_container_add(GTK_CONTAINER(scrolledWindow), webView);
+
+ mainFrame = webkit_web_view_get_main_frame(WEBKIT_WEB_VIEW(webView));
+
+ /* Test we correctly apply policy for not having scrollbars; This
+ * case is special, because we turn the policy from NEVER to
+ * AUTOMATIC, since we cannot easily represent the same thing
+ * using GtkScrolledWindow */
+ webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView),
+ "<html><body>WebKit!</body><script>document.getElementsByTagName('body')[0].style.overflow = 'hidden';</script></html>",
+ "file://");
+
+ g_main_loop_run(loop);
+
+ gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
+ &horizontalPolicy, &verticalPolicy);
+
+ g_assert(horizontalPolicy == GTK_POLICY_AUTOMATIC);
+ g_assert(verticalPolicy == GTK_POLICY_AUTOMATIC);
+
+ g_assert(GTK_POLICY_NEVER == webkit_web_frame_get_horizontal_scrollbar_policy(mainFrame));
+ g_assert(GTK_POLICY_NEVER == webkit_web_frame_get_vertical_scrollbar_policy(mainFrame));
+
+ /* Test we correctly apply policy for always having scrollbars */
+ webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView),
+ "<html><body>WebKit!</body><script>document.getElementsByTagName('body')[0].style.overflow = 'scroll';</script></html>",
+ "file://");
+
+ g_main_loop_run(loop);
+
+ gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
+ &horizontalPolicy, &verticalPolicy);
+
+ g_assert(horizontalPolicy == GTK_POLICY_ALWAYS);
+ g_assert(verticalPolicy == GTK_POLICY_ALWAYS);
+
+ g_assert(horizontalPolicy == webkit_web_frame_get_horizontal_scrollbar_policy(mainFrame));
+ g_assert(verticalPolicy == webkit_web_frame_get_vertical_scrollbar_policy(mainFrame));
+
+ /* Test we correctly apply policy for having scrollbars when needed */
+ webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView),
+ "<html><body>WebKit!</body><script>document.getElementsByTagName('body')[0].style.overflow = 'auto';</script></html>",
+ "file://");
+
+ g_main_loop_run(loop);
+
+ gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
+ &horizontalPolicy, &verticalPolicy);
+
+ g_assert(horizontalPolicy == GTK_POLICY_AUTOMATIC);
+ g_assert(verticalPolicy == GTK_POLICY_AUTOMATIC);
+
+ g_assert(horizontalPolicy == webkit_web_frame_get_horizontal_scrollbar_policy(mainFrame));
+ g_assert(verticalPolicy == webkit_web_frame_get_vertical_scrollbar_policy(mainFrame));
+
+ g_object_unref(webView);
+}
+
+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/window/scrollbar_policy", test_webkit_window_scrollbar_policy);
+ 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