From 231d4e3152a9c27a73b6ac7badbe6be673aa3ddf Mon Sep 17 00:00:00 2001 From: Steve Block Date: Thu, 8 Oct 2009 17:19:54 +0100 Subject: Merge webkit.org at R49305 : Automatic merge by git. Change-Id: I8968561bc1bfd72b8923b7118d3728579c6dbcc7 --- WebKit/gtk/tests/testwindow.c | 128 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 WebKit/gtk/tests/testwindow.c (limited to 'WebKit/gtk/tests/testwindow.c') 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 +#include + +#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), + "WebKit!", + "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), + "WebKit!", + "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), + "WebKit!", + "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 -- cgit v1.1