blob: 3f28ca6a262ffb994a7ba65b9a3333d15e8d961b [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function test()
{
let suite = InspectorTest.createSyncSuite("MIMETypeUtilities");
suite.addTestCase({
name: "fileExtensionForURL",
test() {
InspectorTest.expectEqual(WI.fileExtensionForURL(null), null, `File extension for null URL should be null.`);
InspectorTest.expectEqual(WI.fileExtensionForURL("invalid-url"), null, `File extension for invalid URL should be null.`);
InspectorTest.expectEqual(WI.fileExtensionForURL("https://example.com"), null, `File extension for URL without last path component should be null.`);
InspectorTest.expectEqual(WI.fileExtensionForURL("https://example.com/"), null, `File extension for URL without last path component should be null.`);
InspectorTest.expectEqual(WI.fileExtensionForURL("https://example.com/test"), null, `File extension for URL with last path component without a period should be null.`);
InspectorTest.expectEqual(WI.fileExtensionForURL("https://example.com/foo.bar/test"), null, `File extension for URL with last path component without a period should be null.`);
InspectorTest.expectEqual(WI.fileExtensionForURL("https://example.com/test."), null, `File extension for URL with last path component ending in a period should be null.`);
InspectorTest.expectEqual(WI.fileExtensionForURL("https://example.com/foo.xyz"), "xyz", `File extension for "foo.xyz" should be "xyz".`);
InspectorTest.expectEqual(WI.fileExtensionForURL("https://example.com/image.png"), "png", `File extension for "image.png" should be "png".`);
InspectorTest.expectEqual(WI.fileExtensionForURL("https://example.com/image.gif"), "gif", `File extension for "image.png" should be "gif".`);
InspectorTest.expectEqual(WI.fileExtensionForURL("https://example.com/script.js"), "js", `File extension for "script.js" should be "js".`);
InspectorTest.expectEqual(WI.fileExtensionForURL("https://example.com/script.min.js"), "js", `File extension for "script.min.js" should be "js".`);
return true;
}
});
suite.addTestCase({
name: "fileExtensionForMIMEType",
test() {
InspectorTest.expectEqual(WI.fileExtensionForMIMEType(null), null, `File extension for null mime type should be null.`);
InspectorTest.expectEqual(WI.fileExtensionForMIMEType("invalid-mimetype"), null, `File extension for invalid mime type should be null.`);
InspectorTest.expectEqual(WI.fileExtensionForMIMEType("application/unknown"), null, `File extension for unknown mime type should be null.`);
InspectorTest.expectEqual(WI.fileExtensionForMIMEType("image/jpeg"), "jpg", `File extension for "image/jpeg" should be "jpg".`);
InspectorTest.expectEqual(WI.fileExtensionForMIMEType("image/png"), "png", `File extension for "image/png" should be "png".`);
InspectorTest.expectEqual(WI.fileExtensionForMIMEType("image/gif"), "gif", `File extension for "image/gif" should be "gif".`);
InspectorTest.expectEqual(WI.fileExtensionForMIMEType("text/javascript"), "js", `File extension for "text/javascript" should be "js".`);
InspectorTest.expectEqual(WI.fileExtensionForMIMEType("application/json"), "json", `File extension for "application/json" should be "json".`);
InspectorTest.expectEqual(WI.fileExtensionForMIMEType("application/vnd.api+json"), "json", `File extension for "application/vnd.api+json" should be "json".`);
InspectorTest.expectEqual(WI.fileExtensionForMIMEType("application/xhtml+xml"), "xhtml", `File extension for "application/xhtml+xml" should be "xhtml".`);
InspectorTest.expectEqual(WI.fileExtensionForMIMEType("image/svg+xml"), "svg", `File extension for "image/svg+xml" should be "svg".`);
InspectorTest.expectEqual(WI.fileExtensionForMIMEType("text/foo+xml"), "xml", `File extension for "text/foo+xml" should be "xml".`);
return true;
}
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onLoad="runTest()">
</body>
</html>