[epiphany] Fix EphyShell tests in WK2 waiting until views are loaded



commit 2541eed4d1dfda432e6663fdaab48081c9fef38c
Author: Manuel Rego Casasnovas <rego igalia com>
Date:   Tue Mar 12 14:18:43 2013 +0100

    Fix EphyShell tests in WK2 waiting until views are loaded
    
    /src/ephy-shell/tab_load and /src/ephy-shell/tab_from_external tests were
    failing because of the same issue than session tests. We were not waiting till
    the views reach the committed load status in order to check the address.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695646

 tests/Makefile.am       |    4 ++-
 tests/ephy-shell-test.c |   59 +++++++++++++++++++++++++++-------------------
 tests/ephy-test-utils.c |   30 ++++++++++++++++++++++++
 tests/ephy-test-utils.h |    8 ++++++
 4 files changed, 76 insertions(+), 25 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1c82995..6236ad3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -164,7 +164,9 @@ test_ephy_session_SOURCES = \
 test_ephy_shell_SOURCES = \
        $(top_builddir)/src/epiphany-resources.c \
        $(top_builddir)/src/epiphany-resources.h \
-       ephy-shell-test.c
+       ephy-shell-test.c \
+       ephy-test-utils.c \
+       ephy-test-utils.h
 
 test_ephy_snapshot_service_SOURCES = \
        ephy-snapshot-service-test.c
diff --git a/tests/ephy-shell-test.c b/tests/ephy-shell-test.c
index 2be2859..2525cac 100644
--- a/tests/ephy-shell-test.c
+++ b/tests/ephy-shell-test.c
@@ -32,6 +32,7 @@
 #include "ephy-file-helpers.h"
 #include "ephy-private.h"
 #include "ephy-shell.h"
+#include "ephy-test-utils.h"
 #include "ephy-window.h"
 
 #include <glib.h>
@@ -136,7 +137,6 @@ test_ephy_shell_parent_windows (void)
   gtk_widget_destroy (window2);
 }
 
-#ifndef HAVE_WEBKIT2
 static void
 test_ephy_shell_tab_load (void)
 {
@@ -144,35 +144,44 @@ test_ephy_shell_tab_load (void)
   GtkWidget *window;
   EphyEmbed *embed;
   EphyWebView *view;
+  GMainLoop *loop;
 
   ephy_shell = ephy_shell_get_default ();
   window = GTK_WIDGET (ephy_window_new ());
 
+  loop = ephy_test_utils_setup_ensure_web_views_are_loaded ();
+
   /* homepage is "about:blank" for now, see embed/ephy-web-view.c */
   embed = ephy_shell_new_tab
                   (ephy_shell, NULL, NULL, NULL,
                    EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_HOME_PAGE);
 
   g_assert (EPHY_IS_EMBED (embed));
+
+  ephy_test_utils_ensure_web_views_are_loaded (loop);
+
   view = ephy_embed_get_web_view (embed);
-  g_assert_cmpstr (ephy_web_view_get_address (view), ==, "ephy-about:overview");
+  ephy_test_utils_check_ephy_web_view_address (view, "ephy-about:overview");
   g_assert_cmpstr (ephy_web_view_get_typed_address (view), ==, NULL);
 
   g_object_ref_sink (embed);
   g_object_unref (embed);
 
+  loop = ephy_test_utils_setup_ensure_web_views_are_loaded ();
+
   /* open-page "about:epiphany" for testing. */
   embed = ephy_shell_new_tab
                   (ephy_shell, NULL, NULL, "about:epiphany",
                    EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_OPEN_PAGE);
 
   g_assert (EPHY_IS_EMBED (embed));
-  view = ephy_embed_get_web_view (embed);
-  g_assert_cmpstr (ephy_web_view_get_address (view), ==, "ephy-about:epiphany");
+
+  ephy_test_utils_ensure_web_views_are_loaded (loop);
+
+  ephy_test_utils_check_ephy_embed_address (embed, "ephy-about:epiphany");
 
   gtk_widget_destroy (window);
 }
-#endif
 
 static int
 get_notebook_page_num (GtkWidget *notebook, EphyEmbed *embed)
