зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 2708f3e553cb (bug 1639606) for causing xpcshell failures in toolkit/components/downloads
CLOSED TREE
This commit is contained in:
Родитель
5edeaf80d3
Коммит
9afe3180db
|
@ -212,7 +212,7 @@ async function testOpenPDFPreview({
|
|||
info("Got download pathname:" + download.target.path);
|
||||
|
||||
let pdfFileURI = NetUtil.newURI(new FileUtils.File(download.target.path));
|
||||
info("pdfFileURI:" + pdfFileURI.spec);
|
||||
info("pdfFileURI:" + pdfFileURI);
|
||||
|
||||
let uiWindow = window;
|
||||
let initialTab = gBrowser.selectedTab;
|
||||
|
|
|
@ -784,39 +784,65 @@ var DownloadIntegration = {
|
|||
mimeInfo.preferredAction = Ci.nsIMIMEInfo.useHelperApp;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const PDF_CONTENT_TYPE = "application/pdf";
|
||||
if (
|
||||
aDownload.handleInternally ||
|
||||
(mimeInfo &&
|
||||
mimeInfo.type == PDF_CONTENT_TYPE &&
|
||||
!mimeInfo.alwaysAskBeforeHandling &&
|
||||
mimeInfo.preferredAction === Ci.nsIHandlerInfo.handleInternally &&
|
||||
!aDownload.launchWhenSucceeded)
|
||||
) {
|
||||
DownloadUIHelper.loadFileIn(file, {
|
||||
browsingContextId: aDownload.source.browsingContextId,
|
||||
isPrivate: aDownload.source.isPrivate,
|
||||
openWhere,
|
||||
userContextId: aDownload.source.userContextId,
|
||||
});
|
||||
if (aDownload.handleInternally) {
|
||||
let win = Services.wm.getMostRecentBrowserWindow();
|
||||
let browsingContext =
|
||||
win && win.BrowsingContext.get(aDownload.source.browsingContextId);
|
||||
win = Services.wm.getOuterWindowWithId(
|
||||
browsingContext &&
|
||||
browsingContext.embedderWindowGlobal &&
|
||||
browsingContext.embedderWindowGlobal.outerWindowId
|
||||
);
|
||||
let fileURI = Services.io.newFileURI(file);
|
||||
if (win) {
|
||||
// TODO: Replace openTrustedLinkIn with openUILink once
|
||||
// we have access to the event.
|
||||
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;
|
||||
}
|
||||
|
||||
// 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
|
||||
// handler. First, let's try to launch it through the MIME service.
|
||||
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;
|
||||
try {
|
||||
this.launchFile(file, mimeInfo);
|
||||
|
|
|
@ -72,18 +72,10 @@ var DownloadUIHelper = {
|
|||
* @param options.openWhere String indicating how to open the URI.
|
||||
* One of "window", "tab", "tabshifted"
|
||||
* @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(
|
||||
file,
|
||||
{
|
||||
chromeWindow: browserWin,
|
||||
openWhere = "tab",
|
||||
isPrivate,
|
||||
userContextId = 0,
|
||||
browsingContextId = 0,
|
||||
} = {}
|
||||
{ chromeWindow: browserWin, openWhere = "tab", isPrivate } = {}
|
||||
) {
|
||||
let fileURI = Services.io.newFileURI(file);
|
||||
let allowPrivate =
|
||||
|
@ -125,12 +117,9 @@ var DownloadUIHelper = {
|
|||
}
|
||||
|
||||
// a browser window will have the helpers from utilityOverlay.js
|
||||
let browsingContext = browserWin?.BrowsingContext.get(browsingContextId);
|
||||
browserWin.openTrustedLinkIn(fileURI.spec, openWhere, {
|
||||
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
private: isPrivate,
|
||||
userContextId,
|
||||
openerBrowser: browsingContext?.top?.embedderElement,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -13,10 +13,8 @@ support-files =
|
|||
[browser_download_privatebrowsing.js]
|
||||
[browser_download_open_with_internal_handler.js]
|
||||
support-files =
|
||||
file_pdf_binary_octet_stream.pdf
|
||||
file_pdf_binary_octet_stream.pdf^headers^
|
||||
file_pdf_application_pdf.pdf
|
||||
file_pdf_application_pdf.pdf^headers^
|
||||
file_pdfjs_test.pdf
|
||||
file_pdfjs_test.pdf^headers^
|
||||
file_txt_attachment_test.txt
|
||||
file_txt_attachment_test.txt^headers^
|
||||
[browser_download_urlescape.js]
|
||||
|
|
|
@ -37,13 +37,6 @@ async function waitForPdfJS(browser, url) {
|
|||
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
|
||||
* 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.
|
||||
*/
|
||||
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({
|
||||
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 SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.helperApps.showOpenOptionForPdfJS", true]],
|
||||
});
|
||||
let publicList = await Downloads.getList(Downloads.PUBLIC);
|
||||
registerCleanupFunction(async () => {
|
||||
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"
|
||||
});
|
||||
let dialogWindowPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
|
||||
let loadingTab = await BrowserTestUtils.openNewForegroundTab(
|
||||
gBrowser,
|
||||
TEST_PATH + "file_pdfjs_test.pdf"
|
||||
);
|
||||
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]],
|
||||
// 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();
|
||||
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);
|
||||
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."
|
||||
);
|
||||
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"
|
||||
);
|
||||
|
||||
let oldLaunchFile = DownloadIntegration.launchFile;
|
||||
let waitForLaunchFileCalled = new Promise(resolve => {
|
||||
DownloadIntegration.launchFile = () => {
|
||||
ok(true, "The file should be launched with an external application");
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
subDoc.querySelector("#unknownContentType").cancelDialog();
|
||||
|
||||
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();
|
||||
}
|
||||
BrowserTestUtils.removeTab(loadingTab);
|
||||
BrowserTestUtils.removeTab(newTab);
|
||||
BrowserTestUtils.removeTab(extraTab);
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -276,37 +169,32 @@ add_task(async function test_internal_handler_hidden_with_nonpdf_type() {
|
|||
* when the feature is 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({
|
||||
set: [["browser.helperApps.showOpenOptionForPdfJS", false]],
|
||||
});
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.helperApps.showOpenOptionForPdfJS", false]],
|
||||
});
|
||||
|
||||
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 doc = dialogWindow.document;
|
||||
let dialogWindowPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
|
||||
let loadingTab = await BrowserTestUtils.openNewForegroundTab(
|
||||
gBrowser,
|
||||
TEST_PATH + "file_pdfjs_test.pdf"
|
||||
);
|
||||
let dialogWindow = await dialogWindowPromise;
|
||||
is(
|
||||
dialogWindow.location,
|
||||
"chrome://mozapps/content/downloads/unknownContentType.xhtml",
|
||||
"Should have seen the unknown content dialogWindow."
|
||||
);
|
||||
let doc = dialogWindow.document;
|
||||
|
||||
await waitForAcceptButtonToGetEnabled(doc);
|
||||
await waitForAcceptButtonToGetEnabled(doc);
|
||||
|
||||
let internalHandlerRadio = doc.querySelector("#handleInternally");
|
||||
ok(
|
||||
internalHandlerRadio.hidden,
|
||||
"The option should be hidden for PDF when the pref is false"
|
||||
);
|
||||
let internalHandlerRadio = doc.querySelector("#handleInternally");
|
||||
ok(
|
||||
internalHandlerRadio.hidden,
|
||||
"The option should be hidden for PDF when the pref is false"
|
||||
);
|
||||
|
||||
let dialog = doc.querySelector("#unknownContentType");
|
||||
dialog.cancelDialog();
|
||||
BrowserTestUtils.removeTab(loadingTab);
|
||||
}
|
||||
let dialog = doc.querySelector("#unknownContentType");
|
||||
dialog.cancelDialog();
|
||||
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
|
Двоичный файл не отображается.
|
@ -0,0 +1,2 @@
|
|||
Content-Disposition: attachment; filename=file_pdfjs_test.pdf
|
||||
Content-Type: application/pdf
|
Загрузка…
Ссылка в новой задаче