[epiphany/gnome-3-20] Fix search provider horribly breaking history service



commit 2be9ad7a4f1601d20426279b3c263328bb7d4432
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sat Feb 18 20:47:50 2017 -0600

    Fix search provider horribly breaking history service
    
    If the search provider is running, all database transactions will fail
    because the search provider will take a write lock on the database.
    Ouch! This is worth a good string of profanities....
    
    Notably, this causes opening the database to fail if you searched for
    anything in the shell overview in the minute prior to starting Epiphany.
    (One minute is our search provider timeout.) Then no history will ever
    get saved, ever. I think. Something like that.
    
    So, although our history service has read-only mode, it's enforced at
    the history service level, not the SQLite connection level. SQLite
    actually has a read-only mode, which we are not using, and which we need
    to use in the search provider if we want to have any chance of reliably
    saving history.
    
    Accordingly, give EphySQLiteConnection a mode property, to indicate
    whether it is in writable mode or read-only mode. Teach all callers to
    set it properly. Use it, rather than a boolean, when creating the
    EphyHistoryService, since boolean parameters are hard to read at call
    sites. And actually put the underlying SQLite connection in read-only
    mode when set.
    
    Don't open transactions or ever attempt to rollback in read-only mode,
    because that doesn't make any sense. This should never have been
    happening due to the history service level read-only checks, but it
    should be enforced at the SQLite connection level now, too.
    
    Avoid initializing tables when opening the database in read-only mode.
    This is obviously writing to the database, and now that we really have a
    read-only SQLite connection it fails. As it should.
    
    SQLite connection creation will now fail in case the connection is
    read-only and the database does not yet exist; it will no longer be
    created anyway. So handle this case gracefully. It's fine for the
    history service to return nothing in this case. This has the small
    advantage that the history thread will quit immediately after it's
    created in this case, so it's not constantly running if there's no
    history in incognito mode anymore. To check for this condition, we
    expose the underlying SQLite error; previously, only the error message
    was exposed outside of EphySQLiteConnection. Exposing the error isn't
    really necessary or sufficient, though, since it's super generic and we
    have to check if the file actually exists on disk anyway.
    
    Test it. Ensure that a read/write history service functions properly if
    it's running at the same time as a read-only history service. Using two
    read/write services here fails very badly, but when one of the services
    is read-only it works fine.
    
    Also, remove the original read-only service test. It only ever tested
    that creating a read-only history service with an empty history database
    would succeed. And, as I just explained, that fails now.
    
    Lastly, stop running a second history service for the search provider.
    It needed its own once upon a time when the search provider did not run
    an EphyShell instance. That changed when we stopped using the default
    web context, because nothing works without EphyEmbedShell now, as all
    sorts of places need it to get the embed's web context. And since
    EphyEmbedShell runs its own history service, the search provider can
    just use that now instead of running its own separate one.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=778649

 embed/ephy-embed-shell.c           |   10 ++++-
 lib/Makefile.am                    |    3 +-
 lib/ephy-profile-migrator.c        |    2 +-
 lib/ephy-sqlite-connection.c       |   70 +++++++++++++++++++++++++++++++----
 lib/ephy-sqlite-connection.h       |   13 ++++++-
 lib/history/ephy-history-service.c |   18 +++++++---
 lib/history/ephy-history-service.h |    4 ++-
 src/ephy-search-provider.c         |    8 ++--
 tests/ephy-history-test.c          |   64 ++++++++++++++++++++------------
 tests/ephy-sqlite-test.c           |    2 +-
 10 files changed, 146 insertions(+), 48 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index cd74f7d..9fd6b6d 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -402,10 +402,16 @@ ephy_embed_shell_get_global_history_service (EphyEmbedShell *shell)
 
   if (priv->global_history_service == NULL) {
     char *filename;
+    EphySQLiteConnectionMode mode;
+
+    if (priv->mode == EPHY_EMBED_SHELL_MODE_INCOGNITO ||
+        priv->mode == EPHY_EMBED_SHELL_MODE_SEARCH_PROVIDER)
+      mode = EPHY_SQLITE_CONNECTION_MODE_READ_ONLY;
+    else
+      mode = EPHY_SQLITE_CONNECTION_MODE_READWRITE;
 
     filename = g_build_filename (ephy_dot_dir (), EPHY_HISTORY_FILE, NULL);
-    priv->global_history_service = ephy_history_service_new (filename,
-                                                             priv->mode == EPHY_EMBED_SHELL_MODE_INCOGNITO);
+    priv->global_history_service = ephy_history_service_new (filename, mode);
     g_free (filename);
     g_return_val_if_fail (priv->global_history_service, NULL);
     g_signal_connect (priv->global_history_service, "urls-visited",
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 4dc98e6..36e6c14 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -8,7 +8,8 @@ noinst_LTLIBRARIES = libephymisc.la
 TYPES_H_FILES = \
        ephy-initial-state.h                    \
        ephy-node.h                             \
-       ephy-security-levels.h
+       ephy-security-levels.h                  \
+       ephy-sqlite-connection.h
 
 libephymisc_la_SOURCES = \
        ephy-dbus-util.c                        \
diff --git a/lib/ephy-profile-migrator.c b/lib/ephy-profile-migrator.c
index 59bfb52..da21466 100644
--- a/lib/ephy-profile-migrator.c
+++ b/lib/ephy-profile-migrator.c
@@ -780,7 +780,7 @@ migrate_new_urls_table (void)
   GError *error = NULL;
 
   filename = g_build_filename (ephy_dot_dir (), EPHY_HISTORY_FILE, NULL);
-  history_database = ephy_sqlite_connection_new ();
+  history_database = ephy_sqlite_connection_new (EPHY_SQLITE_CONNECTION_MODE_READWRITE);
   ephy_sqlite_connection_open (history_database, filename, &error);
 
   if (error) {
diff --git a/lib/ephy-sqlite-connection.c b/lib/ephy-sqlite-connection.c
index 273f9d6..eff774d 100644
--- a/lib/ephy-sqlite-connection.c
+++ b/lib/ephy-sqlite-connection.c
@@ -18,15 +18,27 @@
 #include "config.h"
 #include "ephy-sqlite-connection.h"
 
+#include "ephy-lib-type-builtins.h"
+
 #include <sqlite3.h>
 
 struct _EphySQLiteConnection {
   GObject parent_instance;
+
   sqlite3 *database;
+  EphySQLiteConnectionMode mode;
 };
 
 G_DEFINE_TYPE (EphySQLiteConnection, ephy_sqlite_connection, G_TYPE_OBJECT);
 
+enum {
+  PROP_0,
+  PROP_MODE,
+  LAST_PROP
+};
+
+static GParamSpec *obj_properties[LAST_PROP];
+
 static void
 ephy_sqlite_connection_finalize (GObject *self)
 {
@@ -35,10 +47,40 @@ ephy_sqlite_connection_finalize (GObject *self)
 }
 
 static void
+ephy_sqlite_connection_set_property (GObject      *object,
+                                     guint         property_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec)
+{
+  EphySQLiteConnection *self = EPHY_SQLITE_CONNECTION (object);
+
+  switch (property_id) {
+    case PROP_MODE:
+      self->mode = g_value_get_enum (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (self, property_id, pspec);
+      break;
+  }
+}
+
+static void
 ephy_sqlite_connection_class_init (EphySQLiteConnectionClass *klass)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  object_class->finalize = ephy_sqlite_connection_finalize;
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  gobject_class->finalize = ephy_sqlite_connection_finalize;
+  gobject_class->set_property = ephy_sqlite_connection_set_property;
+
+  obj_properties[PROP_MODE] =
+    g_param_spec_enum ("mode",
+                       "SQLite connection mode",
+                       "Whether the SQLite connection is read-only or writable",
+                       EPHY_TYPE_SQ_LITE_CONNECTION_MODE,
+                       EPHY_SQLITE_CONNECTION_MODE_READWRITE,
+                       G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (gobject_class, LAST_PROP, obj_properties);
 }
 
 static void
@@ -47,7 +89,7 @@ ephy_sqlite_connection_init (EphySQLiteConnection *self)
   self->database = NULL;
 }
 
-static GQuark get_ephy_sqlite_quark (void)
+GQuark ephy_sqlite_error_quark (void)
 {
   return g_quark_from_static_string ("ephy-sqlite");
 }
@@ -56,13 +98,15 @@ static void
 set_error_from_string (const char *string, GError **error)
 {
   if (error)
-    *error = g_error_new_literal (get_ephy_sqlite_quark (), 0, string);
+    *error = g_error_new_literal (ephy_sqlite_error_quark (), 0, string);
 }
 
 EphySQLiteConnection *
-ephy_sqlite_connection_new (void)
+ephy_sqlite_connection_new (EphySQLiteConnectionMode mode)
 {
-  return EPHY_SQLITE_CONNECTION (g_object_new (EPHY_TYPE_SQLITE_CONNECTION, NULL));
+  return EPHY_SQLITE_CONNECTION (g_object_new (EPHY_TYPE_SQLITE_CONNECTION,
+                                               "mode", mode,
+                                               NULL));
 }
 
 gboolean
@@ -73,7 +117,11 @@ ephy_sqlite_connection_open (EphySQLiteConnection *self, const gchar *filename,
     return FALSE;
   }
 
-  if (sqlite3_open (filename, &self->database) != SQLITE_OK) {
+  if (sqlite3_open_v2 (filename,
+                       &self->database,
+                       self->mode == EPHY_SQLITE_CONNECTION_MODE_READ_ONLY ? SQLITE_OPEN_READONLY
+                                                                           : SQLITE_OPEN_READWRITE | 
SQLITE_OPEN_CREATE,
+                       NULL) != SQLITE_OK) {
     ephy_sqlite_connection_get_error (self, error);
     self->database = NULL;
     return FALSE;
@@ -95,7 +143,7 @@ void
 ephy_sqlite_connection_get_error (EphySQLiteConnection *self, GError **error)
 {
   if (error)
-    *error = g_error_new_literal (get_ephy_sqlite_quark (), 0, sqlite3_errmsg (self->database));
+    *error = g_error_new_literal (ephy_sqlite_error_quark (), sqlite3_errcode (self->database), 
sqlite3_errmsg (self->database));
 }
 
 gboolean
@@ -143,18 +191,24 @@ ephy_sqlite_connection_get_last_insert_id (EphySQLiteConnection *self)
 gboolean
 ephy_sqlite_connection_begin_transaction (EphySQLiteConnection *self, GError **error)
 {
+  if (self->mode == EPHY_SQLITE_CONNECTION_MODE_READ_ONLY)
+    return TRUE;
   return ephy_sqlite_connection_execute (self, "BEGIN TRANSACTION", error);
 }
 
 gboolean
 ephy_sqlite_connection_rollback_transaction (EphySQLiteConnection *self, GError **error)
 {
+  if (self->mode == EPHY_SQLITE_CONNECTION_MODE_READ_ONLY)
+    return TRUE;
   return ephy_sqlite_connection_execute (self, "ROLLBACK", error);
 }
 
 gboolean
 ephy_sqlite_connection_commit_transaction (EphySQLiteConnection *self, GError **error)
 {
+  if (self->mode == EPHY_SQLITE_CONNECTION_MODE_READ_ONLY)
+    return TRUE;
   return ephy_sqlite_connection_execute (self, "COMMIT", error);
 }
 
diff --git a/lib/ephy-sqlite-connection.h b/lib/ephy-sqlite-connection.h
index a4b971c..aa9ca33 100644
--- a/lib/ephy-sqlite-connection.h
+++ b/lib/ephy-sqlite-connection.h
@@ -21,13 +21,20 @@
 #include <glib-object.h>
 #include "ephy-sqlite-statement.h"
 
+#include <sqlite3.h>
+
 G_BEGIN_DECLS
 
 #define EPHY_TYPE_SQLITE_CONNECTION (ephy_sqlite_connection_get_type ())
 
 G_DECLARE_FINAL_TYPE (EphySQLiteConnection, ephy_sqlite_connection, EPHY, SQLITE_CONNECTION, GObject)
 
-EphySQLiteConnection *  ephy_sqlite_connection_new                     (void);
+typedef enum {
+  EPHY_SQLITE_CONNECTION_MODE_READ_ONLY,
+  EPHY_SQLITE_CONNECTION_MODE_READWRITE
+} EphySQLiteConnectionMode;
+
+EphySQLiteConnection *  ephy_sqlite_connection_new                     (EphySQLiteConnectionMode mode);
 
 gboolean                ephy_sqlite_connection_open                    (EphySQLiteConnection *self, const 
gchar *filename, GError **error);
 void                    ephy_sqlite_connection_close                   (EphySQLiteConnection *self);
@@ -44,6 +51,10 @@ gboolean                ephy_sqlite_connection_commit_transaction      (EphySQLi
 
 gboolean                ephy_sqlite_connection_table_exists            (EphySQLiteConnection *self, const 
char *table_name);
 
+GQuark                  ephy_sqlite_error_quark                        (void);
+
+#define EPHY_SQLITE_ERROR ephy_sqlite_error_quark ()
+
 G_END_DECLS
 
 #endif /* EPHY_SQLITE_CONNECTION_H */
diff --git a/lib/history/ephy-history-service.c b/lib/history/ephy-history-service.c
index 276f264..6cafd46 100644
--- a/lib/history/ephy-history-service.c
+++ b/lib/history/ephy-history-service.c
@@ -266,12 +266,12 @@ ephy_history_service_init (EphyHistoryService *self)
 }
 
 EphyHistoryService *
-ephy_history_service_new (const char *history_filename,
-                          gboolean    read_only)
+ephy_history_service_new (const char               *history_filename,
+                          EphySQLiteConnectionMode  mode)
 {
   return EPHY_HISTORY_SERVICE (g_object_new (EPHY_TYPE_HISTORY_SERVICE,
                                              "history-filename", history_filename,
-                                             "read-only", read_only,
+                                             "read-only", mode == EPHY_SQLITE_CONNECTION_MODE_READ_ONLY,
                                              NULL));
 }
 
@@ -371,12 +371,20 @@ ephy_history_service_open_database_connections (EphyHistoryService *self)
 
   g_assert (self->history_thread == g_thread_self ());
 
-  self->history_database = ephy_sqlite_connection_new ();
+  self->history_database = ephy_sqlite_connection_new (self->read_only ? 
EPHY_SQLITE_CONNECTION_MODE_READ_ONLY
+                                                                       : 
EPHY_SQLITE_CONNECTION_MODE_READWRITE);
   ephy_sqlite_connection_open (self->history_database, self->history_filename, &error);
   if (error) {
     g_object_unref (self->history_database);
     self->history_database = NULL;
-    g_warning ("Could not open history database at %s: %s", self->history_filename, error->message);
+
+    /* Opening the database is expected to fail if it's being opened in read-
+     * only mode and does not already exist. Otherwise, this is bad. */
+    if (!self->read_only ||
+        !g_error_matches (error, EPHY_SQLITE_ERROR, SQLITE_CANTOPEN) ||
+        g_file_test (self->history_filename, G_FILE_TEST_EXISTS)) {
+      g_warning ("Could not open history database at %s: %s", self->history_filename, error->message);
+    }
     g_error_free (error);
     return FALSE;
   }
diff --git a/lib/history/ephy-history-service.h b/lib/history/ephy-history-service.h
index 0436fdc..963f493 100644
--- a/lib/history/ephy-history-service.h
+++ b/lib/history/ephy-history-service.h
@@ -22,7 +22,9 @@
 
 #include <glib-object.h>
 #include <gio/gio.h>
+
 #include "ephy-history-types.h"
+#include "ephy-sqlite-connection.h"
 
 G_BEGIN_DECLS
 
@@ -32,7 +34,7 @@ G_DECLARE_FINAL_TYPE (EphyHistoryService, ephy_history_service, EPHY, HISTORY_SE
 
 typedef void   (*EphyHistoryJobCallback)          (EphyHistoryService *service, gboolean success, gpointer 
result_data, gpointer user_data);
 
-EphyHistoryService *     ephy_history_service_new                     (const char *history_filename, 
gboolean read_only);
+EphyHistoryService *     ephy_history_service_new                     (const char *history_filename, 
EphySQLiteConnectionMode mode);
 
 void                     ephy_history_service_add_visit               (EphyHistoryService *self, 
EphyHistoryPageVisit *visit, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
 void                     ephy_history_service_add_visits              (EphyHistoryService *self, GList 
*visits, GCancellable *cancellable, EphyHistoryJobCallback callback, gpointer user_data);
diff --git a/src/ephy-search-provider.c b/src/ephy-search-provider.c
index e1231dc..d97d021 100644
--- a/src/ephy-search-provider.c
+++ b/src/ephy-search-provider.c
@@ -20,6 +20,7 @@
 #include "ephy-search-provider.h"
 
 #include "ephy-completion-model.h"
+#include "ephy-embed-shell.h"
 #include "ephy-file-helpers.h"
 #include "ephy-prefs.h"
 #include "ephy-profile-utils.h"
@@ -37,7 +38,6 @@ struct _EphySearchProvider {
   GCancellable             *cancellable;
 
   GSettings                *settings;
-  EphyHistoryService       *history_service;
   EphyBookmarks            *bookmarks;
   EphyCompletionModel      *model;
 };
@@ -345,6 +345,7 @@ static void
 ephy_search_provider_init (EphySearchProvider *self)
 {
   char *filename;
+  EphyEmbedShell *shell = ephy_embed_shell_get_default ();
 
   g_application_set_flags (G_APPLICATION (self), G_APPLICATION_IS_SERVICE);
 
@@ -364,9 +365,9 @@ ephy_search_provider_init (EphySearchProvider *self)
   self->settings = g_settings_new (EPHY_PREFS_SCHEMA);
 
   filename = g_build_filename (ephy_dot_dir (), EPHY_HISTORY_FILE, NULL);
-  self->history_service = ephy_history_service_new (filename, TRUE);
   self->bookmarks = ephy_bookmarks_new ();
-  self->model = ephy_completion_model_new (self->history_service, self->bookmarks);
+  self->model = ephy_completion_model_new (EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service 
(shell)),
+                                           self->bookmarks);
   g_free (filename);
 
   self->cancellable = g_cancellable_new ();
@@ -425,7 +426,6 @@ ephy_search_provider_dispose (GObject *object)
   g_clear_object (&self->settings);
   g_clear_object (&self->cancellable);
   g_clear_object (&self->model);
-  g_clear_object (&self->history_service);
   g_clear_object (&self->bookmarks);
 
   G_OBJECT_CLASS (ephy_search_provider_parent_class)->dispose (object);
diff --git a/tests/ephy-history-test.c b/tests/ephy-history-test.c
index ade796c..5ee6181 100644
--- a/tests/ephy-history-test.c
+++ b/tests/ephy-history-test.c
@@ -27,29 +27,19 @@
 #include <gtk/gtk.h>
 
 static EphyHistoryService *
-ensure_empty_history (const char *filename, gboolean readonly)
+ensure_empty_history (const char *filename)
 {
   if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
     g_unlink (filename);
 
-  return ephy_history_service_new (filename, readonly);
+  return ephy_history_service_new (filename, EPHY_SQLITE_CONNECTION_MODE_READWRITE);
 }
 
 static void
 test_create_history_service (void)
 {
   gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
-  EphyHistoryService *service = ensure_empty_history (temporary_file, FALSE);
-
-  g_free (temporary_file);
-  g_object_unref (service);
-}
-
-static void
-test_create_readonly_history_service (void)
-{
-  gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
-  EphyHistoryService *service = ensure_empty_history (temporary_file, TRUE);
+  EphyHistoryService *service = ensure_empty_history (temporary_file);
 
   g_free (temporary_file);
   g_object_unref (service);
@@ -69,7 +59,7 @@ static void
 test_create_history_service_and_destroy_later (void)
 {
   gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
-  EphyHistoryService *service = ensure_empty_history (temporary_file, FALSE);
+  EphyHistoryService *service = ensure_empty_history (temporary_file);
   g_free (temporary_file);
   g_timeout_add (100, (GSourceFunc)destroy_history_service_and_end_main_loop, service);
 
@@ -79,9 +69,12 @@ test_create_history_service_and_destroy_later (void)
 static void
 page_vist_created (EphyHistoryService *service, gboolean success, gpointer result_data, gpointer user_data)
 {
+  if (user_data != NULL) {
+    g_assert (EPHY_IS_HISTORY_SERVICE (user_data));
+    g_object_unref (user_data);
+  }
   g_object_unref (service);
   g_assert (result_data == NULL);
-  g_assert (user_data == NULL);
   g_assert (success);
   gtk_main_quit ();
 }
@@ -90,7 +83,7 @@ static void
 test_create_history_entry (void)
 {
   gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
-  EphyHistoryService *service = ensure_empty_history (temporary_file, FALSE);
+  EphyHistoryService *service = ensure_empty_history (temporary_file);
 
   EphyHistoryPageVisit *visit = ephy_history_page_visit_new ("http://www.gnome.org";, 0, 
EPHY_PAGE_VISIT_TYPED);
   ephy_history_service_add_visit (service, visit, NULL, page_vist_created, NULL);
@@ -100,6 +93,29 @@ test_create_history_entry (void)
   gtk_main ();
 }
 
+static void
+test_readonly_mode (void)
+{
+  gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
+  /* FIXME: This is racy, since we need to be sure the history thread of the
+   * first EphyHistoryService object has created the database before starting
+   * the history thread of the second EphyHistoryService object. This is a test
+   * bug, not an application bug.
+   */
+  EphyHistoryService *service = ensure_empty_history (temporary_file);
+  EphyHistoryService *readonly_service = ephy_history_service_new (temporary_file, 
EPHY_SQLITE_CONNECTION_MODE_READ_ONLY);
+
+  /* Having the database open read-only should not break normal connections.
+   * https://bugzilla.gnome.org/show_bug.cgi?id=778649 */
+  EphyHistoryPageVisit *visit = ephy_history_page_visit_new ("http://www.gnome.org";, 0, 
EPHY_PAGE_VISIT_TYPED);
+  ephy_history_service_add_visit (service, visit, NULL, page_vist_created, readonly_service);
+  ephy_history_page_visit_free (visit);
+  g_free (temporary_file);
+
+  gtk_main ();
+}
+
+
 static GList *
 create_test_page_visit_list (void)
 {
@@ -163,7 +179,7 @@ static void
 test_create_history_entries (void)
 {
   gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
-  EphyHistoryService *service = ensure_empty_history (temporary_file, FALSE);
+  EphyHistoryService *service = ensure_empty_history (temporary_file);
 
   GList *visits = create_test_page_visit_list ();
 
@@ -212,7 +228,7 @@ static void
 test_set_url_title_helper (gboolean test_results)
 {
   gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
-  EphyHistoryService *service = ensure_empty_history (temporary_file, FALSE);
+  EphyHistoryService *service = ensure_empty_history (temporary_file);
 
   EphyHistoryPageVisit *visit = ephy_history_page_visit_new ("http://www.gnome.org";, 0, 
EPHY_PAGE_VISIT_TYPED);
   ephy_history_service_add_visit (service, visit, NULL, set_url_title_visit_created, GINT_TO_POINTER 
(test_results));
@@ -246,7 +262,7 @@ static void
 test_set_url_title_url_not_existent (void)
 {
   gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
-  EphyHistoryService *service = ensure_empty_history (temporary_file, FALSE);
+  EphyHistoryService *service = ensure_empty_history (temporary_file);
   g_free (temporary_file);
 
   ephy_history_service_set_url_title (service, "http://www.gnome.org";, "GNOME", NULL, 
set_url_title_url_not_existent, NULL);
@@ -288,7 +304,7 @@ static void
 test_get_url_helper (gboolean add_entry)
 {
   gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
-  EphyHistoryService *service = ensure_empty_history (temporary_file, FALSE);
+  EphyHistoryService *service = ensure_empty_history (temporary_file);
   g_free (temporary_file);
 
   if (add_entry == TRUE) {
@@ -385,7 +401,7 @@ static void
 test_complex_url_query (void)
 {
   gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
-  EphyHistoryService *service = ensure_empty_history (temporary_file, FALSE);
+  EphyHistoryService *service = ensure_empty_history (temporary_file);
   GList *visits;
 
   visits = create_visits_for_complex_tests ();
@@ -425,7 +441,7 @@ static void
 test_complex_url_query_with_time_range (void)
 {
   gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
-  EphyHistoryService *service = ensure_empty_history (temporary_file, FALSE);
+  EphyHistoryService *service = ensure_empty_history (temporary_file);
   GList *visits;
 
   visits = create_visits_for_complex_tests ();
@@ -474,7 +490,7 @@ static void
 test_clear (void)
 {
   gchar *temporary_file = g_build_filename (g_get_tmp_dir (), "epiphany-history-test.db", NULL);
-  EphyHistoryService *service = ensure_empty_history (temporary_file, FALSE);
+  EphyHistoryService *service = ensure_empty_history (temporary_file);
   GList *visits = create_test_page_visit_list ();
 
   ephy_history_service_add_visits (service, visits, NULL, NULL, NULL);
@@ -489,9 +505,9 @@ main (int argc, char *argv[])
   gtk_test_init (&argc, &argv);
 
   g_test_add_func ("/embed/history/test_create_history_service", test_create_history_service);
-  g_test_add_func ("/embed/history/test_create_readonly_history_service", 
test_create_readonly_history_service);
   g_test_add_func ("/embed/history/test_create_history_service_and_destroy_later", 
test_create_history_service_and_destroy_later);
   g_test_add_func ("/embed/history/test_create_history_entry", test_create_history_entry);
+  g_test_add_func ("/embed/history/test_readonly_mode", test_readonly_mode);
   g_test_add_func ("/embed/history/test_create_history_entries", test_create_history_entries);
   g_test_add_func ("/embed/history/test_set_url_title", test_set_url_title);
   g_test_add_func ("/embed/history/test_set_url_title_is_correct", test_set_url_title_is_correct);
diff --git a/tests/ephy-sqlite-test.c b/tests/ephy-sqlite-test.c
index 8ca8a36..036b99f 100644
--- a/tests/ephy-sqlite-test.c
+++ b/tests/ephy-sqlite-test.c
@@ -29,7 +29,7 @@
 static EphySQLiteConnection *
 ensure_empty_database (const char *filename)
 {
-  EphySQLiteConnection *connection = ephy_sqlite_connection_new ();
+  EphySQLiteConnection *connection = ephy_sqlite_connection_new (EPHY_SQLITE_CONNECTION_MODE_READWRITE);
   GError *error = NULL;
 
   if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))


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