]> Pileus Git - ~andy/gtk/blobdiff - gtk/tests/filechooser.c
filechooserbutton: For the open-dialog-cancel-* tests, add a real nomenclature and...
[~andy/gtk] / gtk / tests / filechooser.c
index 8aa59937930f0168daf4e4765808a1f018a597e9..bc18b2fa5859829be8e675e863b8c24e1734fb78 100644 (file)
 #include "gtk/gtkfilechooserdefault.h"
 #include "gtk/gtkfilechooserentry.h"
 
+#if 0
+static const char *
+get_action_name (GtkFileChooserAction action)
+{
+  switch (action)
+    {
+    case GTK_FILE_CHOOSER_ACTION_OPEN:          return "OPEN";
+    case GTK_FILE_CHOOSER_ACTION_SAVE:          return "SAVE";
+    case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: return "SELECT_FOLDER";
+    case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: return "CREATE_FOLDER";
+
+    default:
+      g_assert_not_reached ();
+      return NULL;
+    }
+}
+#endif
+
 #ifdef BROKEN_TESTS
 static void
 log_test (gboolean passed, const char *test_name, ...)
@@ -53,8 +71,6 @@ log_test (gboolean passed, const char *test_name, ...)
   g_free (str);
 }
 
-static const char *get_action_name (GtkFileChooserAction action);
-
 typedef void (* SetFilenameFn) (GtkFileChooser *chooser, gpointer data);
 typedef void (* CompareFilenameFn) (GtkFileChooser *chooser, gpointer data);
 
@@ -302,9 +318,14 @@ typedef struct
   const char *initial_current_folder;
   const char *initial_filename;
   gboolean open_dialog;
+  enum {
+    BUTTON,
+    DIALOG
+  } what_to_tweak;
   const char *tweak_current_folder;
   const char *tweak_filename;
   gint dialog_response;
+  gboolean unselect_all;
   const char *final_current_folder;
   const char *final_filename;
 } FileChooserButtonTest;
@@ -342,18 +363,6 @@ make_button_test_name (FileChooserButtonTest *t)
 #endif
 }
 
