[epiphany] ephy-session-test: add tests for tab restoring API



commit 0d728a011be9ff6f96c5296f5fe3b33564114a81
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Thu Feb 7 10:24:25 2013 +0200

    ephy-session-test: add tests for tab restoring API
    
    https://bugzilla.gnome.org/show_bug.cgi?id=128184

 tests/ephy-session-test.c |   69 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/tests/ephy-session-test.c b/tests/ephy-session-test.c
index 8ba3203..fc425d0 100644
--- a/tests/ephy-session-test.c
+++ b/tests/ephy-session-test.c
@@ -276,6 +276,72 @@ test_ephy_session_open_empty_uri_forces_new_window (void)
     open_uris_after_loading_session (uris, 3);
 }
 
+static void
+test_ephy_session_restore_tabs (void)
+{
+  EphySession *session = EPHY_SESSION (ephy_shell_get_session (ephy_shell_get_default ()));
+  const char* uris[] = { "ephy-about:epiphany", "ephy-about:config", NULL };
+  guint32 user_time = gdk_x11_display_get_user_time (gdk_display_get_default ());
+  gboolean ret;
+  GList *l;
+  gchar *url;
+  int n_windows;
+  EphyEmbed *embed;
+
+  /* Nothing to restore. */
+  g_assert (ephy_session_get_can_undo_tab_closed (session) == FALSE);
+
+  ephy_shell_open_uris (ephy_shell_get_default(), uris, 0, user_time);
+  while (gtk_events_pending ())
+    gtk_main_iteration_do (FALSE);
+
+  /* Nothing to restore, again. */
+  g_assert (ephy_session_get_can_undo_tab_closed (session) == FALSE);
+
+  l = ephy_shell_get_windows (ephy_shell_get_default ());
+  embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (l->data));
+  url = g_strdup (ephy_web_view_get_address (ephy_embed_get_web_view (embed)));
+  gtk_widget_destroy (GTK_WIDGET (embed));
+
+  /* There should be now at least one tab that can be restored. */
+  g_assert (ephy_session_get_can_undo_tab_closed (session) == TRUE);
+
+  ephy_session_undo_close_tab (session);
+  while (gtk_events_pending ())
+    gtk_main_iteration_do (FALSE);
+
+  /* Nothing to restore, again. */
+  g_assert (ephy_session_get_can_undo_tab_closed (session) == FALSE);
+
+  /* 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);
+  g_free (url);
+
+  ephy_session_clear (session);
+
+  ret = load_session_from_string (session, session_data_many_windows);
+  g_assert (ret);
+
+  l = ephy_shell_get_windows (ephy_shell_get_default ());
+  n_windows = g_list_length (l);
+  /* We need more than one window for the next test to make sense. */
+  g_assert_cmpint (n_windows, >, 1);
+  gtk_widget_destroy (GTK_WIDGET (l->data));
+  /* One window is gone. */
+  g_assert_cmpint (n_windows, ==, g_list_length (ephy_shell_get_windows (ephy_shell_get_default())) + 1);
+  g_assert (ephy_session_get_can_undo_tab_closed (session) == TRUE);
+  ephy_session_undo_close_tab (session);
+  while (gtk_events_pending ())
+    gtk_main_iteration_do (FALSE);
+  /* We have the same amount of windows than before destroying one. */
+  g_assert_cmpint (n_windows, ==, g_list_length (ephy_shell_get_windows (ephy_shell_get_default())));
+
+  ephy_session_clear (session);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -316,6 +382,9 @@ 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);
 
+  g_test_add_func("/src/ephy-session/restore-tabs",
+                  test_ephy_session_restore_tabs);
+
   ret = g_test_run ();
 
   g_object_unref (ephy_shell_get_default ());


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