| <!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: "fileExtensionForFilename", |
| test() { |
| InspectorTest.expectNull(WI.fileExtensionForFilename(null), `File extension for null filename should be null.`); |
| InspectorTest.expectEqual(WI.fileExtensionForURL("test"), null, `File extension for filename without a period should be null.`); |
| InspectorTest.expectEqual(WI.fileExtensionForURL("test."), null, `File extension for filename ending in a period should be null.`); |
| |
| InspectorTest.expectEqual(WI.fileExtensionForFilename("foo.xyz"), "xyz", `File extension for "foo.xyz" should be "xyz".`); |
| InspectorTest.expectEqual(WI.fileExtensionForFilename("image.png"), "png", `File extension for "image.png" should be "png".`); |
| InspectorTest.expectEqual(WI.fileExtensionForFilename("image.gif"), "gif", `File extension for "image.png" should be "gif".`); |
| InspectorTest.expectEqual(WI.fileExtensionForFilename("script.js"), "js", `File extension for "script.js" should be "js".`); |
| InspectorTest.expectEqual(WI.fileExtensionForFilename("script.min.js"), "js", `File extension for "script.min.js" should be "js".`); |
| |
| return true; |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "fileExtensionForURL", |
| test() { |
| InspectorTest.expectNull(WI.fileExtensionForURL(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.addTestCase({ |
| name: "shouldTreatMIMETypeAsText", |
| test() { |
| function expectText(mimeType) { |
| InspectorTest.expectTrue(WI.shouldTreatMIMETypeAsText(mimeType), `"${mimeType}" should be treated as text.`); |
| } |
| function expectNotText(mimeType) { |
| InspectorTest.expectFalse(WI.shouldTreatMIMETypeAsText(mimeType), `"${mimeType}" should not be treated as text.`); |
| } |
| |
| InspectorTest.expectFalse(WI.shouldTreatMIMETypeAsText(null), `null mime type should not be treated as text.`); |
| expectNotText("application/unknown"); |
| |
| expectText("text/plain"); |
| expectText("text/javascript"); |
| expectText("application/json"); |
| expectText("application/vnd.api+json"); |
| expectText("application/vnd.apple.mpegurl"); |
| expectText("image/svg+xml"); |
| expectText("text/x-coffeescript"); |
| expectText("application/xml"); |
| |
| expectNotText("image/jpeg"); |
| expectNotText("image/png"); |
| expectNotText("image/gif"); |
| expectNotText("font/woff"); |
| expectNotText("video/mpeg"); |
| expectNotText("audio/ogg"); |
| expectNotText("application/pdf"); |
| |
| return true; |
| } |
| }) |
| |
| suite.runTestCasesAndFinish(); |
| } |
| </script> |
| </head> |
| <body onLoad="runTest()"> |
| </body> |
| </html> |