-/* Copied from gtkfilechooserutils.c:_gtk_file_chooser_delegate_get_quark() */
-static GQuark
-delegate_get_quark (void)
-{
-  static GQuark quark = 0;
-
-  if (G_UNLIKELY (quark == 0))
-    quark = g_quark_from_static_string ("gtk-file-chooser-delegate");
-
-  return quark;
-}
-
 static gboolean
 sleep_timeout_cb (gpointer data)
 {
@@ -364,42 +373,306 @@ sleep_timeout_cb (gpointer data)
 static void
 sleep_in_main_loop (void)
 {
-  /* process all pending idles and events */
-  while (g_main_context_pending (NULL))
-    g_main_context_iteration (NULL, FALSE);
-  /* sleeping probably isn't strictly necessary here */
   gdk_threads_add_timeout_full (G_MAXINT, 250, sleep_timeout_cb, NULL, NULL);
   gtk_main ();
-  /* process any pending idles or events that arrived during sleep */
-  while (g_main_context_pending (NULL))
-    g_main_context_iteration (NULL, FALSE);
 }
 
 static void
-test_file_chooser_button (gconstpointer data)
+build_children_list (GtkWidget *widget, gpointer data)
 {
-  const FileChooserButtonTest *setup = data;
+  GList **list;
+
+  list = data;
+  *list = g_list_prepend (*list, widget);
+}
+
+static GtkWidget *
+find_child_widget_with_atk_role (GtkWidget *widget, AtkRole role)
+{
+  AtkObject *accessible;
+  AtkRole a_role;
+
+  accessible = gtk_widget_get_accessible (widget);
+  a_role = atk_object_get_role (accessible);
+
+  if (a_role == role)
+    return widget;
+  else
+    {
+      GtkWidget *found_child;
+
+      found_child = NULL;
+
+      if (GTK_IS_CONTAINER (widget))
+       {
+         GList *children;
+         GList *l;
+
+         children = NULL;
+         gtk_container_forall (GTK_CONTAINER (widget), build_children_list, &children);
+
+         l = children;
+
+         while (l && !found_child)
+           {
+             GtkWidget *child;
+
+             child = GTK_WIDGET (l->data);
+
+             found_child = find_child_widget_with_atk_role (child, role);
+
+             l = l->next;
+           }
+
+         g_list_free (children);
+       }
+
+      return found_child;
+    }
+}
+
+static const char *
+get_atk_name_for_filechooser_button (GtkFileChooserButton *button)
+{
+  GtkFileChooserAction action;
+  GtkWidget *widget;
+  AtkObject *accessible;
+
+  action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (button));
+  g_assert (action == GTK_FILE_CHOOSER_ACTION_OPEN || action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+
+  if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
+    widget = find_child_widget_with_atk_role (GTK_WIDGET (button), ATK_ROLE_PUSH_BUTTON);
+  else
+    widget = find_child_widget_with_atk_role (GTK_WIDGET (button), ATK_ROLE_COMBO_BOX);
+
+  accessible = gtk_widget_get_accessible (widget);
+  return atk_object_get_name (accessible);
+}
+
+static void
+check_that_basename_is_shown (GtkFileChooserButton *button, const char *expected_filename)
+{
+  GtkFileChooserAction action;
+  const char *name_on_button;
+  char *expected_basename;
+
+  name_on_button = get_atk_name_for_filechooser_button (button);
+
+  action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (button));
+  g_assert (action == GTK_FILE_CHOOSER_ACTION_OPEN || action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+
+  if (expected_filename)
+    expected_basename = g_path_get_basename (expected_filename);
+  else
+    expected_basename = NULL;
+
+  if (expected_basename)
+    g_assert_cmpstr (expected_basename, ==, name_on_button);
+  else
+    g_assert_cmpstr (name_on_button, ==, "(None)"); /* see gtkfilechooserbutton.c:FALLBACK_DISPLAY_NAME */ /* FIXME: how do we translate this? */
+
+  g_free (expected_basename);
+}
+
+static const char *
+get_expected_shown_filename (GtkFileChooserAction action, const char *folder_name, const char *filename)
+{
+  if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
+    {
+      if (filename)
+       return filename;
+      else
+       return folder_name;
+    }
+  else
+    return filename;
+}
+
+static GtkWidget *
+get_file_chooser_dialog_from_button (GtkFileChooserButton *button)
+{
+  GtkWidget *fc_dialog;
+
+  /* Give me the internal dialog, damnit */
+  fc_dialog = g_object_get_qdata (G_OBJECT (button), g_quark_from_static_string ("gtk-file-chooser-delegate"));
+  g_assert (GTK_IS_FILE_CHOOSER (fc_dialog));
+  g_assert (GTK_IS_DIALOG (fc_dialog));
+
+  return fc_dialog;
+}
+
+typedef struct {
   GtkWidget *window;
   GtkWidget *fc_button;
+} WindowAndButton;
+
+static WindowAndButton
+create_window_and_file_chooser_button (GtkFileChooserAction action)
+{
+  WindowAndButton w;
+
+  w.window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+  w.fc_button = gtk_file_chooser_button_new (action == GTK_FILE_CHOOSER_ACTION_OPEN ? "Select a file" : "Select a folder",
+                                            action);
+  gtk_container_add (GTK_CONTAINER (w.window), w.fc_button);
+
+  return w;
+}
+
+typedef struct
+{
+  GObject *object;
+  GHashTable *signals;
+  gboolean in_main_loop;
+} SignalWatcher;
+
+typedef struct
+{
+  SignalWatcher *watcher;
+  char *signal_name;
+  gulong id;
+  gboolean emitted;
+} SignalConnection;
+
+static SignalWatcher *
+signal_watcher_new (GObject *object)
+{
+  SignalWatcher *watcher = g_new0 (SignalWatcher, 1);
+
+  watcher->object = g_object_ref (object);
+  watcher->signals = g_hash_table_new (g_str_hash, g_str_equal);
+
+  return watcher;
+}
+
+static void
+dummy_callback (GObject *object)
+{
+  /* nothing */
+}
+
+static void
+marshal_notify_cb (gpointer data, GClosure *closure)
+{
+  if (data)
+    {
+      SignalConnection *conn;
+
+      conn = data;
+      conn->emitted = TRUE;
+
+      if (conn->watcher->in_main_loop)
+       {
+         gtk_main_quit ();
+         conn->watcher->in_main_loop = FALSE;
+       }
+    }
+}
+
+static void
+signal_watcher_watch_signal (SignalWatcher *watcher, const char *signal_name)
+{
+  SignalConnection *conn;
+
+  conn = g_hash_table_lookup (watcher->signals, signal_name);
+  if (!conn)
+    {
+      GClosure *closure;
+
+      conn = g_new0 (SignalConnection, 1);
+      conn->watcher = watcher;
+      conn->signal_name = g_strdup (signal_name);
+
+      closure = g_cclosure_new (G_CALLBACK (dummy_callback), NULL, NULL);
+      g_closure_add_marshal_guards (closure, conn, marshal_notify_cb, NULL, marshal_notify_cb);
+      conn->id = g_signal_connect_closure (watcher->object, signal_name, closure, FALSE);
+      conn->emitted = FALSE;
+
+      g_hash_table_insert (watcher->signals, conn->signal_name, conn);
+    }
+  else
+    conn->emitted = FALSE;
+}
+
+static gboolean
+signal_watcher_expect (SignalWatcher *watcher, const char *signal_name)
+{
+  SignalConnection *conn;
+  gboolean emitted;
+
+  conn = g_hash_table_lookup (watcher->signals, signal_name);
+  g_assert (conn != NULL);
+
+  if (!conn->emitted)
+    {
+      gdk_threads_add_timeout_full (G_MAXINT, 1000, sleep_timeout_cb, NULL, NULL);
+      watcher->in_main_loop = TRUE;
+      gtk_main ();
+      watcher->in_main_loop = FALSE;
+    }
+
+  emitted = conn->emitted;
+  conn->emitted = FALSE;
+
+  return emitted;
+}
+
+static void
+destroy_connection (gpointer key, gpointer value, gpointer user_data)
+{
+  SignalConnection *conn;
+
+  conn = value;
+  g_signal_handler_disconnect (conn->watcher->object, conn->id);
+  g_free (conn->signal_name);
+  g_free (conn);
+}
+
+static void
+signal_watcher_destroy (SignalWatcher *watcher)
+{
+  g_hash_table_foreach (watcher->signals, destroy_connection, NULL);
+  g_hash_table_destroy (watcher->signals);
+  g_object_unref (watcher->object);
+  g_free (watcher);
+}
+
+static void
+test_file_chooser_button (gconstpointer data)
+{
+  const FileChooserButtonTest *setup = data;
+  WindowAndButton w;
+  SignalWatcher *watcher;
   GtkWidget *fc_dialog;
   int iterations;
   int i;
 
-  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  w = create_window_and_file_chooser_button (setup->action);
 
-  fc_button = gtk_file_chooser_button_new (setup->action == GTK_FILE_CHOOSER_ACTION_OPEN ? "Select a file" : "Select a folder",
-                                          setup->action);
-  gtk_container_add (GTK_CONTAINER (window), fc_button);
+  watcher = signal_watcher_new (G_OBJECT (w.fc_button));
+  signal_watcher_watch_signal (watcher, "current-folder-changed");
+  signal_watcher_watch_signal (watcher, "selection-changed");
 
   if (setup->initial_current_folder)
-    gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc_button), setup->initial_current_folder);
+    gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w.fc_button), setup->initial_current_folder);
 
   if (setup->initial_filename)
