I have used different options, which do work for me with headlessmode enabled, but not inactive.
prefs.put("profile.default_content_settings.popups", 0);
prefs.put("download.default_directory", driverFactory.getDownloadPath());
prefs.put("download.prompt_for_download", false);
prefs.put("download.default_directory", driverFactory.getDownloadPath());
And when setting the download directory by default, it ignores the previous configurations, and the popup keeps popping up, thus failing me the tests that have some implication in downloading some type of file.