From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../downloads/test/unit/test_Download_noext_win.js | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 toolkit/components/downloads/test/unit/test_Download_noext_win.js (limited to 'toolkit/components/downloads/test/unit/test_Download_noext_win.js') 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); + }); +} -- cgit v1.2.3