-    gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (fc_button), setup->initial_filename);
+    gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (w.fc_button), setup->initial_filename);
 
-  gtk_widget_show_all (window);
+  gtk_widget_show_all (w.window);
   wait_for_idle ();
 
+  if (setup->initial_current_folder)
+    g_assert (signal_watcher_expect (watcher, "current-folder-changed"));
+
+  if (setup->initial_filename)
+    g_assert (signal_watcher_expect (watcher, "selection-changed"));
+
+  check_that_basename_is_shown (GTK_FILE_CHOOSER_BUTTON (w.fc_button),
+                               get_expected_shown_filename (setup->action, setup->initial_current_folder, setup->initial_filename));
+
   /* If there is a dialog to be opened, we actually test going through it a
    * couple of times.  This ensures that any state that the button frobs for
    * each appearance of the dialog will make sense.
@@ -411,43 +684,78 @@ test_file_chooser_button (gconstpointer data)
 
   for (i = 0; i < iterations; i++)
     {
+      GtkFileChooser *chooser_to_tweak;
+
       if (setup->open_dialog)
        {
          GList *children;
 
          /* Hack our way into the file chooser button; get its GtkButton child and click it */
-         children = gtk_container_get_children (GTK_CONTAINER (fc_button));
+         children = gtk_container_get_children (GTK_CONTAINER (w.fc_button));
          g_assert (children && GTK_IS_BUTTON (children->data));
          gtk_button_clicked (GTK_BUTTON (children->data));
          g_list_free (children);
 
-         sleep_in_main_loop ();
+         wait_for_idle ();
 
-         /* Give me the internal dialog, damnit */
-         fc_dialog = g_object_get_qdata (G_OBJECT (fc_button), delegate_get_quark ());
-         g_assert (GTK_IS_FILE_CHOOSER (fc_dialog));
-         g_assert (GTK_IS_DIALOG (fc_dialog));
+         fc_dialog = get_file_chooser_dialog_from_button (GTK_FILE_CHOOSER_BUTTON (w.fc_button));
        }
 
-      /* Okay, now frob the button and its optional dialog */
+      if (setup->what_to_tweak == BUTTON)
+       chooser_to_tweak = GTK_FILE_CHOOSER (w.fc_button);
+      else if (setup->what_to_tweak == DIALOG)
+       chooser_to_tweak = GTK_FILE_CHOOSER (fc_dialog);
+      else
+       g_assert_not_reached ();
+
+      /* Okay, now frob the button or its optional dialog */
 
       if (setup->tweak_current_folder)
