]> Pileus Git - ~andy/gtk/blob - gtk/tests/filechooser.c
filechooserbutton: Duh, remove all the timeouts after tests
[~andy/gtk] / gtk / tests / filechooser.c
1 /* GTK - The GIMP Toolkit
2  * autotestfilechooser.c: Automated unit tests for the GtkFileChooser widget
3  * Copyright (C) 2005, Novell, Inc.
4  *
5  * Authors:
6  *   Federico Mena-Quintero <federico@novell.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 /* TODO:
23  *
24  * - In test_reload_sequence(), test that the selection is preserved properly
25  *   between unmap/map.
26  *
27  * - More tests!
28  */
29
30 #define SLEEP_DURATION  100
31
32 #include "config.h"
33 #include <string.h>
34 #include <glib/gprintf.h>
35 #include <gtk/gtk.h>
36 #include "gtk/gtkfilechooserprivate.h"
37 #include "gtk/gtkfilechooserdefault.h"
38 #include "gtk/gtkfilechooserentry.h"
39
40 #if 0
41 static const char *
42 get_action_name (GtkFileChooserAction action)
43 {
44   switch (action)
45     {
46     case GTK_FILE_CHOOSER_ACTION_OPEN:          return "OPEN";
47     case GTK_FILE_CHOOSER_ACTION_SAVE:          return "SAVE";
48     case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: return "SELECT_FOLDER";
49     case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: return "CREATE_FOLDER";
50
51     default:
52       g_assert_not_reached ();
53       return NULL;
54     }
55 }
56 #endif
57
58 #ifdef BROKEN_TESTS
59 static void
60 log_test (gboolean passed, const char *test_name, ...)
61 {
62   va_list args;
63   char *str;
64
65   va_start (args, test_name);
66   str = g_strdup_vprintf (test_name, args);
67   va_end (args);
68
69   if (g_test_verbose())
70     g_printf ("%s: %s\n", passed ? "PASSED" : "FAILED", str);
71   g_free (str);
72 }
73
74 typedef void (* SetFilenameFn) (GtkFileChooser *chooser, gpointer data);
75 typedef void (* CompareFilenameFn) (GtkFileChooser *chooser, gpointer data);
76
77 struct test_set_filename_closure {
78   GtkWidget *chooser;
79   GtkWidget *accept_button;
80   gboolean focus_button;
81 };
82
83 static gboolean
84 set_filename_timeout_cb (gpointer data)
85 {
86   struct test_set_filename_closure *closure;
87
88   closure = data;
89
90   if (closure->focus_button)
91     gtk_widget_grab_focus (closure->accept_button);
92
93   gtk_button_clicked (GTK_BUTTON (closure->accept_button));
94
95   return FALSE;
96 }
97 #endif
98
99
100 static guint wait_for_idle_id = 0;
101
102 static gboolean
103 wait_for_idle_idle (gpointer data)
104 {
105   wait_for_idle_id = 0;
106
107   return G_SOURCE_REMOVE;
108 }
109
110 static void
111 wait_for_idle (void)
112 {
113   wait_for_idle_id = g_idle_add_full (G_PRIORITY_LOW + 100,
114                                       wait_for_idle_idle,
115                                       NULL, NULL);
116
117   while (wait_for_idle_id)
118     gtk_main_iteration ();
119 }
120
121 #ifdef BROKEN_TESTS
122 static void
123 test_set_filename (GtkFileChooserAction action,
124                    gboolean focus_button,
125                    SetFilenameFn set_filename_fn,const
126                    CompareFilenameFn compare_filename_fn,
127                    gpointer data)
128 {
129   GtkWidget *chooser;
130   struct test_set_filename_closure closure;
131   guint timeout_id;
132
133   chooser = gtk_file_chooser_dialog_new ("hello", NULL, action,
134                                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
135                                          NULL);
136
137   closure.chooser = chooser;
138   closure.accept_button = gtk_dialog_add_button (GTK_DIALOG (chooser), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
139   closure.focus_button = focus_button;
140
141   gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT);
142
143   (* set_filename_fn) (GTK_FILE_CHOOSER (chooser), data);
144
145   timeout_id = gdk_threads_add_timeout_full (G_MAXINT, SLEEP_DURATION, set_filename_timeout_cb, &closure, NULL);
146   gtk_dialog_run (GTK_DIALOG (chooser));
147   g_source_remove (timeout_id);
148
149   (* compare_filename_fn) (GTK_FILE_CHOOSER (chooser), data);
150
151   gtk_widget_destroy (chooser);
152 }
153
154 static void
155 set_filename_cb (GtkFileChooser *chooser, gpointer data)
156 {
157   const char *filename;
158
159   filename = data;
160   gtk_file_chooser_set_filename (chooser, filename);
161 }
162
163 static void
164 compare_filename_cb (GtkFileChooser *chooser, gpointer data)
165 {
166   const char *filename;
167   char *out_filename;
168
169   filename = data;
170   out_filename = gtk_file_chooser_get_filename (chooser);
171
172   g_assert_cmpstr (out_filename, ==, filename);
173
174   if (out_filename)
175     g_free (out_filename);
176 }
177
178 typedef struct
179 {
180   const char *test_name;
181   GtkFileChooserAction action;
182   const char *filename;
183   gboolean focus_button;
184 } TestSetFilenameSetup;
185
186 static void
187 test_black_box_set_filename (gconstpointer data)
188 {
189   const TestSetFilenameSetup *setup = data;
190
191   test_set_filename (setup->action, setup->focus_button, set_filename_cb, compare_filename_cb, (char *) setup->filename);
192 }
193
194 struct current_name_closure {
195         const char *path;
196         const char *current_name;
197 };
198
199 static void
200 set_current_name_cb (GtkFileChooser *chooser, gpointer data)
201 {
202   struct current_name_closure *closure;
203
204   closure = data;
205
206   gtk_file_chooser_set_current_folder (chooser, closure->path);
207   gtk_file_chooser_set_current_name (chooser, closure->current_name);
208 }
209
210 static void
211 compare_current_name_cb (GtkFileChooser *chooser, gpointer data)
212 {
213   struct current_name_closure *closure;
214   char *out_filename;
215   char *filename;
216
217   closure = data;
218
219   out_filename = gtk_file_chooser_get_filename (chooser);
220
221   g_assert (out_filename != NULL);
222
223   filename = g_build_filename (closure->path, closure->current_name, NULL);
224   g_assert_cmpstr (filename, ==, out_filename);
225
226   g_free (filename);
227   g_free (out_filename);
228 }
229
230 typedef struct
231 {
232   const char *test_name;
233   GtkFileChooserAction action;
234   const char *current_name;
235   gboolean focus_button;
236 } TestSetCurrentNameSetup;
237
238 static void
239 test_black_box_set_current_name (gconstpointer data)
240 {
241   const TestSetCurrentNameSetup *setup = data;
242   struct current_name_closure closure;
243   char *cwd;
244
245   cwd = g_get_current_dir ();
246
247   closure.path = cwd;
248   closure.current_name = setup->current_name;
249
250   test_set_filename (setup->action, setup->focus_button, set_current_name_cb, compare_current_name_cb, &closure);
251
252   g_free (cwd);
253 }
254 #endif
255
256 /* FIXME: fails in CREATE_FOLDER mode when FOLDER_NAME == "/" */
257
258 #if 0
259 #define FILE_NAME "/nonexistent"
260 #define FILE_NAME_2 "/nonexistent2"
261 #define FOLDER_NAME "/etc"
262 #define FOLDER_NAME_2 "/usr"
263 #else
264 #define FILE_NAME "/etc/passwd"
265 #define FILE_NAME_2 "/etc/group"
266 #define FOLDER_NAME "/etc"
267 #define FOLDER_NAME_2 "/usr"
268 #endif
269
270 #define CURRENT_NAME "parangaricutirimicuaro.txt"
271 #define CURRENT_NAME_FOLDER "parangaricutirimicuaro"
272
273 /* https://bugzilla.novell.com/show_bug.cgi?id=184875
274  * http://bugzilla.gnome.org/show_bug.cgi?id=347066
275  * http://bugzilla.gnome.org/show_bug.cgi?id=346058
276  */
277
278 #ifdef BROKEN_TESTS
279 static void
280 setup_set_filename_tests (void)
281 {
282   static TestSetFilenameSetup tests[] =
283     {
284       { "/GtkFileChooser/black_box/set_filename/open/no_focus",          GTK_FILE_CHOOSER_ACTION_OPEN,          FILE_NAME,  FALSE },
285       { "/GtkFileChooser/black_box/set_filename/open/focus",             GTK_FILE_CHOOSER_ACTION_OPEN,          FILE_NAME,  TRUE  },
286       { "/GtkFileChooser/black_box/set_filename/save/no_focus",          GTK_FILE_CHOOSER_ACTION_SAVE,          FILE_NAME,  FALSE },
287       { "/GtkFileChooser/black_box/set_filename/save/focus",             GTK_FILE_CHOOSER_ACTION_SAVE,          FILE_NAME,  TRUE  },
288       { "/GtkFileChooser/black_box/set_filename/select_folder/no_focus", GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, FOLDER_NAME,FALSE },
289       { "/GtkFileChooser/black_box/set_filename/select_folder/focus",    GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, FOLDER_NAME,TRUE  },
290       { "/GtkFileChooser/black_box/set_filename/create_folder/no_focus", GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER, FOLDER_NAME,FALSE },
291       { "/GtkFileChooser/black_box/set_filename/create_folder/focus",    GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER, FOLDER_NAME,TRUE  },
292     };
293   int i;
294
295   for (i = 0; i < G_N_ELEMENTS (tests); i++)
296     g_test_add_data_func (tests[i].test_name, &tests[i], test_black_box_set_filename);
297 }
298
299 static void
300 setup_set_current_name_tests (void)
301 {
302   static TestSetCurrentNameSetup tests[] =
303     {
304       { "/GtkFileChooser/black_box/set_current_name/save/no_focus",          GTK_FILE_CHOOSER_ACTION_SAVE,          CURRENT_NAME,        FALSE },
305       { "/GtkFileChooser/black_box/set_current_name/save/focus",             GTK_FILE_CHOOSER_ACTION_SAVE,          CURRENT_NAME,        TRUE  },
306       { "/GtkFileChooser/black_box/set_current_name/create_folder/no_focus", GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER, CURRENT_NAME_FOLDER, FALSE },
307       { "/GtkFileChooser/black_box/set_current_name/create_folder/focus",    GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER, CURRENT_NAME_FOLDER, TRUE  },
308     };
309   int i;
310
311   for (i = 0; i < G_N_ELEMENTS (tests); i++)
312     g_test_add_data_func (tests[i].test_name, &tests[i], test_black_box_set_current_name);
313 }
314 #endif
315
316 typedef struct
317 {
318   const char *shortname;
319   GtkFileChooserAction action;
320   const char *initial_current_folder;
321   const char *initial_filename;
322   gboolean open_dialog;
323   enum {
324     BUTTON,
325     DIALOG
326   } what_to_tweak;
327   const char *tweak_current_folder;
328   const char *tweak_filename;
329   gint dialog_response;
330   gboolean unselect_all;
331   const char *final_current_folder;
332   const char *final_filename;
333 } FileChooserButtonTest;
334
335 static char *
336 make_button_test_name (FileChooserButtonTest *t)
337 {
338   return g_strdup_printf ("/GtkFileChooserButton/%s", t->shortname);
339 #if 0
340   GString *s = g_string_new ("/GtkFileChooserButton");
341
342   g_string_append_printf (s, "/%s/%s/%s/%s",
343                           get_action_name (t->action),
344                           t->initial_current_folder ? "set_initial_folder" : "no_default_folder",
345                           t->initial_filename ? "set_initial_filename" : "no_initial_filename",
346                           t->open_dialog ? "open_dialog" : "no_dialog");
347
348   if (t->tweak_current_folder)
349     g_string_append (s, "/tweak_current_folder");
350
351   if (t->tweak_filename)
352     g_string_append (s, "/tweak_filename");
353
354   if (t->open_dialog)
355     g_string_append_printf (s, "/%s",
356                             t->dialog_response == GTK_RESPONSE_ACCEPT ? "accept" : "cancel");
357
358   if (t->final_current_folder)
359     g_string_append (s, "/final_current_folder");
360
361   if (t->final_filename)
362     g_string_append (s, "/final_filename");
363
364   return g_string_free (s, FALSE);
365 #endif
366 }
367
368 static gboolean
369 sleep_timeout_cb (gpointer data)
370 {
371   gtk_main_quit ();
372   return FALSE;
373 }
374
375 static void
376 sleep_in_main_loop (void)
377 {
378   guint timeout_id;
379
380   timeout_id = gdk_threads_add_timeout_full (G_MAXINT, 250, sleep_timeout_cb, NULL, NULL);
381   gtk_main ();
382   g_source_remove (timeout_id);
383 }
384
385 static void
386 build_children_list (GtkWidget *widget, gpointer data)
387 {
388   GList **list;
389
390   list = data;
391   *list = g_list_prepend (*list, widget);
392 }
393
394 static GtkWidget *
395 find_child_widget_with_atk_role (GtkWidget *widget, AtkRole role)
396 {
397   AtkObject *accessible;
398   AtkRole a_role;
399
400   accessible = gtk_widget_get_accessible (widget);
401   a_role = atk_object_get_role (accessible);
402
403   if (a_role == role)
404     return widget;
405   else
406     {
407       GtkWidget *found_child;
408
409       found_child = NULL;
410
411       if (GTK_IS_CONTAINER (widget))
412         {
413           GList *children;
414           GList *l;
415
416           children = NULL;
417           gtk_container_forall (GTK_CONTAINER (widget), build_children_list, &children);
418
419           l = children;
420
421           while (l && !found_child)
422             {
423               GtkWidget *child;
424
425               child = GTK_WIDGET (l->data);
426
427               found_child = find_child_widget_with_atk_role (child, role);
428
429               l = l->next;
430             }
431
432           g_list_free (children);
433         }
434
435       return found_child;
436     }
437 }
438
439 static const char *
440 get_atk_name_for_filechooser_button (GtkFileChooserButton *button)
441 {
442   GtkFileChooserAction action;
443   GtkWidget *widget;
444   AtkObject *accessible;
445
446   action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (button));
447   g_assert (action == GTK_FILE_CHOOSER_ACTION_OPEN || action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
448
449   if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
450     widget = find_child_widget_with_atk_role (GTK_WIDGET (button), ATK_ROLE_PUSH_BUTTON);
451   else
452     widget = find_child_widget_with_atk_role (GTK_WIDGET (button), ATK_ROLE_COMBO_BOX);
453
454   accessible = gtk_widget_get_accessible (widget);
455   return atk_object_get_name (accessible);
456 }
457
458 static void
459 check_that_basename_is_shown (GtkFileChooserButton *button, const char *expected_filename)
460 {
461   GtkFileChooserAction action;
462   const char *name_on_button;
463   char *expected_basename;
464
465   name_on_button = get_atk_name_for_filechooser_button (button);
466
467   action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (button));
468   g_assert (action == GTK_FILE_CHOOSER_ACTION_OPEN || action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
469
470   if (expected_filename)
471     expected_basename = g_path_get_basename (expected_filename);
472   else
473     expected_basename = NULL;
474
475   if (expected_basename)
476     g_assert_cmpstr (expected_basename, ==, name_on_button);
477   else
478     g_assert_cmpstr (name_on_button, ==, "(None)"); /* see gtkfilechooserbutton.c:FALLBACK_DISPLAY_NAME */ /* FIXME: how do we translate this? */
479
480   g_free (expected_basename);
481 }
482
483 static const char *
484 get_expected_shown_filename (GtkFileChooserAction action, const char *folder_name, const char *filename)
485 {
486   if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
487     {
488       if (filename)
489         return filename;
490       else
491         return folder_name;
492     }
493   else
494     return filename;
495 }
496
497 static GtkWidget *
498 get_file_chooser_dialog_from_button (GtkFileChooserButton *button)
499 {
500   GtkWidget *fc_dialog;
501
502   /* Give me the internal dialog, damnit */
503   fc_dialog = g_object_get_qdata (G_OBJECT (button), g_quark_from_static_string ("gtk-file-chooser-delegate"));
504   g_assert (GTK_IS_FILE_CHOOSER (fc_dialog));
505   g_assert (GTK_IS_DIALOG (fc_dialog));
506
507   return fc_dialog;
508 }
509
510 typedef struct {
511   GtkWidget *window;
512   GtkWidget *fc_button;
513 } WindowAndButton;
514
515 static WindowAndButton
516 create_window_and_file_chooser_button (GtkFileChooserAction action)
517 {
518   WindowAndButton w;
519
520   w.window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
521
522   w.fc_button = gtk_file_chooser_button_new (action == GTK_FILE_CHOOSER_ACTION_OPEN ? "Select a file" : "Select a folder",
523                                              action);
524   gtk_container_add (GTK_CONTAINER (w.window), w.fc_button);
525
526   return w;
527 }
528
529 typedef struct
530 {
531   GObject *object;
532   GHashTable *signals;
533   gboolean in_main_loop;
534 } SignalWatcher;
535
536 typedef struct
537 {
538   SignalWatcher *watcher;
539   char *signal_name;
540   gulong id;
541   gboolean emitted;
542 } SignalConnection;
543
544 static SignalWatcher *
545 signal_watcher_new (GObject *object)
546 {
547   SignalWatcher *watcher = g_new0 (SignalWatcher, 1);
548
549   watcher->object = g_object_ref (object);
550   watcher->signals = g_hash_table_new (g_str_hash, g_str_equal);
551
552   return watcher;
553 }
554
555 static void
556 dummy_callback (GObject *object)
557 {
558   /* nothing */
559 }
560
561 static void
562 marshal_notify_cb (gpointer data, GClosure *closure)
563 {
564   if (data)
565     {
566       SignalConnection *conn;
567
568       conn = data;
569       conn->emitted = TRUE;
570
571       if (conn->watcher->in_main_loop)
572         {
573           gtk_main_quit ();
574           conn->watcher->in_main_loop = FALSE;
575         }
576     }
577 }
578
579 static void
580 signal_watcher_watch_signal (SignalWatcher *watcher, const char *signal_name)
581 {
582   SignalConnection *conn;
583
584   conn = g_hash_table_lookup (watcher->signals, signal_name);
585   if (!conn)
586     {
587       GClosure *closure;
588
589       conn = g_new0 (SignalConnection, 1);
590       conn->watcher = watcher;
591       conn->signal_name = g_strdup (signal_name);
592
593       closure = g_cclosure_new (G_CALLBACK (dummy_callback), NULL, NULL);
594       g_closure_add_marshal_guards (closure, conn, marshal_notify_cb, NULL, marshal_notify_cb);
595       conn->id = g_signal_connect_closure (watcher->object, signal_name, closure, FALSE);
596       conn->emitted = FALSE;
597
598       g_hash_table_insert (watcher->signals, conn->signal_name, conn);
599     }
600   else
601     conn->emitted = FALSE;
602 }
603
604 static gboolean
605 signal_watcher_expect (SignalWatcher *watcher, const char *signal_name, char *unused_description)
606 {
607   SignalConnection *conn;
608   gboolean emitted;
609
610   conn = g_hash_table_lookup (watcher->signals, signal_name);
611   g_assert (conn != NULL);
612
613   if (!conn->emitted)
614     {
615       guint timeout_id;
616       
617       timeout_id = gdk_threads_add_timeout_full (G_MAXINT, 1000, sleep_timeout_cb, NULL, NULL);
618
619       watcher->in_main_loop = TRUE;
620       gtk_main ();
621       watcher->in_main_loop = FALSE;
622
623       g_source_remove (timeout_id);
624     }
625
626   emitted = conn->emitted;
627   conn->emitted = FALSE;
628
629   return emitted;
630 }
631
632 static void
633 destroy_connection (gpointer key, gpointer value, gpointer user_data)
634 {
635   SignalConnection *conn;
636
637   conn = value;
638   g_signal_handler_disconnect (conn->watcher->object, conn->id);
639   g_free (conn->signal_name);
640   g_free (conn);
641 }
642
643 static void
644 signal_watcher_destroy (SignalWatcher *watcher)
645 {
646   g_hash_table_foreach (watcher->signals, destroy_connection, NULL);
647   g_hash_table_destroy (watcher->signals);
648   g_object_unref (watcher->object);
649   g_free (watcher);
650 }
651
652 static void
653 test_file_chooser_button_with_response (const FileChooserButtonTest *setup, gint dialog_response)
654 {
655   WindowAndButton w;
656   SignalWatcher *watcher;
657   GtkWidget *fc_dialog;
658   int iterations;
659   int i;
660
661   w = create_window_and_file_chooser_button (setup->action);
662
663   watcher = signal_watcher_new (G_OBJECT (w.fc_button));
664   signal_watcher_watch_signal (watcher, "current-folder-changed");
665   signal_watcher_watch_signal (watcher, "selection-changed");
666
667   if (setup->initial_current_folder)
668     gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (w.fc_button), setup->initial_current_folder);
669
670   if (setup->initial_filename)
671     gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (w.fc_button), setup->initial_filename);
672
673   gtk_widget_show_all (w.window);
674   wait_for_idle ();
675
676   if (setup->initial_current_folder)
677     g_assert (signal_watcher_expect (watcher, "current-folder-changed", "initial current folder"));
678
679   if (setup->initial_filename)
680     g_assert (signal_watcher_expect (watcher, "selection-changed", "initial filename"));
681
682   check_that_basename_is_shown (GTK_FILE_CHOOSER_BUTTON (w.fc_button),
683                                 get_expected_shown_filename (setup->action, setup->initial_current_folder, setup->initial_filename));
684
685   /* If there is a dialog to be opened, we actually test going through it a
686    * couple of times.  This ensures that any state that the button frobs for
687    * each appearance of the dialog will make sense.
688    */
689   if (setup->open_dialog)
690     iterations = 2;
691   else
692     iterations = 1;
693
694   for (i = 0; i < iterations; i++)
695     {
696       GtkFileChooser *chooser_to_tweak;
697
698       if (setup->open_dialog)
699         {
700           GList *children;
701
702           /* Hack our way into the file chooser button; get its GtkButton child and click it */
703           children = gtk_container_get_children (GTK_CONTAINER (w.fc_button));
704           g_assert (children && GTK_IS_BUTTON (children->data));
705           gtk_button_clicked (GTK_BUTTON (children->data));
706           g_list_free (children);
707
708           wait_for_idle ();
709
710           fc_dialog = get_file_chooser_dialog_from_button (GTK_FILE_CHOOSER_BUTTON (w.fc_button));
711         }
712
713       if (setup->what_to_tweak == BUTTON)
714         chooser_to_tweak = GTK_FILE_CHOOSER (w.fc_button);
715       else if (setup->what_to_tweak == DIALOG)
716         chooser_to_tweak = GTK_FILE_CHOOSER (fc_dialog);
717       else
718         g_assert_not_reached ();
719
720       /* Okay, now frob the button or its optional dialog */
721
722       if (setup->tweak_current_folder)
723         {
724           if (setup->what_to_tweak == BUTTON)
725             signal_watcher_watch_signal (watcher, "current-folder-changed");
726
727           gtk_file_chooser_set_current_folder (chooser_to_tweak, setup->tweak_current_folder);
728
729           if (setup->what_to_tweak == BUTTON)
730             g_assert (signal_watcher_expect (watcher, "current-folder-changed", "tweak current folder in button"));
731         }
732
733       if (setup->tweak_filename)
734         {
735           if (setup->what_to_tweak == BUTTON)
736             signal_watcher_watch_signal (watcher, "selection-changed");
737
738           gtk_file_chooser_select_filename (chooser_to_tweak, setup->tweak_filename);
739
740           if (setup->what_to_tweak == BUTTON)
741             g_assert (signal_watcher_expect (watcher, "selection-changed", "tweak filename in button"));
742         }
743
744       if (setup->unselect_all)
745         {
746           if (setup->what_to_tweak == BUTTON)
747             signal_watcher_watch_signal (watcher, "selection-changed");
748
749           gtk_file_chooser_unselect_all (chooser_to_tweak);
750
751           if (setup->what_to_tweak == BUTTON)
752             g_assert (signal_watcher_expect (watcher, "selection-changed", "tweak unselect_all in button"));
753         }
754
755       wait_for_idle ();
756
757       if (setup->open_dialog)
758         {
759           gtk_dialog_response (GTK_DIALOG (fc_dialog), dialog_response);
760           wait_for_idle ();
761
762           gtk_window_resize (GTK_WINDOW (fc_dialog), 500, 500);
763         }
764
765       if (setup->final_current_folder)
766         {
767           char *folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (w.fc_button));
768
769           g_assert_cmpstr (folder, ==, setup->final_current_folder);
770           g_free (folder);
771         }
772
773       if (setup->final_filename)
774         {
775           char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (w.fc_button));
776
777           g_assert_cmpstr (filename, ==, setup->final_filename);
778           g_free (filename);
779         }
780
781       check_that_basename_is_shown (GTK_FILE_CHOOSER_BUTTON (w.fc_button),
782                                     get_expected_shown_filename (setup->action, setup->final_current_folder, setup->final_filename));
783     }
784
785   signal_watcher_destroy (watcher);
786   gtk_widget_destroy (w.window);
787 }
788
789 static void
790 test_file_chooser_button (gconstpointer data)
791 {
792   const FileChooserButtonTest *setup = data;
793
794   test_file_chooser_button_with_response (setup, setup->dialog_response);
795
796   if (setup->open_dialog && setup->dialog_response == GTK_RESPONSE_CANCEL)
797     {
798       /* Runs the test again, with DELETE_EVENT (as if the user closed the
799        * dialog instead of using the Cancel button), since the button misbehaved
800        * in that case sometimes.
801        */
802       test_file_chooser_button_with_response (setup, GTK_RESPONSE_DELETE_EVENT);
803     }
804 }
805
806 static int
807 find_accessible_action_num (AtkObject *object, const char *action_name)
808 {
809   AtkAction *action_a;
810   int num_actions;
811   int i;
812
813   action_a = ATK_ACTION (object);
814
815   num_actions = atk_action_get_n_actions (action_a);
816
817   for (i = 0; i < num_actions; i++)
818     if (strcmp (atk_action_get_name (action_a, i), action_name) == 0)
819       return i;
820
821   return -1;
822 }
823
824 static void
825 do_accessible_action (AtkObject *object, const char *action_name)
826 {
827   int action_num;
828
829   action_num = find_accessible_action_num (object, action_name);
830   g_assert (action_num != -1);
831
832   atk_action_do_action (ATK_ACTION (object), action_num);
833 }
834
835 static void
836 test_file_chooser_button_combo_box_1 (void)
837 {
838   WindowAndButton w;
839   GtkWidget *combo_box;
840   AtkObject *combo_box_a;
841   AtkObject *menu_a;
842   int num_items;
843   int other_index;
844   AtkObject *item_a;
845   GtkWidget *fc_dialog;
846
847   w = create_window_and_file_chooser_button (GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
848
849   gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (w.fc_button), FOLDER_NAME);
850
851   gtk_widget_show_all (w.window);
852
853   /* Get the accessible for the combo box */
854
855   combo_box = find_child_widget_with_atk_role (GTK_WIDGET (w.fc_button), ATK_ROLE_COMBO_BOX);
856   combo_box_a = gtk_widget_get_accessible (combo_box);
857
858   /* Press the combo box to bring up the menu */
859
860   do_accessible_action (combo_box_a, "press");
861   sleep_in_main_loop (); /* have to wait because bringing up the menu is asynchronous... */
862
863   /* Get the menu from the combo box; it's the first child */
864
865   menu_a = atk_object_ref_accessible_child (combo_box_a, 0);
866   g_assert (atk_object_get_role (menu_a) == ATK_ROLE_MENU);
867
868   /* Check that the last item in the menu is the "Other…" one */
869
870   num_items = atk_object_get_n_accessible_children (menu_a);
871   g_assert (num_items > 0);
872
873   other_index = num_items - 1;
874
875   item_a = atk_object_ref_accessible_child (menu_a, other_index);
876   g_assert_cmpstr (atk_object_get_name (item_a), ==, "Other…");  /* FIXME: how do we translate this? */
877
878   /* Activate the item */
879
880   do_accessible_action (item_a, "click");
881
882   /* Cancel the dialog */
883
884   sleep_in_main_loop ();
885   fc_dialog = get_file_chooser_dialog_from_button (GTK_FILE_CHOOSER_BUTTON (w.fc_button));
886
887   gtk_dialog_response (GTK_DIALOG (fc_dialog), GTK_RESPONSE_CANCEL);
888
889   /* Now check the selection in the combo box */
890   check_that_basename_is_shown (GTK_FILE_CHOOSER_BUTTON (w.fc_button), FOLDER_NAME);
891
892   gtk_widget_destroy (w.window);
893 }
894
895 static void
896 setup_file_chooser_button_combo_box_tests (void)
897 {
898   g_test_add_func ("/GtkFileChooserButton/combo_box-1", test_file_chooser_button_combo_box_1);
899 }
900
901 static FileChooserButtonTest button_tests[] =
902   {
903     /* OPEN tests without dialog */
904
905     {
906       "open-1",
907       GTK_FILE_CHOOSER_ACTION_OPEN,
908       NULL,                     /* initial_current_folder */
909       NULL,                     /* initial_filename */
910       FALSE,                    /* open_dialog */
911       BUTTON,                   /* what_to_tweak */
912       NULL,                     /* tweak_current_folder */
913       NULL,                     /* tweak_filename */
914       0,                        /* dialog_response */
915       FALSE,                    /* unselect_all */
916       NULL,                     /* final_current_folder */
917       NULL                      /* final_filename */
918     },
919     {
920       "open-2",
921       GTK_FILE_CHOOSER_ACTION_OPEN,
922       NULL,                     /* initial_current_folder */
923       FILE_NAME,                /* initial_filename */
924       FALSE,                    /* open_dialog */
925       BUTTON,                   /* what_to_tweak */
926       NULL,                     /* tweak_current_folder */
927       NULL,                     /* tweak_filename */
928       0,                        /* dialog_response */
929       FALSE,                    /* unselect_all */
930       NULL,                     /* final_current_folder */
931       FILE_NAME                 /* final_filename */
932     },
933     {
934       "open-3",
935       GTK_FILE_CHOOSER_ACTION_OPEN,
936       NULL,                     /* initial_current_folder */
937       NULL,                     /* initial_filename */
938       FALSE,                    /* open_dialog */
939       BUTTON,                   /* what_to_tweak */
940       NULL,                     /* tweak_current_folder */
941       FILE_NAME,                /* tweak_filename */
942       0,                        /* dialog_response */
943       FALSE,                    /* unselect_all */
944       NULL,                     /* final_current_folder */
945       FILE_NAME                 /* final_filename */
946     },
947     {
948       "open-4",
949       GTK_FILE_CHOOSER_ACTION_OPEN,
950       NULL,                     /* initial_current_folder */
951       FILE_NAME,                /* initial_filename */
952       FALSE,                    /* open_dialog */
953       BUTTON,                   /* what_to_tweak */
954       NULL,                     /* tweak_current_folder */
955       FILE_NAME_2,              /* tweak_filename */
956       0,                        /* dialog_response */
957       FALSE,                    /* unselect_all */
958       NULL,                     /* final_current_folder */
959       FILE_NAME_2               /* final_filename */
960     },
961     {
962       "open-5",
963       GTK_FILE_CHOOSER_ACTION_OPEN,
964       FOLDER_NAME,              /* initial_current_folder */
965       NULL,                     /* initial_filename */
966       FALSE,                    /* open_dialog */
967       BUTTON,                   /* what_to_tweak */
968       NULL,                     /* tweak_current_folder */
969       NULL,                     /* tweak_filename */
970       0,                        /* dialog_response */
971       FALSE,                    /* unselect_all */
972       FOLDER_NAME,              /* final_current_folder */
973       NULL                      /* final_filename */
974     },
975     {
976       "open-6",
977       GTK_FILE_CHOOSER_ACTION_OPEN,
978       FOLDER_NAME,              /* initial_current_folder */
979       NULL,                     /* initial_filename */
980       FALSE,                    /* open_dialog */
981       BUTTON,                   /* what_to_tweak */
982       FOLDER_NAME_2,            /* tweak_current_folder */
983       NULL,                     /* tweak_filename */
984       0,                        /* dialog_response */
985       FALSE,                    /* unselect_all */
986       FOLDER_NAME_2,            /* final_current_folder */
987       NULL                      /* final_filename */
988     },
989
990     /* SELECT_FOLDER tests without dialog */
991
992     {
993       "select-folder-1",
994       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
995       NULL,                     /* initial_current_folder */
996       NULL,                     /* initial_filename */
997       FALSE,                    /* open_dialog */
998       BUTTON,                   /* what_to_tweak */
999       NULL,                     /* tweak_current_folder */
1000       NULL,                     /* tweak_filename */
1001       0,                        /* dialog_response */
1002       FALSE,                    /* unselect_all */
1003       NULL,                     /* final_current_folder */
1004       NULL                      /* final_filename */
1005     },
1006     {
1007       "select-folder-2",
1008       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1009       NULL,                     /* initial_current_folder */
1010       FOLDER_NAME,              /* initial_filename */
1011       FALSE,                    /* open_dialog */
1012       BUTTON,                   /* what_to_tweak */
1013       NULL,                     /* tweak_current_folder */
1014       NULL,                     /* tweak_filename */
1015       0,                        /* dialog_response */
1016       FALSE,                    /* unselect_all */
1017       NULL,                     /* final_current_folder */
1018       FOLDER_NAME               /* final_filename */
1019     },
1020     {
1021       "select-folder-3",
1022       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1023       NULL,                     /* initial_current_folder */
1024       FOLDER_NAME,              /* initial_filename */
1025       FALSE,                    /* open_dialog */
1026       BUTTON,                   /* what_to_tweak */
1027       NULL,                     /* tweak_current_folder */
1028       FOLDER_NAME_2,            /* tweak_filename */
1029       0,                        /* dialog_response */
1030       FALSE,                    /* unselect_all */
1031       NULL,                     /* final_current_folder */
1032       FOLDER_NAME_2             /* final_filename */
1033     },
1034     {
1035       "select-folder-4",
1036       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1037       FOLDER_NAME,              /* initial_current_folder */
1038       NULL,                     /* initial_filename */
1039       FALSE,                    /* open_dialog */
1040       BUTTON,                   /* what_to_tweak */
1041       NULL,                     /* tweak_current_folder */
1042       NULL,                     /* tweak_filename */
1043       0,                        /* dialog_response */
1044       FALSE,                    /* unselect_all */
1045       NULL,                     /* final_current_folder */
1046       FOLDER_NAME               /* final_filename */
1047     },
1048     {
1049       "select-folder-5",
1050       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1051       FOLDER_NAME,              /* initial_current_folder */
1052       NULL,                     /* initial_filename */
1053       FALSE,                    /* open_dialog */
1054       BUTTON,                   /* what_to_tweak */
1055       NULL,                     /* tweak_current_folder */
1056       NULL,                     /* tweak_filename */
1057       0,                        /* dialog_response */
1058       FALSE,                    /* unselect_all */
1059       FOLDER_NAME,              /* final_current_folder */
1060       NULL                      /* final_filename */
1061     },
1062     {
1063       "select-folder-6",
1064       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1065       FOLDER_NAME,              /* initial_current_folder */
1066       NULL,                     /* initial_filename */
1067       FALSE,                    /* open_dialog */
1068       BUTTON,                   /* what_to_tweak */
1069       FOLDER_NAME_2,            /* tweak_current_folder */
1070       NULL,                     /* tweak_filename */
1071       0,                        /* dialog_response */
1072       FALSE,                    /* unselect_all */
1073       NULL,                     /* final_current_folder */
1074       FOLDER_NAME_2             /* final_filename */
1075     },
1076     {
1077       "select-folder-7",
1078       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1079       FOLDER_NAME,              /* initial_current_folder */
1080       NULL,                     /* initial_filename */
1081       FALSE,                    /* open_dialog */
1082       BUTTON,                   /* what_to_tweak */
1083       FOLDER_NAME_2,            /* tweak_current_folder */
1084       NULL,                     /* tweak_filename */
1085       0,                        /* dialog_response */
1086       FALSE,                    /* unselect_all */
1087       FOLDER_NAME_2,            /* final_current_folder */
1088       NULL                      /* final_filename */
1089     },
1090     {
1091       "select-folder-8",
1092       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1093       FOLDER_NAME,              /* initial_current_folder */
1094       NULL,                     /* initial_filename */
1095       FALSE,                    /* open_dialog */
1096       BUTTON,                   /* what_to_tweak */
1097       NULL,                     /* tweak_current_folder */
1098       FOLDER_NAME_2,            /* tweak_filename */
1099       0,                        /* dialog_response */
1100       FALSE,                    /* unselect_all */
1101       NULL,                     /* final_current_folder */
1102       FOLDER_NAME_2             /* final_filename */
1103     },
1104
1105     /* OPEN tests with dialog, cancelled
1106      *
1107      * Test names are "open-dialog-cancel-A-B", where A and B can be:
1108      *
1109      *   A:
1110      *      ni - no initial filename
1111      *       i - initial filename
1112      *      nf - no initial folder
1113      *       f - initial folder
1114      *
1115      *   B:
1116      *      nt - no tweaks
1117      *       b - tweak button
1118      *       d - tweak dialog
1119      */
1120
1121     {
1122       "open-dialog-cancel-ni-nt",
1123       GTK_FILE_CHOOSER_ACTION_OPEN,
1124       NULL,                     /* initial_current_folder */
1125       NULL,                     /* initial_filename */
1126       TRUE,                     /* open_dialog */
1127       BUTTON,                   /* what_to_tweak */
1128       NULL,                     /* tweak_current_folder */
1129       NULL,                     /* tweak_filename */
1130       GTK_RESPONSE_CANCEL,      /* dialog_response */
1131       FALSE,                    /* unselect_all */
1132       NULL,                     /* final_current_folder */
1133       NULL                      /* final_filename */
1134     },
1135     {
1136       "open-dialog-cancel-ni-b",
1137       GTK_FILE_CHOOSER_ACTION_OPEN,
1138       NULL,                     /* initial_current_folder */
1139       NULL,                     /* initial_filename */
1140       TRUE,                     /* open_dialog */
1141       BUTTON,                   /* what_to_tweak */
1142       NULL,                     /* tweak_current_folder */
1143       FILE_NAME,                /* tweak_filename */
1144       GTK_RESPONSE_CANCEL,      /* dialog_response */
1145       FALSE,                    /* unselect_all */
1146       NULL,                     /* final_current_folder */
1147       FILE_NAME                 /* final_filename */
1148     },
1149     {
1150       "open-dialog-cancel-ni-d",
1151       GTK_FILE_CHOOSER_ACTION_OPEN,
1152       NULL,                     /* initial_current_folder */
1153       NULL,                     /* initial_filename */
1154       TRUE,                     /* open_dialog */
1155       DIALOG,                   /* what_to_tweak */
1156       NULL,                     /* tweak_current_folder */
1157       FILE_NAME,                /* tweak_filename */
1158       GTK_RESPONSE_CANCEL,      /* dialog_response */
1159       FALSE,                    /* unselect_all */
1160       NULL,                     /* final_current_folder */
1161       NULL                      /* final_filename */
1162     },
1163     {
1164       "open-dialog-cancel-i-nt",
1165       GTK_FILE_CHOOSER_ACTION_OPEN,
1166       NULL,                     /* initial_current_folder */
1167       FILE_NAME,                /* initial_filename */
1168       TRUE,                     /* open_dialog */
1169       BUTTON,                   /* what_to_tweak */
1170       NULL,                     /* tweak_current_folder */
1171       NULL,                     /* tweak_filename */
1172       GTK_RESPONSE_CANCEL,      /* dialog_response */
1173       FALSE,                    /* unselect_all */
1174       NULL,                     /* final_current_folder */
1175       FILE_NAME                 /* final_filename */
1176     },
1177     {
1178       "open-dialog-cancel-i-b",
1179       GTK_FILE_CHOOSER_ACTION_OPEN,
1180       NULL,                     /* initial_current_folder */
1181       FILE_NAME,                /* initial_filename */
1182       TRUE,                     /* open_dialog */
1183       BUTTON,                   /* what_to_tweak */
1184       NULL,                     /* tweak_current_folder */
1185       FILE_NAME_2,              /* tweak_filename */
1186       GTK_RESPONSE_CANCEL,      /* dialog_response */
1187       FALSE,                    /* unselect_all */
1188       NULL,                     /* final_current_folder */
1189       FILE_NAME_2               /* final_filename */
1190     },
1191     {
1192       "open-dialog-cancel-i-d",
1193       GTK_FILE_CHOOSER_ACTION_OPEN,
1194       NULL,                     /* initial_current_folder */
1195       FILE_NAME,                /* initial_filename */
1196       TRUE,                     /* open_dialog */
1197       DIALOG,                   /* what_to_tweak */
1198       NULL,                     /* tweak_current_folder */
1199       FILE_NAME_2,              /* tweak_filename */
1200       GTK_RESPONSE_CANCEL,      /* dialog_response */
1201       FALSE,                    /* unselect_all */
1202       NULL,                     /* final_current_folder */
1203       FILE_NAME                 /* final_filename */
1204     },
1205     {
1206       "open-dialog-cancel-nf-nt",
1207       GTK_FILE_CHOOSER_ACTION_OPEN,
1208       NULL,                     /* initial_current_folder */
1209       NULL,                     /* initial_filename */
1210       TRUE,                     /* open_dialog */
1211       BUTTON,                   /* what_to_tweak */
1212       NULL,                     /* tweak_current_folder */
1213       NULL,                     /* tweak_filename */
1214       GTK_RESPONSE_CANCEL,      /* dialog_response */
1215       FALSE,                    /* unselect_all */
1216       NULL,                     /* final_current_folder */
1217       NULL                      /* final_filename */
1218     },
1219     {
1220       "open-dialog-cancel-nf-b",
1221       GTK_FILE_CHOOSER_ACTION_OPEN,
1222       NULL,                     /* initial_current_folder */
1223       NULL,                     /* initial_filename */
1224       TRUE,                     /* open_dialog */
1225       BUTTON,                   /* what_to_tweak */
1226       FOLDER_NAME,              /* tweak_current_folder */
1227       NULL,                     /* tweak_filename */
1228       GTK_RESPONSE_CANCEL,      /* dialog_response */
1229       FALSE,                    /* unselect_all */
1230       FOLDER_NAME,              /* final_current_folder */
1231       NULL                      /* final_filename */
1232     },
1233     {
1234       "open-dialog-cancel-nf-d",
1235       GTK_FILE_CHOOSER_ACTION_OPEN,
1236       NULL,                     /* initial_current_folder */
1237       NULL,                     /* initial_filename */
1238       TRUE,                     /* open_dialog */
1239       DIALOG,                   /* what_to_tweak */
1240       FOLDER_NAME,              /* tweak_current_folder */
1241       NULL,                     /* tweak_filename */
1242       GTK_RESPONSE_CANCEL,      /* dialog_response */
1243       FALSE,                    /* unselect_all */
1244       NULL,                     /* final_current_folder */
1245       NULL                      /* final_filename */
1246     },
1247     {
1248       "open-dialog-cancel-f-nt",
1249       GTK_FILE_CHOOSER_ACTION_OPEN,
1250       FOLDER_NAME,              /* initial_current_folder */
1251       NULL,                     /* initial_filename */
1252       TRUE,                     /* open_dialog */
1253       BUTTON,                   /* what_to_tweak */
1254       NULL,                     /* tweak_current_folder */
1255       NULL,                     /* tweak_filename */
1256       GTK_RESPONSE_CANCEL,      /* dialog_response */
1257       FALSE,                    /* unselect_all */
1258       FOLDER_NAME,              /* final_current_folder */
1259       NULL                      /* final_filename */
1260     },
1261     {
1262       "open-dialog-cancel-f-b",
1263       GTK_FILE_CHOOSER_ACTION_OPEN,
1264       FOLDER_NAME,              /* initial_current_folder */
1265       NULL,                     /* initial_filename */
1266       TRUE,                     /* open_dialog */
1267       BUTTON,                   /* what_to_tweak */
1268       FOLDER_NAME_2,            /* tweak_current_folder */
1269       NULL,                     /* tweak_filename */
1270       GTK_RESPONSE_CANCEL,      /* dialog_response */
1271       FALSE,                    /* unselect_all */
1272       FOLDER_NAME_2,            /* final_current_folder */
1273       NULL                      /* final_filename */
1274     },
1275     {
1276       "open-dialog-cancel-f-d",
1277       GTK_FILE_CHOOSER_ACTION_OPEN,
1278       FOLDER_NAME,              /* initial_current_folder */
1279       NULL,                     /* initial_filename */
1280       TRUE,                     /* open_dialog */
1281       DIALOG,                   /* what_to_tweak */
1282       FOLDER_NAME_2,            /* tweak_current_folder */
1283       NULL,                     /* tweak_filename */
1284       GTK_RESPONSE_CANCEL,      /* dialog_response */
1285       FALSE,                    /* unselect_all */
1286       FOLDER_NAME,              /* final_current_folder */
1287       NULL                      /* final_filename */
1288     },
1289
1290     /* SELECT_FOLDER tests with dialog, cancelled */
1291
1292     {
1293       "select-folder-dialog-cancel-ni-nt",
1294       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1295       NULL,                     /* initial_current_folder */
1296       NULL,                     /* initial_filename */
1297       TRUE,                     /* open_dialog */
1298       BUTTON,                   /* what_to_tweak */
1299       NULL,                     /* tweak_current_folder */
1300       NULL,                     /* tweak_filename */
1301       GTK_RESPONSE_CANCEL,      /* dialog_response */
1302       FALSE,                    /* unselect_all */
1303       NULL,                     /* final_current_folder */
1304       NULL                      /* final_filename */
1305     },
1306     {
1307       "select-folder-dialog-cancel-ni-b",
1308       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1309       NULL,                     /* initial_current_folder */
1310       NULL,                     /* initial_filename */
1311       TRUE,                     /* open_dialog */
1312       BUTTON,                   /* what_to_tweak */
1313       NULL,                     /* tweak_current_folder */
1314       FOLDER_NAME,              /* tweak_filename */
1315       GTK_RESPONSE_CANCEL,      /* dialog_response */
1316       FALSE,                    /* unselect_all */
1317       NULL,                     /* final_current_folder */
1318       FOLDER_NAME               /* final_filename */
1319     },
1320     {
1321       "select-folder-dialog-cancel-ni-d",
1322       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1323       NULL,                     /* initial_current_folder */
1324       NULL,                     /* initial_filename */
1325       TRUE,                     /* open_dialog */
1326       DIALOG,                   /* what_to_tweak */
1327       NULL,                     /* tweak_current_folder */
1328       FOLDER_NAME,              /* tweak_filename */
1329       GTK_RESPONSE_CANCEL,      /* dialog_response */
1330       FALSE,                    /* unselect_all */
1331       NULL,                     /* final_current_folder */
1332       NULL                      /* final_filename */
1333     },
1334     {
1335       "select-folder-dialog-cancel-i-nt",
1336       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1337       NULL,                     /* initial_current_folder */
1338       FOLDER_NAME,              /* initial_filename */
1339       TRUE,                     /* open_dialog */
1340       BUTTON,                   /* what_to_tweak */
1341       NULL,                     /* tweak_current_folder */
1342       NULL,                     /* tweak_filename */
1343       GTK_RESPONSE_CANCEL,      /* dialog_response */
1344       FALSE,                    /* unselect_all */
1345       NULL,                     /* final_current_folder */
1346       FOLDER_NAME               /* final_filename */
1347     },
1348     {
1349       "select-folder-dialog-cancel-i-b",
1350       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1351       NULL,                     /* initial_current_folder */
1352       FOLDER_NAME,              /* initial_filename */
1353       TRUE,                     /* open_dialog */
1354       BUTTON,                   /* what_to_tweak */
1355       NULL,                     /* tweak_current_folder */
1356       FOLDER_NAME_2,            /* tweak_filename */
1357       GTK_RESPONSE_CANCEL,      /* dialog_response */
1358       FALSE,                    /* unselect_all */
1359       NULL,                     /* final_current_folder */
1360       FOLDER_NAME_2             /* final_filename */
1361     },
1362     {
1363       "select-folder-dialog-cancel-i-d",
1364       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1365       NULL,                     /* initial_current_folder */
1366       FOLDER_NAME,              /* initial_filename */
1367       TRUE,                     /* open_dialog */
1368       DIALOG,                   /* what_to_tweak */
1369       NULL,                     /* tweak_current_folder */
1370       FOLDER_NAME_2,            /* tweak_filename */
1371       GTK_RESPONSE_CANCEL,      /* dialog_response */
1372       FALSE,                    /* unselect_all */
1373       NULL,                     /* final_current_folder */
1374       FOLDER_NAME               /* final_filename */
1375     },
1376     {
1377       "select-folder-dialog-cancel-nf-nt",
1378       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1379       NULL,                     /* initial_current_folder */
1380       NULL,                     /* initial_filename */
1381       TRUE,                     /* open_dialog */
1382       BUTTON,                   /* what_to_tweak */
1383       NULL,                     /* tweak_current_folder */
1384       NULL,                     /* tweak_filename */
1385       GTK_RESPONSE_CANCEL,      /* dialog_response */
1386       FALSE,                    /* unselect_all */
1387       NULL,                     /* final_current_folder */
1388       NULL                      /* final_filename */
1389     },
1390     {
1391       "select-folder-dialog-cancel-nf-b",
1392       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1393       NULL,                     /* initial_current_folder */
1394       NULL,                     /* initial_filename */
1395       TRUE,                     /* open_dialog */
1396       BUTTON,                   /* what_to_tweak */
1397       FOLDER_NAME,              /* tweak_current_folder */
1398       NULL,                     /* tweak_filename */
1399       GTK_RESPONSE_CANCEL,      /* dialog_response */
1400       FALSE,                    /* unselect_all */
1401       FOLDER_NAME,              /* final_current_folder */
1402       NULL                      /* final_filename */
1403     },
1404     {
1405       "select-folder-dialog-cancel-nf-d",
1406       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1407       NULL,                     /* initial_current_folder */
1408       NULL,                     /* initial_filename */
1409       TRUE,                     /* open_dialog */
1410       DIALOG,                   /* what_to_tweak */
1411       FOLDER_NAME,              /* tweak_current_folder */
1412       NULL,                     /* tweak_filename */
1413       GTK_RESPONSE_CANCEL,      /* dialog_response */
1414       FALSE,                    /* unselect_all */
1415       NULL,                     /* final_current_folder */
1416       NULL                      /* final_filename */
1417     },
1418     {
1419       "select-folder-dialog-cancel-f-nt",
1420       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1421       FOLDER_NAME,              /* initial_current_folder */
1422       NULL,                     /* initial_filename */
1423       TRUE,                     /* open_dialog */
1424       BUTTON,                   /* what_to_tweak */
1425       NULL,                     /* tweak_current_folder */
1426       NULL,                     /* tweak_filename */
1427       GTK_RESPONSE_CANCEL,      /* dialog_response */
1428       FALSE,                    /* unselect_all */
1429       FOLDER_NAME,              /* final_current_folder */
1430       NULL                      /* final_filename */
1431     },
1432     {
1433       "select-folder-dialog-cancel-f-nt-2",
1434       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1435       FOLDER_NAME,              /* initial_current_folder */
1436       NULL,                     /* initial_filename */
1437       TRUE,                     /* open_dialog */
1438       BUTTON,                   /* what_to_tweak */
1439       NULL,                     /* tweak_current_folder */
1440       NULL,                     /* tweak_filename */
1441       GTK_RESPONSE_CANCEL,      /* dialog_response */
1442       FALSE,                    /* unselect_all */
1443       NULL,                     /* final_current_folder */
1444       FOLDER_NAME               /* final_filename */
1445     },
1446     {
1447       "select-folder-dialog-cancel-f-b",
1448       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1449       FOLDER_NAME,              /* initial_current_folder */
1450       NULL,                     /* initial_filename */
1451       TRUE,                     /* open_dialog */
1452       BUTTON,                   /* what_to_tweak */
1453       FOLDER_NAME_2,            /* tweak_current_folder */
1454       NULL,                     /* tweak_filename */
1455       GTK_RESPONSE_CANCEL,      /* dialog_response */
1456       FALSE,                    /* unselect_all */
1457       FOLDER_NAME_2,            /* final_current_folder */
1458       NULL                      /* final_filename */
1459     },
1460     {
1461       "select-folder-dialog-cancel-f-b-2",
1462       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1463       FOLDER_NAME,              /* initial_current_folder */
1464       NULL,                     /* initial_filename */
1465       TRUE,                     /* open_dialog */
1466       BUTTON,                   /* what_to_tweak */
1467       NULL,                     /* tweak_current_folder */
1468       FOLDER_NAME_2,            /* tweak_filename */
1469       GTK_RESPONSE_CANCEL,      /* dialog_response */
1470       FALSE,                    /* unselect_all */
1471       NULL,                     /* final_current_folder */
1472       FOLDER_NAME_2             /* final_filename */
1473     },
1474     {
1475       "select-folder-dialog-cancel-f-d",
1476       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1477       FOLDER_NAME,              /* initial_current_folder */
1478       NULL,                     /* initial_filename */
1479       TRUE,                     /* open_dialog */
1480       DIALOG,                   /* what_to_tweak */
1481       FOLDER_NAME_2,            /* tweak_current_folder */
1482       NULL,                     /* tweak_filename */
1483       GTK_RESPONSE_CANCEL,      /* dialog_response */
1484       FALSE,                    /* unselect_all */
1485       FOLDER_NAME,              /* final_current_folder */
1486       NULL                      /* final_filename */
1487     },
1488     {
1489       "select-folder-dialog-cancel-f-d-2",
1490       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1491       FOLDER_NAME,              /* initial_current_folder */
1492       NULL,                     /* initial_filename */
1493       TRUE,                     /* open_dialog */
1494       DIALOG,                   /* what_to_tweak */
1495       NULL,                     /* tweak_current_folder */
1496       FOLDER_NAME_2,            /* tweak_filename */
1497       GTK_RESPONSE_CANCEL,      /* dialog_response */
1498       FALSE,                    /* unselect_all */
1499       FOLDER_NAME,              /* final_current_folder */
1500       NULL                      /* final_filename */
1501     },
1502
1503     /* OPEN tests with dialog */
1504
1505     {
1506       "open-dialog-1",
1507       GTK_FILE_CHOOSER_ACTION_OPEN,
1508       NULL,                     /* initial_current_folder */
1509       NULL,                     /* initial_filename */
1510       TRUE,                     /* open_dialog */
1511       BUTTON,                   /* what_to_tweak */
1512       NULL,                     /* tweak_current_folder */
1513       FILE_NAME,                /* tweak_filename */
1514       GTK_RESPONSE_ACCEPT,      /* dialog_response */
1515       FALSE,                    /* unselect_all */
1516       NULL,                     /* final_current_folder */
1517       FILE_NAME                 /* final_filename */
1518     },
1519     {
1520       "open-dialog-2",
1521       GTK_FILE_CHOOSER_ACTION_OPEN,
1522       NULL,                     /* initial_current_folder */
1523       FILE_NAME,                /* initial_filename */
1524       TRUE,                     /* open_dialog */
1525       BUTTON,                   /* what_to_tweak */
1526       NULL,                     /* tweak_current_folder */
1527       NULL,                     /* tweak_filename */
1528       GTK_RESPONSE_ACCEPT,      /* dialog_response */
1529       FALSE,                    /* unselect_all */
1530       NULL,                     /* final_current_folder */
1531       FILE_NAME                 /* final_filename */
1532     },
1533     {
1534       "open-dialog-3",
1535       GTK_FILE_CHOOSER_ACTION_OPEN,
1536       NULL,                     /* initial_current_folder */
1537       FILE_NAME,                /* initial_filename */
1538       TRUE,                     /* open_dialog */
1539       BUTTON,                   /* what_to_tweak */
1540       NULL,                     /* tweak_current_folder */
1541       FILE_NAME_2,              /* tweak_filename */
1542       GTK_RESPONSE_ACCEPT,      /* dialog_response */
1543       FALSE,                    /* unselect_all */
1544       NULL,                     /* final_current_folder */
1545       FILE_NAME_2               /* final_filename */
1546     },
1547     {
1548       "open-dialog-4",
1549       GTK_FILE_CHOOSER_ACTION_OPEN,
1550       FOLDER_NAME,              /* initial_current_folder */
1551       NULL,                     /* initial_filename */
1552       TRUE,                     /* open_dialog */
1553       BUTTON,                   /* what_to_tweak */
1554       NULL,                     /* tweak_current_folder */
1555       FILE_NAME,                /* tweak_filename */
1556       GTK_RESPONSE_ACCEPT,      /* dialog_response */
1557       FALSE,                    /* unselect_all */
1558       NULL,                     /* final_current_folder */
1559       FILE_NAME                 /* final_filename */
1560     },
1561
1562     /* SELECT_FOLDER tests with dialog */
1563
1564     {
1565       "select-folder-dialog-1",
1566       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1567       NULL,                     /* initial_current_folder */
1568       FOLDER_NAME,              /* initial_filename */
1569       TRUE,                     /* open_dialog */
1570       BUTTON,                   /* what_to_tweak */
1571       NULL,                     /* tweak_current_folder */
1572       NULL,                     /* tweak_filename */
1573       GTK_RESPONSE_ACCEPT,      /* dialog_response */
1574       FALSE,                    /* unselect_all */
1575       NULL,                     /* final_current_folder */
1576       FOLDER_NAME               /* final_filename */
1577     },
1578     {
1579       "select-folder-dialog-2",
1580       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1581       FOLDER_NAME,              /* initial_current_folder */
1582       NULL,                     /* initial_filename */
1583       TRUE,                     /* open_dialog */
1584       BUTTON,                   /* what_to_tweak */
1585       NULL,                     /* tweak_current_folder */
1586       NULL,                     /* tweak_filename */
1587       GTK_RESPONSE_ACCEPT,      /* dialog_response */
1588       FALSE,                    /* unselect_all */
1589       NULL,                     /* final_current_folder */
1590       FOLDER_NAME               /* final_filename */
1591     },
1592     {
1593       "select-folder-dialog-3",
1594       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1595       NULL,                     /* initial_current_folder */
1596       FOLDER_NAME,              /* initial_filename */
1597       TRUE,                     /* open_dialog */
1598       BUTTON,                   /* what_to_tweak */
1599       NULL,                     /* tweak_current_folder */
1600       FOLDER_NAME_2,            /* tweak_filename */
1601       GTK_RESPONSE_ACCEPT,      /* dialog_response */
1602       FALSE,                    /* unselect_all */
1603       NULL,                     /* final_current_folder */
1604       FOLDER_NAME_2             /* final_filename */
1605     },
1606     {
1607       "select-folder-dialog-4",
1608       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1609       FOLDER_NAME,              /* initial_current_folder */
1610       NULL,                     /* initial_filename */
1611       TRUE,                     /* open_dialog */
1612       BUTTON,                   /* what_to_tweak */
1613       NULL,                     /* tweak_current_folder */
1614       FOLDER_NAME_2,            /* tweak_filename */
1615       GTK_RESPONSE_ACCEPT,      /* dialog_response */
1616       FALSE,                    /* unselect_all */
1617       NULL,                     /* final_current_folder */
1618       FOLDER_NAME_2             /* final_filename */
1619     },
1620
1621     /* Unselection tests */
1622     {
1623       "unselect-all-1",
1624       GTK_FILE_CHOOSER_ACTION_OPEN,
1625       NULL,                     /* initial_current_folder */
1626       NULL,                     /* initial_filename */
1627       FALSE,                    /* open_dialog */
1628       BUTTON,                   /* what_to_tweak */
1629       NULL,                     /* tweak_current_folder */
1630       NULL,                     /* tweak_filename */
1631       0,                        /* dialog_response */
1632       TRUE,                     /* unselect_all */
1633       NULL,                     /* final_current_folder */
1634       NULL                      /* final_filename */
1635     },
1636     {
1637       "unselect-all-2",
1638       GTK_FILE_CHOOSER_ACTION_OPEN,
1639       NULL,                     /* initial_current_folder */
1640       FILE_NAME,                /* initial_filename */
1641       FALSE,                    /* open_dialog */
1642       BUTTON,                   /* what_to_tweak */
1643       NULL,                     /* tweak_current_folder */
1644       NULL,                     /* tweak_filename */
1645       0,                        /* dialog_response */
1646       TRUE,                     /* unselect_all */
1647       NULL,                     /* final_current_folder */
1648       NULL                      /* final_filename */
1649     },
1650     {
1651       "unselect-all-3",
1652       GTK_FILE_CHOOSER_ACTION_OPEN,
1653       NULL,                     /* initial_current_folder */
1654       FILE_NAME,                /* initial_filename */
1655       FALSE,                    /* open_dialog */
1656       BUTTON,                   /* what_to_tweak */
1657       NULL,                     /* tweak_current_folder */
1658       FILE_NAME_2,              /* tweak_filename */
1659       0,                        /* dialog_response */
1660       TRUE,                     /* unselect_all */
1661       NULL,                     /* final_current_folder */
1662       NULL                      /* final_filename */
1663     },
1664     {
1665       "unselect-all-4",
1666       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1667       NULL,                     /* initial_current_folder */
1668       NULL,                     /* initial_filename */
1669       FALSE,                    /* open_dialog */
1670       BUTTON,                   /* what_to_tweak */
1671       NULL,                     /* tweak_current_folder */
1672       NULL,                     /* tweak_filename */
1673       0,                        /* dialog_response */
1674       TRUE,                     /* unselect_all */
1675       NULL,                     /* final_current_folder */
1676       NULL                      /* final_filename */
1677     },
1678     {
1679       "unselect-all-5",
1680       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1681       NULL,                     /* initial_current_folder */
1682       FOLDER_NAME,              /* initial_filename */
1683       FALSE,                    /* open_dialog */
1684       BUTTON,                   /* what_to_tweak */
1685       NULL,                     /* tweak_current_folder */
1686       NULL,                     /* tweak_filename */
1687       0,                        /* dialog_response */
1688       TRUE,                     /* unselect_all */
1689       NULL,                     /* final_current_folder */
1690       NULL                      /* final_filename */
1691     },
1692     {
1693       "unselect-all-6",
1694       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1695       NULL,                     /* initial_current_folder */
1696       FOLDER_NAME,              /* initial_filename */
1697       FALSE,                    /* open_dialog */
1698       BUTTON,                   /* what_to_tweak */
1699       NULL,                     /* tweak_current_folder */
1700       FOLDER_NAME_2,            /* tweak_filename */
1701       0,                        /* dialog_response */
1702       TRUE,                     /* unselect_all */
1703       NULL,                     /* final_current_folder */
1704       NULL                      /* final_filename */
1705     },
1706
1707   };
1708
1709 static void
1710 setup_file_chooser_button_tests (void)
1711 {
1712   int i;
1713
1714   for (i = 0; i < G_N_ELEMENTS (button_tests); i++)
1715     {
1716       char *test_name;
1717
1718       test_name = make_button_test_name (&button_tests[i]);
1719       g_test_add_data_func (test_name, &button_tests[i], test_file_chooser_button);
1720       g_free (test_name);
1721     }
1722
1723   setup_file_chooser_button_combo_box_tests ();
1724 }
1725
1726 #ifdef BROKEN_TESTS
1727 struct confirm_overwrite_closure {
1728   GtkWidget *chooser;
1729   GtkWidget *accept_button;
1730   gint confirm_overwrite_signal_emitted;
1731   gchar *extension;
1732 };
1733
1734 static GtkFileChooserConfirmation
1735 confirm_overwrite_cb (GtkFileChooser *chooser, gpointer data)
1736 {
1737   struct confirm_overwrite_closure *closure = data;
1738
1739   if (g_test_verbose())
1740     printf ("bling!\n");
1741   closure->confirm_overwrite_signal_emitted += 1;
1742
1743   return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
1744 }
1745
1746 static void
1747 overwrite_response_cb (GtkFileChooser *chooser, gint response, gpointer data)
1748 {
1749   struct confirm_overwrite_closure *closure = data;
1750   char *filename;
1751
1752   if (g_test_verbose())
1753     printf ("plong!\n");
1754
1755   if (response != GTK_RESPONSE_ACCEPT)
1756     return;
1757
1758   filename = gtk_file_chooser_get_filename (chooser);
1759
1760   if (!g_str_has_suffix (filename, closure->extension))
1761     {
1762       char *basename;
1763
1764       basename = g_path_get_basename (filename);
1765       g_free (filename);
1766
1767       filename = g_strconcat (basename, closure->extension, NULL);
1768       gtk_file_chooser_set_current_name (chooser, filename);
1769
1770       g_signal_stop_emission_by_name (chooser, "response");
1771       gtk_dialog_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT);
1772     }
1773 }
1774
1775 static gboolean
1776 confirm_overwrite_timeout_cb (gpointer data)
1777 {
1778   struct confirm_overwrite_closure *closure;
1779
1780   closure = data;
1781   gtk_button_clicked (GTK_BUTTON (closure->accept_button));
1782
1783   return FALSE;
1784 }
1785
1786 /* http://bugzilla.gnome.org/show_bug.cgi?id=347883 */
1787 static gboolean
1788 test_confirm_overwrite_for_path (const char *path, gboolean append_extension)
1789 {
1790   gboolean passed;
1791   struct confirm_overwrite_closure closure;
1792   char *filename;
1793   guint timeout_id;
1794
1795   passed = TRUE;
1796
1797   closure.extension = NULL;
1798   closure.confirm_overwrite_signal_emitted = 0;
1799   closure.chooser = gtk_file_chooser_dialog_new ("hello", NULL, GTK_FILE_CHOOSER_ACTION_SAVE,
1800                                                  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1801                                                  NULL);
1802   closure.accept_button = gtk_dialog_add_button (GTK_DIALOG (closure.chooser),
1803                                                  GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT);
1804   gtk_dialog_set_default_response (GTK_DIALOG (closure.chooser), GTK_RESPONSE_ACCEPT);
1805
1806   gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (closure.chooser), TRUE);
1807
1808   g_signal_connect (closure.chooser, "confirm-overwrite",
1809                     G_CALLBACK (confirm_overwrite_cb), &closure);
1810
1811   if (append_extension)
1812     {
1813       char *extension;
1814
1815       filename = g_path_get_dirname (path);
1816       gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (closure.chooser), filename);
1817       g_free (filename);
1818
1819       filename = g_path_get_basename (path);
1820       extension = strchr (filename, '.');
1821
1822       if (extension)
1823         {
1824           closure.extension = g_strdup (extension);
1825           *extension = '\0';
1826         }
1827
1828       gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (closure.chooser), filename);
1829       g_free (filename);
1830
1831       g_signal_connect (closure.chooser, "response",
1832                         G_CALLBACK (overwrite_response_cb), &closure);
1833     }
1834   else
1835     {
1836       gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (closure.chooser), path);
1837     }
1838
1839   timeout_id = gdk_threads_add_timeout_full (G_MAXINT, SLEEP_DURATION, confirm_overwrite_timeout_cb, &closure, NULL);
1840   gtk_dialog_run (GTK_DIALOG (closure.chooser));
1841   g_source_remove (timeout_id);
1842
1843   filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (closure.chooser));
1844   passed = passed && filename && (strcmp (filename, path) == 0);
1845   g_free (filename);
1846
1847   gtk_widget_destroy (closure.chooser);
1848
1849   passed = passed && (1 == closure.confirm_overwrite_signal_emitted);
1850
1851   log_test (passed, "Confirm overwrite for %s", path);
1852
1853   return passed;
1854 }
1855
1856 static void
1857 test_confirm_overwrite (void)
1858 {
1859   gboolean passed = TRUE;
1860
1861   /* first test for a file we know will always exist */
1862   passed = passed && test_confirm_overwrite_for_path ("/etc/passwd", FALSE);
1863   g_assert (passed);
1864   passed = passed && test_confirm_overwrite_for_path ("/etc/resolv.conf", TRUE);
1865   g_assert (passed);
1866 }
1867 #endif
1868
1869 static const GtkFileChooserAction open_actions[] = {
1870   GTK_FILE_CHOOSER_ACTION_OPEN,
1871   GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
1872 };
1873
1874 static const GtkFileChooserAction save_actions[] = {
1875   GTK_FILE_CHOOSER_ACTION_SAVE,
1876   GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
1877 };
1878
1879
1880 #ifdef BROKEN_TESTS
1881 static gboolean
1882 has_action (const GtkFileChooserAction *actions,
1883             int n_actions,
1884             GtkFileChooserAction sought_action)
1885 {
1886   int i;
1887
1888   for (i = 0; i < n_actions; i++)
1889     if (actions[i] == sought_action)
1890       return TRUE;
1891
1892   return FALSE;
1893 }
1894
1895 static GtkFileChooserDefault *
1896 get_impl_from_dialog (GtkWidget *dialog)
1897 {
1898   GtkFileChooserDialog *d;
1899   GtkFileChooserDialogPrivate *dialog_priv;
1900   GtkFileChooserWidget *chooser_widget;
1901   GtkFileChooserWidgetPrivate *widget_priv;
1902   GtkFileChooserDefault *impl;
1903
1904   d = GTK_FILE_CHOOSER_DIALOG (dialog);
1905   dialog_priv = d->priv;
1906   chooser_widget = GTK_FILE_CHOOSER_WIDGET (dialog_priv->widget);
1907   if (!chooser_widget)
1908     g_error ("BUG: dialog_priv->widget is not a GtkFileChooserWidget");
1909
1910   widget_priv = chooser_widget->priv;
1911   impl = (GtkFileChooserDefault *) (widget_priv->impl);
1912   if (!impl)
1913     g_error ("BUG: widget_priv->impl is not a GtkFileChooserDefault");
1914
1915   return impl;
1916 }
1917
1918 static gboolean
1919 test_widgets_for_current_action (GtkFileChooserDialog *dialog,
1920                                  GtkFileChooserAction  expected_action)
1921 {
1922   GtkFileChooserDefault *impl;
1923   gboolean passed;
1924
1925   if (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) != expected_action)
1926     return FALSE;
1927
1928   impl = get_impl_from_dialog (GTK_WIDGET (dialog));
1929
1930   g_assert (impl->action == expected_action);
1931
1932   passed = TRUE;
1933
1934   /* OPEN implies that the "new folder" button is hidden; otherwise it is shown */
1935   if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
1936     passed = passed && !gtk_widget_get_visible (impl->browse_new_folder_button);
1937   else
1938     passed = passed && gtk_widget_get_visible (impl->browse_new_folder_button);
1939
1940   /* Check that the widgets are present/visible or not */
1941   if (has_action (open_actions, G_N_ELEMENTS (open_actions), impl->action))
1942     {
1943       passed = passed && (impl->save_widgets == NULL
1944                           && (impl->location_mode == LOCATION_MODE_PATH_BAR
1945                               ? impl->location_entry == NULL
1946                               : impl->location_entry != NULL)
1947                           && impl->save_folder_label == NULL
1948                           && impl->save_folder_combo == NULL
1949                           && impl->save_expander == NULL
1950                           && GTK_IS_CONTAINER (impl->browse_widgets) && gtk_widget_is_drawable (impl->browse_widgets));
1951     }
1952   else if (has_action (save_actions, G_N_ELEMENTS (save_actions), impl->action))
1953     {
1954       /* FIXME: we can't use GTK_IS_FILE_CHOOSER_ENTRY() because it uses
1955        * _gtk_file_chooser_entry_get_type(), which is a non-exported symbol.
1956        * So, we just test impl->location_entry for being non-NULL
1957        */
1958       passed = passed && (GTK_IS_CONTAINER (impl->save_widgets) && gtk_widget_is_drawable (impl->save_widgets)
1959                           && impl->location_entry != NULL && gtk_widget_is_drawable (impl->location_entry)
1960                           && GTK_IS_LABEL (impl->save_folder_label) && gtk_widget_is_drawable (impl->save_folder_label)
1961                           && GTK_IS_COMBO_BOX (impl->save_folder_combo) && gtk_widget_is_drawable (impl->save_folder_combo)
1962                           && GTK_IS_EXPANDER (impl->save_expander) && gtk_widget_is_drawable (impl->save_expander)
1963                           && GTK_IS_CONTAINER (impl->browse_widgets));
1964
1965       /* FIXME: we are in a SAVE mode; test the visibility and sensitivity of
1966        * the children that change depending on the state of the expander.
1967        */
1968     }
1969   else
1970     {
1971       g_error ("BAD TEST: test_widgets_for_current_action() doesn't know about %s", get_action_name (impl->action));
1972       passed = FALSE;
1973     }
1974
1975   return passed;
1976 }
1977
1978 typedef gboolean (* ForeachActionCallback) (GtkFileChooserDialog *dialog,
1979                                             GtkFileChooserAction  action,
1980                                             gpointer              user_data);
1981
1982 static gboolean
1983 foreach_action (GtkFileChooserDialog *dialog,
1984                 ForeachActionCallback callback,
1985                 gpointer              user_data)
1986 {
1987   GEnumClass *enum_class;
1988   int i;
1989
1990   enum_class = g_type_class_peek (GTK_TYPE_FILE_CHOOSER_ACTION);
1991   if (!enum_class)
1992     g_error ("BUG: get_action_name(): no GEnumClass for GTK_TYPE_FILE_CHOOSER_ACTION");
1993
1994   for (i = 0; i < enum_class->n_values; i++)
1995     {
1996       GEnumValue *enum_value;
1997       GtkFileChooserAction action;
1998       gboolean passed;
1999
2000       enum_value = enum_class->values + i;
2001       action = enum_value->value;
2002
2003       passed = (* callback) (dialog, action, user_data);
2004       if (!passed)
2005         return FALSE;
2006     }
2007
2008   return TRUE;
2009 }
2010
2011 struct action_closure {
2012   GtkFileChooserAction from_action;
2013 };
2014
2015 static gboolean
2016 switch_from_to_action_cb (GtkFileChooserDialog *dialog,
2017                           GtkFileChooserAction  action,
2018                           gpointer              user_data)
2019 {
2020   struct action_closure *closure;
2021   gboolean passed;
2022
2023   closure = user_data;
2024
2025   gtk_file_chooser_set_action (GTK_FILE_CHOOSER (dialog), closure->from_action);
2026
2027   passed = test_widgets_for_current_action (dialog, closure->from_action);
2028   log_test (passed, "switch_from_to_action_cb(): reset to action %s", get_action_name (closure->from_action));
2029   if (!passed)
2030     return FALSE;
2031
2032   gtk_file_chooser_set_action (GTK_FILE_CHOOSER (dialog), action);
2033
2034   passed = test_widgets_for_current_action (dialog, action);
2035   log_test (passed, "switch_from_to_action_cb(): transition from %s to %s",
2036             get_action_name (closure->from_action),
2037             get_action_name (action));
2038   return passed;
2039 }
2040
2041 static gboolean
2042 switch_from_action_cb (GtkFileChooserDialog *dialog,
2043                        GtkFileChooserAction  action,
2044                        gpointer              user_data)
2045 {
2046   struct action_closure closure;
2047
2048   closure.from_action = action;
2049
2050   return foreach_action (dialog, switch_from_to_action_cb, &closure);
2051 }
2052
2053 static void
2054 test_action_widgets (void)
2055 {
2056   GtkWidget *dialog;
2057   GtkFileChooserAction action;
2058   gboolean passed;
2059
2060   dialog = gtk_file_chooser_dialog_new ("Test file chooser",
2061                                         NULL,
2062                                         GTK_FILE_CHOOSER_ACTION_OPEN,
2063                                         GTK_STOCK_CANCEL,
2064                                         GTK_RESPONSE_CANCEL,
2065                                         GTK_STOCK_OK,
2066                                         GTK_RESPONSE_ACCEPT,
2067                                         NULL);
2068   gtk_widget_show_now (dialog);
2069
2070   action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog));
2071
2072   passed = test_widgets_for_current_action (GTK_FILE_CHOOSER_DIALOG (dialog), action);
2073   log_test (passed, "test_action_widgets(): widgets for initial action %s", get_action_name (action));
2074   g_assert (passed);
2075
2076   passed = foreach_action (GTK_FILE_CHOOSER_DIALOG (dialog), switch_from_action_cb, NULL);
2077   log_test (passed, "test_action_widgets(): all transitions through property change");
2078   g_assert (passed);
2079
2080   gtk_widget_destroy (dialog);
2081 }
2082 #endif
2083
2084 #ifdef BROKEN_TESTS
2085 static gboolean
2086 test_reload_sequence (gboolean set_folder_before_map)
2087 {
2088   GtkWidget *dialog;
2089   GtkFileChooserDefault *impl;
2090   gboolean passed;
2091   char *folder;
2092   char *current_working_dir;
2093
2094   passed = TRUE;
2095
2096   current_working_dir = g_get_current_dir ();
2097
2098   dialog = gtk_file_chooser_dialog_new ("Test file chooser",
2099                                         NULL,
2100                                         GTK_FILE_CHOOSER_ACTION_OPEN,
2101                                         GTK_STOCK_CANCEL,
2102                                         GTK_RESPONSE_CANCEL,
2103                                         GTK_STOCK_OK,
2104                                         GTK_RESPONSE_ACCEPT,
2105                                         NULL);
2106   impl = get_impl_from_dialog (dialog);
2107
2108   if (set_folder_before_map)
2109     {
2110       gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), g_get_home_dir ());
2111
2112       wait_for_idle ();
2113
2114       passed = passed && (impl->current_folder != NULL
2115                           && impl->browse_files_model != NULL
2116                           && (impl->load_state == LOAD_PRELOAD || impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
2117                           && impl->reload_state == RELOAD_HAS_FOLDER
2118                           && (impl->load_state == LOAD_PRELOAD ? (impl->load_timeout_id != 0) : TRUE)
2119                           && ((impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
2120                               ? (impl->load_timeout_id == 0 && impl->sort_model != NULL)
2121                               : TRUE));
2122
2123       wait_for_idle ();
2124
2125       folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
2126       passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);
2127       g_free (folder);
2128     }
2129   else
2130     {
2131       /* Initially, no folder is not loaded or pending */
2132       passed = passed && (impl->current_folder == NULL
2133                           && impl->sort_model == NULL
2134                           && impl->browse_files_model == NULL
2135                           && impl->load_state == LOAD_EMPTY
2136                           && impl->reload_state == RELOAD_EMPTY
2137                           && impl->load_timeout_id == 0);
2138
2139       wait_for_idle ();
2140
2141       folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
2142       passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);
2143     }
2144
2145   log_test (passed, "test_reload_sequence(): initial status");
2146
2147   /* After mapping, it is loading some folder, either the one that was explicitly set or the default one */
2148
2149   gtk_widget_show_now (dialog);
2150
2151   wait_for_idle ();
2152
2153   passed = passed && (impl->current_folder != NULL
2154                       && impl->browse_files_model != NULL
2155                       && (impl->load_state == LOAD_PRELOAD || impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
2156                       && impl->reload_state == RELOAD_HAS_FOLDER
2157                       && (impl->load_state == LOAD_PRELOAD ? (impl->load_timeout_id != 0) : TRUE)
2158                       && ((impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
2159                           ? (impl->load_timeout_id == 0 && impl->sort_model != NULL)
2160                           : TRUE));
2161
2162   folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
2163   if (set_folder_before_map)
2164     passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);
2165   else
2166     passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);
2167
2168   g_free (folder);
2169
2170   log_test (passed, "test_reload_sequence(): status after map");
2171
2172   /* Unmap it; we should still have a folder */
2173
2174   gtk_widget_hide (dialog);
2175
2176   wait_for_idle ();
2177
2178   passed = passed && (impl->current_folder != NULL
2179                       && impl->browse_files_model != NULL
2180                       && (impl->load_state == LOAD_PRELOAD || impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
2181                       && (impl->load_state == LOAD_PRELOAD ? (impl->load_timeout_id != 0) : TRUE)
2182                       && ((impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
2183                           ? (impl->load_timeout_id == 0 && impl->sort_model != NULL)
2184                           : TRUE));
2185
2186   folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
2187   if (set_folder_before_map)
2188     passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);
2189   else
2190     passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);
2191
2192   g_free (folder);
2193
2194   log_test (passed, "test_reload_sequence(): status after unmap");
2195
2196   /* Map it again! */
2197
2198   gtk_widget_show_now (dialog);
2199
2200   wait_for_idle ();
2201
2202   passed = passed && (impl->current_folder != NULL
2203                       && impl->browse_files_model != NULL
2204                       && (impl->load_state == LOAD_PRELOAD || impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
2205                       && impl->reload_state == RELOAD_HAS_FOLDER
2206                       && (impl->load_state == LOAD_PRELOAD ? (impl->load_timeout_id != 0) : TRUE)
2207                       && ((impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
2208                           ? (impl->load_timeout_id == 0 && impl->sort_model != NULL)
2209                           : TRUE));
2210
2211   folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
2212   if (set_folder_before_map)
2213     passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);
2214   else
2215     passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);
2216
2217   g_free (folder);
2218
2219   log_test (passed, "test_reload_sequence(): status after re-map");
2220
2221   gtk_widget_destroy (dialog);
2222   g_free (current_working_dir);
2223
2224   return passed;
2225 }
2226
2227 static void
2228 test_reload (void)
2229 {
2230   gboolean passed;
2231
2232   passed = test_reload_sequence (FALSE);
2233   log_test (passed, "test_reload(): create and use the default folder");
2234   g_assert (passed);
2235
2236   passed = test_reload_sequence (TRUE);
2237   log_test (passed, "test_reload(): set a folder explicitly before mapping");
2238   g_assert (passed);
2239 }
2240
2241 static gboolean
2242 test_button_folder_states_for_action (GtkFileChooserAction action, gboolean use_dialog, gboolean set_folder_on_dialog)
2243 {
2244   gboolean passed;
2245   GtkWidget *window;
2246   GtkWidget *button;
2247   char *folder;
2248   GtkWidget *dialog;
2249   char *current_working_dir;
2250   gboolean must_have_cwd;
2251
2252   passed = TRUE;
2253
2254   current_working_dir = g_get_current_dir ();
2255   must_have_cwd = !(use_dialog && set_folder_on_dialog);
2256
2257   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2258
2259   if (use_dialog)
2260     {
2261       dialog = gtk_file_chooser_dialog_new ("Test", NULL, action,
2262                                             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2263                                             GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2264                                             NULL);
2265       button = gtk_file_chooser_button_new_with_dialog (dialog);
2266
2267       if (set_folder_on_dialog)
2268         gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), g_get_home_dir ());
2269     }
2270   else
2271     {
2272       button = gtk_file_chooser_button_new ("Test", action);
2273       dialog = NULL; /* keep gcc happy */
2274     }
2275
2276   gtk_container_add (GTK_CONTAINER (window), button);
2277
2278   /* Pre-map; no folder is set */
2279   wait_for_idle ();
2280
2281   folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (button));
2282   if (must_have_cwd)
2283     passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);
2284   else
2285     passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);
2286
2287   log_test (passed, "test_button_folder_states_for_action(): %s, use_dialog=%d, set_folder_on_dialog=%d, pre-map, %s",
2288             get_action_name (action),
2289             use_dialog,
2290             set_folder_on_dialog,
2291             must_have_cwd ? "must have $cwd" : "must have explicit folder");
2292
2293   /* Map; folder should be set */
2294
2295   gtk_widget_show_all (window);
2296   gtk_widget_show_now (window);
2297
2298   wait_for_idle ();
2299
2300   folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (button));
2301
2302   if (must_have_cwd)
2303     passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);
2304   else
2305     passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);
2306
2307   log_test (passed, "test_button_folder_states_for_action(): %s, use_dialog=%d, set_folder_on_dialog=%d, mapped, %s",
2308             get_action_name (action),
2309             use_dialog,
2310             set_folder_on_dialog,
2311             must_have_cwd ? "must have $cwd" : "must have explicit folder");
2312   g_free (folder);
2313
2314   /* Unmap; folder should be set */
2315
2316   gtk_widget_hide (window);
2317   wait_for_idle ();
2318   folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (button));
2319
2320   if (must_have_cwd)
2321     passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);
2322   else
2323     passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);
2324
2325   log_test (passed, "test_button_folder_states_for_action(): %s, use_dialog=%d, set_folder_on_dialog=%d, unmapped, %s",
2326             get_action_name (action),
2327             use_dialog,
2328             set_folder_on_dialog,
2329             must_have_cwd ? "must have $cwd" : "must have explicit folder");
2330   g_free (folder);
2331
2332   /* Re-map; folder should be set */
2333
2334   gtk_widget_show_now (window);
2335   folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (button));
2336
2337   if (must_have_cwd)
2338     passed = passed && (g_strcmp0 (folder, current_working_dir) == 0);
2339   else
2340     passed = passed && (g_strcmp0 (folder, g_get_home_dir()) == 0);
2341   wait_for_idle ();
2342   log_test (passed, "test_button_folder_states_for_action(): %s, use_dialog=%d, set_folder_on_dialog=%d, re-mapped, %s",
2343             get_action_name (action),
2344             use_dialog,
2345             set_folder_on_dialog,
2346             must_have_cwd ? "must have $cwd" : "must have explicit folder");
2347   g_free (folder);
2348
2349   g_free (current_working_dir);
2350
2351   gtk_widget_destroy (window);
2352
2353   return passed;
2354 }
2355
2356 static void
2357 test_button_folder_states (void)
2358 {
2359   /* GtkFileChooserButton only supports OPEN and SELECT_FOLDER */
2360   static const GtkFileChooserAction actions_to_test[] = {
2361     GTK_FILE_CHOOSER_ACTION_OPEN,
2362     GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
2363   };
2364   gboolean passed;
2365   int i;
2366
2367   passed = TRUE;
2368
2369   for (i = 0; i < G_N_ELEMENTS (actions_to_test); i++)
2370     {
2371       passed = passed && test_button_folder_states_for_action (actions_to_test[i], FALSE, FALSE);
2372       g_assert (passed);
2373       passed = passed && test_button_folder_states_for_action (actions_to_test[i], TRUE, FALSE);
2374       g_assert (passed);
2375       passed = passed && test_button_folder_states_for_action (actions_to_test[i], TRUE, TRUE);
2376       g_assert (passed);
2377       log_test (passed, "test_button_folder_states(): action %s", get_action_name (actions_to_test[i]));
2378     }
2379
2380   log_test (passed, "test_button_folder_states(): all supported actions");
2381 }
2382
2383 static void
2384 test_folder_switch_and_filters (void)
2385 {
2386   gboolean passed;
2387   char *cwd;
2388   char *base_dir;
2389   GFile *cwd_file;
2390   GFile *base_dir_file;
2391   GtkWidget *dialog;
2392   GtkFileFilter *all_filter;
2393   GtkFileFilter *txt_filter;
2394   GtkFileChooserDefault *impl;
2395
2396   passed = TRUE;
2397
2398   cwd = g_get_current_dir ();
2399   base_dir = g_build_filename (cwd, "file-chooser-test-dir", NULL);
2400
2401   dialog = gtk_file_chooser_dialog_new ("Test", NULL, GTK_FILE_CHOOSER_ACTION_OPEN,
2402                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2403                                         GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2404                                         NULL);
2405   impl = get_impl_from_dialog (dialog);
2406
2407   cwd_file = g_file_new_for_path (cwd);
2408   base_dir_file = g_file_new_for_path (base_dir);
2409
2410   passed = passed && gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), base_dir);
2411   g_assert (passed);
2412
2413   /* All files filter */
2414
2415   all_filter = gtk_file_filter_new ();
2416   gtk_file_filter_set_name (all_filter, "All files");
2417   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), all_filter);
2418
2419   /* *.txt filter */
2420
2421   txt_filter = gtk_file_filter_new ();
2422   gtk_file_filter_set_name (all_filter, "*.txt");
2423   gtk_file_filter_add_pattern (txt_filter, "*.txt");
2424   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), txt_filter);
2425
2426   /* Test filter set */
2427
2428   gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), all_filter);
2429   passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == all_filter);
2430   g_assert (passed);
2431
2432   gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), txt_filter);
2433   passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == txt_filter);
2434   log_test (passed, "test_folder_switch_and_filters(): set and get filter");
2435   g_assert (passed);
2436
2437   gtk_widget_show (dialog);
2438
2439   /* Test that filter is unchanged when we switch folders */
2440
2441   gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd);
2442   sleep_in_main_loop ();
2443   passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == txt_filter);
2444   g_assert (passed);
2445
2446   gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), base_dir);
2447   sleep_in_main_loop ();
2448
2449   g_signal_emit_by_name (impl->browse_path_bar, "path-clicked",
2450                          cwd_file,
2451                          base_dir_file,
2452                          FALSE);
2453   sleep_in_main_loop ();
2454   passed = passed && (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == txt_filter);
2455   log_test (passed, "test_folder_switch_and_filters(): filter after changing folder");
2456   g_assert (passed);
2457
2458   /* cleanups */
2459   g_free (cwd);
2460   g_free (base_dir);
2461   g_object_unref (cwd_file);
2462   g_object_unref (base_dir_file);
2463
2464   gtk_widget_destroy (dialog);
2465
2466   log_test (passed, "test_folder_switch_and_filters(): all filter tests");
2467 }
2468 #endif
2469
2470 int
2471 main (int    argc,
2472       char **argv)
2473 {
2474   /* initialize test program */
2475   gtk_test_init (&argc, &argv);
2476
2477   /* Register tests */
2478
2479   setup_file_chooser_button_tests ();
2480 #ifdef BROKEN_TESTS
2481   setup_set_filename_tests ();
2482   setup_set_current_name_tests ();
2483
2484   g_test_add_func ("/GtkFileChooser/confirm_overwrite", test_confirm_overwrite);
2485   g_test_add_func ("/GtkFileChooser/action_widgets", test_action_widgets);
2486   g_test_add_func ("/GtkFileChooser/reload", test_reload);
2487   g_test_add_func ("/GtkFileChooser/button_folder_states", test_button_folder_states);
2488   g_test_add_func ("/GtkFileChooser/folder_switch_and_filters", test_folder_switch_and_filters);
2489 #endif
2490
2491   /* run and check selected tests */
2492   return g_test_run();
2493 }