Backed out changeset 2708f3e553cb (bug 1639606) for causing xpcshell failures in toolkit/components/downloads

CLOSED TREE
This commit is contained in:
Mihai Alexandru Michis 2020-05-23 00:26:32 +03:00
Родитель 5edeaf80d3
Коммит 9afe3180db
11 изменённых файлов: 160 добавлений и 261 удалений

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

@ -212,7 +212,7 @@ async function testOpenPDFPreview({
info("Got download pathname:" + download.target.path); info("Got download pathname:" + download.target.path);
let pdfFileURI = NetUtil.newURI(new FileUtils.File(download.target.path)); let pdfFileURI = NetUtil.newURI(new FileUtils.File(download.target.path));
info("pdfFileURI:" + pdfFileURI.spec); info("pdfFileURI:" + pdfFileURI);
let uiWindow = window; let uiWindow = window;
let initialTab = gBrowser.selectedTab; let initialTab = gBrowser.selectedTab;

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

@ -784,39 +784,65 @@ var DownloadIntegration = {
mimeInfo.preferredAction = Ci.nsIMIMEInfo.useHelperApp; mimeInfo.preferredAction = Ci.nsIMIMEInfo.useHelperApp;
this.launchFile(file, mimeInfo); this.launchFile(file, mimeInfo);
// After an attempt has been made to launch the download, clear the
// launchWhenSucceeded bit so future attempts to open the download can go
// through Firefox when possible.
aDownload.launchWhenSucceeded = false;
return; return;
} }
const PDF_CONTENT_TYPE = "application/pdf"; if (aDownload.handleInternally) {
if ( let win = Services.wm.getMostRecentBrowserWindow();
aDownload.handleInternally || let browsingContext =
(mimeInfo && win && win.BrowsingContext.get(aDownload.source.browsingContextId);
mimeInfo.type == PDF_CONTENT_TYPE && win = Services.wm.getOuterWindowWithId(
!mimeInfo.alwaysAskBeforeHandling && browsingContext &&
mimeInfo.preferredAction === Ci.nsIHandlerInfo.handleInternally && browsingContext.embedderWindowGlobal &&
!aDownload.launchWhenSucceeded) browsingContext.embedderWindowGlobal.outerWindowId
) { );
DownloadUIHelper.loadFileIn(file, { let fileURI = Services.io.newFileURI(file);
browsingContextId: aDownload.source.browsingContextId, if (win) {
isPrivate: aDownload.source.isPrivate, // TODO: Replace openTrustedLinkIn with openUILink once
openWhere, // we have access to the event.
win.openTrustedLinkIn(fileURI.spec, "tab", {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
userContextId: aDownload.source.userContextId, userContextId: aDownload.source.userContextId,
openerBrowser: browsingContext?.top?.embedderElement,
}); });
return; return;
} }
let features = "chrome,dialog=no,all";
// An attempt will now be made to launch the download, clear the if (aDownload.source.isPrivate) {
// launchWhenSucceeded bit so future attempts to open the download can go features += ",private";
// through Firefox when possible. }
aDownload.launchWhenSucceeded = false; let args = Cc["@mozilla.org/supports-string;1"].createInstance(
Ci.nsISupportsString
);
args.data = fileURI.spec;
win = Services.ww.openWindow(
null,
AppConstants.BROWSER_CHROME_URL,
"_blank",
features,
args
);
return;
}
// No custom application chosen, let's launch the file with the default // No custom application chosen, let's launch the file with the default
// handler. First, let's try to launch it through the MIME service. // handler. First, let's try to launch it through the MIME service.
if (mimeInfo) { if (mimeInfo) {
const PDF_CONTENT_TYPE = "application/pdf";
// Open PDFs internally unless explicitly configured to do otherwise
if (
mimeInfo.type == PDF_CONTENT_TYPE &&
!mimeInfo.alwaysAskBeforeHandling &&
mimeInfo.preferredAction === Ci.nsIHandlerInfo.handleInternally
// TODO: also preview for save to disk and always ask file actions?
) {
DownloadUIHelper.loadFileIn(file, {
isPrivate: aDownload.source.isPrivate,
openWhere,
});
return;
}
mimeInfo.preferredAction = Ci.nsIMIMEInfo.useSystemDefault; mimeInfo.preferredAction = Ci.nsIMIMEInfo.useSystemDefault;
try { try {
this.launchFile(file, mimeInfo); this.launchFile(file, mimeInfo);

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

@ -72,18 +72,10 @@ var DownloadUIHelper = {
* @param options.openWhere String indicating how to open the URI. * @param options.openWhere String indicating how to open the URI.
* One of "window", "tab", "tabshifted" * One of "window", "tab", "tabshifted"
* @param options.isPrivate Open in private window or not * @param options.isPrivate Open in private window or not
* @param options.browsingContextId BrowsingContext ID of the initiating document
* @param options.userContextId UserContextID of the initiating document
*/ */
loadFileIn( loadFileIn(
file, file,
{ { chromeWindow: browserWin, openWhere = "tab", isPrivate } = {}
chromeWindow: browserWin,
openWhere = "tab",
isPrivate,
userContextId = 0,
browsingContextId = 0,
} = {}
) { ) {
let fileURI = Services.io.newFileURI(file); let fileURI = Services.io.newFileURI(file);
let allowPrivate = let allowPrivate =
@ -125,12 +117,9 @@ var DownloadUIHelper = {
} }
// a browser window will have the helpers from utilityOverlay.js // a browser window will have the helpers from utilityOverlay.js
let browsingContext = browserWin?.BrowsingContext.get(browsingContextId);
browserWin.openTrustedLinkIn(fileURI.spec, openWhere, { browserWin.openTrustedLinkIn(fileURI.spec, openWhere, {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
private: isPrivate, private: isPrivate,
userContextId,
openerBrowser: browsingContext?.top?.embedderElement,
}); });
}, },
}; };

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

@ -13,10 +13,8 @@ support-files =
[browser_download_privatebrowsing.js] [browser_download_privatebrowsing.js]
[browser_download_open_with_internal_handler.js] [browser_download_open_with_internal_handler.js]
support-files = support-files =
file_pdf_binary_octet_stream.pdf file_pdfjs_test.pdf
file_pdf_binary_octet_stream.pdf^headers^ file_pdfjs_test.pdf^headers^
file_pdf_application_pdf.pdf
file_pdf_application_pdf.pdf^headers^
file_txt_attachment_test.txt file_txt_attachment_test.txt
file_txt_attachment_test.txt^headers^ file_txt_attachment_test.txt^headers^
[browser_download_urlescape.js] [browser_download_urlescape.js]

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

@ -37,13 +37,6 @@ async function waitForPdfJS(browser, url) {
return loadPromise; return loadPromise;
} }
add_task(async function setup() {
// Remove the security delay for the dialog during the test.
await SpecialPowers.pushPrefEnv({
set: [["security.dialog_enable_delay", 0]],
});
});
/** /**
* Check that loading a PDF file with content-disposition: attachment * Check that loading a PDF file with content-disposition: attachment
* shows an option to open with the internal handler, and that the * shows an option to open with the internal handler, and that the
@ -51,14 +44,6 @@ add_task(async function setup() {
* is clicked from pdf.js. * is clicked from pdf.js.
*/ */
add_task(async function test_check_open_with_internal_handler() { add_task(async function test_check_open_with_internal_handler() {
const { DownloadIntegration } = ChromeUtils.import(
"resource://gre/modules/DownloadIntegration.jsm"
);
for (let file of [
"file_pdf_application_pdf.pdf",
"file_pdf_binary_octet_stream.pdf",
]) {
info("Testing with " + file);
await SpecialPowers.pushPrefEnv({ await SpecialPowers.pushPrefEnv({
set: [["browser.helperApps.showOpenOptionForPdfJS", true]], set: [["browser.helperApps.showOpenOptionForPdfJS", true]],
}); });
@ -69,7 +54,7 @@ add_task(async function test_check_open_with_internal_handler() {
let dialogWindowPromise = BrowserTestUtils.domWindowOpenedAndLoaded(); let dialogWindowPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
let loadingTab = await BrowserTestUtils.openNewForegroundTab( let loadingTab = await BrowserTestUtils.openNewForegroundTab(
gBrowser, gBrowser,
TEST_PATH + file TEST_PATH + "file_pdfjs_test.pdf"
); );
// Add an extra tab after the loading tab so we can test that // Add an extra tab after the loading tab so we can test that
// pdf.js is opened in the adjacent tab and not at the end of // pdf.js is opened in the adjacent tab and not at the end of
@ -110,7 +95,7 @@ add_task(async function test_check_open_with_internal_handler() {
}); });
let publicDownloads = await publicList.getAll(); let publicDownloads = await publicList.getAll();
is( Assert.equal(
publicDownloads.length, publicDownloads.length,
1, 1,
"download should appear in publicDownloads list" "download should appear in publicDownloads list"
@ -138,104 +123,12 @@ add_task(async function test_check_open_with_internal_handler() {
subInternalHandlerRadio.hidden, subInternalHandlerRadio.hidden,
"The option should be hidden when the dialog is opened from pdf.js" "The option should be hidden when the dialog is opened from pdf.js"
); );
subDoc.querySelector("#open").click();
let tabOpenListener = () => { subDoc.querySelector("#unknownContentType").cancelDialog();
ok(
false,
"A new tab should not be opened when accepting the dialog with 'Save' chosen"
);
};
gBrowser.tabContainer.addEventListener("TabOpen", tabOpenListener);
let oldLaunchFile = DownloadIntegration.launchFile;
let waitForLaunchFileCalled = new Promise(resolve => {
DownloadIntegration.launchFile = async () => {
ok(true, "The file should be launched with an external application");
resolve();
};
});
info("Accepting the dialog");
subDoc.querySelector("#unknownContentType").acceptDialog();
info("Waiting until DownloadIntegration.launchFile is called");
await waitForLaunchFileCalled;
DownloadIntegration.launchFile = oldLaunchFile;
gBrowser.tabContainer.removeEventListener("TabOpen", tabOpenListener);
BrowserTestUtils.removeTab(loadingTab); BrowserTestUtils.removeTab(loadingTab);
BrowserTestUtils.removeTab(newTab); BrowserTestUtils.removeTab(newTab);
BrowserTestUtils.removeTab(extraTab); BrowserTestUtils.removeTab(extraTab);
await publicList.removeFinished();
}
});
/**
* Test that choosing to open in an external application doesn't
* open the PDF into pdf.js
*/
add_task(async function test_check_open_with_external_application() {
const { DownloadIntegration } = ChromeUtils.import(
"resource://gre/modules/DownloadIntegration.jsm"
);
for (let file of [
"file_pdf_application_pdf.pdf",
"file_pdf_binary_octet_stream.pdf",
]) {
info("Testing with " + file);
await SpecialPowers.pushPrefEnv({
set: [["browser.helperApps.showOpenOptionForPdfJS", true]],
});
let publicList = await Downloads.getList(Downloads.PUBLIC);
registerCleanupFunction(async () => {
await publicList.removeFinished();
});
let dialogWindowPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
let loadingTab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
TEST_PATH + file
);
let dialogWindow = await dialogWindowPromise;
is(
dialogWindow.location,
"chrome://mozapps/content/downloads/unknownContentType.xhtml",
"Should have seen the unknown content dialogWindow."
);
let oldLaunchFile = DownloadIntegration.launchFile;
let waitForLaunchFileCalled = new Promise(resolve => {
DownloadIntegration.launchFile = () => {
ok(true, "The file should be launched with an external application");
resolve();
};
});
let doc = dialogWindow.document;
await waitForAcceptButtonToGetEnabled(doc);
let dialog = doc.querySelector("#unknownContentType");
doc.querySelector("#open").click();
let button = dialog.getButton("accept");
button.disabled = false;
info("Accepting the dialog");
dialog.acceptDialog();
info("Waiting until DownloadIntegration.launchFile is called");
await waitForLaunchFileCalled;
DownloadIntegration.launchFile = oldLaunchFile;
let publicDownloads = await publicList.getAll();
is(
publicDownloads.length,
1,
"download should appear in publicDownloads list"
);
ok(
!publicDownloads[0].launchWhenSucceeded,
"launchWhenSucceeded should be false after launchFile is called"
);
BrowserTestUtils.removeTab(loadingTab);
await publicList.removeFinished();
}
}); });
/** /**
@ -276,10 +169,6 @@ add_task(async function test_internal_handler_hidden_with_nonpdf_type() {
* when the feature is disabled. * when the feature is disabled.
*/ */
add_task(async function test_internal_handler_hidden_with_pref_disabled() { add_task(async function test_internal_handler_hidden_with_pref_disabled() {
for (let file of [
"file_pdf_application_pdf.pdf",
"file_pdf_binary_octet_stream.pdf",
]) {
await SpecialPowers.pushPrefEnv({ await SpecialPowers.pushPrefEnv({
set: [["browser.helperApps.showOpenOptionForPdfJS", false]], set: [["browser.helperApps.showOpenOptionForPdfJS", false]],
}); });
@ -287,7 +176,7 @@ add_task(async function test_internal_handler_hidden_with_pref_disabled() {
let dialogWindowPromise = BrowserTestUtils.domWindowOpenedAndLoaded(); let dialogWindowPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
let loadingTab = await BrowserTestUtils.openNewForegroundTab( let loadingTab = await BrowserTestUtils.openNewForegroundTab(
gBrowser, gBrowser,
TEST_PATH + file TEST_PATH + "file_pdfjs_test.pdf"
); );
let dialogWindow = await dialogWindowPromise; let dialogWindow = await dialogWindowPromise;
is( is(
@ -308,5 +197,4 @@ add_task(async function test_internal_handler_hidden_with_pref_disabled() {
let dialog = doc.querySelector("#unknownContentType"); let dialog = doc.querySelector("#unknownContentType");
dialog.cancelDialog(); dialog.cancelDialog();
BrowserTestUtils.removeTab(loadingTab); BrowserTestUtils.removeTab(loadingTab);
}
}); });

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

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

@ -1,2 +0,0 @@
content-disposition: attachment; filename=file_pdf_application_pdf.pdf; filename*=UTF-8''file_pdf_application_pdf.pdf
content-type: application/pdf

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

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

@ -1,2 +0,0 @@
Content-Disposition: attachment; filename="file_pdf_binary_octet_stream.pdf"; filename*=UTF-8''file_pdf_binary_octet_stream.pdf
Content-Type: binary/octet-stream

Двоичные данные
uriloader/exthandler/tests/mochitest/file_pdfjs_test.pdf Normal file

Двоичный файл не отображается.

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

@ -0,0 +1,2 @@
Content-Disposition: attachment; filename=file_pdfjs_test.pdf
Content-Type: application/pdf