-       gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc_button), setup->tweak_current_folder);
+       {
+         if (setup->what_to_tweak == BUTTON)
+           signal_watcher_watch_signal (watcher, "current-folder-changed");
+
+         gtk_file_chooser_set_current_folder (chooser_to_tweak, setup->tweak_current_folder);
+
+         if (setup->what_to_tweak == BUTTON)
+           g_assert (signal_watcher_expect (watcher, "current-folder-changed"));
+       }
 
       if (setup->tweak_filename)
-       gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (fc_button), setup->tweak_filename);
+       {
+         if (setup->what_to_tweak == BUTTON)
+           signal_watcher_watch_signal (watcher, "selection-changed");
+
+         gtk_file_chooser_select_filename (chooser_to_tweak, setup->tweak_filename);
+
+         if (setup->what_to_tweak == BUTTON)
+           g_assert (signal_watcher_expect (watcher, "selection-changed"));
+       }
 
-      sleep_in_main_loop ();
+      if (setup->unselect_all)
+       {
+         if (setup->what_to_tweak == BUTTON)
+           signal_watcher_watch_signal (watcher, "selection-changed");
+
+         gtk_file_chooser_unselect_all (chooser_to_tweak);
+
+         if (setup->what_to_tweak == BUTTON)
+           g_assert (signal_watcher_expect (watcher, "selection-changed"));
+       }
+
+      wait_for_idle ();
 
       if (setup->open_dialog)
        {
          gtk_dialog_response (GTK_DIALOG (fc_dialog), setup->dialog_response);
          wait_for_idle ();
+
+         gtk_window_resize (GTK_WINDOW (fc_dialog), 500, 500);
        }
 
       if (setup->final_current_folder)
        {
-         char *folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (fc_button));
+         char *folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (w.fc_button));
 
          g_assert_cmpstr (folder, ==, setup->final_current_folder);
          g_free (folder);
@@ -455,14 +763,113 @@ test_file_chooser_button (gconstpointer data)
 
       if (setup->final_filename)
        {
-         char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fc_button));
+         char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (w.fc_button));
 
          g_assert_cmpstr (filename, ==, setup->final_filename);
          g_free (filename);
        }
+
+      check_that_basename_is_shown (GTK_FILE_CHOOSER_BUTTON (w.fc_button),
+                                   get_expected_shown_filename (setup->action, setup->final_current_folder, setup->final_filename));
     }
 
-  gtk_widget_destroy (window);
+  signal_watcher_destroy (watcher);
+  gtk_widget_destroy (w.window);
+}
+
+static int
+find_accessible_action_num (AtkObject *object, const char *action_name)
+{
+  AtkAction *action_a;
+  int num_actions;
+  int i;
+
+  action_a = ATK_ACTION (object);
+
+  num_actions = atk_action_get_n_actions (action_a);
+
+  for (i = 0; i < num_actions; i++)
+    if (strcmp (atk_action_get_name (action_a, i), action_name) == 0)
+      return i;
+
+  return -1;
+}
+
+static void
+do_accessible_action (AtkObject *object, const char *action_name)
+{
+  int action_num;
+
+  action_num = find_accessible_action_num (object, action_name);
+  g_assert (action_num != -1);
+
+  atk_action_do_action (ATK_ACTION (object), action_num);
+}
+
+static void
+test_file_chooser_button_combo_box_1 (void)
+{
+  WindowAndButton w;
+  GtkWidget *combo_box;
+  AtkObject *combo_box_a;
+  AtkObject *menu_a;
+  int num_items;
+  int other_index;
+  AtkObject *item_a;
+  GtkWidget *fc_dialog;
+
+  w = create_window_and_file_chooser_button (GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+
+  gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (w.fc_button), FOLDER_NAME);
+
+  gtk_widget_show_all (w.window);
+
+  /* Get the accessible for the combo box */
+
+  combo_box = find_child_widget_with_atk_role (GTK_WIDGET (w.fc_button), ATK_ROLE_COMBO_BOX);
+  combo_box_a = gtk_widget_get_accessible (combo_box);
+
+  /* Press the combo box to bring up the menu */
+
+  do_accessible_action (combo_box_a, "press");
+  sleep_in_main_loop (); /* have to wait because bringing up the menu is asynchronous... */
+
+  /* Get the menu from the combo box; it's the first child */
+
+  menu_a = atk_object_ref_accessible_child (combo_box_a, 0);
+  g_assert (atk_object_get_role (menu_a) == ATK_ROLE_MENU);
+
+  /* Check that the last item in the menu is the "Other…" one */
+
+  num_items = atk_object_get_n_accessible_children (menu_a);
+  g_assert (num_items > 0);
+
+  other_index = num_items - 1;
+
+  item_a = atk_object_ref_accessible_child (menu_a, other_index);
+  g_assert_cmpstr (atk_object_get_name (item_a), ==, "Other…");  /* FIXME: how do we translate this? */
+
+  /* Activate the item */
+
+  do_accessible_action (item_a, "click");
+
+  /* Cancel the dialog */
+
+  sleep_in_main_loop ();
+  fc_dialog = get_file_chooser_dialog_from_button (GTK_FILE_CHOOSER_BUTTON (w.fc_button));
+
+  gtk_dialog_response (GTK_DIALOG (fc_dialog), GTK_RESPONSE_CANCEL);
+
+  /* Now check the selection in the combo box */
+  check_that_basename_is_shown (GTK_FILE_CHOOSER_BUTTON (w.fc_button), FOLDER_NAME);
+
+  gtk_widget_destroy (w.window);
+}
+
+static void
+setup_file_chooser_button_combo_box_tests (void)
+{
+  g_test_add_func ("/GtkFileChooserButton/combo_box-1", test_file_chooser_button_combo_box_1);
 }
 
 static FileChooserButtonTest button_tests[] =
