Backed out changeset a713faa51ebb (bug 1706871) for causing bc failures on browser_test_mixed_content_download.js. CLOSED TREE

This commit is contained in:
Iulian Moraru 2021-06-16 16:25:09 +03:00
Родитель 5982f7b637
Коммит 27bb808f36
5 изменённых файлов: 15 добавлений и 97 удалений

Просмотреть файл

@ -41,15 +41,8 @@ async function task_openPanel() {
await promise; await promise;
} }
/** function shouldPromptDownload() {
* Waits until the download Prompt is shown, selects // Waits until the download Prompt is shown
* the choosen <action>, then accepts the dialog
* @param [action] Which action to select, either:
* "handleInternally", "save" or "open".
* @returns {Promise} Resolved once done.
*/
function shouldPromptDownload(action = "save") {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
Services.wm.addListener({ Services.wm.addListener({
onOpenWindow(xulWin) { onOpenWindow(xulWin) {
@ -62,8 +55,8 @@ function shouldPromptDownload(action = "save") {
) { ) {
let dialog = win.document.getElementById("unknownContentType"); let dialog = win.document.getElementById("unknownContentType");
let button = dialog.getButton("accept"); let button = dialog.getButton("accept");
let actionRadio = win.document.getElementById(action); let saveRadio = win.document.getElementById("save");
actionRadio.click(); saveRadio.click();
button.disabled = false; button.disabled = false;
dialog.acceptDialog(); dialog.acceptDialog();
resolve(); resolve();
@ -106,22 +99,14 @@ async function shouldNotifyDownloadUI() {
// Waits until a Blocked download was added to the Download List // Waits until a Blocked download was added to the Download List
// -> returns the blocked Download // -> returns the blocked Download
let list = await Downloads.getList(Downloads.ALL); let list = await Downloads.getList(Downloads.ALL);
return new Promise((res, err) => { return new Promise(res => {
const view = { const view = {
onDownloadAdded: async aDownload => { onDownloadAdded: aDownload => {
let { error } = aDownload; let { error } = aDownload;
if ( if (
error.becauseBlockedByReputationCheck && error.becauseBlockedByReputationCheck &&
error.reputationCheckVerdict == Downloads.Error.BLOCK_VERDICT_INSECURE error.reputationCheckVerdict == Downloads.Error.BLOCK_VERDICT_INSECURE
) { ) {
// It's an insecure Download, now Check that it has been cleaned up properly
if ((await IOUtils.stat(aDownload.target.path)).size != 0) {
throw new Error(`Download target is not empty!`);
}
if ((await IOUtils.stat(aDownload.target.path)).size != 0) {
throw new Error(`Download partFile was not cleaned up properly`);
}
res(aDownload); res(aDownload);
list.removeView(view); list.removeView(view);
} }
@ -131,7 +116,7 @@ async function shouldNotifyDownloadUI() {
}); });
} }
async function runTest(url, link, checkFunction, description) { async function runTest(url, link, checkFunction, decscription) {
await SpecialPowers.pushPrefEnv({ await SpecialPowers.pushPrefEnv({
set: [["dom.block_download_insecure", true]], set: [["dom.block_download_insecure", true]],
}); });
@ -143,7 +128,7 @@ async function runTest(url, link, checkFunction, description) {
let browser = gBrowser.getBrowserForTab(tab); let browser = gBrowser.getBrowserForTab(tab);
await BrowserTestUtils.browserLoaded(browser); await BrowserTestUtils.browserLoaded(browser);
info("Checking: " + description); info("Checking: " + decscription);
let checkPromise = checkFunction(); let checkPromise = checkFunction();
// Click the Link to trigger the download // Click the Link to trigger the download
@ -153,7 +138,7 @@ async function runTest(url, link, checkFunction, description) {
await checkPromise; await checkPromise;
ok(true, description); ok(true, decscription);
BrowserTestUtils.removeTab(tab); BrowserTestUtils.removeTab(tab);
await SpecialPowers.popPrefEnv(); await SpecialPowers.popPrefEnv();
@ -228,28 +213,3 @@ add_task(async function() {
"A Blocked Download Should open the Download Panel" "A Blocked Download Should open the Download Panel"
); );
}); });
// Test Download an insecure pdf and choose "Open with Firefox"
add_task(async function download_open_insecure_pdf() {
await promiseFocus();
await runTest(
SECURE_BASE_URL,
"insecurePDF",
async () => {
info("awaiting that the Download Prompt is shown");
await shouldPromptDownload("handleInternally");
let download = await shouldNotifyDownloadUI();
let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
await download.unblock();
ok(download.error == null, "There should be no error after unblocking");
let tab = await newTabPromise;
ok(
tab.linkedBrowser._documentURI.filePath == download.target.path,
"The download target was opened"
);
BrowserTestUtils.removeTab(tab);
ok(true, "The Content was opened in a new tab");
},
"A Blocked PDF can be opened internally"
);
});

Просмотреть файл

@ -19,6 +19,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=676619
secureLink.href=`https://${host}/${path}`; secureLink.href=`https://${host}/${path}`;
secureLink.download="true"; secureLink.download="true";
secureLink.textContent="Secure Link"; secureLink.textContent="Secure Link";
secureLink.id="secure"; secureLink.id="secure";
const insecureLink = document.createElement("a"); const insecureLink = document.createElement("a");
@ -27,13 +28,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=676619
insecureLink.id="insecure"; insecureLink.id="insecure";
insecureLink.textContent="Not secure Link"; insecureLink.textContent="Not secure Link";
const insecurePDF = document.createElement("a");
insecurePDF.href=`http://${host}/${path}?type=application/pdf&name=example.pdf`;
insecurePDF.download="true";
insecurePDF.id="insecurePDF";
insecurePDF.textContent="Not secure Link to PDF";
document.body.append(insecurePDF);
document.body.append(secureLink); document.body.append(secureLink);
document.body.append(insecureLink); document.body.append(insecureLink);
</script> </script>

Просмотреть файл

@ -2,20 +2,8 @@
function handleRequest(request, response) function handleRequest(request, response)
{ {
let type = "image/png";
let filename = "hello.png";
request.queryString.split('&').forEach((val) => {
var [key, value] = val.split('=');
if (key == "type"){
type= value;
}
if (key == "name"){
filename = value;
}
});
response.setHeader("Cache-Control", "no-cache", false); response.setHeader("Cache-Control", "no-cache", false);
response.setHeader("Content-Disposition", `attachment; filename=${filename}`); response.setHeader("Content-Disposition", "attachment");
response.setHeader("Content-Type", type); response.setHeader("Content-Type", "image/png");
response.write('🙈🙊🐵🙊'); response.write('🙈🙊🐵🙊');
} }

Просмотреть файл

@ -29,7 +29,6 @@ const { XPCOMUtils } = ChromeUtils.import(
XPCOMUtils.defineLazyModuleGetters(this, { XPCOMUtils.defineLazyModuleGetters(this, {
AppConstants: "resource://gre/modules/AppConstants.jsm", AppConstants: "resource://gre/modules/AppConstants.jsm",
DownloadHistory: "resource://gre/modules/DownloadHistory.jsm", DownloadHistory: "resource://gre/modules/DownloadHistory.jsm",
DownloadPaths: "resource://gre/modules/DownloadPaths.jsm",
E10SUtils: "resource://gre/modules/E10SUtils.jsm", E10SUtils: "resource://gre/modules/E10SUtils.jsm",
FileUtils: "resource://gre/modules/FileUtils.jsm", FileUtils: "resource://gre/modules/FileUtils.jsm",
NetUtil: "resource://gre/modules/NetUtil.jsm", NetUtil: "resource://gre/modules/NetUtil.jsm",
@ -2471,21 +2470,7 @@ DownloadCopySaver.prototype = {
} }
if (partFilePath) { if (partFilePath) {
try { await IOUtils.move(partFilePath, targetPath);
await IOUtils.move(partFilePath, targetPath);
} catch (e) {
if (e.name === "NotAllowedError") {
// In case we cannot write to the target file
// retry with a new unique name
let uniquePath = DownloadPaths.createNiceUniqueFile(
new FileUtils.File(targetPath)
).path;
await IOUtils.move(partFilePath, uniquePath);
this.download.target.path = uniquePath;
} else {
throw e;
}
}
} }
}, },

Просмотреть файл

@ -1704,11 +1704,6 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest* request) {
request->Cancel(NS_ERROR_ABORT); request->Cancel(NS_ERROR_ABORT);
return NS_OK; return NS_OK;
} }
if (mDownloadClassification != nsITransfer::DOWNLOAD_ACCEPTABLE) {
// in any other case, we need to suspend the request so
// no bytes are transferred into the tempFile
request->Suspend();
}
nsCOMPtr<nsIFileChannel> fileChan(do_QueryInterface(request)); nsCOMPtr<nsIFileChannel> fileChan(do_QueryInterface(request));
mIsFileChannel = fileChan != nullptr; mIsFileChannel = fileChan != nullptr;
@ -2296,10 +2291,6 @@ nsresult nsExternalAppHandler::CreateTransfer() {
if (mDownloadClassification != nsITransfer::DOWNLOAD_ACCEPTABLE) { if (mDownloadClassification != nsITransfer::DOWNLOAD_ACCEPTABLE) {
mCanceled = true; mCanceled = true;
mRequest->Cancel(NS_ERROR_ABORT); mRequest->Cancel(NS_ERROR_ABORT);
if (mSaver) {
mSaver->Finish(NS_ERROR_ABORT);
mSaver = nullptr;
}
return CreateFailedTransfer(); return CreateFailedTransfer();
} }
nsresult rv; nsresult rv;
@ -2402,11 +2393,11 @@ nsresult nsExternalAppHandler::CreateFailedTransfer() {
if (mBrowsingContext) { if (mBrowsingContext) {
rv = transfer->InitWithBrowsingContext( rv = transfer->InitWithBrowsingContext(
mSourceUrl, pseudoTarget, u""_ns, mMimeInfo, mTimeDownloadStarted, mSourceUrl, pseudoTarget, u""_ns, mMimeInfo, mTimeDownloadStarted,
mTempFile, this, channel && NS_UsePrivateBrowsing(channel), nullptr, this, channel && NS_UsePrivateBrowsing(channel),
mDownloadClassification, mBrowsingContext, mHandleInternally); mDownloadClassification, mBrowsingContext, mHandleInternally);
} else { } else {
rv = transfer->Init(mSourceUrl, pseudoTarget, u""_ns, mMimeInfo, rv = transfer->Init(mSourceUrl, pseudoTarget, u""_ns, mMimeInfo,
mTimeDownloadStarted, mTempFile, this, mTimeDownloadStarted, nullptr, this,
channel && NS_UsePrivateBrowsing(channel), channel && NS_UsePrivateBrowsing(channel),
mDownloadClassification); mDownloadClassification);
} }