Files
tubestation/uriloader/exthandler/tests/mochitest/test_nullCharFile.xhtml
Shane Hughes 0604bb580c 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

68 lines
2.1 KiB
HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test for Handling of null char</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<iframe id="test"></iframe>
<script type="text/javascript">
var tests = [
["test.html\u0000.png", "test.html_.png"],
["test.html.\u0000png", "test.html._png"],
];
add_task(async function() {
function promiseMessage(messageName) {
return new Promise(resolve => {
chromeScript.addMessageListener(messageName, function listener(data) {
chromeScript.removeMessageListener(messageName, listener);
resolve(data);
});
});
}
let url = SimpleTest.getTestFileURL("HelperAppLauncherDialog_chromeScript.js");
let chromeScript = SpecialPowers.loadChromeScript(url);
function wrongAPICallListener(msg) {
ok(
false,
`Called ${msg} when always ask pref was set to ${
Services.prefs.getBoolPref(
"browser.download.always_ask_before_handling_new_types"
)
}, which shouldn't happen.`
);
}
chromeScript.addMessageListener("wrongAPICall", wrongAPICallListener);
for (let prefVal of [false, true]) {
info("Pushing pref");
await SpecialPowers.pushPrefEnv({
set: [["browser.download.always_ask_before_handling_new_types", prefVal]]
});
for (let [name, expected] of tests) {
let promiseName = promiseMessage("suggestedFileName");
const a = document.createElement('a');
// Pass an unknown mimetype so we don't "correct" the extension:
a.href = "data:application/baconizer;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==";
a.download = name;
a.dispatchEvent(new MouseEvent('click'));
is((await promiseName), expected, "got the expected sanitized name");
}
}
// Clean up.
let promise = promiseMessage("unregistered");
chromeScript.sendAsyncMessage("unregister");
await promise;
chromeScript.removeMessageListener("wrongAPICall", wrongAPICallListener);
chromeScript.destroy();
});
</script>
</body>
</html>