@@ -475,9 +882,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       NULL,                    /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -487,9 +896,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       FILE_NAME,               /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FILE_NAME                        /* final_filename */
     },
@@ -499,9 +910,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       NULL,                    /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FILE_NAME,               /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FILE_NAME                        /* final_filename */
     },
@@ -511,9 +924,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       FILE_NAME,               /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FILE_NAME_2,             /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FILE_NAME_2              /* final_filename */
     },
@@ -523,9 +938,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       FOLDER_NAME,             /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -535,9 +952,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       FOLDER_NAME_2,           /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       FOLDER_NAME_2,           /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -550,9 +969,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       NULL,                    /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -562,9 +983,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       FOLDER_NAME,             /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME              /* final_filename */
     },
@@ -574,9 +997,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       FOLDER_NAME,             /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FOLDER_NAME_2,           /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME_2            /* final_filename */
     },
@@ -586,9 +1011,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME              /* final_filename */
     },
@@ -598,9 +1025,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       FOLDER_NAME,             /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -610,9 +1039,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       FOLDER_NAME_2,           /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME_2            /* final_filename */
     },
@@ -622,9 +1053,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       FOLDER_NAME_2,           /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       FOLDER_NAME_2,           /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -634,84 +1067,196 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FOLDER_NAME_2,           /* tweak_filename */
       0,                       /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME_2            /* final_filename */
     },
 
