MIME Sniffing: tests for MIME type groups
Note: these are currently not run by browsers, but might be useful for tooling.
diff --git a/mimesniff/mime-types/README.md b/mimesniff/mime-types/README.md
index 3a2681e..4b3c813 100644
--- a/mimesniff/mime-types/README.md
+++ b/mimesniff/mime-types/README.md
@@ -1,4 +1,4 @@
-== MIME types ==
+## MIME types
`resources/mime-types.json` and `resources/generated-mime-types.json` contain MIME type tests. The tests are encoded as a JSON array. String values in the array serve as documentation. All other values are objects with the following fields:
@@ -29,3 +29,14 @@
`resources/generated-mime-types.json` is generated by running `resources/generated-mime-types.py`. Modify the latter to correct the former.
These tests are used by resources in this directory to test various aspects of MIME types.
+
+## MIME type groups
+
+`resources/mime-groups.json` contains MIME type group-membership tests. The tests are encoded as a JSON array. String values in the array serve as documentation. All other values are objects with the following fields:
+
+* `input`: The MIME type to test.
+* `groups`: An array of zero or more groups to which the MIME type belongs.
+
+In order to pass the tests an implementation must treat each MIME type as belonging to the exact set of groups listed, with no additions or omissions.
+
+Note: As MIME type groups are used only while determining the computed MIME type of a resource and are not exposed in any API, no browser-based test harness is available.
diff --git a/mimesniff/mime-types/resources/mime-groups.json b/mimesniff/mime-types/resources/mime-groups.json
new file mode 100644
index 0000000..1b5d7d5
--- /dev/null
+++ b/mimesniff/mime-types/resources/mime-groups.json
@@ -0,0 +1,159 @@
+[
+ {"input": "x/x", "groups": []},
+ {"input": "image/x", "groups": ["image"]},
+ {"input": "audio/x", "groups": ["audio or video"]},
+ {"input": "video/x", "groups": ["audio or video"]},
+ {"input": "application/ogg", "groups": ["audio or video"]},
+ {"input": "application/ogg;x=x", "groups": ["audio or video"]},
+ {"input": "font/x", "groups": ["font"]},
+ {"input": "application/font-cff", "groups": ["font"]},
+ {"input": "application/font-cff;x=x", "groups": ["font"]},
+ {"input": "application/font-off", "groups": ["font"]},
+ {"input": "application/font-off;x=x", "groups": ["font"]},
+ {"input": "application/font-sfnt", "groups": ["font"]},
+ {"input": "application/font-sfnt;x=x", "groups": ["font"]},
+ {"input": "application/font-ttf", "groups": ["font"]},
+ {"input": "application/font-ttf;x=x", "groups": ["font"]},
+ {"input": "application/font-woff", "groups": ["font"]},
+ {"input": "application/font-woff;x=x", "groups": ["font"]},
+ {"input": "application/vnd.ms-fontobject", "groups": ["font"]},
+ {"input": "application/vnd.ms-fontobject;x=x", "groups": ["font"]},
+ {"input": "application/vnd.ms-opentype", "groups": ["font"]},
+ {"input": "application/vnd.ms-opentype;x=x", "groups": ["font"]},
+ {"input": "x/x+zip", "groups": ["ZIP-based"]},
+ {"input": "x/x+zip;x=x", "groups": ["ZIP-based"]},
+ {"input": "x/+zip", "groups": ["ZIP-based"]},
+ {"input": "x/+zip;x=x", "groups": ["ZIP-based"]},
+ "application/zip also matches the archive group",
+ {"input": "application/zip", "groups": ["ZIP-based", "archive"]},
+ {"input": "application/zip;x=x", "groups": ["ZIP-based", "archive"]},
+ {"input": "application/x-rar-compressed", "groups": ["archive"]},
+ {"input": "application/x-rar-compressed;x=x", "groups": ["archive"]},
+ {"input": "application/x-gzip", "groups": ["archive"]},
+ {"input": "application/x-gzip;x=x", "groups": ["archive"]},
+ "XML is also scriptable",
+ {"input": "x/x+xml", "groups": ["XML", "scriptable"]},
+ {"input": "x/x+xml;x=x", "groups": ["XML", "scriptable"]},
+ {"input": "x/+xml", "groups": ["XML", "scriptable"]},
+ {"input": "x/+xml;x=x", "groups": ["XML", "scriptable"]},
+ {"input": "application/xml", "groups": ["XML", "scriptable"]},
+ {"input": "application/xml;x=x", "groups": ["XML", "scriptable"]},
+ {"input": "text/xml", "groups": ["XML", "scriptable"]},
+ {"input": "text/xml;x=x", "groups": ["XML", "scriptable"]},
+ "HTML is scriptable",
+ {"input": "text/html", "groups": ["HTML", "scriptable"]},
+ {"input": "text/html;x=x", "groups": ["HTML", "scriptable"]},
+ "PDF is scriptable",
+ {"input": "application/pdf", "groups": ["scriptable"]},
+ {"input": "application/pdf;x=x", "groups": ["scriptable"]},
+ {"input": "application/ecmascript", "groups": ["JavaScript"]},
+ {"input": "application/ecmascript;x=x", "groups": ["JavaScript"]},
+ {"input": "application/javascript", "groups": ["JavaScript"]},
+ {"input": "application/javascript;x=x", "groups": ["JavaScript"]},
+ {"input": "application/x-ecmascript", "groups": ["JavaScript"]},
+ {"input": "application/x-ecmascript;x=x", "groups": ["JavaScript"]},
+ {"input": "application/x-javascript", "groups": ["JavaScript"]},
+ {"input": "application/x-javascript;x=x", "groups": ["JavaScript"]},
+ {"input": "text/ecmascript", "groups": ["JavaScript"]},
+ {"input": "text/ecmascript;x=x", "groups": ["JavaScript"]},
+ {"input": "text/javascript", "groups": ["JavaScript"]},
+ {"input": "text/javascript;x=x", "groups": ["JavaScript"]},
+ {"input": "text/javascript1.0", "groups": ["JavaScript"]},
+ {"input": "text/javascript1.0;x=x", "groups": ["JavaScript"]},
+ {"input": "text/javascript1.1", "groups": ["JavaScript"]},
+ {"input": "text/javascript1.1;x=x", "groups": ["JavaScript"]},
+ {"input": "text/javascript1.2", "groups": ["JavaScript"]},
+ {"input": "text/javascript1.2;x=x", "groups": ["JavaScript"]},
+ {"input": "text/javascript1.3", "groups": ["JavaScript"]},
+ {"input": "text/javascript1.3;x=x", "groups": ["JavaScript"]},
+ {"input": "text/javascript1.4", "groups": ["JavaScript"]},
+ {"input": "text/javascript1.4;x=x", "groups": ["JavaScript"]},
+ {"input": "text/javascript1.5", "groups": ["JavaScript"]},
+ {"input": "text/javascript1.5;x=x", "groups": ["JavaScript"]},
+ {"input": "text/jscript", "groups": ["JavaScript"]},
+ {"input": "text/jscript;x=x", "groups": ["JavaScript"]},
+ {"input": "text/livescript", "groups": ["JavaScript"]},
+ {"input": "text/livescript;x=x", "groups": ["JavaScript"]},
+ {"input": "text/x-ecmascript", "groups": ["JavaScript"]},
+ {"input": "text/x-ecmascript;x=x", "groups": ["JavaScript"]},
+ {"input": "text/x-javascript", "groups": ["JavaScript"]},
+ {"input": "text/x-javascript;x=x", "groups": ["JavaScript"]},
+ {"input": "x/x+json", "groups": ["JSON"]},
+ {"input": "x/x+json;x=x", "groups": ["JSON"]},
+ {"input": "x/+json", "groups": ["JSON"]},
+ {"input": "x/+json;x=x", "groups": ["JSON"]},
+ {"input": "application/json", "groups": ["JSON"]},
+ {"input": "application/json;x=x", "groups": ["JSON"]},
+ {"input": "text/json", "groups": ["JSON"]},
+ {"input": "text/json;x=x", "groups": ["JSON"]},
+ {"input": "x/x;type=image", "groups": []},
+ {"input": "x/x;type=audio", "groups": []},
+ {"input": "x/x;type=video", "groups": []},
+ {"input": "x/x;type=font", "groups": []},
+ {"input": "ximage/x", "groups": []},
+ {"input": "xaudio/x", "groups": []},
+ {"input": "xvideo/x", "groups": []},
+ {"input": "xfont/x", "groups": []},
+ {"input": "imagex/x", "groups": []},
+ {"input": "audiox/x", "groups": []},
+ {"input": "videox/x", "groups": []},
+ {"input": "fontx/x", "groups": []},
+ {"input": "x/image", "groups": []},
+ {"input": "x/png", "groups": []},
+ {"input": "x/audio", "groups": []},
+ {"input": "x/video", "groups": []},
+ {"input": "x/ogg", "groups": []},
+ {"input": "x/font", "groups": []},
+ {"input": "x/woff", "groups": []},
+ {"input": "x/font-ttf", "groups": []},
+ {"input": "x/x;x=\"application/font-ttf\"", "groups": []},
+ {"input": "x/zip", "groups": []},
+ {"input": "x/x-gzip", "groups": []},
+ {"input": "x/x-rar-compressed", "groups": []},
+ {"input": "x/x;x=\"application/x-gip\"", "groups": []},
+ {"input": "x+zip/x", "groups": []},
+ {"input": "x/x;x=x+zip", "groups": []},
+ {"input": "x/x;subtype=x+zip", "groups": []},
+ {"input": "x/xml", "groups": []},
+ {"input": "x/x;x=\"application/xml\"", "groups": []},
+ {"input": "x+xml/x", "groups": []},
+ {"input": "x/x;x=x+xml", "groups": []},
+ {"input": "x/x;subtype=x+xml", "groups": []},
+ {"input": "x/pdf", "groups": []},
+ {"input": "x/html", "groups": []},
+ {"input": "x/ecmascript", "groups": []},
+ {"input": "x/javascript", "groups": []},
+ {"input": "x/x-ecmascript", "groups": []},
+ {"input": "x/x-javascript", "groups": []},
+ {"input": "x/jscript", "groups": []},
+ {"input": "x/livescript", "groups": []},
+ {"input": "x/javascript1.0", "groups": []},
+ {"input": "x/javascript1.1", "groups": []},
+ {"input": "x/javascript1.2", "groups": []},
+ {"input": "x/javascript1.3", "groups": []},
+ {"input": "x/javascript1.4", "groups": []},
+ {"input": "x/javascript1.5", "groups": []},
+ {"input": "x/x;x=\"application/javascript\"", "groups": []},
+ {"input": "x/json", "groups": []},
+ {"input": "x/x;x=\"application/json\"", "groups": []},
+ {"input": "x+json/x", "groups": []},
+ {"input": "x/x;x=x+json", "groups": []},
+ {"input": "x/x;subtype=x+json", "groups": []},
+ {"input": "image/png", "groups": ["image"]},
+ {"input": "audio/mp4", "groups": ["audio or video"]},
+ {"input": "video/mpeg", "groups": ["audio or video"]},
+ {"input": "font/woff", "groups": ["font"]},
+ "SVG is both image and XML, thus also scriptable",
+ {"input": "image/svg+xml", "groups": ["image", "XML", "scriptable"]},
+ "Hypothetical SVG font type",
+ {"input": "font/svg+xml", "groups": ["font", "XML", "scriptable"]},
+ "XHTML is not considered HTML",
+ {"input": "application/xhtml+xml", "groups": ["XML", "scriptable"]},
+ "Subtype longer than 255",
+ {"input": "x/01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789+zip",
+ "groups": ["ZIP-based"]},
+ {"input": "x/01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789+xml",
+ "groups": ["XML", "scriptable"]},
+ {"input": "x/01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789+json",
+ "groups": ["JSON"]}
+]