Remove some duplication in testfilechooserbutton
Most of the code creating the two types of dialogs (open file, choose folder) is the same. This refactors the common code into a helper method. This also makes it easier to add other chooser types for this test (e.g. save file).