-    /* OPEN tests with dialog, cancelled */
-
-    {
-      "open-dialog-cancel-1",
+    /* OPEN tests with dialog, cancelled
+     *
+     * Test names are "open-dialog-cancel-A-B", where A and B can be:
+     *
+     *   A:
+     *      ni - no initial filename
+     *       i - initial filename
+     *      nf - no initial folder
+     *       f - initial folder
+     *
+     *   B:
+     *      nt - no tweaks
+     *       b - tweak button
+     *       d - tweak dialog
+     */
+
+    {
+      "open-dialog-cancel-ni-nt",
       GTK_FILE_CHOOSER_ACTION_OPEN,
       NULL,                    /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       NULL                     /* final_filename */
     },
     {
-      "open-dialog-cancel-2",
+      "open-dialog-cancel-ni-b",
       GTK_FILE_CHOOSER_ACTION_OPEN,
       NULL,                    /* initial_current_folder */
-      FILE_NAME,               /* initial_filename */
+      NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
-      NULL,                    /* tweak_filename */
+      FILE_NAME,               /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FILE_NAME                        /* final_filename */
     },
     {
-      "open-dialog-cancel-3",
+      "open-dialog-cancel-ni-d",
       GTK_FILE_CHOOSER_ACTION_OPEN,
-      FOLDER_NAME,             /* initial_current_folder */
-      NULL,                    /* initial_filename */
+      NULL,                    /* initial_current_folder */
+      NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      DIALOG,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
-      NULL,                    /* tweak_filename */
+      FILE_NAME,               /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
-      FOLDER_NAME,             /* final_current_folder */
+      FALSE,                   /* unselect_all */
+      NULL,                    /* final_current_folder */
       NULL                     /* final_filename */
     },
     {
-      "open-dialog-cancel-4",
+      "open-dialog-cancel-i-nt",
       GTK_FILE_CHOOSER_ACTION_OPEN,
       NULL,                    /* initial_current_folder */
-      NULL,                    /* initial_filename */
+      FILE_NAME,               /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
-      FILE_NAME,               /* tweak_filename */
+      NULL,                    /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
-      NULL                     /* final_filename */
+      FILE_NAME                        /* final_filename */
     },
     {
-      "open-dialog-cancel-5",
+      "open-dialog-cancel-i-b",
       GTK_FILE_CHOOSER_ACTION_OPEN,
       NULL,                    /* initial_current_folder */
       FILE_NAME,               /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FILE_NAME_2,             /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
+      NULL,                    /* final_current_folder */
+      FILE_NAME_2              /* final_filename */
+    },
+    {
+      "open-dialog-cancel-i-d",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      NULL,                    /* initial_current_folder */
+      FILE_NAME,               /* initial_filename */
+      TRUE,                    /* open_dialog */
+      DIALOG,                  /* what_to_tweak */
+      NULL,                    /* tweak_current_folder */
+      FILE_NAME_2,             /* tweak_filename */
+      GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FILE_NAME                        /* final_filename */
     },
     {
-      "open-dialog-cancel-6",
+      "open-dialog-cancel-nf-nt",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      NULL,                    /* initial_current_folder */
+      NULL,                    /* initial_filename */
+      TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
+      NULL,                    /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
+      GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
+      NULL,                    /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "open-dialog-cancel-nf-b",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      NULL,                    /* initial_current_folder */
+      NULL,                    /* initial_filename */
+      TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
+      FOLDER_NAME,             /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
+      GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
+      FOLDER_NAME,             /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "open-dialog-cancel-nf-d",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      NULL,                    /* initial_current_folder */
+      NULL,                    /* initial_filename */
+      TRUE,                    /* open_dialog */
+      DIALOG,                  /* what_to_tweak */
+      FOLDER_NAME,             /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
+      GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
+      NULL,                    /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "open-dialog-cancel-f-nt",
       GTK_FILE_CHOOSER_ACTION_OPEN,
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
-      FILE_NAME_2,             /* tweak_filename */
+      NULL,                    /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
+      FOLDER_NAME,             /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "open-dialog-cancel-f-b",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      FOLDER_NAME,             /* initial_current_folder */
+      NULL,                    /* initial_filename */
+      TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
+      FOLDER_NAME_2,           /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
+      GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
+      FOLDER_NAME_2,           /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "open-dialog-cancel-f-d",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      FOLDER_NAME,             /* initial_current_folder */
+      NULL,                    /* initial_filename */
+      TRUE,                    /* open_dialog */
+      DIALOG,                  /* what_to_tweak */
+      FOLDER_NAME_2,           /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
+      GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       FOLDER_NAME,             /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -719,74 +1264,170 @@ static FileChooserButtonTest button_tests[] =
     /* OPEN tests with dialog, cancelled via closing the dialog (not by selecting the Cancel button) */
 
     {
-      "open-dialog-close-1",
+      "open-dialog-close-ni-nt",
       GTK_FILE_CHOOSER_ACTION_OPEN,
       NULL,                    /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       NULL                     /* final_filename */
     },
     {
-      "open-dialog-close-2",
+      "open-dialog-close-ni-b",
       GTK_FILE_CHOOSER_ACTION_OPEN,
       NULL,                    /* initial_current_folder */
-      FILE_NAME,               /* initial_filename */
+      NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
-      NULL,                    /* tweak_filename */
+      FILE_NAME,               /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FILE_NAME                        /* final_filename */
     },
     {
-      "open-dialog-close-3",
+      "open-dialog-close-ni-d",
       GTK_FILE_CHOOSER_ACTION_OPEN,
-      FOLDER_NAME,             /* initial_current_folder */
-      NULL,                    /* initial_filename */
+      NULL,                    /* initial_current_folder */
+      NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      DIALOG,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
-      NULL,                    /* tweak_filename */
+      FILE_NAME,               /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
-      FOLDER_NAME,             /* final_current_folder */
+      FALSE,                   /* unselect_all */
+      NULL,                    /* final_current_folder */
       NULL                     /* final_filename */
     },
     {
-      "open-dialog-close-4",
+      "open-dialog-close-i-nt",
       GTK_FILE_CHOOSER_ACTION_OPEN,
       NULL,                    /* initial_current_folder */
-      NULL,                    /* initial_filename */
+      FILE_NAME,               /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
-      FILE_NAME,               /* tweak_filename */
+      NULL,                    /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
-      NULL                     /* final_filename */
+      FILE_NAME                        /* final_filename */
     },
     {
-      "open-dialog-close-5",
+      "open-dialog-close-i-b",
       GTK_FILE_CHOOSER_ACTION_OPEN,
       NULL,                    /* initial_current_folder */
       FILE_NAME,               /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FILE_NAME_2,             /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
+      NULL,                    /* final_current_folder */
+      FILE_NAME_2              /* final_filename */
+    },
+    {
+      "open-dialog-close-i-d",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      NULL,                    /* initial_current_folder */
+      FILE_NAME,               /* initial_filename */
+      TRUE,                    /* open_dialog */
+      DIALOG,                  /* what_to_tweak */
+      NULL,                    /* tweak_current_folder */
+      FILE_NAME_2,             /* tweak_filename */
+      GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FILE_NAME                        /* final_filename */
     },
     {
-      "open-dialog-close-6",
+      "open-dialog-close-nf-nt",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      NULL,                    /* initial_current_folder */
+      NULL,                    /* initial_filename */
+      TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
+      NULL,                    /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
+      GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
+      NULL,                    /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "open-dialog-close-nf-b",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      NULL,                    /* initial_current_folder */
+      NULL,                    /* initial_filename */
+      TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
+      FOLDER_NAME,             /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
+      GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
+      FOLDER_NAME,             /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "open-dialog-close-nf-d",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      NULL,                    /* initial_current_folder */
+      NULL,                    /* initial_filename */
+      TRUE,                    /* open_dialog */
+      DIALOG,                  /* what_to_tweak */
+      FOLDER_NAME,             /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
+      GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
+      NULL,                    /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "open-dialog-close-f-nt",
       GTK_FILE_CHOOSER_ACTION_OPEN,
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
-      FILE_NAME_2,             /* tweak_filename */
+      NULL,                    /* tweak_filename */
+      GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
+      FOLDER_NAME,             /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "open-dialog-close-f-b",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      FOLDER_NAME,             /* initial_current_folder */
+      NULL,                    /* initial_filename */
+      TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
+      FOLDER_NAME_2,           /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
+      GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
+      FOLDER_NAME_2,           /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "open-dialog-close-f-d",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      FOLDER_NAME,             /* initial_current_folder */
+      NULL,                    /* initial_filename */
+      TRUE,                    /* open_dialog */
+      DIALOG,                  /* what_to_tweak */
+      FOLDER_NAME_2,           /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
       FOLDER_NAME,             /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -799,9 +1440,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -811,9 +1454,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       FOLDER_NAME,             /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME              /* final_filename */
     },
@@ -823,9 +1468,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       FOLDER_NAME,             /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -835,9 +1482,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME              /* final_filename */
     },
@@ -847,9 +1496,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FOLDER_NAME,             /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -859,9 +1510,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       FOLDER_NAME,             /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FOLDER_NAME_2,           /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME              /* final_filename */
     },
