aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXan Lopez <xan@igalia.com>2013-03-08 20:15:44 +0800
committerXan Lopez <xan@igalia.com>2013-03-12 02:18:37 +0800
commit094af6305e6248eb62ddfb1f05ee7920e5f17ee5 (patch)
treed43d795df22a29e72c50c878c6d774dd6283fc8f
parent3e97755d7ef4b19dff5e192673e4440aecd6c571 (diff)
downloadgsoc2013-epiphany-094af6305e6248eb62ddfb1f05ee7920e5f17ee5.tar
gsoc2013-epiphany-094af6305e6248eb62ddfb1f05ee7920e5f17ee5.tar.gz
gsoc2013-epiphany-094af6305e6248eb62ddfb1f05ee7920e5f17ee5.tar.bz2
gsoc2013-epiphany-094af6305e6248eb62ddfb1f05ee7920e5f17ee5.tar.lz
gsoc2013-epiphany-094af6305e6248eb62ddfb1f05ee7920e5f17ee5.tar.xz
gsoc2013-epiphany-094af6305e6248eb62ddfb1f05ee7920e5f17ee5.tar.zst
gsoc2013-epiphany-094af6305e6248eb62ddfb1f05ee7920e5f17ee5.zip
ephy-session-test: make session tests work more reliably
Based on a patch by Manuel Rego. Ensure the WebViews created during the session load are fully loaded before we check their URIs. This was working more or less by pure chance in WK1, and was failing in WK2 because of the process separation. The restore tab test is skipped in WK2 for now, since it's crashing. The patch excludes some asserts in WK2 while bug #695437 is not fixed. https://bugzilla.gnome.org/show_bug.cgi?id=695300
-rw-r--r--tests/ephy-session-test.c139
1 files changed, 131 insertions, 8 deletions
diff --git a/tests/ephy-session-test.c b/tests/ephy-session-test.c
index eda9ab497..2397ba4a7 100644
--- a/tests/ephy-session-test.c
+++ b/tests/ephy-session-test.c
@@ -1,4 +1,5 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=2 ts=2 sts=2 et: */
/*
* Copyright © 2012 - Igalia S.L.
*
@@ -88,6 +89,78 @@ disable_delayed_loading (void)
FALSE);
}
+static guint web_view_ready_counter = 0;
+
+static void
+load_changed_cb (WebKitWebView *web_view,
+#ifdef HAVE_WEBKIT2
+ WebKitLoadEvent status,
+#else
+ GParamSpec *pspec,
+#endif
+ GMainLoop *loop)
+{
+#ifndef HAVE_WEBKIT2
+ WebKitLoadStatus status = webkit_web_view_get_load_status (web_view);
+#endif
+
+ if (status == WEBKIT_LOAD_COMMITTED) {
+ web_view_ready_counter--;
+ g_signal_handlers_disconnect_by_func (web_view, load_changed_cb, loop);
+
+ if (web_view_ready_counter == 0)
+ g_main_loop_quit (loop);
+ }
+
+}
+
+static void
+wait_until_load_is_committed (WebKitWebView *web_view, GMainLoop *loop)
+{
+#ifdef HAVE_WEBKIT2
+ g_signal_connect (web_view, "load-changed", G_CALLBACK (load_changed_cb), loop);
+#else
+ g_signal_connect (web_view, "notify::load-status", G_CALLBACK (load_changed_cb), loop);
+#endif
+}
+
+static void
+check_ephy_web_view_address (EphyWebView *view,
+ const gchar *address)
+{
+ g_assert_cmpstr (ephy_web_view_get_address (view), ==, address);
+}
+
+static void
+web_view_created_cb (EphyEmbedShell *shell, EphyWebView *view, GMainLoop *loop)
+{
+ web_view_ready_counter++;
+ wait_until_load_is_committed (WEBKIT_WEB_VIEW (view), loop);
+}
+
+static GMainLoop* setup_ensure_web_views_are_loaded (void)
+{
+ GMainLoop *loop;
+
+ web_view_ready_counter = 0;
+
+ loop = g_main_loop_new (NULL, FALSE);
+ g_signal_connect (ephy_embed_shell_get_default (), "web-view-created",
+ G_CALLBACK (web_view_created_cb), loop);
+
+ return loop;
+}
+
+static void ensure_web_views_are_loaded (GMainLoop *loop)
+{
+ if (web_view_ready_counter != 0)
+ g_main_loop_run (loop);
+
+ g_signal_handlers_disconnect_by_func (ephy_embed_shell_get_default (), G_CALLBACK (web_view_created_cb), loop);
+ g_assert_cmpint (web_view_ready_counter, ==, 0);
+ g_main_loop_unref (loop);
+}
+
static void
test_ephy_session_load (void)
{
@@ -96,15 +169,20 @@ test_ephy_session_load (void)
GList *l;
EphyEmbed *embed;
EphyWebView *view;
+ GMainLoop *loop;
disable_delayed_loading ();
session = ephy_shell_get_session (ephy_shell_get_default ());
g_assert (session);
+ loop = setup_ensure_web_views_are_loaded ();
+
ret = load_session_from_string (session, session_data);
g_assert (ret);
+ ensure_web_views_are_loaded (loop);
+
l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
g_assert (l);
g_assert_cmpint (g_list_length (l), ==, 1);
@@ -113,13 +191,26 @@ test_ephy_session_load (void)
g_assert (embed);
view = ephy_embed_get_web_view (embed);
g_assert (view);
- g_assert_cmpstr (ephy_web_view_get_address (view), ==, "ephy-about:memory");
+ check_ephy_web_view_address (view, "ephy-about:memory");
ephy_session_clear (session);
enable_delayed_loading ();
}
+/* FIXME: This #ifdef should be removed once bug #695437 is fixed. */
+#ifdef HAVE_WEBKIT2
+const char *session_data_many_windows =
+"<?xml version=\"1.0\"?>"
+"<session>"
+ "<window x=\"100\" y=\"26\" width=\"1067\" height=\"740\" active-tab=\"0\" role=\"epiphany-window-7da420dd\">"
+ "<embed url=\"about:epiphany\" title=\"Epiphany\"/>"
+ "</window>"
+ "<window x=\"73\" y=\"26\" width=\"1067\" height=\"740\" active-tab=\"0\" role=\"epiphany-window-1261c786\">"
+ "<embed url=\"about:config\" title=\"Epiphany\"/>"
+ "</window>"
+"</session>";
+#else
const char *session_data_many_windows =
"<?xml version=\"1.0\"?>"
"<session>"
@@ -130,18 +221,25 @@ const char *session_data_many_windows =
"<embed url=\"about:epiphany\" title=\"Epiphany\"/>"
"</window>"
"</session>";
+#endif
static void
test_ephy_session_clear (void)
{
EphySession *session;
GList *l;
+ GMainLoop *loop;
disable_delayed_loading ();
session = EPHY_SESSION (ephy_shell_get_session (ephy_shell_get_default ()));
+
+ loop = setup_ensure_web_views_are_loaded ();
+
load_session_from_string (session, session_data_many_windows);
+ ensure_web_views_are_loaded (loop);
+
l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
gtk_widget_destroy (GTK_WIDGET (l->data));
@@ -162,12 +260,15 @@ test_ephy_session_load_empty_session (void)
GList *l;
EphyEmbed *embed;
EphyWebView *view;
+ GMainLoop *loop;
disable_delayed_loading ();
session = ephy_shell_get_session (ephy_shell_get_default ());
g_assert (session);
+ loop = setup_ensure_web_views_are_loaded ();
+
ret = load_session_from_string (session, session_data_empty);
g_assert (ret == FALSE);
@@ -175,8 +276,7 @@ test_ephy_session_load_empty_session (void)
* the default empty window. Got to spin the mainloop though,
* since the fallback is done by queueing another session
* command. */
- while (g_main_context_pending (NULL))
- g_main_context_iteration (NULL, FALSE);
+ ensure_web_views_are_loaded (loop);
l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
g_assert (l);
@@ -186,7 +286,7 @@ test_ephy_session_load_empty_session (void)
g_assert (embed);
view = ephy_embed_get_web_view (embed);
g_assert (view);
- g_assert_cmpstr (ephy_web_view_get_address (view), ==, "ephy-about:overview");
+ check_ephy_web_view_address (view, "ephy-about:overview");
enable_delayed_loading ();
ephy_session_clear (session);
@@ -200,14 +300,21 @@ test_ephy_session_load_many_windows (void)
GList *l, *p;
EphyEmbed *embed;
EphyWebView *view;
+ GMainLoop *loop;
disable_delayed_loading ();
session = ephy_shell_get_session (ephy_shell_get_default ());
g_assert (session);
+ loop = setup_ensure_web_views_are_loaded ();
+
ret = load_session_from_string (session, session_data_many_windows);
g_assert (ret);
+ g_assert_cmpint (web_view_ready_counter, >=, 0);
+ g_assert_cmpint (web_view_ready_counter, <=, 2);
+
+ ensure_web_views_are_loaded (loop);
l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
g_assert (l);
@@ -218,7 +325,10 @@ test_ephy_session_load_many_windows (void)
g_assert (embed);
view = ephy_embed_get_web_view (embed);
g_assert (view);
- g_assert_cmpstr (ephy_web_view_get_address (view), ==, "ephy-about:epiphany");
+#ifndef HAVE_WEBKIT2
+ /* FIXME: This #ifndef should be removed once bug #695437 is fixed. */
+ check_ephy_web_view_address (view, "ephy-about:epiphany");
+#endif
}
enable_delayed_loading ();
@@ -234,16 +344,23 @@ open_uris_after_loading_session (const char** uris, int final_num_windows)
EphyEmbed *embed;
EphyWebView *view;
guint32 user_time;
+ GMainLoop *loop;
disable_delayed_loading ();
session = ephy_shell_get_session (ephy_shell_get_default ());
g_assert (session);
+ loop = setup_ensure_web_views_are_loaded ();
+
user_time = gdk_x11_display_get_user_time (gdk_display_get_default ());
ret = load_session_from_string (session, session_data_many_windows);
g_assert (ret);
+ g_assert_cmpint (web_view_ready_counter, >=, 0);
+ g_assert_cmpint (web_view_ready_counter, <=, 2);
+
+ ensure_web_views_are_loaded (loop);
l = gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default ()));
@@ -255,7 +372,10 @@ open_uris_after_loading_session (const char** uris, int final_num_windows)
g_assert (embed);
view = ephy_embed_get_web_view (embed);
g_assert (view);
- g_assert_cmpstr (ephy_web_view_get_address (view), ==, "ephy-about:epiphany");
+#ifndef HAVE_WEBKIT2
+ /* FIXME: This #ifndef should be removed once bug #695437 is fixed. */
+ check_ephy_web_view_address (view, "ephy-about:epiphany");
+#endif
}
/* Causing a session load here should not create new windows, since we
@@ -309,6 +429,7 @@ test_ephy_session_open_empty_uri_forces_new_window (void)
open_uris_after_loading_session (uris, 3);
}
+#ifndef HAVE_WEBKIT2
static void
test_ephy_session_restore_tabs (void)
{
@@ -351,8 +472,7 @@ test_ephy_session_restore_tabs (void)
/* The active child should now be pointing to the restored tab,
whose address is the one we copied previously. */
embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (l->data));
- g_assert_cmpstr (ephy_web_view_get_address (ephy_embed_get_web_view (embed)),
- ==, url);
+ check_ephy_web_view_address (ephy_embed_get_web_view (embed), url);
g_free (url);
ephy_session_clear (session);
@@ -377,6 +497,7 @@ test_ephy_session_restore_tabs (void)
enable_delayed_loading ();
ephy_session_clear (session);
}
+#endif
int
main (int argc, char *argv[])
@@ -420,8 +541,10 @@ main (int argc, char *argv[])
g_test_add_func ("/src/ephy-session/open-empty-uri-forces-new-window",
test_ephy_session_open_empty_uri_forces_new_window);
+#ifndef HAVE_WEBKIT2
g_test_add_func("/src/ephy-session/restore-tabs",
test_ephy_session_restore_tabs);
+#endif
ret = g_test_run ();