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_save_wrongextension.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_save_wrongextension.js | 98 |
1 files changed, 98 insertions, 0 deletions
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 0000000000..ba1b6cde5c --- /dev/null +++ b/toolkit/mozapps/downloads/tests/browser/browser_save_wrongextension.js @@ -0,0 +1,98 @@ +/* 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,<a id='link' href='http://localhost:8000/thefile.js'>Link</a>"; + +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)); +}); + +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; +} |