@@ -230,13 +239,13 @@ test_ephy_shell_tab_append (void)
   gtk_widget_destroy (window);
 }
 
-#ifndef HAVE_WEBKIT2
 static void
 test_ephy_shell_tab_from_external (void)
 {
   EphyShell *ephy_shell;
   GtkWidget *window;
   GtkWidget *notebook;
+  GMainLoop *loop;
 
   EphyEmbed *embed;
   EphyEmbed *embed2;
@@ -245,6 +254,9 @@ test_ephy_shell_tab_from_external (void)
   EphyEmbed *embed5;
 
   ephy_shell = ephy_shell_get_default ();
+
+  loop = ephy_test_utils_setup_ensure_web_views_are_loaded ();
+
   embed = ephy_shell_new_tab (ephy_shell, NULL, NULL, "about:epiphany",
                                EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_OPEN_PAGE);
   window = gtk_widget_get_toplevel (GTK_WIDGET (embed));
@@ -261,41 +273,46 @@ test_ephy_shell_tab_from_external (void)
    * loop, fake one so we get a working test. */
   ephy_web_view_load_homepage (ephy_embed_get_web_view (embed2));
 
-  while (g_main_context_pending (NULL))
-      g_main_context_iteration (NULL, FALSE);
-
   embed3 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), NULL, "about:memory",
                                EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_OPEN_PAGE | 
EPHY_NEW_TAB_IN_EXISTING_WINDOW);
   g_assert (gtk_widget_get_toplevel (GTK_WIDGET (embed3)) == window);
 
+  ephy_test_utils_ensure_web_views_are_loaded (loop);
+
   /* This one should fail, because the active embed is not @embed2. */
-  g_assert_cmpstr (ephy_web_view_get_address (ephy_embed_get_web_view (embed2)), ==, "ephy-about:overview");
+  ephy_test_utils_check_ephy_embed_address (embed2, "ephy-about:overview");
   g_assert_cmpint (gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)), ==, 0);
 
+  loop = ephy_test_utils_setup_ensure_web_views_are_loaded ();
+
   embed4 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), NULL, "about:applications",
                                EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_IN_EXISTING_WINDOW | 
EPHY_NEW_TAB_OPEN_PAGE | EPHY_NEW_TAB_FROM_EXTERNAL);
   g_assert (embed4 != embed2);
-  g_assert_cmpstr (ephy_web_view_get_address (ephy_embed_get_web_view (embed2)), ==, "ephy-about:overview");
-  g_assert_cmpstr (ephy_web_view_get_address (ephy_embed_get_web_view (embed4)), ==, 
"ephy-about:applications");
+
+  ephy_test_utils_ensure_web_views_are_loaded (loop);
+
+  ephy_test_utils_check_ephy_embed_address (embed2, "ephy-about:overview");
+  ephy_test_utils_check_ephy_embed_address (embed4, "ephy-about:applications");
 
   gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 1);
 
   /* This should work */
-  g_assert_cmpstr (ephy_web_view_get_address (ephy_embed_get_web_view (embed2)), ==, "ephy-about:overview");
+  ephy_test_utils_check_ephy_embed_address (embed2, "ephy-about:overview");
   g_assert_cmpint (gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)), ==, 1);
   
+  loop = ephy_test_utils_setup_wait_until_load_is_committed (ephy_embed_get_web_view (embed2));
+
   embed5 = ephy_shell_new_tab (ephy_shell, EPHY_WINDOW (window), NULL, "about:applications",
                                EPHY_NEW_TAB_DONT_SHOW_WINDOW | EPHY_NEW_TAB_IN_EXISTING_WINDOW | 
EPHY_NEW_TAB_OPEN_PAGE | EPHY_NEW_TAB_FROM_EXTERNAL);
 
-  while (g_main_context_pending (NULL))
-      g_main_context_iteration (NULL, FALSE);
-
   g_assert (embed5 == embed2);
-  g_assert_cmpstr (ephy_web_view_get_address (ephy_embed_get_web_view (embed5)), ==, 
"ephy-about:applications");
+
+  ephy_test_utils_wait_until_load_is_committed (loop);
+
+  ephy_test_utils_check_ephy_embed_address (embed5, "ephy-about:applications");
 
   gtk_widget_destroy (window);
 }
