[geary/wip/714104-refine-account-dialog] Move CredentialsMediator back to AccountInformation



commit 8fe6d4f85aeba3c6073ef5e32d4c0268374b8758
Author: Michael Gratton <mike vee net>
Date:   Sat Dec 8 13:53:37 2018 +1100

    Move CredentialsMediator back to AccountInformation
    
    In practice, the same mediator is always being used for both services,
    and by removing it from ServiceInformation we can provide default
    instances for both IMAP and SMTP, meaning we can load account config
    before service config, making handling loading for both much tidier.

 src/client/accounts/accounts-editor-add-pane.vala  |   4 +-
 src/client/accounts/accounts-editor-row.vala       |   2 +-
 .../accounts/accounts-editor-servers-pane.vala     |   4 +-
 src/client/accounts/accounts-manager.vala          | 115 ++++++++-------------
 src/client/accounts/add-edit-page.vala             |  11 +-
 src/engine/api/geary-account-information.vala      |  66 ++++++++++--
 src/engine/api/geary-service-information.vala      |  15 +--
 test/client/accounts/accounts-manager-test.vala    |  67 +++++++-----
 .../engine/api/geary-account-information-test.vala |   1 +
 test/engine/api/geary-engine-test.vala             |  52 +++++-----
 test/engine/app/app-conversation-monitor-test.vala |   1 +
 .../engine/imap-engine/account-processor-test.vala |   1 +
 12 files changed, 172 insertions(+), 167 deletions(-)
