From b45047739e9ebc02200267a52295f24adf4ca668 Mon Sep 17 00:00:00 2001 From: Gustavo Noronha Silva Date: Fri, 22 Feb 2013 15:38:01 -0300 Subject: Add setting for delayed tab loading, and use it to fix the session tests The session tests were broken by the delayed tab loading feature - the restored embeds would not finish loading and thus the expectations for the URIs were not met. This change adds a setting that is now used by those tests to disable the feature temporarily. Also revert "ephy-session-test: make tests pass", which is no longer necessary. This reverts commit 75da5fff3f4489dacf4ded6f012daa06af306709. https://bugzilla.gnome.org/show_bug.cgi?id=694470 --- data/org.gnome.epiphany.gschema.xml | 5 +++++ lib/ephy-prefs.h | 1 + src/ephy-session.c | 21 +++++++++++++++--- tests/ephy-session-test.c | 43 ++++++++++++++++++++++++++++++++++--- 4 files changed, 64 insertions(+), 6 deletions(-) diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml index becb0a23d..b815635cc 100644 --- a/data/org.gnome.epiphany.gschema.xml +++ b/data/org.gnome.epiphany.gschema.xml @@ -54,6 +54,11 @@ Whether to automatically restore the last session Defines how the session will be restored during startup. Allowed values are 'always' (the previous state of the application is always restored), 'crashed' (the session is only restored if the application crashes) and 'never' (the homepage is always shown). + + true + Whether to delay loading of tabs that are not immediately visible on session restore + When this option is set to true, tabs will not start loading until the user switches to them, upon session restore. + diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h index c390e37a1..7fe2aeebd 100644 --- a/lib/ephy-prefs.h +++ b/lib/ephy-prefs.h @@ -123,6 +123,7 @@ typedef enum #define EPHY_PREFS_ENABLE_CARET_BROWSING "enable-caret-browsing" #define EPHY_PREFS_INTERNAL_VIEW_SOURCE "internal-view-source" #define EPHY_PREFS_RESTORE_SESSION_POLICY "restore-session-policy" +#define EPHY_PREFS_RESTORE_SESSION_DELAYING_LOADS "restore-session-delaying-loads" #define EPHY_PREFS_LOCKDOWN_SCHEMA "org.gnome.Epiphany.lockdown" #define EPHY_PREFS_LOCKDOWN_FULLSCREEN "disable-fullscreen" diff --git a/src/ephy-session.c b/src/ephy-session.c index 82ecf4149..1099cddbb 100644 --- a/src/ephy-session.c +++ b/src/ephy-session.c @@ -1105,16 +1105,31 @@ session_parse_embed (SessionParserContext *context, EphyNewTabFlags flags; EphyEmbed *embed; EphyWebView *web_view; + gboolean delay_loading; + + delay_loading = g_settings_get_boolean (EPHY_SETTINGS_MAIN, + EPHY_PREFS_RESTORE_SESSION_DELAYING_LOADS); flags = EPHY_NEW_TAB_IN_EXISTING_WINDOW; flags |= EPHY_NEW_TAB_APPEND_LAST; - flags |= EPHY_NEW_TAB_DELAYED_OPEN_PAGE; + + if (delay_loading) + { + flags |= EPHY_NEW_TAB_DELAYED_OPEN_PAGE; + } + else + { + flags |= EPHY_NEW_TAB_OPEN_PAGE; + } embed = ephy_shell_new_tab (ephy_shell_get_default (), context->window, NULL, url, flags); - web_view = ephy_embed_get_web_view (embed); - ephy_web_view_set_placeholder (web_view, url, title); + if (delay_loading) + { + web_view = ephy_embed_get_web_view (embed); + ephy_web_view_set_placeholder (web_view, url, title); + } } else if (was_loading && url != NULL) { diff --git a/tests/ephy-session-test.c b/tests/ephy-session-test.c index 01d10aa62..eda9ab497 100644 --- a/tests/ephy-session-test.c +++ b/tests/ephy-session-test.c @@ -25,6 +25,7 @@ #include "ephy-embed-private.h" #include "ephy-file-helpers.h" #include "ephy-private.h" +#include "ephy-settings.h" #include "ephy-shell.h" #include "ephy-session.h" @@ -71,6 +72,22 @@ load_session_from_string (EphySession *session, return load_stream_retval; } +static void +enable_delayed_loading (void) +{ + g_settings_set_boolean (EPHY_SETTINGS_MAIN, + EPHY_PREFS_RESTORE_SESSION_DELAYING_LOADS, + TRUE); +} + +static void +disable_delayed_loading (void) +{ + g_settings_set_boolean (EPHY_SETTINGS_MAIN, + EPHY_PREFS_RESTORE_SESSION_DELAYING_LOADS, + FALSE); +} + static void test_ephy_session_load (void) { @@ -80,6 +97,8 @@ test_ephy_session_load (void) EphyEmbed *embed; EphyWebView *view; + disable_delayed_loading (); + session = ephy_shell_get_session (ephy_shell_get_default ()); g_assert (session); @@ -94,9 +113,11 @@ 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), ==, "about:memory"); + g_assert_cmpstr (ephy_web_view_get_address (view), ==, "ephy-about:memory"); ephy_session_clear (session); + + enable_delayed_loading (); } const char *session_data_many_windows = @@ -116,6 +137,8 @@ test_ephy_session_clear (void) EphySession *session; GList *l; + disable_delayed_loading (); + session = EPHY_SESSION (ephy_shell_get_session (ephy_shell_get_default ())); load_session_from_string (session, session_data_many_windows); @@ -140,6 +163,8 @@ test_ephy_session_load_empty_session (void) EphyEmbed *embed; EphyWebView *view; + disable_delayed_loading (); + session = ephy_shell_get_session (ephy_shell_get_default ()); g_assert (session); @@ -163,6 +188,7 @@ test_ephy_session_load_empty_session (void) g_assert (view); g_assert_cmpstr (ephy_web_view_get_address (view), ==, "ephy-about:overview"); + enable_delayed_loading (); ephy_session_clear (session); } @@ -175,6 +201,8 @@ test_ephy_session_load_many_windows (void) EphyEmbed *embed; EphyWebView *view; + disable_delayed_loading (); + session = ephy_shell_get_session (ephy_shell_get_default ()); g_assert (session); @@ -190,9 +218,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), ==, "about:epiphany"); + g_assert_cmpstr (ephy_web_view_get_address (view), ==, "ephy-about:epiphany"); } + enable_delayed_loading (); ephy_session_clear (session); } @@ -206,6 +235,8 @@ open_uris_after_loading_session (const char** uris, int final_num_windows) EphyWebView *view; guint32 user_time; + disable_delayed_loading (); + session = ephy_shell_get_session (ephy_shell_get_default ()); g_assert (session); @@ -224,7 +255,7 @@ 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), ==, "about:epiphany"); + g_assert_cmpstr (ephy_web_view_get_address (view), ==, "ephy-about:epiphany"); } /* Causing a session load here should not create new windows, since we @@ -258,6 +289,7 @@ open_uris_after_loading_session (const char** uris, int final_num_windows) g_assert (l); g_assert_cmpint (g_list_length (l), ==, final_num_windows); + enable_delayed_loading (); ephy_session_clear (session); } @@ -289,6 +321,8 @@ test_ephy_session_restore_tabs (void) int n_windows; EphyEmbed *embed; + disable_delayed_loading (); + /* Nothing to restore. */ g_assert (ephy_session_get_can_undo_tab_closed (session) == FALSE); @@ -340,6 +374,7 @@ test_ephy_session_restore_tabs (void) /* We have the same amount of windows than before destroying one. */ g_assert_cmpint (n_windows, ==, g_list_length (gtk_application_get_windows (GTK_APPLICATION (ephy_shell_get_default())))); + enable_delayed_loading (); ephy_session_clear (session); } @@ -348,6 +383,8 @@ main (int argc, char *argv[]) { int ret; + setenv ("GSETTINGS_BACKEND", "memory", TRUE); + gtk_test_init (&argc, &argv); ephy_debug_init (); -- cgit v1.2.3