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.
userContextId: aDownload.source.userContextId, win.openTrustedLinkIn(fileURI.spec, "tab", {
}); triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
userContextId: aDownload.source.userContextId,
openerBrowser: browsingContext?.top?.embedderElement,
});
return;
}
let features = "chrome,dialog=no,all";
if (aDownload.source.isPrivate) {
features += ",private";
}
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; return;
} }
// An attempt will now be 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;
// 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,191 +44,91 @@ 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( await SpecialPowers.pushPrefEnv({
"resource://gre/modules/DownloadIntegration.jsm" set: [["browser.helperApps.showOpenOptionForPdfJS", true]],
); });
for (let file of [ let publicList = await Downloads.getList(Downloads.PUBLIC);
"file_pdf_application_pdf.pdf", registerCleanupFunction(async () => {
"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
);
// 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
// the tab strip.
let extraTab = await BrowserTestUtils.addTab(gBrowser, "about:blank");
let dialogWindow = await dialogWindowPromise;
is(
dialogWindow.location,
"chrome://mozapps/content/downloads/unknownContentType.xhtml",
"Should have seen the unknown content dialogWindow."
);
let doc = dialogWindow.document;
let internalHandlerRadio = doc.querySelector("#handleInternally");
await waitForAcceptButtonToGetEnabled(doc);
ok(!internalHandlerRadio.hidden, "The option should be visible for PDF");
ok(internalHandlerRadio.selected, "The option should be selected");
let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
let dialog = doc.querySelector("#unknownContentType");
let button = dialog.getButton("accept");
button.disabled = false;
dialog.acceptDialog();
info("waiting for new tab to open");
let newTab = await newTabPromise;
is(
newTab._tPos - 1,
loadingTab._tPos,
"pdf.js should be opened in an adjacent tab"
);
await ContentTask.spawn(newTab.linkedBrowser, null, async () => {
await ContentTaskUtils.waitForCondition(
() => content.document.readyState == "complete"
);
});
let publicDownloads = await publicList.getAll();
is(
publicDownloads.length,
1,
"download should appear in publicDownloads list"
);
let subdialogPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
await SpecialPowers.spawn(newTab.linkedBrowser, [], async () => {
let downloadButton;
await ContentTaskUtils.waitForCondition(() => {
downloadButton = content.document.querySelector("#download");
return !!downloadButton;
});
ok(downloadButton, "Download button should be present in pdf.js");
downloadButton.click();
});
info(
"Waiting for unknown content type dialog to appear from pdf.js download button click"
);
let subDialogWindow = await subdialogPromise;
let subDoc = subDialogWindow.document;
// Prevent racing with initialization of the dialog and make sure that
// the final state of the dialog has the correct visibility of the internal-handler option.
await waitForAcceptButtonToGetEnabled(subDoc);
let subInternalHandlerRadio = subDoc.querySelector("#handleInternally");
ok(
subInternalHandlerRadio.hidden,
"The option should be hidden when the dialog is opened from pdf.js"
);
subDoc.querySelector("#open").click();
let tabOpenListener = () => {
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(newTab);
BrowserTestUtils.removeTab(extraTab);
await publicList.removeFinished(); await publicList.removeFinished();
} });
}); let dialogWindowPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
let loadingTab = await BrowserTestUtils.openNewForegroundTab(
/** gBrowser,
* Test that choosing to open in an external application doesn't TEST_PATH + "file_pdfjs_test.pdf"
* 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 [ // Add an extra tab after the loading tab so we can test that
"file_pdf_application_pdf.pdf", // pdf.js is opened in the adjacent tab and not at the end of
"file_pdf_binary_octet_stream.pdf", // the tab strip.
]) { let extraTab = await BrowserTestUtils.addTab(gBrowser, "about:blank");
info("Testing with " + file); let dialogWindow = await dialogWindowPromise;
await SpecialPowers.pushPrefEnv({ is(
set: [["browser.helperApps.showOpenOptionForPdfJS", true]], dialogWindow.location,
"chrome://mozapps/content/downloads/unknownContentType.xhtml",
"Should have seen the unknown content dialogWindow."
);
let doc = dialogWindow.document;
let internalHandlerRadio = doc.querySelector("#handleInternally");
await waitForAcceptButtonToGetEnabled(doc);
ok(!internalHandlerRadio.hidden, "The option should be visible for PDF");
ok(internalHandlerRadio.selected, "The option should be selected");
let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
let dialog = doc.querySelector("#unknownContentType");
let button = dialog.getButton("accept");
button.disabled = false;
dialog.acceptDialog();
info("waiting for new tab to open");
let newTab = await newTabPromise;
is(
newTab._tPos - 1,
loadingTab._tPos,
"pdf.js should be opened in an adjacent tab"
);
await ContentTask.spawn(newTab.linkedBrowser, null, async () => {
await ContentTaskUtils.waitForCondition(
() => content.document.readyState == "complete"
);
});
let publicDownloads = await publicList.getAll();
Assert.equal(
publicDownloads.length,
1,
"download should appear in publicDownloads list"
);
let subdialogPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
await SpecialPowers.spawn(newTab.linkedBrowser, [], async () => {
let downloadButton;
await ContentTaskUtils.waitForCondition(() => {
downloadButton = content.document.querySelector("#download");
return !!downloadButton;
}); });
let publicList = await Downloads.getList(Downloads.PUBLIC); ok(downloadButton, "Download button should be present in pdf.js");
registerCleanupFunction(async () => { downloadButton.click();
await publicList.removeFinished(); });
}); info(
let dialogWindowPromise = BrowserTestUtils.domWindowOpenedAndLoaded(); "Waiting for unknown content type dialog to appear from pdf.js download button click"
let loadingTab = await BrowserTestUtils.openNewForegroundTab( );
gBrowser, let subDialogWindow = await subdialogPromise;
TEST_PATH + file let subDoc = subDialogWindow.document;
); // Prevent racing with initialization of the dialog and make sure that
let dialogWindow = await dialogWindowPromise; // the final state of the dialog has the correct visibility of the internal-handler option.
is( await waitForAcceptButtonToGetEnabled(subDoc);
dialogWindow.location, let subInternalHandlerRadio = subDoc.querySelector("#handleInternally");
"chrome://mozapps/content/downloads/unknownContentType.xhtml", ok(
"Should have seen the unknown content dialogWindow." subInternalHandlerRadio.hidden,
); "The option should be hidden when the dialog is opened from pdf.js"
);
let oldLaunchFile = DownloadIntegration.launchFile; subDoc.querySelector("#unknownContentType").cancelDialog();
let waitForLaunchFileCalled = new Promise(resolve => {
DownloadIntegration.launchFile = () => {
ok(true, "The file should be launched with an external application");
resolve();
};
});
let doc = dialogWindow.document; BrowserTestUtils.removeTab(loadingTab);
await waitForAcceptButtonToGetEnabled(doc); BrowserTestUtils.removeTab(newTab);
let dialog = doc.querySelector("#unknownContentType"); BrowserTestUtils.removeTab(extraTab);
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,37 +169,32 @@ 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 [ await SpecialPowers.pushPrefEnv({
"file_pdf_application_pdf.pdf", set: [["browser.helperApps.showOpenOptionForPdfJS", false]],
"file_pdf_binary_octet_stream.pdf", });
]) {
await SpecialPowers.pushPrefEnv({
set: [["browser.helperApps.showOpenOptionForPdfJS", false]],
});
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(
dialogWindow.location, dialogWindow.location,
"chrome://mozapps/content/downloads/unknownContentType.xhtml", "chrome://mozapps/content/downloads/unknownContentType.xhtml",
"Should have seen the unknown content dialogWindow." "Should have seen the unknown content dialogWindow."
); );
let doc = dialogWindow.document; let doc = dialogWindow.document;
await waitForAcceptButtonToGetEnabled(doc); await waitForAcceptButtonToGetEnabled(doc);
let internalHandlerRadio = doc.querySelector("#handleInternally"); let internalHandlerRadio = doc.querySelector("#handleInternally");
ok( ok(
internalHandlerRadio.hidden, internalHandlerRadio.hidden,
"The option should be hidden for PDF when the pref is false" "The option should be hidden for PDF when the pref is false"
); );
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