diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c
index b9eef3c..7c85254 100644
--- a/libempathy/empathy-chatroom-manager.c
+++ b/libempathy/empathy-chatroom-manager.c
@@ -39,10 +39,14 @@
 
 #define CHATROOMS_XML_FILENAME "chatrooms.xml"
 #define CHATROOMS_DTD_FILENAME "empathy-chatroom-manager.dtd"
+#define SAVE_TIMER 4
 
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChatroomManager)
 typedef struct {
 	GList      *chatrooms;
+  gchar *file;
+  /* source id of the autosave timer */
+  gint save_timer_id;
 } EmpathyChatroomManagerPriv;
 
 static void     chatroom_manager_finalize          (GObject                    *object);
@@ -52,6 +56,7 @@ static gboolean chatroom_manager_file_parse        (EmpathyChatroomManager
 static void     chatroom_manager_parse_chatroom    (EmpathyChatroomManager      *manager,
 						    xmlNodePtr                  node);
 static gboolean chatroom_manager_file_save         (EmpathyChatroomManager      *manager);
+static void reset_save_timeout (EmpathyChatroomManager *self);
 
 enum {
 	CHATROOM_ADDED,
@@ -61,15 +66,112 @@ enum {
 
 static guint signals[LAST_SIGNAL];
 
+/* properties */
+enum
+{
+  PROP_FILE = 1,
+  LAST_PROPERTY
+};
+
 G_DEFINE_TYPE (EmpathyChatroomManager, empathy_chatroom_manager, G_TYPE_OBJECT);
 
 static void
+empathy_chatroom_manager_get_property (GObject *object,
+                                       guint property_id,
+                                       GValue *value,
+                                       GParamSpec *pspec)
+{
+  EmpathyChatroomManager *self = EMPATHY_CHATROOM_MANAGER (object);
+  EmpathyChatroomManagerPriv *priv = GET_PRIV (self);
+
+  switch (property_id)
+    {
+      case PROP_FILE:
+        g_value_set_string (value, priv->file);
+        break;
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
+}
+
+static void
+empathy_chatroom_manager_set_property (GObject *object,
+                                       guint property_id,
+                                       const GValue *value,
+                                       GParamSpec *pspec)
+{
+  EmpathyChatroomManager *self = EMPATHY_CHATROOM_MANAGER (object);
+  EmpathyChatroomManagerPriv *priv = GET_PRIV (self);
+
+  switch (property_id)
+    {
+      case PROP_FILE:
+        g_free (priv->file);
+        priv->file = g_value_dup_string (value);
+        break;
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
+}
+
+static GObject *
+empathy_chatroom_manager_constructor (GType type,
+                                      guint n_props,
+                                      GObjectConstructParam *props)
+{
+  GObject *obj;
+  EmpathyChatroomManager *self;
+  EmpathyChatroomManagerPriv *priv;
+
+  /* Parent constructor chain */
+  obj = G_OBJECT_CLASS (empathy_chatroom_manager_parent_class)->
+        constructor (type, n_props, props);
+
+  self = EMPATHY_CHATROOM_MANAGER (obj);
+  priv = GET_PRIV (self);
+
+  if (priv->file == NULL)
+    {
+      /* Set the default file path */
+      gchar *dir;
+
+      dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
+      if (!g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
+        g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
+
+      priv->file = g_build_filename (dir, CHATROOMS_XML_FILENAME, NULL);
+      g_free (dir);
+    }
+
+  chatroom_manager_get_all (self);
+  return obj;
+}
+
+static void
 empathy_chatroom_manager_class_init (EmpathyChatroomManagerClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GParamSpec *param_spec;
 
+  object_class->constructor = empathy_chatroom_manager_constructor;
+  object_class->get_property = empathy_chatroom_manager_get_property;
+  object_class->set_property = empathy_chatroom_manager_set_property;
 	object_class->finalize = chatroom_manager_finalize;
 
+  param_spec = g_param_spec_string (
+      "file",
+      "path of the favorite file",
+      "The path of the XML file containing user's favorites",
+      NULL,
+      G_PARAM_CONSTRUCT_ONLY |
+      G_PARAM_READWRITE |
+      G_PARAM_STATIC_NAME |
+      G_PARAM_STATIC_NICK |
+      G_PARAM_STATIC_BLURB);
+  g_object_class_install_property (object_class, PROP_FILE, param_spec);
+
 	signals[CHATROOM_ADDED] =
 		g_signal_new ("chatroom-added",
 			      G_TYPE_FROM_CLASS (klass),
@@ -103,29 +205,55 @@ empathy_chatroom_manager_init (EmpathyChatroomManager *manager)
 }
 
 static void
+chatroom_changed_cb (EmpathyChatroom *chatroom,
+                     GParamSpec *spec,
+                     EmpathyChatroomManager *self)
+{
+  reset_save_timeout (self);
+}
+
+static void
 chatroom_manager_finalize (GObject *object)
 {
+  EmpathyChatroomManager *self = EMPATHY_CHATROOM_MANAGER (object);
 	EmpathyChatroomManagerPriv *priv;
+  GList *l;
 
 	priv = GET_PRIV (object);
 
-	g_list_foreach (priv->chatrooms, (GFunc) g_object_unref, NULL);
+  if (priv->save_timer_id > 0)
+    {
+      /* have to save before destroy the object */
+      g_source_remove (priv->save_timer_id);
+      priv->save_timer_id = 0;
+      chatroom_manager_file_save (self);
+    }
+
+  for (l = priv->chatrooms; l != NULL; l = g_list_next (l))
+    {
+      EmpathyChatroom *chatroom = l->data;
+
+      g_signal_handlers_disconnect_by_func (chatroom, chatroom_changed_cb,
+          self);
+
+      g_object_unref (chatroom);
+    }
+
 	g_list_free (priv->chatrooms);
+  g_free (priv->file);
 
 	(G_OBJECT_CLASS (empathy_chatroom_manager_parent_class)->finalize) (object);
 }
 
 EmpathyChatroomManager *
-empathy_chatroom_manager_new (void)
+empathy_chatroom_manager_new (const gchar *file)
 {
 	static EmpathyChatroomManager *manager = NULL;
 
 	if (!manager) {
-		EmpathyChatroomManagerPriv *priv;
-
-		manager = g_object_new (EMPATHY_TYPE_CHATROOM_MANAGER, NULL);
-		priv = GET_PRIV (manager);
-		chatroom_manager_get_all (manager);
+		manager = g_object_new (EMPATHY_TYPE_CHATROOM_MANAGER,
+        "file", file,
+        NULL);
 	
 		g_object_add_weak_pointer (G_OBJECT (manager), (gpointer) &manager);
 	} else {
@@ -135,6 +263,51 @@ empathy_chatroom_manager_new (void)
 	return manager;
 }
 
+static gboolean
+save_timeout (EmpathyChatroomManager *self)
+{
+  EmpathyChatroomManagerPriv *priv = GET_PRIV (self);
+
+  priv->save_timer_id = 0;
+  chatroom_manager_file_save (self);
+
+  return FALSE;
+}
+
+static void
+reset_save_timeout (EmpathyChatroomManager *self)
+{
+  EmpathyChatroomManagerPriv *priv = GET_PRIV (self);
+
+  if (priv->save_timer_id > 0)
+    {
+      g_source_remove (priv->save_timer_id);
+    }
+
+  priv->save_timer_id = g_timeout_add_seconds (SAVE_TIMER,
+      (GSourceFunc) save_timeout, self);
+}
+
+static void
+add_chatroom (EmpathyChatroomManager *self,
+              EmpathyChatroom *chatroom)
+{
+  EmpathyChatroomManagerPriv *priv = GET_PRIV (self);
+
+  priv->chatrooms = g_list_prepend (priv->chatrooms, g_object_ref (chatroom));
+
+  g_signal_connect (chatroom, "notify::favorite",
+      G_CALLBACK (chatroom_changed_cb), self);
+  g_signal_connect (chatroom, "notify::name",
+      G_CALLBACK (chatroom_changed_cb), self);
+  g_signal_connect (chatroom, "notify::auto-connect",
+      G_CALLBACK (chatroom_changed_cb), self);
+  g_signal_connect (chatroom, "notify::room",
+      G_CALLBACK (chatroom_changed_cb), self);
+  g_signal_connect (chatroom, "notify::account",
+      G_CALLBACK (chatroom_changed_cb), self);
+}
+
 gboolean
 empathy_chatroom_manager_add (EmpathyChatroomManager *manager,
 			     EmpathyChatroom        *chatroom)
@@ -150,8 +323,16 @@ empathy_chatroom_manager_add (EmpathyChatroomManager *manager,
 	if (!empathy_chatroom_manager_find (manager,
 					   empathy_chatroom_get_account (chatroom),
 					   empathy_chatroom_get_room (chatroom))) {
-		priv->chatrooms = g_list_prepend (priv->chatrooms, g_object_ref (chatroom));
-		chatroom_manager_file_save (manager);
+      gboolean favorite;
+
+      g_object_get (chatroom, "favorite", &favorite, NULL);
+
+    add_chatroom (manager, chatroom);
+
+    if (favorite)
+      {
+        reset_save_timeout (manager);
+      }
 
 		g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom);
 
@@ -179,11 +360,21 @@ empathy_chatroom_manager_remove (EmpathyChatroomManager *manager,
 		this_chatroom = l->data;
 
 		if (empathy_chatroom_equal (chatroom, this_chatroom)) {
+        gboolean favorite;
 			priv->chatrooms = g_list_delete_link (priv->chatrooms, l);
 
-			chatroom_manager_file_save (manager);
+      g_object_get (chatroom, "favorite", &favorite, NULL);
+
+      if (favorite)
+        {
+          reset_save_timeout (manager);
+        }
 
 			g_signal_emit (manager, signals[CHATROOM_REMOVED], 0, this_chatroom);
+
+      g_signal_handlers_disconnect_by_func (chatroom, chatroom_changed_cb,
+          manager);
+
 			g_object_unref (this_chatroom);
 			break;
 		}
@@ -283,14 +474,6 @@ empathy_chatroom_manager_get_count (EmpathyChatroomManager *manager,
 	return count;
 }
 
-void
-empathy_chatroom_manager_store (EmpathyChatroomManager *manager)
-{
-	g_return_if_fail (EMPATHY_IS_CHATROOM_MANAGER (manager));
-
-	chatroom_manager_file_save (manager);
-}
-
 /*
  * API to save/load and parse the chatrooms file.
  */
@@ -299,27 +482,13 @@ static gboolean
 chatroom_manager_get_all (EmpathyChatroomManager *manager)
 {
 	EmpathyChatroomManagerPriv *priv;
-	gchar                     *dir;
-	gchar                     *file_with_path = NULL;
 
 	priv = GET_PRIV (manager);
 
-	dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
-	if (!g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
-		g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
-	}
-
-	file_with_path = g_build_filename (dir, CHATROOMS_XML_FILENAME, NULL);
-	g_free (dir);
-
 	/* read file in */
-	if (g_file_test (file_with_path, G_FILE_TEST_EXISTS) &&
-	    !chatroom_manager_file_parse (manager, file_with_path)) {
-		g_free (file_with_path);
-		return FALSE;
-	}
-
-	g_free (file_with_path);
+	if (g_file_test (priv->file, G_FILE_TEST_EXISTS) &&
+	    !chatroom_manager_file_parse (manager, priv->file))
+    return FALSE;
 
 	return TRUE;
 }
@@ -433,7 +602,8 @@ chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager,
 	}
 
 	chatroom = empathy_chatroom_new_full (account, room, name, auto_connect);
-	priv->chatrooms = g_list_prepend (priv->chatrooms, chatroom);
+  g_object_set (chatroom, "favorite", TRUE, NULL);
+  add_chatroom (manager, chatroom);
 	g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom);
 
 	g_object_unref (account);
@@ -449,19 +619,9 @@ chatroom_manager_file_save (EmpathyChatroomManager *manager)
 	xmlDocPtr                  doc;
 	xmlNodePtr                 root;
 	GList                     *l;
-	gchar                     *dir;
-	gchar                     *file;
 
 	priv = GET_PRIV (manager);
 
-	dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
-	if (!g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
-		g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
-	}
-
-	file = g_build_filename (dir, CHATROOMS_XML_FILENAME, NULL);
-	g_free (dir);
-
 	doc = xmlNewDoc ("1.0");
 	root = xmlNewNode (NULL, "chatrooms");
 	xmlDocSetRootElement (doc, root);
@@ -470,8 +630,14 @@ chatroom_manager_file_save (EmpathyChatroomManager *manager)
 		EmpathyChatroom *chatroom;
 		xmlNodePtr      node;
 		const gchar    *account_id;
+    gboolean favorite;
 
 		chatroom = l->data;
+
+    g_object_get (chatroom, "favorite", &favorite, NULL);
+    if (!favorite)
+      continue;
+
 		account_id = mc_account_get_unique_name (empathy_chatroom_get_account (chatroom));
 
 		node = xmlNewChild (root, NULL, "chatroom", NULL);
@@ -484,14 +650,12 @@ chatroom_manager_file_save (EmpathyChatroomManager *manager)
 	/* Make sure the XML is indented properly */
 	xmlIndentTreeOutput = 1;
 
-	DEBUG ("Saving file:'%s'", file);
-	xmlSaveFormatFileEnc (file, doc, "utf-8", 1);
+	DEBUG ("Saving file:'%s'", priv->file);
+	xmlSaveFormatFileEnc (priv->file, doc, "utf-8", 1);
 	xmlFreeDoc (doc);
 
 	xmlCleanupParser ();
 	xmlMemoryDump ();
 
-	g_free (file);
-
 	return TRUE;
 }
diff --git a/libempathy/empathy-chatroom-manager.h b/libempathy/empathy-chatroom-manager.h
index 0b21b65..c070005 100644
--- a/libempathy/empathy-chatroom-manager.h
+++ b/libempathy/empathy-chatroom-manager.h
@@ -53,7 +53,7 @@ struct _EmpathyChatroomManagerClass {
 };
 
 GType                  empathy_chatroom_manager_get_type      (void) G_GNUC_CONST;
-EmpathyChatroomManager *empathy_chatroom_manager_new           (void);
+EmpathyChatroomManager *empathy_chatroom_manager_new           (const gchar *file);
 gboolean               empathy_chatroom_manager_add           (EmpathyChatroomManager *manager,
 							      EmpathyChatroom        *chatroom);
 void                   empathy_chatroom_manager_remove        (EmpathyChatroomManager *manager,
@@ -65,7 +65,6 @@ GList *                empathy_chatroom_manager_get_chatrooms (EmpathyChatroomMa
 							      McAccount             *account);
 guint                  empathy_chatroom_manager_get_count     (EmpathyChatroomManager *manager,
 							      McAccount             *account);
-void                   empathy_chatroom_manager_store         (EmpathyChatroomManager *manager);
 
 G_END_DECLS
 
diff --git a/libempathy/empathy-chatroom.c b/libempathy/empathy-chatroom.c
index 91f86d0..ac81af2 100644
--- a/libempathy/empathy-chatroom.c
+++ b/libempathy/empathy-chatroom.c
@@ -34,6 +34,11 @@ typedef struct {
 	gchar     *room;
 	gchar     *name;
 	gboolean   auto_connect;
+  gboolean favorite;
+  /* FIXME: This is crack. We should store EmapthyTpChat but can't
+   * as it's not created in the dispatcher. At some point it should be
+   * automatically created by tp-glib */
+  TpChannel *tp_channel;
 } EmpathyChatroomPriv;
 
 
@@ -53,6 +58,8 @@ enum {
 	PROP_ROOM,
 	PROP_NAME,
 	PROP_AUTO_CONNECT,
+  PROP_FAVORITE,
+  PROP_TP_CHANNEL
 };
 
 G_DEFINE_TYPE (EmpathyChatroom, empathy_chatroom, G_TYPE_OBJECT);
@@ -98,6 +105,30 @@ empathy_chatroom_class_init (EmpathyChatroomClass *klass)
 							       FALSE,
 							       G_PARAM_READWRITE));
 
+  g_object_class_install_property (object_class,
+      PROP_FAVORITE,
+      g_param_spec_boolean ("favorite",
+        "Favorite",
+        "TRUE if the chatroom is in user's favorite list",
+        FALSE,
+        G_PARAM_READWRITE |
+        G_PARAM_CONSTRUCT |
+        G_PARAM_STATIC_NAME |
+        G_PARAM_STATIC_NICK |
+        G_PARAM_STATIC_BLURB));
+
+  g_object_class_install_property (object_class,
+      PROP_TP_CHANNEL,
+      g_param_spec_object ("tp-channel",
+        "TpChannel object",
+        "The TpChannel associated with this chatroom if we are in the"
+        " room. NULL otherwise.",
+        TP_TYPE_CHANNEL,
+        G_PARAM_READWRITE |
+        G_PARAM_CONSTRUCT |
+        G_PARAM_STATIC_NAME |
+        G_PARAM_STATIC_NICK |
+        G_PARAM_STATIC_BLURB));
 
 	g_type_class_add_private (object_class, sizeof (EmpathyChatroomPriv));
 }
@@ -118,6 +149,12 @@ chatroom_finalize (GObject *object)
 
 	priv = GET_PRIV (object);
 
+  if (priv->tp_channel != NULL)
+    {
+      g_object_unref (priv->tp_channel);
+      priv->tp_channel = NULL;
+    }
+
 	g_object_unref (priv->account);
 	g_free (priv->room);
 	g_free (priv->name);
@@ -148,6 +185,12 @@ chatroom_get_property (GObject    *object,
 	case PROP_AUTO_CONNECT:
 		g_value_set_boolean (value, priv->auto_connect);
 		break;
+  case PROP_FAVORITE:
+    g_value_set_boolean (value, priv->favorite);
+    break;
+  case PROP_TP_CHANNEL:
+    g_value_set_object (value, priv->tp_channel);
+    break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 		break;
@@ -181,6 +224,22 @@ chatroom_set_property (GObject      *object,
 		empathy_chatroom_set_auto_connect (EMPATHY_CHATROOM (object),
 						  g_value_get_boolean (value));
 		break;
+  case PROP_FAVORITE:
+    priv->favorite = g_value_get_boolean (value);
+    if (!priv->favorite)
+      {
+        empathy_chatroom_set_auto_connect (EMPATHY_CHATROOM (object),
+            FALSE);
+      }
+    break;
+  case PROP_TP_CHANNEL:
+    if (priv->tp_channel != NULL)
+      {
+        g_object_unref (priv->tp_channel);
+      }
+
+    priv->tp_channel = g_value_dup_object (value);
+    break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 		break;
@@ -333,6 +392,12 @@ empathy_chatroom_set_auto_connect (EmpathyChatroom *chatroom,
 
 	priv->auto_connect = auto_connect;
 
+  if (priv->auto_connect)
+    {
+      /* auto_connect implies favorite */
+      priv->favorite = TRUE;
+    }
+
 	g_object_notify (G_OBJECT (chatroom), "auto-connect");
 }
 
diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c
index 1d2b989..5f26eee 100644
--- a/libempathy/empathy-dispatcher.c
+++ b/libempathy/empathy-dispatcher.c
@@ -41,6 +41,8 @@
 #include "empathy-tube-handler.h"
 #include "empathy-contact-factory.h"
 #include "empathy-tp-group.h"
+#include "empathy-chatroom-manager.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
 #include <libempathy/empathy-debug.h>
@@ -51,6 +53,7 @@ typedef struct {
 	gpointer        token;
 	MissionControl *mc;
 	GSList         *tubes;
+  EmpathyChatroomManager *chatroom_mgr;
 } EmpathyDispatcherPriv;
 
 G_DEFINE_TYPE (EmpathyDispatcher, empathy_dispatcher, G_TYPE_OBJECT);
@@ -389,6 +392,59 @@ dispatcher_connection_invalidated_cb (TpConnection  *connection,
 	}
 }
 
+typedef struct
+{
+  EmpathyDispatcher *self;
+  EmpathyChatroom *chatroom;
+} dispatcher_connection_invalidated_cb_ctx;
+
+static dispatcher_connection_invalidated_cb_ctx *
+dispatcher_connection_invalidated_cb_ctx_new (EmpathyDispatcher *dispatcher,
+                                              EmpathyChatroom *chatroom)
+{
+  dispatcher_connection_invalidated_cb_ctx *ctx;
+
+  ctx = g_slice_new (dispatcher_connection_invalidated_cb_ctx);
+
+  ctx->self = g_object_ref (dispatcher);
+  ctx->chatroom = g_object_ref (chatroom);
+
+  return ctx;
+}
+
+static void
+dispatcher_connection_invalidated_cb_ctx_free (
+    dispatcher_connection_invalidated_cb_ctx *ctx)
+{
+  g_object_unref (ctx->self);
+  g_object_unref (ctx->chatroom);
+
+  g_slice_free (dispatcher_connection_invalidated_cb_ctx, ctx);
+}
+
+static void dispatcher_chatroom_invalidated_cb (
+    TpProxy *channel,
+    guint domain,
+    gint code,
+    gchar *message,
+    dispatcher_connection_invalidated_cb_ctx *ctx)
+{
+  EmpathyDispatcherPriv *priv = GET_PRIV (ctx->self);
+  gboolean favorite;
+
+  g_object_get (ctx->chatroom, "favorite", &favorite, NULL);
+
+  if (favorite)
+    {
+      /* Chatroom is in favorites so don't remove it from the manager */
+      g_object_set (ctx->chatroom, "tp-channel", NULL, NULL);
+    }
+  else
+    {
+      empathy_chatroom_manager_remove (priv->chatroom_mgr, ctx->chatroom);
+    }
+}
+
 static void
 dispatcher_connection_new_channel_cb (TpConnection *connection,
 				      const gchar  *object_path,
@@ -400,6 +456,7 @@ dispatcher_connection_new_channel_cb (TpConnection *connection,
 				      GObject      *object)
 {
 	EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object);
+  EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
 	TpChannel         *channel;
 	gpointer           had_channels;
 
@@ -418,6 +475,56 @@ dispatcher_connection_new_channel_cb (TpConnection *connection,
 		dispatcher_tubes_handle_channel (dispatcher, channel);
 	}
 
+  if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TEXT) &&
+      handle_type == TP_HANDLE_TYPE_ROOM)
+    {
+      /* Add the chatroom to the chatroom manager */
+      EmpathyChatroom *chatroom;
+      GArray *handles;
+      gchar **room_ids;
+      MissionControl *mc;
+      McAccount *account;
+      dispatcher_connection_invalidated_cb_ctx *ctx;
+
+      handles = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
+      g_array_append_val (handles, handle);
+
+      tp_cli_connection_run_inspect_handles (connection, -1,
+          TP_HANDLE_TYPE_ROOM, handles, &room_ids, NULL, NULL);
+
+      mc = empathy_mission_control_new ();
+      account = mission_control_get_account_for_tpconnection (mc, connection,
+          NULL);
+
+      chatroom = empathy_chatroom_manager_find (priv->chatroom_mgr, account,
+          room_ids[0]);
+      if (chatroom == NULL)
+        {
+          chatroom = empathy_chatroom_new (account);
+          empathy_chatroom_set_name (chatroom, room_ids[0]);
+          empathy_chatroom_manager_add (priv->chatroom_mgr, chatroom);
+        }
+      else
+        {
+          g_object_ref (chatroom);
+        }
+
+      g_object_set (chatroom, "tp-channel", channel, NULL);
+
+      ctx = dispatcher_connection_invalidated_cb_ctx_new (dispatcher, chatroom);
+
+      g_signal_connect_data (channel, "invalidated",
+          G_CALLBACK (dispatcher_chatroom_invalidated_cb), ctx,
+          (GClosureNotify) dispatcher_connection_invalidated_cb_ctx_free, 0);
+
+      g_free (room_ids[0]);
+      g_free (room_ids);
+      g_array_free (handles, TRUE);
+      g_object_unref (mc);
+      g_object_unref (account);
+      g_object_unref (chatroom);
+    }
+
 	if (suppress_handler) {
 		g_signal_emit (dispatcher, signals[DISPATCH_CHANNEL], 0, channel);
 	} else {
@@ -579,6 +686,8 @@ dispatcher_finalize (GObject *object)
 	g_slist_free (priv->tubes);
 
 	g_hash_table_destroy (priv->connections);
+
+  g_object_unref (priv->chatroom_mgr);
 }
 
 static void
@@ -642,6 +751,8 @@ empathy_dispatcher_init (EmpathyDispatcher *dispatcher)
 		g_object_unref (l->data);
 	}
 	g_list_free (accounts);
+
+  priv->chatroom_mgr = empathy_chatroom_manager_new (NULL);
 }
 
 EmpathyDispatcher *
diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c
index 8760c6e..7ae404e 100644
--- a/src/empathy-chat-window.c
+++ b/src/empathy-chat-window.c
@@ -1235,7 +1235,7 @@ empathy_chat_window_init (EmpathyChatWindow *window)
 
 	g_object_unref (glade);
 
-	priv->chatroom_manager = empathy_chatroom_manager_new ();
+	priv->chatroom_manager = empathy_chatroom_manager_new (NULL);
 
 	priv->notebook = gtk_notebook_new ();
  	gtk_notebook_set_group (GTK_NOTEBOOK (priv->notebook), "EmpathyChatWindow"); 
diff --git a/src/empathy-chatrooms-window.c b/src/empathy-chatrooms-window.c
index 52c6635..a29c527 100644
--- a/src/empathy-chatrooms-window.c
+++ b/src/empathy-chatrooms-window.c
@@ -144,7 +144,7 @@ empathy_chatrooms_window_show (GtkWindow *parent)
 	g_object_add_weak_pointer (G_OBJECT (window->window), (gpointer) &window);
 
 	/* Get the session and chat room manager */
-	window->manager = empathy_chatroom_manager_new ();
+	window->manager = empathy_chatroom_manager_new (NULL);
 
 	g_signal_connect (window->manager, "chatroom-added",
 			  G_CALLBACK (chatrooms_window_chatroom_added_cb),
@@ -413,7 +413,6 @@ chatrooms_window_model_cell_auto_connect_toggled (GtkCellRendererToggle  *cell,
 	enabled = !enabled;
 
 	empathy_chatroom_set_auto_connect (chatroom, enabled);
-	empathy_chatroom_manager_store (window->manager);
 
 	gtk_list_store_set (store, &iter, COL_AUTO_CONNECT, enabled, -1);
 	gtk_tree_path_free (path);
diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c
index e41b3f1..2fc8578 100644
--- a/src/empathy-main-window.c
+++ b/src/empathy-main-window.c
@@ -619,7 +619,7 @@ main_window_favorite_chatroom_menu_setup (EmpathyMainWindow *window)
 {
 	GList *chatrooms, *l;
 
-	window->chatroom_manager = empathy_chatroom_manager_new ();
+	window->chatroom_manager = empathy_chatroom_manager_new (NULL);
 	chatrooms = empathy_chatroom_manager_get_chatrooms (window->chatroom_manager, NULL);
 	window->room_menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (window->room));
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5f8cbb6..4e26540 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -33,11 +33,15 @@ check_main_SOURCES =                             \
     check-helpers.h                              \
     check-libempathy.h                           \
     check-empathy-utils.c                        \
+    check-empathy-helpers.h                      \
+    check-empathy-helpers.c                      \
     check-irc-helper.h                           \
     check-irc-helper.c                           \
     check-empathy-irc-server.c                   \
     check-empathy-irc-network.c                  \
-    check-empathy-irc-network-manager.c
+    check-empathy-irc-network-manager.c          \
+    check-empathy-chatroom.c                     \
+    check-empathy-chatroom-manager.c
 
 check_main_LDADD = \
     @CHECK_LIBS@ \
@@ -49,4 +53,6 @@ check_main_CFLAGS = \
     @CHECK_CFLAGS@ \
     $(AM_CFLAGS)
 
-TESTS_ENVIRONMENT = EMPATHY_SRCDIR=@abs_top_srcdir@
+TESTS_ENVIRONMENT = EMPATHY_SRCDIR=@abs_top_srcdir@ \
+		    MC_PROFILE_DIR=@abs_top_srcdir@/tests \
+		    MC_MANAGER_DIR=@abs_top_srcdir@/tests
diff --git a/tests/check-empathy-chatroom-manager.c b/tests/check-empathy-chatroom-manager.c
new file mode 100644
index 0000000..73f164b
--- /dev/null
+++ b/tests/check-empathy-chatroom-manager.c
@@ -0,0 +1,380 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <glib/gstdio.h>
+
+#include <gconf/gconf.h>
+#include <gconf/gconf-client.h>
+#include <telepathy-glib/util.h>
+#include <check.h>
+
+#include "check-helpers.h"
+#include "check-libempathy.h"
+#include "check-empathy-helpers.h"
+
+#include <libempathy/empathy-chatroom-manager.h>
+
+#define CHATROOM_SAMPLE "chatrooms-sample.xml"
+#define CHATROOM_FILE "chatrooms.xml"
+
+static void
+check_chatroom (EmpathyChatroom *chatroom,
+                const gchar *name,
+                const gchar *room,
+                gboolean auto_connect,
+                gboolean favorite)
+{
+  gboolean _favorite;
+
+  fail_if (tp_strdiff (empathy_chatroom_get_name (chatroom), name));
+  fail_if (tp_strdiff (empathy_chatroom_get_room (chatroom), room));
+  fail_if (empathy_chatroom_get_auto_connect (chatroom) != auto_connect);
+  g_object_get (chatroom, "favorite", &_favorite, NULL);
+  fail_if (favorite != _favorite);
+}
+
+struct chatroom_t
+{
+  gchar *name;
+  gchar *room;
+  gboolean auto_connect;
+  gboolean favorite;
+};
+
+static void
+check_chatrooms_list (EmpathyChatroomManager *mgr,
+                      McAccount *account,
+                      struct chatroom_t *_chatrooms,
+                      guint nb_chatrooms)
+{
+  GList *chatrooms, *l;
+  guint i;
+  GHashTable *found;
+
+  fail_if (empathy_chatroom_manager_get_count (mgr, account) != nb_chatrooms);
+
+  found = g_hash_table_new (g_str_hash, g_str_equal);
+  for (i = 0; i < nb_chatrooms; i++)
+    {
+      g_hash_table_insert (found, _chatrooms[i].room, &_chatrooms[i]);
+    }
+
+  chatrooms = empathy_chatroom_manager_get_chatrooms (mgr, account);
+  fail_if (g_list_length (chatrooms) != nb_chatrooms);
+
+  for (l = chatrooms; l != NULL; l = g_list_next (l))
+    {
+      EmpathyChatroom *chatroom = l->data;
+      struct chatroom_t *tmp;
+
+      tmp = g_hash_table_lookup (found, empathy_chatroom_get_room (chatroom));
+      fail_if (tmp == NULL);
+
+      check_chatroom (chatroom, tmp->name, tmp->room, tmp->auto_connect,
+          tmp->favorite);
+
+      g_hash_table_remove (found, empathy_chatroom_get_room (chatroom));
+    }
+
+  fail_if (g_hash_table_size (found) != 0);
+
+  g_list_free (chatrooms);
+  g_hash_table_destroy (found);
+}
+
+START_TEST (test_empathy_chatroom_manager_new)
+{
+  EmpathyChatroomManager *mgr;
+  gchar *cmd;
+  gchar *file;
+  McAccount *account;
+  struct chatroom_t chatrooms[] = {
+        { "name1", "room1", TRUE, TRUE },
+        { "name2", "room2", FALSE, TRUE }};
+
+  account = get_test_account ();
+
+  copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
+
+  file = get_user_xml_file (CHATROOM_FILE);
+  /* change the chatrooms XML file to use the account we just created */
+  cmd = g_strdup_printf ("sed -i 's/CHANGE_ME/%s/' %s",
+      mc_account_get_unique_name (account), file);
+  system (cmd);
+  g_free (cmd);
+
+  mgr = empathy_chatroom_manager_new (file);
+  check_chatrooms_list (mgr, account, chatrooms, 2);
+
+  g_free (file);
+  g_object_unref (mgr);
+  g_object_unref (account);
+}
+END_TEST
+
+START_TEST (test_empathy_chatroom_manager_add)
+{
+  EmpathyChatroomManager *mgr;
+  gchar *cmd;
+  gchar *file;
+  McAccount *account;
+  struct chatroom_t chatrooms[] = {
+        { "name1", "room1", TRUE, TRUE },
+        { "name2", "room2", FALSE, TRUE },
+        { "name3", "room3", FALSE, TRUE },
+        { "name4", "room4", FALSE, FALSE }};
+  EmpathyChatroom *chatroom;
+
+  account = get_test_account ();
+
+  copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
+
+  file = get_user_xml_file (CHATROOM_FILE);
+  /* change the chatrooms XML file to use the account we just created */
+  cmd = g_strdup_printf ("sed -i 's/CHANGE_ME/%s/' %s",
+      mc_account_get_unique_name (account), file);
+  system (cmd);
+  g_free (cmd);
+
+  mgr = empathy_chatroom_manager_new (file);
+
+  /* add a favorite chatroom */
+  chatroom = empathy_chatroom_new_full (account, "room3", "name3", FALSE);
+  g_object_set (chatroom, "favorite", TRUE, NULL);
+  empathy_chatroom_manager_add (mgr, chatroom);
+  g_object_unref (chatroom);
+
+  check_chatrooms_list (mgr, account, chatrooms, 3);
+
+  /* reload chatrooms file */
+  g_object_unref (mgr);
+  mgr = empathy_chatroom_manager_new (file);
+
+  /* chatroom has been added to the XML file as it's a favorite */
+  check_chatrooms_list (mgr, account, chatrooms, 3);
+
+  /* add a non favorite chatroom */
+  chatroom = empathy_chatroom_new_full (account, "room4", "name4", FALSE);
+  g_object_set (chatroom, "favorite", FALSE, NULL);
+  empathy_chatroom_manager_add (mgr, chatroom);
+  g_object_unref (chatroom);
+
+  check_chatrooms_list (mgr, account, chatrooms, 4);
+
+  /* reload chatrooms file */
+  g_object_unref (mgr);
+  mgr = empathy_chatroom_manager_new (file);
+
+  /* chatrooms has not been added to the XML file */
+  check_chatrooms_list (mgr, account, chatrooms, 3);
+
+  g_object_unref (mgr);
+  g_free (file);
+  g_object_unref (account);
+}
+END_TEST
+
+START_TEST (test_empathy_chatroom_manager_remove)
+{
+  EmpathyChatroomManager *mgr;
+  gchar *cmd;
+  gchar *file;
+  McAccount *account;
+  struct chatroom_t chatrooms[] = {
+        { "name2", "room2", FALSE, TRUE }};
+  EmpathyChatroom *chatroom;
+
+  account = get_test_account ();
+
+  copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
+
+  file = get_user_xml_file (CHATROOM_FILE);
+  /* change the chatrooms XML file to use the account we just created */
+  cmd = g_strdup_printf ("sed -i 's/CHANGE_ME/%s/' %s",
+      mc_account_get_unique_name (account), file);
+  system (cmd);
+  g_free (cmd);
+
+  mgr = empathy_chatroom_manager_new (file);
+
+  /* remove room1 */
+  chatroom = empathy_chatroom_manager_find (mgr, account, "room1");
+  fail_if (chatroom == NULL);
+  empathy_chatroom_manager_remove (mgr, chatroom);
+
+  check_chatrooms_list (mgr, account, chatrooms, 1);
+
+  /* reload chatrooms file */
+  g_object_unref (mgr);
+  mgr = empathy_chatroom_manager_new (file);
+
+  check_chatrooms_list (mgr, account, chatrooms, 1);
+
+  /* remove room1 */
+  chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
+  fail_if (chatroom == NULL);
+
+  empathy_chatroom_manager_remove (mgr, chatroom);
+
+  check_chatrooms_list (mgr, account, chatrooms, 0);
+
+  /* reload chatrooms file */
+  g_object_unref (mgr);
+  mgr = empathy_chatroom_manager_new (file);
+
+  check_chatrooms_list (mgr, account, chatrooms, 0);
+
+  g_object_unref (mgr);
+  g_free (file);
+  g_object_unref (account);
+}
+END_TEST
+
+START_TEST (test_empathy_chatroom_manager_change_favorite)
+{
+  EmpathyChatroomManager *mgr;
+  gchar *cmd;
+  gchar *file;
+  McAccount *account;
+  struct chatroom_t chatrooms[] = {
+        { "name1", "room1", TRUE, TRUE },
+        { "name2", "room2", FALSE, FALSE }};
+  EmpathyChatroom *chatroom;
+
+  account = get_test_account ();
+
+  copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
+
+  file = get_user_xml_file (CHATROOM_FILE);
+  /* change the chatrooms XML file to use the account we just created */
+  cmd = g_strdup_printf ("sed -i 's/CHANGE_ME/%s/' %s",
+      mc_account_get_unique_name (account), file);
+  system (cmd);
+  g_free (cmd);
+
+  mgr = empathy_chatroom_manager_new (file);
+
+  /* room2 is not favorite anymore */
+  chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
+  fail_if (chatroom == NULL);
+  g_object_set (chatroom, "favorite", FALSE, NULL);
+
+  check_chatrooms_list (mgr, account, chatrooms, 2);
+
+  /* reload chatrooms file */
+  g_object_unref (mgr);
+  mgr = empathy_chatroom_manager_new (file);
+
+  /* room2 is not present in the XML file anymore as it's not a favorite */
+  check_chatrooms_list (mgr, account, chatrooms, 1);
+
+  /* re-add room2 */
+  chatroom = empathy_chatroom_new_full (account, "room2", "name2", FALSE);
+  empathy_chatroom_manager_add (mgr, chatroom);
+
+  check_chatrooms_list (mgr, account, chatrooms, 2);
+
+  /* set room2 as favorite */
+  g_object_set (chatroom, "favorite", TRUE, NULL);
+
+  chatrooms[1].favorite = TRUE;
+  check_chatrooms_list (mgr, account, chatrooms, 2);
+
+  /* reload chatrooms file */
+  g_object_unref (mgr);
+  mgr = empathy_chatroom_manager_new (file);
+
+  /* room2 is back in the XML file now */
+  check_chatrooms_list (mgr, account, chatrooms, 2);
+
+  g_object_unref (mgr);
+  g_object_unref (chatroom);
+  g_free (file);
+  g_object_unref (account);
+}
+END_TEST
+
+START_TEST (test_empathy_chatroom_manager_change_chatroom)
+{
+  EmpathyChatroomManager *mgr;
+  gchar *cmd;
+  gchar *file;
+  McAccount *account;
+  struct chatroom_t chatrooms[] = {
+        { "name1", "room1", TRUE, TRUE },
+        { "name2", "room2", FALSE, TRUE }};
+  EmpathyChatroom *chatroom;
+
+  account = get_test_account ();
+
+  /*
+  copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
+
+  file = get_user_xml_file (CHATROOM_FILE);
+  */
+  copy_xml_file (CHATROOM_SAMPLE, "foo.xml");
+
+  file = get_user_xml_file ("foo.xml");
+  /* change the chatrooms XML file to use the account we just created */
+  cmd = g_strdup_printf ("sed -i 's/CHANGE_ME/%s/' %s",
+      mc_account_get_unique_name (account), file);
+  system (cmd);
+  g_free (cmd);
+
+  mgr = empathy_chatroom_manager_new (file);
+
+  check_chatrooms_list (mgr, account, chatrooms, 2);
+
+  /* change room2 name */
+  chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
+  fail_if (chatroom == NULL);
+  empathy_chatroom_set_name (chatroom, "new_name");
+
+  /* reload chatrooms file */
+  g_object_unref (mgr);
+  mgr = empathy_chatroom_manager_new (file);
+
+  chatrooms[1].name = "new_name";
+  check_chatrooms_list (mgr, account, chatrooms, 2);
+
+  /* change room2 auto-connect status */
+  chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
+  fail_if (chatroom == NULL);
+  empathy_chatroom_set_auto_connect (chatroom, TRUE);
+
+  /* reload chatrooms file */
+  g_object_unref (mgr);
+  mgr = empathy_chatroom_manager_new (file);
+
+  chatrooms[1].auto_connect = TRUE;
+  check_chatrooms_list (mgr, account, chatrooms, 2);
+
+  /* change room2 room */
+  chatroom = empathy_chatroom_manager_find (mgr, account, "room2");
+  fail_if (chatroom == NULL);
+  empathy_chatroom_set_room (chatroom, "new_room");
+
+  /* reload chatrooms file */
+  g_object_unref (mgr);
+  mgr = empathy_chatroom_manager_new (file);
+
+  chatrooms[1].room = "new_room";
+  check_chatrooms_list (mgr, account, chatrooms, 2);
+
+  g_object_unref (mgr);
+  g_free (file);
+  g_object_unref (account);
+}
+END_TEST
+
+TCase *
+make_empathy_chatroom_manager_tcase (void)
+{
+    TCase *tc = tcase_create ("empathy-chatroom-manager");
+    tcase_add_test (tc, test_empathy_chatroom_manager_new);
+    tcase_add_test (tc, test_empathy_chatroom_manager_add);
+    tcase_add_test (tc, test_empathy_chatroom_manager_remove);
+    tcase_add_test (tc, test_empathy_chatroom_manager_change_favorite);
+    tcase_add_test (tc, test_empathy_chatroom_manager_change_chatroom);
+    return tc;
+}
diff --git a/tests/check-empathy-chatroom.c b/tests/check-empathy-chatroom.c
new file mode 100644
index 0000000..a4adf6c
--- /dev/null
+++ b/tests/check-empathy-chatroom.c
@@ -0,0 +1,155 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <check.h>
+#include "check-helpers.h"
+#include "check-libempathy.h"
+#include "check-empathy-helpers.h"
+
+#include <libempathy/empathy-chatroom.h>
+
+static EmpathyChatroom *
+create_chatroom (void)
+{
+  McAccount *account;
+  EmpathyChatroom *chatroom;
+
+  account = get_test_account ();
+  chatroom = empathy_chatroom_new (account);
+  fail_if (chatroom == NULL);
+
+  return chatroom;
+}
+
+START_TEST (test_empathy_chatroom_new)
+{
+  EmpathyChatroom *chatroom;
+  gboolean auto_connect, favorite;
+
+  chatroom = create_chatroom ();
+  fail_if (empathy_chatroom_get_auto_connect (chatroom));
+  g_object_get (chatroom,
+      "auto_connect", &auto_connect,
+      "favorite", &favorite,
+      NULL);
+  fail_if (auto_connect);
+  fail_if (favorite);
+
+  g_object_unref (empathy_chatroom_get_account (chatroom));
+  g_object_unref (chatroom);
+}
+END_TEST
+
+START_TEST (test_favorite_and_auto_connect)
+{
+  /* auto connect implies favorite */
+  EmpathyChatroom *chatroom;
+  gboolean auto_connect, favorite;
+
+  chatroom = create_chatroom ();
+
+  /* set auto_connect so favorite as a side effect */
+  empathy_chatroom_set_auto_connect (chatroom, TRUE);
+  fail_if (!empathy_chatroom_get_auto_connect (chatroom));
+  g_object_get (chatroom,
+      "auto_connect", &auto_connect,
+      "favorite", &favorite,
+      NULL);
+  fail_if (!auto_connect);
+  fail_if (!favorite);
+
+  /* Remove auto_connect. Chatroom is still favorite */
+  empathy_chatroom_set_auto_connect (chatroom, FALSE);
+  fail_if (empathy_chatroom_get_auto_connect (chatroom));
+  g_object_get (chatroom,
+      "auto_connect", &auto_connect,
+      "favorite", &favorite,
+      NULL);
+  fail_if (auto_connect);
+  fail_if (!favorite);
+
+  /* Remove favorite too now */
+  g_object_set (chatroom, "favorite", FALSE, NULL);
+  fail_if (empathy_chatroom_get_auto_connect (chatroom));
+  g_object_get (chatroom,
+      "auto_connect", &auto_connect,
+      "favorite", &favorite,
+      NULL);
+  fail_if (auto_connect);
+  fail_if (favorite);
+
+  /* Just add favorite but not auto-connect */
+  g_object_set (chatroom, "favorite", TRUE, NULL);
+  fail_if (empathy_chatroom_get_auto_connect (chatroom));
+  g_object_get (chatroom,
+      "auto_connect", &auto_connect,
+      "favorite", &favorite,
+      NULL);
+  fail_if (auto_connect);
+  fail_if (!favorite);
+
+  /* ... and re-add auto_connect */
+  g_object_set (chatroom, "auto_connect", TRUE, NULL);
+  fail_if (!empathy_chatroom_get_auto_connect (chatroom));
+  g_object_get (chatroom,
+      "auto_connect", &auto_connect,
+      "favorite", &favorite,
+      NULL);
+  fail_if (!auto_connect);
+  fail_if (!favorite);
+
+  /* Remove favorite remove auto_connect too */
+  g_object_set (chatroom, "favorite", FALSE, NULL);
+  fail_if (empathy_chatroom_get_auto_connect (chatroom));
+  g_object_get (chatroom,
+      "auto_connect", &auto_connect,
+      "favorite", &favorite,
+      NULL);
+  fail_if (auto_connect);
+  fail_if (favorite);
+
+  g_object_unref (empathy_chatroom_get_account (chatroom));
+  g_object_unref (chatroom);
+}
+END_TEST
+
+static void
+favorite_changed (EmpathyChatroom *chatroom,
+                  GParamSpec *spec,
+                  gboolean *changed)
+{
+  *changed = TRUE;
+}
+
+START_TEST (test_change_favorite)
+{
+  EmpathyChatroom *chatroom;
+  gboolean changed = FALSE;
+
+  chatroom = create_chatroom ();
+
+  g_signal_connect (chatroom, "notify::favorite", G_CALLBACK (favorite_changed),
+      &changed);
+
+  /* change favorite to TRUE */
+  g_object_set (chatroom, "favorite", TRUE, NULL);
+  fail_if (!changed);
+
+  changed = FALSE;
+
+  /* change favorite to FALSE */
+  g_object_set (chatroom, "favorite", FALSE, NULL);
+  fail_if (!changed);
+}
+END_TEST
+
+TCase *
+make_empathy_chatroom_tcase (void)
+{
+    TCase *tc = tcase_create ("empathy-chatroom");
+    tcase_add_test (tc, test_empathy_chatroom_new);
+    tcase_add_test (tc, test_favorite_and_auto_connect);
+    tcase_add_test (tc, test_change_favorite);
+    return tc;
+}
diff --git a/tests/check-empathy-helpers.c b/tests/check-empathy-helpers.c
new file mode 100644
index 0000000..2e808c0
--- /dev/null
+++ b/tests/check-empathy-helpers.c
@@ -0,0 +1,156 @@
+/*
+ * check-empathy-helpers.c - Source for some check helpers
+ * Copyright (C) 2007-2008 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <glib/gstdio.h>
+#include <gconf/gconf.h>
+#include <gconf/gconf-client.h>
+
+#include "check-helpers.h"
+#include "check-empathy-helpers.h"
+
+gchar *
+get_xml_file (const gchar *filename)
+{
+  return g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "tests", "xml",
+      filename, NULL);
+}
+
+gchar *
+get_user_xml_file (const gchar *filename)
+{
+  return g_build_filename (g_get_tmp_dir (), filename, NULL);
+}
+
+void
+copy_xml_file (const gchar *orig,
+               const gchar *dest)
+{
+  gboolean result;
+  gchar *buffer;
+  gsize length;
+  gchar *sample;
+  gchar *file;
+
+  sample = get_xml_file (orig);
+  result = g_file_get_contents (sample, &buffer, &length, NULL);
+  fail_if (!result);
+
+  file = get_user_xml_file (dest);
+  result = g_file_set_contents (file, buffer, length, NULL);
+  fail_if (!result);
+
+  g_free (sample);
+  g_free (file);
+  g_free (buffer);
+}
+
+McAccount *
+get_test_account (void)
+{
+  McProfile *profile;
+  McAccount *account;
+  GList *accounts;
+
+  profile = mc_profile_lookup ("test");
+  accounts = mc_accounts_list_by_profile (profile);
+  if (g_list_length (accounts) == 0)
+    {
+      /* need to create a test account */
+      account = mc_account_create (profile);
+    }
+  else
+    {
+      /* reuse an existing test account */
+      account = accounts->data;
+    }
+
+  g_object_unref (profile);
+
+  return account;
+}
+
+/* Not used for now as there is no API to remove completely gconf keys.
+ * So we reuse existing accounts instead of creating new ones */
+void
+destroy_test_account (McAccount *account)
+{
+  GConfClient *client;
+  gchar *path;
+  GError *error = NULL;
+  GSList *entries = NULL, *l;
+
+  client = gconf_client_get_default ();
+  path = g_strdup_printf ("/apps/telepathy/mc/accounts/%s",
+      mc_account_get_unique_name (account));
+
+  entries = gconf_client_all_entries (client, path, &error);
+  if (error != NULL)
+    {
+      g_print ("failed to list entries in %s: %s\n", path, error->message);
+      g_error_free (error);
+      error = NULL;
+    }
+
+  for (l = entries; l != NULL; l = g_slist_next (l))
+    {
+      GConfEntry *entry = l->data;
+
+      if (g_str_has_suffix (entry->key, "data_dir"))
+        {
+          gchar *dir;
+
+          dir = gconf_client_get_string (client, entry->key, &error);
+          if (error != NULL)
+            {
+              g_print ("get data_dir string failed: %s\n", entry->key);
+              g_error_free (error);
+              error = NULL;
+            }
+          else
+            {
+              if (g_rmdir (dir) != 0)
+                g_print ("can't remove %s\n", dir);
+            }
+
+          g_free (dir);
+        }
+
+      /* FIXME: this doesn't remove the key */
+      gconf_client_unset (client, entry->key, &error);
+      if (error != NULL)
+        {
+          g_print ("unset of %s failed: %s\n", path, error->message);
+          g_error_free (error);
+          error = NULL;
+        }
+
+      gconf_entry_free (entry);
+    }
+
+  g_slist_free (entries);
+
+  g_object_unref (client);
+  g_free (path);
+
+  mc_account_delete (account);
+  g_object_unref (account);
+}
diff --git a/tests/check-empathy-helpers.h b/tests/check-empathy-helpers.h
new file mode 100644
index 0000000..4d52c04
--- /dev/null
+++ b/tests/check-empathy-helpers.h
@@ -0,0 +1,31 @@
+/*
+ * check-empathy-helpers.c - Source for some check helpers
+ * Copyright (C) 2007 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+#ifndef __CHECK_EMPATHY_HELPERS_H__
+#define __CHECK_EMPATHY_HELPERS_H__
+
+#include <glib.h>
+#include <libmissioncontrol/mc-account.h>
+
+gchar * get_xml_file (const gchar *filename);
+gchar * get_user_xml_file (const gchar *filename);
+void copy_xml_file (const gchar *orig, const gchar *dest);
+McAccount * get_test_account (void);
+void destroy_test_account (McAccount *account);
+
+#endif /* #ifndef __CHECK_EMPATHY_HELPERS_H__ */
diff --git a/tests/check-empathy-irc-network-manager.c b/tests/check-empathy-irc-network-manager.c
index 3244a8e..44d6f7f 100644
--- a/tests/check-empathy-irc-network-manager.c
+++ b/tests/check-empathy-irc-network-manager.c
@@ -7,6 +7,7 @@
 #include "check-helpers.h"
 #include "check-libempathy.h"
 #include "check-irc-helper.h"
+#include "check-empathy-helpers.h"
 
 #include <libempathy/empathy-irc-network-manager.h>
 
@@ -14,18 +15,6 @@
 #define USER_SAMPLE "user-irc-networks-sample.xml"
 #define USER_FILE "user-irc-networks.xml"
 
-static gchar *
-get_xml_file (const gchar *filename)
-{
-  return g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "tests", "xml", filename, NULL);
-}
-
-static gchar *
-get_user_xml_file (const gchar *filename)
-{
-  return g_build_filename (g_get_tmp_dir (), filename, NULL);
-}
-
 START_TEST (test_empathy_irc_network_manager_add)
 {
   EmpathyIrcNetworkManager *mgr;
@@ -251,28 +240,6 @@ START_TEST (test_empathy_irc_network_manager_remove)
 }
 END_TEST
 
-static void
-copy_user_file (void)
-{
-  gboolean result;
-  gchar *buffer;
-  gsize length;
-  gchar *user_sample;
-  gchar *user_file;
-
-  user_sample = get_xml_file (USER_SAMPLE);
-  result = g_file_get_contents (user_sample, &buffer, &length, NULL);
-  fail_if (!result);
-
-  user_file = get_user_xml_file (USER_FILE);
-  result = g_file_set_contents (user_file, buffer, length, NULL);
-  fail_if (!result);
-
-  g_free (user_sample);
-  g_free (user_file);
-  g_free (buffer);
-}
-
 START_TEST (test_load_user_file)
 {
   EmpathyIrcNetworkManager *mgr;
@@ -289,7 +256,7 @@ START_TEST (test_load_user_file)
   gboolean network_checked[3];
   gchar *user_file_orig;
 
-  copy_user_file ();
+  copy_xml_file (USER_SAMPLE, USER_FILE);
   user_file_orig = get_user_xml_file (USER_FILE);
   mgr = empathy_irc_network_manager_new (NULL, user_file_orig);
 
@@ -453,7 +420,7 @@ START_TEST (test_modify_user_file)
   gboolean network_checked[3];
   gchar *user_file_orig;
 
-  copy_user_file ();
+  copy_xml_file (USER_SAMPLE, USER_FILE);
   user_file_orig = get_user_xml_file (USER_FILE);
   mgr = empathy_irc_network_manager_new (NULL, user_file_orig);
 
@@ -622,7 +589,7 @@ START_TEST (test_modify_both_files)
   gboolean network_checked[4];
   gchar *global_file_orig, *user_file_orig;
 
-  copy_user_file ();
+  copy_xml_file (USER_SAMPLE, USER_FILE);
   global_file_orig = get_xml_file (GLOBAL_SAMPLE);
   user_file_orig = get_user_xml_file (USER_FILE);
   mgr = empathy_irc_network_manager_new (global_file_orig, user_file_orig);
diff --git a/tests/check-helpers.c b/tests/check-helpers.c
index 7a7663f..5f1f32f 100644
--- a/tests/check-helpers.c
+++ b/tests/check-helpers.c
@@ -20,6 +20,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <glib/gstdio.h>
+#include <gconf/gconf.h>
+#include <gconf/gconf-client.h>
+
 #include "check-helpers.h"
 
 static gboolean expecting_critical = FALSE;
diff --git a/tests/check-helpers.h b/tests/check-helpers.h
index b71b3b6..3e07838 100644
--- a/tests/check-helpers.h
+++ b/tests/check-helpers.h
@@ -21,6 +21,7 @@
 
 #include <glib.h>
 #include <check.h>
+#include <libmissioncontrol/mc-account.h>
 
 void
 check_helpers_init (void);
diff --git a/tests/check-libempathy.h b/tests/check-libempathy.h
index 0f9388d..5dcb2b1 100644
--- a/tests/check-libempathy.h
+++ b/tests/check-libempathy.h
@@ -5,5 +5,7 @@ TCase * make_empathy_utils_tcase (void);
 TCase * make_empathy_irc_server_tcase (void);
 TCase * make_empathy_irc_network_tcase (void);
 TCase * make_empathy_irc_network_manager_tcase (void);
+TCase * make_empathy_chatroom_tcase (void);
+TCase * make_empathy_chatroom_manager_tcase (void);
 
 #endif /* #ifndef __CHECK_LIBEMPATHY__ */
diff --git a/tests/check-main.c b/tests/check-main.c
index f0e366d..886e1e5 100644
--- a/tests/check-main.c
+++ b/tests/check-main.c
@@ -19,6 +19,8 @@ make_libempathy_suite (void)
     suite_add_tcase (s, make_empathy_irc_server_tcase ());
     suite_add_tcase (s, make_empathy_irc_network_tcase ());
     suite_add_tcase (s, make_empathy_irc_network_manager_tcase ());
+    suite_add_tcase (s, make_empathy_chatroom_tcase ());
+    suite_add_tcase (s, make_empathy_chatroom_manager_tcase ());
 
     return s;
 }
diff --git a/tests/test.manager b/tests/test.manager
new file mode 100644
index 0000000..8a49c32
--- /dev/null
+++ b/tests/test.manager
@@ -0,0 +1,5 @@
+[ConnectionManager]
+BusName=org.freedesktop.Telepathy.ConnectionManager.test
+ObjectPath=/org/freedesktop/Telepathy/ConnectionManager/test
+
+[Protocol test]
diff --git a/tests/test.profile b/tests/test.profile
new file mode 100644
index 0000000..20e552a
--- /dev/null
+++ b/tests/test.profile
@@ -0,0 +1,4 @@
+[Profile]
+Manager = test
+Protocol = test
+DisplayName = test
diff --git a/tests/xml/Makefile.am b/tests/xml/Makefile.am
index eafe8de..d35bdc6 100644
--- a/tests/xml/Makefile.am
+++ b/tests/xml/Makefile.am
@@ -1,3 +1,4 @@
 EXTRA_DIST = 				\
 	default-irc-networks-sample.xml	\
-	user-irc-networks-sample.xml
+	user-irc-networks-sample.xml \
+	chatrooms.xml
diff --git a/tests/xml/chatrooms-sample.xml b/tests/xml/chatrooms-sample.xml
new file mode 100644
index 0000000..e06c43e
--- /dev/null
+++ b/tests/xml/chatrooms-sample.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<chatrooms>
+  <chatroom>
+    <name>name1</name>
+    <room>room1</room>
+    <account>CHANGE_ME</account>
+    <auto_connect>yes</auto_connect>
+  </chatroom>
+  <chatroom>
+    <name>name2</name>
+    <room>room2</room>
+    <account>CHANGE_ME</account>
+    <auto_connect>no</auto_connect>
+  </chatroom>
+</chatrooms>
