summaryrefslogtreecommitdiffstats
path: root/uriloader/exthandler/tests/mochitest/test_nullCharFile.xhtml
diff options
context:
space:
mode:
Diffstat (limited to 'uriloader/exthandler/tests/mochitest/test_nullCharFile.xhtml')
-rw-r--r--uriloader/exthandler/tests/mochitest/test_nullCharFile.xhtml67
1 files changed, 67 insertions, 0 deletions
diff --git a/uriloader/exthandler/tests/mochitest/test_nullCharFile.xhtml b/uriloader/exthandler/tests/mochitest/test_nullCharFile.xhtml
new file mode 100644
index 0000000000..b153395e81
--- /dev/null
+++ b/uriloader/exthandler/tests/mochitest/test_nullCharFile.xhtml
@@ -0,0 +1,67 @@
+<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>