summaryrefslogtreecommitdiffstats
path: root/uriloader/exthandler/tests/mochitest/browser_download_idn_blocklist.js
blob: a5de2870af61a888712cd47ba42d2ced38632bc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TEST_HOST = "example.org";
const TEST_FILE = "\u3002.bin";
const TEST_URL = `http://${TEST_HOST}/${TEST_FILE}`;

const { XPCShellContentUtils } = ChromeUtils.importESModule(
  "resource://testing-common/XPCShellContentUtils.sys.mjs"
);
XPCShellContentUtils.initMochitest(this);
const server = XPCShellContentUtils.createHttpServer({
  hosts: [TEST_HOST],
});
let file = getChromeDir(getResolvedURI(gTestPath));
file.append("download.bin");
server.registerFile(`/${encodeURIComponent(TEST_FILE)}`, file);

/**
 * Check that IDN blocklisted characters are not escaped in
 * download file names.
 */
add_task(async function test_idn_blocklisted_char_not_escaped() {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["browser.download.always_ask_before_handling_new_types", false],
      ["dom.block_download_insecure", false],
    ],
  });

  info("Testing with " + TEST_URL);
  let publicList = await Downloads.getList(Downloads.PUBLIC);
  registerCleanupFunction(async () => {
    await publicList.removeFinished();
  });
  let downloadFinished = promiseDownloadFinished(publicList);
  var tab = BrowserTestUtils.addTab(gBrowser, TEST_URL);
  let dl = await downloadFinished;
  ok(dl.succeeded, "Download should succeed.");
  Assert.equal(
    PathUtils.filename(dl.target.path),
    TEST_FILE,
    "Should not escape a download file name."
  );
  await IOUtils.remove(dl.target.path);

  BrowserTestUtils.removeTab(tab);
});