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/mozapps/downloads/tests/browser/browser_unknownContentType_extension.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.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 '')
-rw-r--r-- | toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_extension.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_extension.js b/toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_extension.js new file mode 100644 index 0000000000..1bb836c1d8 --- /dev/null +++ b/toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_extension.js @@ -0,0 +1,58 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const TEST_PATH = getRootDirectory(gTestPath).replace( + "chrome://mochitests/content", + "http://example.com" +); + +/** + * Check that case-sensitivity doesn't cause us to duplicate + * file name extensions. + */ +add_task(async function test_download_filename_extension() { + forcePromptForFiles("application/octet-stream", "exe"); + let windowObserver = BrowserTestUtils.domWindowOpenedAndLoaded(); + + let tab = await BrowserTestUtils.openNewForegroundTab({ + gBrowser, + opening: TEST_PATH + "unknownContentType.EXE", + waitForLoad: false, + }); + let win = await windowObserver; + + let list = await Downloads.getList(Downloads.ALL); + let downloadFinishedPromise = new Promise(resolve => { + list.addView({ + onDownloadChanged(download) { + if (download.stopped) { + list.removeView(this); + resolve(download); + } + }, + }); + }); + + let dialog = win.document.querySelector("dialog"); + dialog.getButton("accept").removeAttribute("disabled"); + dialog.acceptDialog(); + let download = await downloadFinishedPromise; + // We cannot assume that the filename didn't change. + let filename = PathUtils.filename(download.target.path); + Assert.ok( + filename.indexOf(".") == filename.lastIndexOf("."), + "Should not duplicate extension" + ); + Assert.ok(filename.endsWith(".EXE"), "Should not change extension"); + await list.remove(download); + BrowserTestUtils.removeTab(tab); + try { + await IOUtils.remove(download.target.path); + } catch (ex) { + // Ignore errors in removing the file, the system may keep it locked and + // it's not a critical issue. + info("Failed to remove the file " + ex); + } +}); |