gecko-dev/toolkit/components/pdfjs/test/browser_pdfjs_savedialog.js
Shane Hughes 7810a6da05 Bug 1747343 - Add pref to set default action for new mimetypes. r=Gijs,fluent-reviewers,preferences-reviewers
When downloading a file, we check for existing mime types and construct
a new one if it's unrecognized. Mime types have a flag,
alwaysAskBeforeHandling, that determines whether the unknown content
type dialog should be opened before handling the file. Before bug
1733492, the default value for that flag was simply true. Since the new
downloads flow is intended to avoid unnecessary steps, the default value
was changed to the inverted value of the new downloads panel
improvements pref. This patch adds a new pref that the mime info
constructor will read in configuring the flag's value. If the
improvements pref is not enabled, then the flag will be true, so the UCT
dialog will open. If the improvements pref is enabled, then it'll use
the value of the new pref. Also add a an interface for the pref to the
about:preferences UI, and automatically migrate a false value for
browser.download.improvements_to_download_panel to a true value for this
pref. I'm updating some tangentially related test files since they
happen to be touched slightly by this change. Strictly speaking they
would still work, but if the pref value was somehow changed from the
default they would fail.

Differential Revision: https://phabricator.services.mozilla.com/D143002
2022-04-15 18:13:11 +00:00

53 lines
1.6 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const RELATIVE_DIR = "toolkit/components/pdfjs/test/";
const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
function test() {
// When the always ask pref is disabled, we expect the PDF to be simply
// downloaded without a prompt, so ensure the pref is enabled here.
Services.prefs.setBoolPref(
"browser.download.always_ask_before_handling_new_types",
true
);
var oldAction = changeMimeHandler(Ci.nsIHandlerInfo.useSystemDefault, true);
var tab = BrowserTestUtils.addTab(gBrowser, TESTROOT + "file_pdfjs_test.pdf");
// Test: "Open with" dialog comes up when pdf.js is not selected as the default
// handler.
addWindowListener(
"chrome://mozapps/content/downloads/unknownContentType.xhtml",
finish
);
waitForExplicitFinish();
registerCleanupFunction(function() {
Services.prefs.clearUserPref(
"browser.download.always_ask_before_handling_new_types"
);
changeMimeHandler(oldAction[0], oldAction[1]);
gBrowser.removeTab(tab);
});
}
function addWindowListener(aURL, aCallback) {
Services.wm.addListener({
onOpenWindow(aXULWindow) {
info("window opened, waiting for focus");
Services.wm.removeListener(this);
var domwindow = aXULWindow.docShell.domWindow;
waitForFocus(function() {
is(
domwindow.document.location.href,
aURL,
"should have seen the right window open"
);
domwindow.close();
aCallback();
}, domwindow);
},
onCloseWindow(aXULWindow) {},
});
}