diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/components/downloads/test/unit/test_Download_noext_win.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/downloads/test/unit/test_Download_noext_win.js')
-rw-r--r-- | toolkit/components/downloads/test/unit/test_Download_noext_win.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/toolkit/components/downloads/test/unit/test_Download_noext_win.js b/toolkit/components/downloads/test/unit/test_Download_noext_win.js new file mode 100644 index 0000000000..0e226229f6 --- /dev/null +++ b/toolkit/components/downloads/test/unit/test_Download_noext_win.js @@ -0,0 +1,59 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function () { + info("Get a file without extension"); + let noExtFile = getTempFile("test_bug_1661365"); + Assert.ok(!noExtFile.leafName.includes("."), "Sanity check the filename"); + info("Create an exe file with the same name"); + await IOUtils.remove(noExtFile.path + ".exe", { ignoreAbsent: true }); + let exeFile = new FileUtils.File(noExtFile.path + ".exe"); + exeFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); + Assert.ok(await fileExists(exeFile.path), "Sanity check the exe exists."); + Assert.equal( + exeFile.leafName, + noExtFile.leafName + ".exe", + "Sanity check the file names." + ); + registerCleanupFunction(async function () { + await IOUtils.remove(noExtFile.path, { ignoreAbsent: true }); + await IOUtils.remove(exeFile.path, { ignoreAbsent: true }); + }); + + info("Download to the no-extension file"); + let download = await Downloads.createDownload({ + source: httpUrl("source.txt"), + target: noExtFile, + }); + await download.start(); + + Assert.ok( + await fileExists(download.target.path), + "The file should have been created." + ); + Assert.ok(await fileExists(exeFile.path), "Sanity check the exe exists."); + + info("Launch should open the containing folder"); + let promiseShowInFolder = waitForDirectoryShown(); + download.launch(); + Assert.equal(await promiseShowInFolder, noExtFile.path); +}); + +/** + * Waits for an attempt to show the directory where a file is located, and + * returns the path of the file. + */ +function waitForDirectoryShown() { + return new Promise(resolve => { + let waitFn = base => ({ + showContainingDirectory(path) { + Integration.downloads.unregister(waitFn); + resolve(path); + return Promise.resolve(); + }, + }); + Integration.downloads.register(waitFn); + }); +} |