• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 Gustavo Noronha Silva
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 <gtk/gtk.h>
21 #include <webkit/webkit.h>
22 
23 #if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0)
24 
25 static gboolean has_been_provisional = FALSE;
26 static gboolean has_been_committed = FALSE;
27 static gboolean has_been_first_visually_non_empty_layout = FALSE;
28 
load_finished_cb(WebKitWebView * web_view,WebKitWebFrame * web_frame,gpointer data)29 static void load_finished_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, gpointer data)
30 {
31     GMainLoop* loop = (GMainLoop*)data;
32 
33     g_assert(has_been_provisional);
34     g_assert(has_been_committed);
35     g_assert(has_been_first_visually_non_empty_layout);
36 
37     g_main_loop_quit(loop);
38 }
39 
40 
status_changed_cb(GObject * object,GParamSpec * pspec,gpointer data)41 static void status_changed_cb(GObject* object, GParamSpec* pspec, gpointer data)
42 {
43     WebKitLoadStatus status = webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(object));
44 
45     switch (status) {
46     case WEBKIT_LOAD_PROVISIONAL:
47         g_assert(!has_been_provisional);
48         g_assert(!has_been_committed);
49         g_assert(!has_been_first_visually_non_empty_layout);
50         has_been_provisional = TRUE;
51         break;
52     case WEBKIT_LOAD_COMMITTED:
53         g_assert(has_been_provisional);
54         g_assert(!has_been_committed);
55         g_assert(!has_been_first_visually_non_empty_layout);
56         has_been_committed = TRUE;
57         break;
58     case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT:
59         g_assert(has_been_provisional);
60         g_assert(has_been_committed);
61         g_assert(!has_been_first_visually_non_empty_layout);
62         has_been_first_visually_non_empty_layout = TRUE;
63         break;
64     case WEBKIT_LOAD_FINISHED:
65         g_assert(has_been_provisional);
66         g_assert(has_been_committed);
67         g_assert(has_been_first_visually_non_empty_layout);
68         break;
69     default:
70         g_assert_not_reached();
71     }
72 }
73 
test_loading_status()74 static void test_loading_status()
75 {
76     WebKitWebView* web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
77     GMainLoop* loop = g_main_loop_new(NULL, TRUE);
78 
79     g_object_ref_sink(web_view);
80 
81     g_assert_cmpint(webkit_web_view_get_load_status(web_view), ==, WEBKIT_LOAD_PROVISIONAL);
82 
83     g_object_connect(G_OBJECT(web_view),
84                      "signal::notify::load-status", G_CALLBACK(status_changed_cb), NULL,
85                      "signal::load-finished", G_CALLBACK(load_finished_cb), loop,
86                      NULL);
87 
88     /* load_uri will trigger the navigation-policy-decision-requested
89      * signal emission;
90      */
91     webkit_web_view_load_uri(web_view, "http://gnome.org/");
92 
93     g_main_loop_run(loop);
94 
95     g_object_unref(web_view);
96 }
97 
main(int argc,char ** argv)98 int main(int argc, char** argv)
99 {
100     g_thread_init(NULL);
101     gtk_test_init(&argc, &argv, NULL);
102 
103     g_test_bug_base("https://bugs.webkit.org/");
104     g_test_add_func("/webkit/loading/status", test_loading_status);
105     return g_test_run();
106 }
107 
108 #else
main(int argc,char ** argv)109 int main(int argc, char** argv)
110 {
111     g_critical("You will need at least glib-2.16.0 and gtk-2.14.0 to run the unit tests. Doing nothing now.");
112     return 0;
113 }
114 
115 #endif
116