uriloader/exthandler/tests/mochitest/test_nullCharFile.xhtml
author Marco Bonardo <mbonardo@mozilla.com>
Tue, 27 Oct 2020 10:36:47 +0000
changeset 554718 e301b90c2b0e7da0b43d27f4625780c927c20fe4
parent 553698 a3815d601038dc3b8103224a5da4d6fa76aea511
child 595137 4a54d16de0c15200de6bb58a3f95436087290e18
permissions -rw-r--r--
Bug 1672238 - Fix test_nullCharFile.xhtml on fission x-origin. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D94784

<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() {
  let url = SimpleTest.getTestFileURL("HelperAppLauncherDialog_chromeScript.js");
  let chromeScript = SpecialPowers.loadChromeScript(url);

  for (let [name, expected] of tests) {
    let promiseName = new Promise(function(resolve) {
      chromeScript.addMessageListener("suggestedFileName",
                                      function listener(data) {
        chromeScript.removeMessageListener("suggestedFileName", listener);
        resolve(data);
      });
    });
    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");
  }

  let promise = new Promise(function(resolve) {
    chromeScript.addMessageListener("unregistered", function listener() {
      chromeScript.removeMessageListener("unregistered", listener);
      resolve();
    });
  });
  chromeScript.sendAsyncMessage("unregister");
  await promise;

  chromeScript.destroy();
});
</script>
</body>
</html>