]> 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 eb382130587c6280d11cc62d417e3f8105dd150a..bc18b2fa5859829be8e675e863b8c24e1734fb78 100644 (file)
@@ -318,6 +318,10 @@ 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;
@@ -369,15 +373,8 @@ 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
@@ -522,19 +519,142 @@ create_window_and_file_chooser_button (GtkFileChooserAction 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;
 
   w = create_window_and_file_chooser_button (setup->action);
 
+  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 (w.fc_button), setup->initial_current_folder);
 
@@ -542,7 +662,13 @@ test_file_chooser_button (gconstpointer data)
     gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (w.fc_button), setup->initial_filename);
 
   gtk_widget_show_all (w.window);
-  sleep_in_main_loop ();
+  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));
@@ -558,6 +684,8 @@ test_file_chooser_button (gconstpointer data)
 
   for (i = 0; i < iterations; i++)
     {
+      GtkFileChooser *chooser_to_tweak;
+
       if (setup->open_dialog)
        {
          GList *children;
@@ -568,23 +696,54 @@ test_file_chooser_button (gconstpointer data)
          gtk_button_clicked (GTK_BUTTON (children->data));
          g_list_free (children);
 
-         sleep_in_main_loop ();
+         wait_for_idle ();
 
          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 (w.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 (w.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"));
+       }
 
       if (setup->unselect_all)
-       gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (w.fc_button));
+       {
+         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"));
+       }
 
-      sleep_in_main_loop ();
+      wait_for_idle ();
 
       if (setup->open_dialog)
        {
@@ -614,6 +773,7 @@ test_file_chooser_button (gconstpointer data)
                                    get_expected_shown_filename (setup->action, setup->final_current_folder, setup->final_filename));
     }
 
+  signal_watcher_destroy (watcher);
   gtk_widget_destroy (w.window);
 }
 
@@ -722,6 +882,7 @@ 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 */
@@ -735,6 +896,7 @@ 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 */
@@ -748,6 +910,7 @@ 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 */
@@ -761,6 +924,7 @@ 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 */
@@ -774,6 +938,7 @@ 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 */
@@ -787,6 +952,7 @@ 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 */
@@ -803,6 +969,7 @@ 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 */
@@ -816,6 +983,7 @@ 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 */
@@ -829,6 +997,7 @@ 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 */
@@ -842,6 +1011,7 @@ 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 */
@@ -855,6 +1025,7 @@ 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 */
@@ -868,6 +1039,7 @@ 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 */
@@ -881,6 +1053,7 @@ 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 */
@@ -894,6 +1067,7 @@ 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 */
@@ -902,14 +1076,29 @@ static FileChooserButtonTest button_tests[] =
       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 */
@@ -918,50 +1107,68 @@ static FileChooserButtonTest button_tests[] =
       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 */
       FALSE,                   /* unselect_all */
-      FOLDER_NAME,             /* final_current_folder */
+      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 */
@@ -970,13 +1177,84 @@ static FileChooserButtonTest button_tests[] =
       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 */
@@ -986,11 +1264,12 @@ 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 */
@@ -999,50 +1278,68 @@ static FileChooserButtonTest button_tests[] =
       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 */
       FALSE,                   /* unselect_all */
-      FOLDER_NAME,             /* final_current_folder */
+      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-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-5",
+      "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 */
@@ -1051,13 +1348,84 @@ static FileChooserButtonTest button_tests[] =
       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 */
@@ -1072,6 +1440,7 @@ 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 */
@@ -1085,6 +1454,7 @@ 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 */
@@ -1098,6 +1468,7 @@ 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 */
@@ -1111,6 +1482,7 @@ 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 */
@@ -1124,6 +1496,7 @@ 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 */
@@ -1137,6 +1510,7 @@ 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 */
@@ -1150,6 +1524,7 @@ 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 */
@@ -1163,6 +1538,7 @@ 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 */
@@ -1179,6 +1555,7 @@ 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 */
@@ -1192,6 +1569,7 @@ 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 */
@@ -1205,6 +1583,7 @@ 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 */
@@ -1218,6 +1597,7 @@ 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 */
@@ -1231,6 +1611,7 @@ 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 */
@@ -1244,6 +1625,7 @@ 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 */
@@ -1257,6 +1639,7 @@ 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 */
@@ -1270,6 +1653,7 @@ 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 */
@@ -1286,6 +1670,7 @@ 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 */
@@ -1299,6 +1684,7 @@ 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 */
@@ -1312,6 +1698,7 @@ 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 */
@@ -1325,6 +1712,7 @@ 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 */
@@ -1341,6 +1729,7 @@ 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 */
@@ -1354,6 +1743,7 @@ 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 */
@@ -1367,6 +1757,7 @@ 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 */
@@ -1380,6 +1771,7 @@ 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 */
@@ -1395,6 +1787,7 @@ 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 */
@@ -1408,6 +1801,7 @@ 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 */
@@ -1421,6 +1815,7 @@ 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 */
@@ -1434,19 +1829,7 @@ static FileChooserButtonTest button_tests[] =
       NULL,                    /* initial_current_folder */
       NULL,                    /* initial_filename */
       FALSE,                   /* open_dialog */
-      NULL,                    /* tweak_current_folder */
-      NULL,                    /* tweak_filename */
-      0,                       /* dialog_response */
-      TRUE,                    /* unselect_all */
-      NULL,                    /* final_current_folder */
-      NULL                     /* final_filename */
-    },
-    {
-      "unselect-all-4",
-      GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
-      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 */
@@ -1460,6 +1843,7 @@ 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 */
@@ -1473,6 +1857,7 @@ 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 */
@@ -1618,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);
@@ -1634,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