summaryrefslogtreecommitdiffstats
path: root/uriloader/exthandler/tests/unit/test_getMIMEInfo_unknown_mime_type.js
blob: 9beef9d9c5599d70f77f16aba8862dbeaa5629f0 (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
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Zip files can be opened by Windows explorer, so we should always be able to
// determine a description and default handler for them. However, things can
// get messy if they are sent to us with a mime type other than what Windows
// considers the "right" mimetype (application/x-zip-compressed), like
// application/zip, which is what most places (IANA, macOS, probably all linux
// distros, Apache, etc.) think is the "right" mimetype.
add_task(async function test_check_unknown_mime_type() {
  const mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
  let zipType = mimeService.getTypeFromExtension("zip");
  Assert.equal(zipType, "application/x-zip-compressed");
  try {
    let extension = mimeService.getPrimaryExtension("application/zip", "");
    Assert.equal(
      extension,
      "zip",
      "Expect our own info to provide an extension for zip files."
    );
  } catch (ex) {
    Assert.ok(false, "We shouldn't throw when getting zip info.");
  }
  let found = {};
  let mimeInfo = mimeService.getMIMEInfoFromOS("application/zip", "zip", found);
  Assert.ok(
    mimeInfo.hasDefaultHandler,
    "Should have a default app for zip files"
  );
});