@@ -871,9 +1524,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FOLDER_NAME_2,           /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       FOLDER_NAME,             /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -883,9 +1538,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FOLDER_NAME_2,           /* tweak_filename */
       GTK_RESPONSE_CANCEL,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME              /* final_filename */
     },
@@ -898,9 +1555,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -910,9 +1569,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       FOLDER_NAME,             /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME              /* final_filename */
     },
@@ -922,9 +1583,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
       FOLDER_NAME,             /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -934,9 +1597,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME              /* final_filename */
     },
@@ -946,9 +1611,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FOLDER_NAME,             /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -958,9 +1625,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       FOLDER_NAME,             /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FOLDER_NAME_2,           /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME              /* final_filename */
     },
@@ -970,9 +1639,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FOLDER_NAME_2,           /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
       FOLDER_NAME,             /* final_current_folder */
       NULL                     /* final_filename */
     },
@@ -982,9 +1653,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FOLDER_NAME_2,           /* tweak_filename */
       GTK_RESPONSE_DELETE_EVENT,/* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME              /* final_filename */
     },
@@ -997,9 +1670,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FILE_NAME,               /* tweak_filename */
       GTK_RESPONSE_ACCEPT,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FILE_NAME                        /* final_filename */
     },
@@ -1009,9 +1684,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       FILE_NAME,               /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       GTK_RESPONSE_ACCEPT,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FILE_NAME                        /* final_filename */
     },
@@ -1021,9 +1698,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       FILE_NAME,               /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FILE_NAME_2,             /* tweak_filename */
       GTK_RESPONSE_ACCEPT,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FILE_NAME_2              /* final_filename */
     },
@@ -1033,9 +1712,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FILE_NAME,               /* tweak_filename */
       GTK_RESPONSE_ACCEPT,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FILE_NAME                        /* final_filename */
     },
@@ -1048,9 +1729,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       FOLDER_NAME,             /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       GTK_RESPONSE_ACCEPT,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME              /* final_filename */
     },
@@ -1060,9 +1743,11 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       NULL,                    /* tweak_filename */
       GTK_RESPONSE_ACCEPT,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME              /* final_filename */
     },
@@ -1072,9 +1757,11 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       FOLDER_NAME,             /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FOLDER_NAME_2,           /* tweak_filename */
       GTK_RESPONSE_ACCEPT,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME_2            /* final_filename */
     },
