1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*
* 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 "config.h"
#include <gtk/gtk.h>
#include <webkit/webkit.h>
static void notify_load_status_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
{
if (webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FINISHED) {
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, "notify::load-status",
G_CALLBACK(notify_load_status_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)
{
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 ();
}
|