-#endif
 
 static void
 test_ephy_shell_tab_no_history (void)
@@ -370,20 +387,14 @@ main (int argc, char *argv[])
   g_test_add_func ("/src/ephy-shell/parent_windows",
                    test_ephy_shell_parent_windows);
 
-#ifndef HAVE_WEBKIT2
-  /* FIXME: see https://bugzilla.gnome.org/show_bug.cgi?id=695646 */
   g_test_add_func ("/src/ephy-shell/tab_load",
                    test_ephy_shell_tab_load);
-#endif
 
   g_test_add_func ("/src/ephy-shell/tab_append",
                    test_ephy_shell_tab_append);
 
-#ifndef HAVE_WEBKIT2
-  /* FIXME: see https://bugzilla.gnome.org/show_bug.cgi?id=695646 */
   g_test_add_func ("/src/ephy-shell/tab_from_external",
                    test_ephy_shell_tab_from_external);
-#endif
 
   g_test_add_func ("/src/ephy-shell/tab_no_history",
                    test_ephy_shell_tab_no_history);
diff --git a/tests/ephy-test-utils.c b/tests/ephy-test-utils.c
index 95a90ec..83272de 100644
--- a/tests/ephy-test-utils.c
+++ b/tests/ephy-test-utils.c
@@ -41,6 +41,13 @@ ephy_test_utils_check_ephy_web_view_address (EphyWebView *view,
   g_assert_cmpstr (ephy_web_view_get_address (view), ==, address);
 }
 
+void
+ephy_test_utils_check_ephy_embed_address (EphyEmbed *embed,
+                                          const gchar *address)
+{
+  ephy_test_utils_check_ephy_web_view_address (ephy_embed_get_web_view (embed), address);
+}
+
 static void
 load_changed_cb (WebKitWebView *web_view,
 #ifdef HAVE_WEBKIT2
@@ -105,3 +112,26 @@ ephy_test_utils_ensure_web_views_are_loaded (GMainLoop *loop)
   g_assert_cmpint (web_view_ready_counter, ==, 0);
   g_main_loop_unref (loop);
 }
+
+GMainLoop*
+ephy_test_utils_setup_wait_until_load_is_committed (EphyWebView *view)
+{
+  GMainLoop *loop;
+
+  web_view_ready_counter = 1;
+
+  loop = g_main_loop_new (NULL, FALSE);
+  wait_until_load_is_committed (WEBKIT_WEB_VIEW (view), loop);
+
+  return loop;
+}
+
+void
+ephy_test_utils_wait_until_load_is_committed (GMainLoop *loop)
+{
+  if (web_view_ready_counter != 0)
+    g_main_loop_run (loop);
+
+  g_assert_cmpint (web_view_ready_counter, ==, 0);
+  g_main_loop_unref (loop);
+}
diff --git a/tests/ephy-test-utils.h b/tests/ephy-test-utils.h
index afd05f1..66a9f44 100644
--- a/tests/ephy-test-utils.h
+++ b/tests/ephy-test-utils.h
@@ -24,6 +24,7 @@
 #ifndef EPHY_TEST_UTILS_H
 #define EPHY_TEST_UTILS_H
 
+#include "ephy-embed.h"
 #include "ephy-web-view.h"
 
 #include <glib.h>
@@ -35,10 +36,17 @@ guint ephy_test_utils_get_web_view_ready_counter (void);
 void ephy_test_utils_check_ephy_web_view_address (EphyWebView *view,
                                                   const gchar *address);
 
+void ephy_test_utils_check_ephy_embed_address (EphyEmbed *embed,
+                                               const gchar *address);
+
 GMainLoop* ephy_test_utils_setup_ensure_web_views_are_loaded (void);
 
 void ephy_test_utils_ensure_web_views_are_loaded (GMainLoop *loop);
 
+GMainLoop* ephy_test_utils_setup_wait_until_load_is_committed (EphyWebView *view);
+
+void ephy_test_utils_wait_until_load_is_committed (GMainLoop *loop);
+
 G_END_DECLS
 
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]