---
diff --git a/src/client/accounts/accounts-editor-add-pane.vala 
b/src/client/accounts/accounts-editor-add-pane.vala
index e8771d05..ad07d298 100644
--- a/src/client/accounts/accounts-editor-add-pane.vala
+++ b/src/client/accounts/accounts-editor-add-pane.vala
@@ -279,7 +279,7 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
 
     private Geary.ServiceInformation new_imap_service() {
         Geary.ServiceInformation service =
-           this.accounts.new_libsecret_service(Geary.Protocol.IMAP);
+            new Geary.ServiceInformation(Geary.Protocol.IMAP);
 
         if (this.provider == Geary.ServiceProvider.OTHER) {
             service.credentials = new Geary.Credentials(
@@ -313,7 +313,7 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
 
     private Geary.ServiceInformation new_smtp_service() {
         Geary.ServiceInformation service =
-           this.accounts.new_libsecret_service(Geary.Protocol.SMTP);
+            new Geary.ServiceInformation(Geary.Protocol.SMTP);
 
         if (this.provider == Geary.ServiceProvider.OTHER) {
             switch (this.smtp_auth.value.source) {
diff --git a/src/client/accounts/accounts-editor-row.vala b/src/client/accounts/accounts-editor-row.vala
index ec55ff09..45f8fe18 100644
--- a/src/client/accounts/accounts-editor-row.vala
+++ b/src/client/accounts/accounts-editor-row.vala
@@ -338,7 +338,7 @@ private abstract class Accounts.ServiceRow<PaneType,V> : AccountRow<PaneType,V>
 
     // XXX convenience method until we get a better way of doing this.
     protected bool is_goa_account {
-        get { return (this.service.mediator is GoaMediator); }
+        get { return (this.account.mediator is GoaMediator); }
     }
 
 
diff --git a/src/client/accounts/accounts-editor-servers-pane.vala 
b/src/client/accounts/accounts-editor-servers-pane.vala
index 3cf8db9d..09dd5aef 100644
--- a/src/client/accounts/accounts-editor-servers-pane.vala
+++ b/src/client/accounts/accounts-editor-servers-pane.vala
@@ -68,7 +68,7 @@ internal class Accounts.EditorServersPane : Gtk.Grid, EditorPane, AccountPane {
 
         this.details_list.set_header_func(Editor.seperator_headers);
         // Only add an account provider if it is esoteric enough.
-        if (this.account.imap.mediator is GoaMediator) {
+        if (this.account.mediator is GoaMediator) {
             this.details_list.add(
                 new AccountProviderRow(editor.accounts, this.account)
             );
@@ -307,7 +307,7 @@ private class Accounts.AccountProviderRow :
     public override void update() {
         string? source = null;
         bool enabled = false;
-        if (this.account.imap.mediator is GoaMediator) {
+        if (this.account.mediator is GoaMediator) {
             source = _("GNOME Online Accounts");
             enabled = true;
         } else {
diff --git a/src/client/accounts/accounts-manager.vala b/src/client/accounts/accounts-manager.vala
index 63fec935..319ea1b9 100644
--- a/src/client/accounts/accounts-manager.vala
+++ b/src/client/accounts/accounts-manager.vala
@@ -48,13 +48,14 @@ public enum Accounts.CredentialsProvider {
 }
 
 
-/** Objects that can be used load/save account configuration. */
+/** Objects that can be used to load/save account configuration. */
 public interface Accounts.AccountConfig : GLib.Object {
 
     /** Loads a supported account from a config file. */
     public abstract Geary.AccountInformation
         load(Geary.ConfigFile config,
              string id,
+             Geary.CredentialsMediator mediator,
              Geary.ServiceProvider? default_provider,
              string? default_name)
         throws ConfigError, GLib.KeyFileError;
@@ -66,15 +67,13 @@ public interface Accounts.AccountConfig : GLib.Object {
 }
 
 
-/** Objects that can be used load/save service configuration. */
+/** Objects that can be used to load/save service configuration. */
 public interface Accounts.ServiceConfig : GLib.Object {
 
     /** Loads a service from a config file. */
-    public abstract Geary.ServiceInformation
-        load(Geary.ConfigFile config,
-             Geary.AccountInformation account,
-             Geary.Protocol protocol,
-             Geary.CredentialsMediator mediator)
+    public abstract void load(Geary.ConfigFile config,
+                              Geary.AccountInformation account,
+                              Geary.ServiceInformation service)
         throws ConfigError, GLib.KeyFileError;
 
     /** Saves a service to a config file. */
@@ -295,11 +294,9 @@ public class Accounts.Manager : GLib.Object {
         }
         string id = LOCAL_ID_FORMAT.printf(next_id);
 
-        return new Geary.AccountInformation(id, provider, primary_mailbox);
-    }
-
-    public Geary.ServiceInformation new_libsecret_service(Geary.Protocol service) {
-        return new Geary.ServiceInformation(service, libsecret);
+        return new Geary.AccountInformation(
+            id, provider, this.libsecret, primary_mailbox
+        );
     }
 
     /**
@@ -312,24 +309,11 @@ public class Accounts.Manager : GLib.Object {
         yield save_account(account, cancellable);
         set_enabled(account, true);
 
-        SecretMediator? mediator = account.imap.mediator as SecretMediator;
+        // if it's a local account, save the passwords now
+        SecretMediator? mediator = account.mediator as SecretMediator;
         if (mediator != null) {
-            try {
-                yield mediator.update_token(account, account.imap, cancellable);
-            } catch (Error e) {
-                debug("Error saving IMAP password: %s", e.message);
-            }
-        }
-
-        if (account.smtp.credentials != null) {
-            mediator = account.smtp.mediator as SecretMediator;
-            if (mediator != null) {
-                try {
-                    yield mediator.update_token(account, account.smtp, cancellable);
-                } catch (Error e) {
-                    debug("Error saving IMAP password: %s", e.message);
-                }
-            }
+            yield mediator.update_token(account, account.imap, cancellable);
+            yield mediator.update_token(account, account.smtp, cancellable);
         }
     }
 
@@ -364,7 +348,7 @@ public class Accounts.Manager : GLib.Object {
                             file.get_name(), cancellable
                         );
 
-                        GoaMediator? mediator = info.imap.mediator as GoaMediator;
+                        GoaMediator? mediator = info.mediator as GoaMediator;
                         if (mediator == null || mediator.is_valid) {
                             set_enabled(info, true);
                         } else {
@@ -470,7 +454,7 @@ public class Accounts.Manager : GLib.Object {
      * Determines if an account is a GOA account or not.
      */
     public bool is_goa_account(Geary.AccountInformation account) {
-        return (account.imap.mediator is GoaMediator);
+        return (account.mediator is GoaMediator);
     }
 
     /**
@@ -605,6 +589,7 @@ public class Accounts.Manager : GLib.Object {
             account = accounts.load(
                 config,
                 id,
+                mediator,
                 default_provider,
                 get_account_name()
             );
@@ -623,19 +608,13 @@ public class Accounts.Manager : GLib.Object {
 
         if (!is_goa) {
             try {
-                account.imap = services.load(
-                    config, account, Geary.Protocol.IMAP, mediator
-                );
-                account.smtp = services.load(
-                    config, account, Geary.Protocol.SMTP, mediator
-                );
+                services.load(config, account, account.imap);
+                services.load(config, account, account.smtp);
             } catch (GLib.KeyFileError err) {
                 throw new ConfigError.SYNTAX(err.message);
             }
         } else {
             account.service_label = goa_mediator.get_service_label();
-            account.imap = new Geary.ServiceInformation(Geary.Protocol.IMAP, mediator);
-            account.smtp = new Geary.ServiceInformation(Geary.Protocol.SMTP, mediator);
 
             try {
                 // This updates the service configs as well
@@ -703,17 +682,17 @@ public class Accounts.Manager : GLib.Object {
     private async void delete_account(Geary.AccountInformation info,
                                       GLib.Cancellable? cancellable)
         throws GLib.Error {
-        SecretMediator? mediator = info.imap.mediator as SecretMediator;
+        // If it's a local account, try clearing the passwords. Keep
+        // going if there's an error though since we really want to
+        // delete the account dirs.
+        SecretMediator? mediator = info.mediator as SecretMediator;
         if (mediator != null) {
             try {
                 yield mediator.clear_token(info, info.imap, cancellable);
             } catch (Error e) {
                 debug("Error clearing IMAP password: %s", e.message);
             }
-        }
 
-        mediator = info.smtp.mediator as SecretMediator;
-        if (mediator != null) {
             try {
                 yield mediator.clear_token(info, info.smtp, cancellable);
             } catch (Error e) {
@@ -816,6 +795,7 @@ public class Accounts.Manager : GLib.Object {
             Geary.AccountInformation info = new Geary.AccountInformation(
                 to_geary_id(account),
                 mediator.get_service_provider(),
+                mediator,
                 new Geary.RFC822.MailboxAddress(name, mail.email_address)
             );
 
@@ -915,7 +895,7 @@ public class Accounts.Manager : GLib.Object {
             // We already know about this account, so check that it is
             // still valid. If not, the account should be disabled,
             // not deleted, since it may be re-enabled at some point.
-            GoaMediator mediator = (GoaMediator) state.account.imap.mediator;
+            GoaMediator mediator = (GoaMediator) state.account.mediator;
             mediator.update.begin(
                 state.account,
                 null, // XXX Get a cancellable to this somehow
@@ -989,6 +969,7 @@ public class Accounts.AccountConfigV1 : AccountConfig, GLib.Object {
 
     public  Geary.AccountInformation load(Geary.ConfigFile config,
                                           string id,
+                                          Geary.CredentialsMediator mediator,
                                           Geary.ServiceProvider? default_provider,
                                           string? default_name)
         throws ConfigError, GLib.KeyFileError {
@@ -1025,7 +1006,7 @@ public class Accounts.AccountConfigV1 : AccountConfig, GLib.Object {
         }
 
         Geary.AccountInformation account = new Geary.AccountInformation(
-            id, provider, senders.remove_at(0)
+            id, provider, mediator, senders.remove_at(0)
         );
 
         account.ordinal = account_config.get_int(
@@ -1146,11 +1127,11 @@ public class Accounts.AccountConfigLegacy : AccountConfig, GLib.Object {
     private const string USE_EMAIL_SIGNATURE_KEY = "use_email_signature";
 
 
-    public Geary.AccountInformation
-        load(Geary.ConfigFile config_file,
-             string id,
-             Geary.ServiceProvider? default_provider,
-             string? default_name)
+    public Geary.AccountInformation load(Geary.ConfigFile config_file,
+                                         string id,
+                                         Geary.CredentialsMediator mediator,
+                                         Geary.ServiceProvider? default_provider,
+                                         string? default_name)
         throws ConfigError, GLib.KeyFileError {
         Geary.ConfigFile.Group config = config_file.get_group(GROUP);
 
@@ -1168,7 +1149,7 @@ public class Accounts.AccountConfigLegacy : AccountConfig, GLib.Object {
         }
 
         Geary.AccountInformation info = new Geary.AccountInformation(
-            id, provider,
+            id, provider, mediator,
             new Geary.RFC822.MailboxAddress(real_name, primary_email)
         );
 
@@ -1291,17 +1272,12 @@ public class Accounts.ServiceConfigV1 : ServiceConfig, GLib.Object {
 
 
     /** Loads a supported service from a config file. */
-    public Geary.ServiceInformation load(Geary.ConfigFile config,
-                                         Geary.AccountInformation account,
-                                         Geary.Protocol protocol,
-                                         Geary.CredentialsMediator mediator)
+    public void load(Geary.ConfigFile config,
+                     Geary.AccountInformation account,
+                     Geary.ServiceInformation service)
         throws ConfigError, GLib.KeyFileError {
         Geary.ConfigFile.Group service_config = config.get_group(
-            protocol == IMAP ? GROUP_INCOMING : GROUP_OUTGOING
-        );
-
-        Geary.ServiceInformation service = new Geary.ServiceInformation(
-            protocol, mediator
+            service.protocol == IMAP ? GROUP_INCOMING : GROUP_OUTGOING
         );
 
         string? login = service_config.get_string(LOGIN, null);
@@ -1327,7 +1303,7 @@ public class Accounts.ServiceConfigV1 : ServiceConfig, GLib.Object {
             } catch (GLib.Error err) {
                 // Oh well
                 debug("%s: No/invalid transport security config for %s",
-                      account.id, protocol.to_value());
+                      account.id, service.protocol.to_value());
             }
 
             if (service.protocol == Geary.Protocol.SMTP) {
@@ -1345,8 +1321,6 @@ public class Accounts.ServiceConfigV1 : ServiceConfig, GLib.Object {
                 service.port = service.get_default_port();
             }
         }
-
-        return service;
     }
 
     /** Saves an service to a config file. */
@@ -1398,15 +1372,10 @@ public class Accounts.ServiceConfigLegacy : ServiceConfig, GLib.Object {
 
 
     /** Loads a supported service from a config file. */
-    public Geary.ServiceInformation load(Geary.ConfigFile config,
-                                         Geary.AccountInformation account,
-                                         Geary.Protocol protocol,
-                                         Geary.CredentialsMediator mediator)
+    public void load(Geary.ConfigFile config,
+                     Geary.AccountInformation account,
+                     Geary.ServiceInformation service)
         throws ConfigError, GLib.KeyFileError {
-        Geary.ServiceInformation service = new Geary.ServiceInformation(
-            protocol, mediator
-        );
-
         Geary.ConfigFile.Group service_config =
             config.get_group(AccountConfigLegacy.GROUP);
 
@@ -1431,7 +1400,7 @@ public class Accounts.ServiceConfigLegacy : ServiceConfig, GLib.Object {
             );
 
             bool use_tls = service_config.get_bool(
-                prefix + SSL, protocol == Geary.Protocol.IMAP
+                prefix + SSL, service.protocol == Geary.Protocol.IMAP
             );
             bool use_starttls = service_config.get_bool(
                 prefix + STARTTLS, true
@@ -1463,8 +1432,6 @@ public class Accounts.ServiceConfigLegacy : ServiceConfig, GLib.Object {
                 }
             }
         }
-
-        return service;
     }
 
     /** Saves an service to a config file. */
diff --git a/src/client/accounts/add-edit-page.vala b/src/client/accounts/add-edit-page.vala
index 790871ab..b06495be 100644
--- a/src/client/accounts/add-edit-page.vala
+++ b/src/client/accounts/add-edit-page.vala
@@ -370,7 +370,7 @@ public class AddEditPage : Gtk.Box {
     
     // Sets the account information to display on this page.
     public void set_account_information(Geary.AccountInformation info, Geary.Engine.ValidationResult result) 
{
-        this.is_sso_account = (info.imap.mediator is GoaMediator);
+        this.is_sso_account = (info.mediator is GoaMediator);
         set_all_info(
             info.id,
             info.primary_mailbox.name,
@@ -694,13 +694,6 @@ public class AddEditPage : Gtk.Box {
         Geary.ServiceInformation? smtp = null;
         if (info == null) {
             // New account
-            imap = this.application.controller.account_manager.new_libsecret_service(
-                Geary.Protocol.IMAP
-            );
-            smtp = this.application.controller.account_manager.new_libsecret_service(
-                Geary.Protocol.SMTP
-            );
-
             try {
                 info = this.application.controller.account_manager.new_orphan_account(
                     this.get_service_provider(),
@@ -712,6 +705,8 @@ public class AddEditPage : Gtk.Box {
                 debug("Unable to create account %s for %s: %s",
                       this.id, this.email_address, err.message);
             }
+            imap = info.imap;
+            smtp = info.smtp;
         } else {
             // Existing account: create a copy so we don't mess up the
             // original.
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index a0c924e4..ea0a791b 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -1,8 +1,9 @@
 /*
  * Copyright 2016 Software Freedom Conservancy Inc.
+ * Copyright 2018 Michael Gratton <mike vee net>
  *
  * This software is licensed under the GNU Lesser General Public License
- * (version 2.1 or later).  See the COPYING file in this distribution.
+ * (version 2.1 or later). See the COPYING file in this distribution.
  */
 
 public class Geary.AccountInformation : BaseObject {
@@ -165,16 +166,21 @@ public class Geary.AccountInformation : BaseObject {
         get; set; default = AccountInformation.next_ordinal++;
     }
 
+    /**
+     * The source of authentication credentials for this account.
+     */
+    public CredentialsMediator mediator { get; private set; }
+
     /* Incoming email service configuration. */
     public ServiceInformation imap {
         get; set;
-        default = new ServiceInformation(Protocol.IMAP, null);
+        default = new ServiceInformation(Protocol.IMAP);
     }
 
     /* Outgoing email service configuration. */
     public ServiceInformation smtp {
         get; set;
-        default = new ServiceInformation(Protocol.SMTP, null);
+        default = new ServiceInformation(Protocol.SMTP);
     }
 
     /** A lock that can be used to ensure saving is serialised. */
@@ -220,16 +226,54 @@ public class Geary.AccountInformation : BaseObject {
     public signal void information_changed();
 
     /**
-     * Creates a new, empty account info file.
+     * Creates a new account with default settings.
      */
     public AccountInformation(string id,
                               ServiceProvider provider,
+                              CredentialsMediator mediator,
                               RFC822.MailboxAddress primary_mailbox) {
         this.id = id;
+        this.mediator = mediator;
         this.service_provider = provider;
         append_sender(primary_mailbox);
     }
 
+    /**
+     * Creates a copy of an existing config.
+     */
+    public AccountInformation.copy(AccountInformation other) {
+        this(
+            other.id,
+            other.service_provider,
+            other.mediator,
+            other.primary_mailbox
+        );
+        this.service_label = other.service_label;
+        this.nickname = other.nickname;
+        if (other.mailboxes.size > 1) {
+            this.mailboxes.add_all(
+                other.mailboxes.slice(1, other.mailboxes.size)
+            );
+        }
+        this.prefetch_period_days = other.prefetch_period_days;
+        this.save_sent_mail = other.save_sent_mail;
+        this.use_email_signature = other.use_email_signature;
+        this.email_signature = other.email_signature;
+        this.save_drafts = other.save_drafts;
+
+        this.imap = new ServiceInformation.copy(other.imap);
+        this.smtp = new ServiceInformation.copy(other.smtp);
+
+        this.drafts_folder_path = other.drafts_folder_path;
+        this.sent_mail_folder_path = other.sent_mail_folder_path;
+        this.spam_folder_path = other.spam_folder_path;
+        this.trash_folder_path = other.trash_folder_path;
+        this.archive_folder_path = other.archive_folder_path;
+
+        this.config_dir = other.config_dir;
+        this.data_dir = other.data_dir;
+    }
+
     /** Sets the location of the account's storage directories. */
     public void set_account_directories(GLib.File config, GLib.File data) {
         this.config_dir = config;
@@ -392,7 +436,7 @@ public class Geary.AccountInformation : BaseObject {
     }
 
     /**
-     * Loads this account's SMTP credentials from its mediator, if needed.
+     * Loads this account's SMTP credentials from the mediator, if needed.
      *
      * This method may cause the user to be prompted for their
      * secrets, thus it may yield for some time.
@@ -410,7 +454,7 @@ public class Geary.AccountInformation : BaseObject {
             if (this.smtp.smtp_use_imap_credentials) {
                 service = this.imap;
             }
-            loaded = yield service.mediator.load_token(
+            loaded = yield this.mediator.load_token(
                 this, service, cancellable
             );
         }
@@ -425,13 +469,13 @@ public class Geary.AccountInformation : BaseObject {
      */
     public async bool prompt_smtp_credentials(GLib.Cancellable? cancellable)
         throws GLib.Error {
-        return yield this.smtp.mediator.prompt_token(
+        return yield this.mediator.prompt_token(
             this, this.smtp, cancellable
         );
     }
 
     /**
-     * Loads this account's IMAP credentials from its mediator, if needed.
+     * Loads this account's IMAP credentials from the mediator, if needed.
      *
      * This method may cause the user to be prompted for their
      * secrets, thus it may yield for some time.
@@ -445,7 +489,7 @@ public class Geary.AccountInformation : BaseObject {
         Credentials? creds = this.imap.credentials;
         bool loaded = creds.is_complete();
         if (!loaded) {
-            loaded = yield this.imap.mediator.load_token(
+            loaded = yield this.mediator.load_token(
                 this, this.imap, cancellable
             );
         }
@@ -460,7 +504,7 @@ public class Geary.AccountInformation : BaseObject {
      */
     public async bool prompt_imap_credentials(GLib.Cancellable? cancellable)
         throws GLib.Error {
-        return yield this.imap.mediator.prompt_token(
+        return yield this.mediator.prompt_token(
             this, this.imap, cancellable
         );
     }
@@ -478,8 +522,10 @@ public class Geary.AccountInformation : BaseObject {
     public bool equal_to(AccountInformation other) {
         return (
             this == other || (
+                // This is probably overkill, but handy for testing.
                 this.id == other.id &&
                 this.ordinal == other.ordinal &&
+                this.mediator == other.mediator &&
                 this.service_provider == other.service_provider &&
                 this.service_label == other.service_label &&
                 this.nickname == other.nickname &&
diff --git a/src/engine/api/geary-service-information.vala b/src/engine/api/geary-service-information.vala
index dece1e0e..3a565df1 100644
--- a/src/engine/api/geary-service-information.vala
+++ b/src/engine/api/geary-service-information.vala
@@ -162,14 +162,6 @@ public class Geary.ServiceInformation : GLib.Object {
     /** The credentials used for authenticating. */
     public Credentials? credentials { get; set; default = null; }
 
-    /**
-     * The credentials mediator used with this service.
-     *
-     * It is responsible for fetching and storing the credentials if
-     * as needed.
-     */
-    public CredentialsMediator mediator { get; private set; }
-
     /**
      * Whether the password should be remembered.
      *
@@ -227,16 +219,15 @@ public class Geary.ServiceInformation : GLib.Object {
     /**
      * Constructs a new configuration for a specific service.
      */
-    public ServiceInformation(Protocol proto, CredentialsMediator mediator) {
+    public ServiceInformation(Protocol proto) {
         this.protocol = proto;
-        this.mediator = mediator;
     }
 
     /**
      * Constructs a copy of the given service configuration.
      */
     public ServiceInformation.copy(ServiceInformation other) {
-        this(other.protocol, other.mediator);
+        this(other.protocol);
         this.host = other.host;
         this.port = other.port;
         this.use_starttls = other.use_starttls;
@@ -244,7 +235,6 @@ public class Geary.ServiceInformation : GLib.Object {
         this.credentials = (
             other.credentials != null ? other.credentials.copy() : null
         );
-        this.mediator = other.mediator;
         this.remember_password = other.remember_password;
         this.smtp_noauth = other.smtp_noauth;
         this.smtp_use_imap_credentials = other.smtp_use_imap_credentials;
@@ -290,7 +280,6 @@ public class Geary.ServiceInformation : GLib.Object {
              this.use_ssl == other.use_ssl &&
              (this.credentials == null && other.credentials == null ||
               this.credentials != null && this.credentials.equal_to(other.credentials)) &&
-             this.mediator == other.mediator &&
              this.remember_password == other.remember_password &&
              this.smtp_noauth == other.smtp_noauth &&
              this.smtp_use_imap_credentials == other.smtp_use_imap_credentials)
diff --git a/test/client/accounts/accounts-manager-test.vala b/test/client/accounts/accounts-manager-test.vala
index ffcf6cb9..64ee42dd 100644
--- a/test/client/accounts/accounts-manager-test.vala
+++ b/test/client/accounts/accounts-manager-test.vala
@@ -11,8 +11,8 @@ class Accounts.ManagerTest : TestCase {
     private const string TEST_ID = "test";
 
     private Manager? test = null;
+    private Geary.CredentialsMediator? mediator = null;
     private Geary.AccountInformation? account = null;
-    private Geary.ServiceInformation? service = null;
     private File? tmp = null;
 
 
@@ -42,20 +42,19 @@ class Accounts.ManagerTest : TestCase {
         data.make_directory();
 
         this.test = new Manager(new GearyApplication(), config, data);
-
+        this.mediator = new Geary.MockCredentialsMediator();
         this.account = new Geary.AccountInformation(
             TEST_ID,
             Geary.ServiceProvider.OTHER,
+            this.mediator,
             new Geary.RFC822.MailboxAddress(null, "test1 example com")
         );
-
-        this.service = new Geary.ServiceInformation(Geary.Protocol.SMTP, null);
     }
 
        public override void tear_down() throws GLib.Error {
-        this.test = null;
         this.account = null;
-        this.service = null;
+        this.mediator = null;
+        this.test = null;
         @delete(this.tmp);
        }
 
@@ -140,7 +139,9 @@ class Accounts.ManagerTest : TestCase {
             new Geary.ConfigFile(this.tmp.get_child("config"));
 
         config.save(this.account, file);
-        Geary.AccountInformation copy = config.load(file, TEST_ID, null, null);
+        Geary.AccountInformation copy = config.load(
+            file, TEST_ID, this.mediator, null, null
+        );
 
         assert_true(this.account.equal_to(copy));
     }
@@ -160,49 +161,59 @@ class Accounts.ManagerTest : TestCase {
             new Geary.ConfigFile(this.tmp.get_child("config"));
 
         config.save(this.account, file);
-        Geary.AccountInformation copy = config.load(file, TEST_ID, null, null);
+        Geary.AccountInformation copy = config.load(
+            file, TEST_ID, this.mediator, null, null
+        );
 
         assert_true(this.account.equal_to(copy));
     }
 
     public void service_config_v1() throws GLib.Error {
-        this.service.host = "blarg";
-        this.service.port = 1234;
-        this.service.transport_security = Geary.TlsNegotiationMethod.NONE;
-        this.service.smtp_credentials_source = Geary.SmtpCredentials.CUSTOM;
-        this.service.credentials = new Geary.Credentials(
+        // take a copy before updating the service info so we don't
+        // also copy the test data
+        Geary.AccountInformation copy = new Geary.AccountInformation.copy(
+            this.account
+        );
+
+        this.account.smtp.host = "blarg";
+        this.account.smtp.port = 1234;
+        this.account.smtp.transport_security = Geary.TlsNegotiationMethod.NONE;
+        this.account.smtp.smtp_credentials_source = Geary.SmtpCredentials.CUSTOM;
+        this.account.smtp.credentials = new Geary.Credentials(
             Geary.Credentials.Method.PASSWORD, "testerson"
         );
         Accounts.ServiceConfigV1 config = new Accounts.ServiceConfigV1();
         Geary.ConfigFile file =
             new Geary.ConfigFile(this.tmp.get_child("config"));
 
-        config.save(this.account, this.service, file);
-        Geary.ServiceInformation copy = config.load(
-            file, this.account, this.service.protocol, null
-        );
+        config.save(this.account, this.account.smtp, file);
+        config.load(file, copy, copy.smtp);
 
-        assert_true(this.service.equal_to(copy));
+        assert_true(this.account.smtp.equal_to(copy.smtp));
     }
 
     public void service_config_legacy() throws GLib.Error {
-        this.service.host = "blarg";
-        this.service.port = 1234;
-        this.service.transport_security = Geary.TlsNegotiationMethod.NONE;
-        this.service.smtp_credentials_source = Geary.SmtpCredentials.CUSTOM;
-        this.service.credentials = new Geary.Credentials(
+        // take a copy before updating the service info so we don't
+        // also copy the test data
+        Geary.AccountInformation copy = new Geary.AccountInformation.copy(
+            this.account
+        );
+
+        this.account.smtp.host = "blarg";
+        this.account.smtp.port = 1234;
+        this.account.smtp.transport_security = Geary.TlsNegotiationMethod.NONE;
+        this.account.smtp.smtp_credentials_source = Geary.SmtpCredentials.CUSTOM;
+        this.account.smtp.credentials = new Geary.Credentials(
             Geary.Credentials.Method.PASSWORD, "testerson"
         );
         Accounts.ServiceConfigLegacy config = new Accounts.ServiceConfigLegacy();
         Geary.ConfigFile file =
             new Geary.ConfigFile(this.tmp.get_child("config"));
 
-        config.save(this.account, this.service, file);
-        Geary.ServiceInformation copy = config.load(
-            file, this.account, this.service.protocol, null
-        );
+        config.save(this.account, this.account.smtp, file);
+        config.load(file, copy, copy.smtp);
 
-        assert_true(this.service.equal_to(copy));
+        assert_true(this.account.smtp.equal_to(copy.smtp));
     }
 
     private void delete(File parent) throws GLib.Error {
diff --git a/test/engine/api/geary-account-information-test.vala 
b/test/engine/api/geary-account-information-test.vala
index 08d51b17..6ec75420 100644
--- a/test/engine/api/geary-account-information-test.vala
+++ b/test/engine/api/geary-account-information-test.vala
@@ -17,6 +17,7 @@ class Geary.AccountInformationTest : TestCase {
         AccountInformation test = new AccountInformation(
             "test",
             ServiceProvider.OTHER,
+            new MockCredentialsMediator(),
             new RFC822.MailboxAddress(null, "test1 example com")
         );
 
diff --git a/test/engine/api/geary-engine-test.vala b/test/engine/api/geary-engine-test.vala
index 99206fd4..4fb78ea0 100644
--- a/test/engine/api/geary-engine-test.vala
+++ b/test/engine/api/geary-engine-test.vala
@@ -11,6 +11,7 @@ class Geary.EngineTest : TestCase {
     private Engine? engine = null;
     private File? tmp = null;
     private File? res = null;
+    private Geary.AccountInformation? account = null;
 
 
     public EngineTest() {
@@ -50,9 +51,17 @@ class Geary.EngineTest : TestCase {
                 async_complete(res);
             });
         this.engine.open_async.end(async_result());
+
+        this.account = new AccountInformation(
+            "test",
+            ServiceProvider.OTHER,
+            new MockCredentialsMediator(),
+            new RFC822.MailboxAddress(null, "test1 example com")
+        );
     }
 
        public override void tear_down () {
+        this.account = null;
         try {
             this.res.delete();
             this.tmp.delete();
@@ -63,18 +72,13 @@ class Geary.EngineTest : TestCase {
        }
 
     public void add_account() throws GLib.Error {
-        AccountInformation info = new AccountInformation(
-            "test",
-            ServiceProvider.OTHER,
-            new RFC822.MailboxAddress(null, "test1 example com")
-        );
-        assert_false(this.engine.has_account(info.id));
+        assert_false(this.engine.has_account(this.account.id));
 
-        this.engine.add_account(info);
-        assert_true(this.engine.has_account(info.id), "Account not added");
+        this.engine.add_account(this.account);
+        assert_true(this.engine.has_account(this.account.id), "Account not added");
 
         try {
-            this.engine.add_account(info);
+            this.engine.add_account(this.account);
             assert_not_reached();
         } catch (GLib.Error err) {
             // expected
@@ -82,34 +86,24 @@ class Geary.EngineTest : TestCase {
     }
 
     public void remove_account() throws GLib.Error {
-        AccountInformation info = new AccountInformation(
-            "test",
-            ServiceProvider.OTHER,
-            new RFC822.MailboxAddress(null, "test1 example com")
-        );
-        this.engine.add_account(info);
-        assert_true(this.engine.has_account(info.id));
+        this.engine.add_account(this.account);
+        assert_true(this.engine.has_account(this.account.id));
 
-        this.engine.remove_account(info);
-        assert_false(this.engine.has_account(info.id), "Account not rmoeved");
+        this.engine.remove_account(this.account);
+        assert_false(this.engine.has_account(this.account.id), "Account not rmoeved");
 
         // Should not throw an error
-        this.engine.remove_account(info);
+        this.engine.remove_account(this.account);
     }
 
     public void re_add_account() throws GLib.Error {
-        AccountInformation info = new AccountInformation(
-            "test",
-            ServiceProvider.OTHER,
-            new RFC822.MailboxAddress(null, "test1 example com")
-        );
-        assert_false(this.engine.has_account(info.id));
+        assert_false(this.engine.has_account(this.account.id));
 
-        this.engine.add_account(info);
-        this.engine.remove_account(info);
-        this.engine.add_account(info);
+        this.engine.add_account(this.account);
+        this.engine.remove_account(this.account);
+        this.engine.add_account(this.account);
 
-        assert_true(this.engine.has_account(info.id));
+        assert_true(this.engine.has_account(this.account.id));
     }
 
    private void delete(File parent) throws Error {
diff --git a/test/engine/app/app-conversation-monitor-test.vala 
b/test/engine/app/app-conversation-monitor-test.vala
index f3715170..8f3c2a7e 100644
--- a/test/engine/app/app-conversation-monitor-test.vala
+++ b/test/engine/app/app-conversation-monitor-test.vala
@@ -31,6 +31,7 @@ class Geary.App.ConversationMonitorTest : TestCase {
         this.account_info = new AccountInformation(
             "account_01",
             ServiceProvider.OTHER,
+            new MockCredentialsMediator(),
             new RFC822.MailboxAddress(null, "test1 example com")
         );
         this.account = new MockAccount(this.account_info);
diff --git a/test/engine/imap-engine/account-processor-test.vala 
b/test/engine/imap-engine/account-processor-test.vala
index e80865eb..35577c26 100644
--- a/test/engine/imap-engine/account-processor-test.vala
+++ b/test/engine/imap-engine/account-processor-test.vala
@@ -72,6 +72,7 @@ public class Geary.ImapEngine.AccountProcessorTest : TestCase {
         this.info = new Geary.AccountInformation(
             "test-info",
             ServiceProvider.OTHER,
+            new MockCredentialsMediator(),
             new RFC822.MailboxAddress(null, "test1 example com")
         );
         this.account = new Geary.MockAccount(this.info);



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