1/* 2 * Copyright (C) 2009 Collabora Ltd. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20#include "autotoolsconfig.h" 21#include <gtk/gtk.h> 22#include <webkit/webkit.h> 23 24static void notify_load_status_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data) 25{ 26 if (webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FINISHED) { 27 GMainLoop* loop = (GMainLoop*)data; 28 29 g_main_loop_quit(loop); 30 } 31} 32 33static void test_webkit_window_scrollbar_policy(void) 34{ 35 GMainLoop* loop; 36 GtkWidget* scrolledWindow; 37 GtkWidget* webView; 38 WebKitWebFrame* mainFrame; 39 GtkPolicyType horizontalPolicy; 40 GtkPolicyType verticalPolicy; 41 42 loop = g_main_loop_new(NULL, TRUE); 43 44 scrolledWindow = gtk_scrolled_window_new(NULL, NULL); 45 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow), 46 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); 47 48 webView = webkit_web_view_new(); 49 g_object_ref_sink(webView); 50 51 g_signal_connect(webView, "notify::load-status", 52 G_CALLBACK(notify_load_status_cb), loop); 53 54 gtk_container_add(GTK_CONTAINER(scrolledWindow), webView); 55 56 mainFrame = webkit_web_view_get_main_frame(WEBKIT_WEB_VIEW(webView)); 57 58 /* Test we correctly apply policy for not having scrollbars; This 59 * case is special, because we turn the policy from NEVER to 60 * AUTOMATIC, since we cannot easily represent the same thing 61 * using GtkScrolledWindow */ 62 webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView), 63 "<html><body>WebKit!</body><script>document.getElementsByTagName('body')[0].style.overflow = 'hidden';</script></html>", 64 "file://"); 65 66 g_main_loop_run(loop); 67 68 gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(scrolledWindow), 69 &horizontalPolicy, &verticalPolicy); 70 71 g_assert(horizontalPolicy == GTK_POLICY_AUTOMATIC); 72 g_assert(verticalPolicy == GTK_POLICY_AUTOMATIC); 73 74 g_assert(GTK_POLICY_NEVER == webkit_web_frame_get_horizontal_scrollbar_policy(mainFrame)); 75 g_assert(GTK_POLICY_NEVER == webkit_web_frame_get_vertical_scrollbar_policy(mainFrame)); 76 77 /* Test we correctly apply policy for always having scrollbars */ 78 webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView), 79 "<html><body>WebKit!</body><script>document.getElementsByTagName('body')[0].style.overflow = 'scroll';</script></html>", 80 "file://"); 81 82 g_main_loop_run(loop); 83 84 gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(scrolledWindow), 85 &horizontalPolicy, &verticalPolicy); 86 87 g_assert(horizontalPolicy == GTK_POLICY_ALWAYS); 88 g_assert(verticalPolicy == GTK_POLICY_ALWAYS); 89 90 g_assert(horizontalPolicy == webkit_web_frame_get_horizontal_scrollbar_policy(mainFrame)); 91 g_assert(verticalPolicy == webkit_web_frame_get_vertical_scrollbar_policy(mainFrame)); 92 93 /* Test we correctly apply policy for having scrollbars when needed */ 94 webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView), 95 "<html><body>WebKit!</body><script>document.getElementsByTagName('body')[0].style.overflow = 'auto';</script></html>", 96 "file://"); 97 98 g_main_loop_run(loop); 99 100 gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(scrolledWindow), 101 &horizontalPolicy, &verticalPolicy); 102 103 g_assert(horizontalPolicy == GTK_POLICY_AUTOMATIC); 104 g_assert(verticalPolicy == GTK_POLICY_AUTOMATIC); 105 106 g_assert(horizontalPolicy == webkit_web_frame_get_horizontal_scrollbar_policy(mainFrame)); 107 g_assert(verticalPolicy == webkit_web_frame_get_vertical_scrollbar_policy(mainFrame)); 108 109 g_object_unref(webView); 110} 111 112int main(int argc, char** argv) 113{ 114 gtk_test_init(&argc, &argv, NULL); 115 116 g_test_bug_base("https://bugs.webkit.org/"); 117 g_test_add_func("/webkit/window/scrollbar_policy", test_webkit_window_scrollbar_policy); 118 return g_test_run (); 119} 120