@@ -1084,13 +1771,101 @@ static FileChooserButtonTest button_tests[] =
       FOLDER_NAME,             /* initial_current_folder */
       NULL,                    /* initial_filename */
       TRUE,                    /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
       NULL,                    /* tweak_current_folder */
       FOLDER_NAME_2,           /* tweak_filename */
       GTK_RESPONSE_ACCEPT,     /* dialog_response */
+      FALSE,                   /* unselect_all */
       NULL,                    /* final_current_folder */
       FOLDER_NAME_2            /* final_filename */
     },
 
+    /* Unselection tests */
+    {
+      "unselect-all-1",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      NULL,                    /* initial_current_folder */
+      NULL,                    /* initial_filename */
+      FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
+      NULL,                    /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
+      0,                       /* dialog_response */
+      TRUE,                    /* unselect_all */
+      NULL,                    /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "unselect-all-2",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      NULL,                    /* initial_current_folder */
+      FILE_NAME,               /* initial_filename */
+      FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
+      NULL,                    /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
+      0,                       /* dialog_response */
+      TRUE,                    /* unselect_all */
+      NULL,                    /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "unselect-all-3",
+      GTK_FILE_CHOOSER_ACTION_OPEN,
+      NULL,                    /* initial_current_folder */
+      FILE_NAME,               /* initial_filename */
+      FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
+      NULL,                    /* tweak_current_folder */
+      FILE_NAME_2,             /* tweak_filename */
+      0,                       /* dialog_response */
+      TRUE,                    /* unselect_all */
+      NULL,                    /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "unselect-all-4",
+      GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+      NULL,                    /* initial_current_folder */
+      NULL,                    /* initial_filename */
+      FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
+      NULL,                    /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
+      0,                       /* dialog_response */
+      TRUE,                    /* unselect_all */
+      NULL,                    /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "unselect-all-5",
+      GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+      NULL,                    /* initial_current_folder */
+      FOLDER_NAME,             /* initial_filename */
+      FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
+      NULL,                    /* tweak_current_folder */
+      NULL,                    /* tweak_filename */
+      0,                       /* dialog_response */
+      TRUE,                    /* unselect_all */
+      NULL,                    /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+    {
+      "unselect-all-6",
+      GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+      NULL,                    /* initial_current_folder */
+      FOLDER_NAME,             /* initial_filename */
+      FALSE,                   /* open_dialog */
+      BUTTON,                  /* what_to_tweak */
+      NULL,                    /* tweak_current_folder */
+      FOLDER_NAME_2,           /* tweak_filename */
+      0,                       /* dialog_response */
+      TRUE,                    /* unselect_all */
+      NULL,                    /* final_current_folder */
+      NULL                     /* final_filename */
+    },
+
   };
 
 static void
@@ -1106,6 +1881,8 @@ setup_file_chooser_button_tests (void)
       g_test_add_data_func (test_name, &button_tests[i], test_file_chooser_button);
       g_free (test_name);
     }
+
+  setup_file_chooser_button_combo_box_tests ();
 }
 
 #ifdef BROKEN_TESTS
@@ -1226,7 +2003,7 @@ test_confirm_overwrite_for_path (const char *path, gboolean append_extension)
   filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (closure.chooser));
   passed = passed && filename && (strcmp (filename, path) == 0);
   g_free (filename);
-  
+
   gtk_widget_destroy (closure.chooser);
 
   passed = passed && (1 == closure.confirm_overwrite_signal_emitted);
@@ -1242,9 +2019,9 @@ test_confirm_overwrite (void)
   gboolean passed = TRUE;
 
   /* first test for a file we know will always exist */
-  passed = passed && test_confirm_overwrite_for_path ("/etc/passwd", FALSE); 
+  passed = passed && test_confirm_overwrite_for_path ("/etc/passwd", FALSE);
   g_assert (passed);
-  passed = passed && test_confirm_overwrite_for_path ("/etc/resolv.conf", TRUE); 
+  passed = passed && test_confirm_overwrite_for_path ("/etc/resolv.conf", TRUE);
   g_assert (passed);
 }
 #endif
@@ -1275,22 +2052,6 @@ has_action (const GtkFileChooserAction *actions,
   return FALSE;
 }
 
-static const char *
-get_action_name (GtkFileChooserAction action)
-{
-  switch (action)
-    {
-    case GTK_FILE_CHOOSER_ACTION_OPEN:          return "OPEN";
-    case GTK_FILE_CHOOSER_ACTION_SAVE:          return "SAVE";
-    case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: return "SELECT_FOLDER";
-    case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: return "CREATE_FOLDER";
-
-    default:
-      g_assert_not_reached ();
-      return NULL;
-    }
-}
-
 static GtkFileChooserDefault *
 get_impl_from_dialog (GtkWidget *dialog)
 {