diff --git a/toolkit/mozapps/downloads/HelperAppDlg.jsm b/toolkit/mozapps/downloads/HelperAppDlg.jsm
index 9042007f3d57..df3f7d66dbaf 100644
--- a/toolkit/mozapps/downloads/HelperAppDlg.jsm
+++ b/toolkit/mozapps/downloads/HelperAppDlg.jsm
@@ -461,29 +461,6 @@ nsUnknownContentTypeDialog.prototype = {
validatedFile = aLocalFolder;
}
- if (AppConstants.platform == "win") {
- let ext;
- try {
- // We can fail here if there's no primary extension set
- ext = "." + this.mLauncher.MIMEInfo.primaryExtension;
- } catch (e) {}
-
- // Append a file extension if it's an executable that doesn't have one
- // but make sure we actually have an extension to add
- let leaf = validatedFile.leafName;
- if (
- ext &&
- !leaf.toLowerCase().endsWith(ext.toLowerCase()) &&
- validatedFile.isExecutable()
- ) {
- validatedFile.remove(false);
- aLocalFolder.leafName = leaf + ext;
- if (!aAllowExisting) {
- validatedFile = DownloadPaths.createNiceUniqueFile(aLocalFolder);
- }
- }
- }
-
return validatedFile;
},
diff --git a/toolkit/mozapps/downloads/tests/browser/browser.ini b/toolkit/mozapps/downloads/tests/browser/browser.ini
index be4b5b33ce5c..da1cf956e027 100644
--- a/toolkit/mozapps/downloads/tests/browser/browser.ini
+++ b/toolkit/mozapps/downloads/tests/browser/browser.ini
@@ -6,6 +6,7 @@ support-files =
unknownContentType_dialog_layout_data.txt^headers^
head.js
+[browser_save_wrongextension.js]
[browser_unknownContentType_blob.js]
[browser_unknownContentType_delayedbutton.js]
skip-if =
diff --git a/toolkit/mozapps/downloads/tests/browser/browser_save_wrongextension.js b/toolkit/mozapps/downloads/tests/browser/browser_save_wrongextension.js
new file mode 100644
index 000000000000..00099a0078da
--- /dev/null
+++ b/toolkit/mozapps/downloads/tests/browser/browser_save_wrongextension.js
@@ -0,0 +1,99 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+let url =
+ "data:text/html,Link";
+
+let MockFilePicker = SpecialPowers.MockFilePicker;
+MockFilePicker.init(window);
+
+let httpServer = null;
+
+add_task(async function test() {
+ const { HttpServer } = ChromeUtils.import(
+ "resource://testing-common/httpd.js"
+ );
+
+ httpServer = new HttpServer();
+ httpServer.start(8000);
+
+ function handleRequest(aRequest, aResponse) {
+ aResponse.setStatusLine(aRequest.httpVersion, 200);
+ aResponse.setHeader("Content-Type", "text/plain");
+ aResponse.write("Some Text");
+ }
+ httpServer.registerPathHandler("/thefile.js", handleRequest);
+
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
+
+ let popupShownPromise = BrowserTestUtils.waitForEvent(document, "popupshown");
+
+ await BrowserTestUtils.synthesizeMouseAtCenter(
+ "#link",
+ { type: "contextmenu", button: 2 },
+ gBrowser.selectedBrowser
+ );
+ await popupShownPromise;
+
+ let tempDir = createTemporarySaveDirectory();
+ let destFile;
+
+ MockFilePicker.displayDirectory = tempDir;
+ MockFilePicker.showCallback = fp => {
+ let fileName = fp.defaultString;
+ destFile = tempDir.clone();
+ destFile.append(fileName);
+
+ MockFilePicker.setFiles([destFile]);
+ MockFilePicker.filterIndex = 1; // kSaveAsType_URL
+ };
+
+ let transferCompletePromise = new Promise(resolve => {
+ mockTransferCallback = resolve;
+ mockTransferRegisterer.register();
+ });
+
+ registerCleanupFunction(function() {
+ mockTransferRegisterer.unregister();
+ tempDir.remove(true);
+ });
+
+ document.getElementById("context-savelink").doCommand();
+
+ let contextMenu = document.getElementById("contentAreaContextMenu");
+ let popupHiddenPromise = BrowserTestUtils.waitForEvent(
+ document,
+ "popuphidden"
+ );
+ contextMenu.hidePopup();
+ await popupHiddenPromise;
+
+ await transferCompletePromise;
+
+ is(destFile.leafName, "thefile.js", "filename extension is not modified");
+
+ BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async () => {
+ MockFilePicker.cleanup();
+ await new Promise(resolve => httpServer.stop(resolve));
+});
+
+/* import-globals-from ../../../../../toolkit/content/tests/browser/common/mockTransfer.js */
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/toolkit/content/tests/browser/common/mockTransfer.js",
+ this
+);
+
+function createTemporarySaveDirectory() {
+ let saveDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
+ saveDir.append("testsavedir");
+ if (!saveDir.exists()) {
+ saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
+ }
+ return saveDir;
+}
diff --git a/uriloader/exthandler/tests/mochitest/browser_save_filenames.js b/uriloader/exthandler/tests/mochitest/browser_save_filenames.js
index 679e1c1efca9..ea46fa5a5777 100644
--- a/uriloader/exthandler/tests/mochitest/browser_save_filenames.js
+++ b/uriloader/exthandler/tests/mochitest/browser_save_filenames.js
@@ -202,14 +202,12 @@ function getItems(parentid) {
elem.localName == "img" && elem.dataset.nodrag != "true";
let unknown = elem.dataset.unknown;
let noattach = elem.dataset.noattach;
- let winexeext = elem.dataset.winexeext;
elements.push({
draggable,
unknown,
filename,
url,
noattach,
- winexeext,
});
elem = elem.nextElementSibling;
}
@@ -588,16 +586,6 @@ add_task(async function save_links() {
let filename = PathUtils.filename(download.target.path);
let expectedFilename = expectedItems[idx].filename;
- if (AppConstants.platform == "win") {
- // On Windows, an extension is added to executable files when saving as
- // an attachment to avoid the file looking like an executable. This is
- // done in validateLeafName in HelperAppDlg.jsm.
- // XXXndeakin should we do this for all save mechanisms?
- if (expectedItems[idx].winexeext) {
- expectedFilename += "." + expectedItems[idx].winexeext;
- }
- }
-
// Use checkShortenedFilename to check long filenames.
if (expectedItems[idx].filename.length > 240) {
ok(
diff --git a/uriloader/exthandler/tests/mochitest/save_filenames.html b/uriloader/exthandler/tests/mochitest/save_filenames.html
index 583ba55ba072..0d7004515a9b 100644
--- a/uriloader/exthandler/tests/mochitest/save_filenames.html
+++ b/uriloader/exthandler/tests/mochitest/save_filenames.html
@@ -86,14 +86,13 @@
-
+
+ data-filename="script2.exe">
+ data-filename="script 3.exe">
+ data-filename="script5.exe">
+ data-filename="script 6.exe">
-
+
+ data-nodrag="true" data-filename="notypebin.exe">
+ data-unknown="true">