diff --git a/netwerk/test/unit/test_parse_content_type.js b/netwerk/test/unit/test_parse_content_type.js index 7c0e414160a..d804be673b7 100644 --- a/netwerk/test/unit/test_parse_content_type.js +++ b/netwerk/test/unit/test_parse_content_type.js @@ -25,81 +25,162 @@ function run_test() { var netutil = Components.classes["@mozilla.org/network/util;1"] .getService(Components.interfaces.nsINetUtil); + type = netutil.parseRequestContentType("text/html", charset, hadCharset); + check("text/html", "", false); + type = netutil.parseResponseContentType("text/html", charset, hadCharset); check("text/html", "", false); + type = netutil.parseRequestContentType("TEXT/HTML", charset, hadCharset); + check("text/html", "", false); + type = netutil.parseResponseContentType("TEXT/HTML", charset, hadCharset); check("text/html", "", false); + type = netutil.parseRequestContentType("text/html, text/html", charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType("text/html, text/html", charset, hadCharset); check("text/html", "", false); + type = netutil.parseRequestContentType("text/html, text/plain", + charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType("text/html, text/plain", charset, hadCharset); check("text/plain", "", false); + type = netutil.parseRequestContentType('text/html, ', charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType('text/html, ', charset, hadCharset); check("text/html", "", false); + type = netutil.parseRequestContentType('text/html, */*', charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType('text/html, */*', charset, hadCharset); check("text/html", "", false); + type = netutil.parseRequestContentType('text/html, foo', charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType('text/html, foo', charset, hadCharset); check("text/html", "", false); + type = netutil.parseRequestContentType("text/html; charset=ISO-8859-1", + charset, hadCharset); + check("text/html", "ISO-8859-1", true); + type = netutil.parseResponseContentType("text/html; charset=ISO-8859-1", charset, hadCharset); check("text/html", "ISO-8859-1", true); + type = netutil.parseRequestContentType('text/html; charset="ISO-8859-1"', + charset, hadCharset); + check("text/html", "ISO-8859-1", true); + type = netutil.parseResponseContentType('text/html; charset="ISO-8859-1"', charset, hadCharset); check("text/html", "ISO-8859-1", true); + type = netutil.parseRequestContentType("text/html; charset='ISO-8859-1'", + charset, hadCharset); + check("text/html", "'ISO-8859-1'", true); + type = netutil.parseResponseContentType("text/html; charset='ISO-8859-1'", charset, hadCharset); check("text/html", "'ISO-8859-1'", true); + type = netutil.parseRequestContentType("text/html; charset=\"ISO-8859-1\", text/html", + charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType("text/html; charset=\"ISO-8859-1\", text/html", charset, hadCharset); check("text/html", "ISO-8859-1", true); + type = netutil.parseRequestContentType("text/html; charset=\"ISO-8859-1\", text/html; charset=UTF8", + charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType("text/html; charset=\"ISO-8859-1\", text/html; charset=UTF8", charset, hadCharset); check("text/html", "UTF8", true); + type = netutil.parseRequestContentType("text/html; charset=ISO-8859-1, TEXT/HTML", charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType("text/html; charset=ISO-8859-1, TEXT/HTML", charset, hadCharset); check("text/html", "ISO-8859-1", true); + type = netutil.parseRequestContentType("text/html; charset=ISO-8859-1, TEXT/plain", charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType("text/html; charset=ISO-8859-1, TEXT/plain", charset, hadCharset); check("text/plain", "", true); + type = netutil.parseRequestContentType("text/plain, TEXT/HTML; charset=ISO-8859-1, text/html, TEXT/HTML", charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType("text/plain, TEXT/HTML; charset=ISO-8859-1, text/html, TEXT/HTML", charset, hadCharset); check("text/html", "ISO-8859-1", true); + type = netutil.parseRequestContentType('text/plain, TEXT/HTML; param="charset=UTF8"; charset="ISO-8859-1"; param2="charset=UTF16", text/html, TEXT/HTML', charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType('text/plain, TEXT/HTML; param="charset=UTF8"; charset="ISO-8859-1"; param2="charset=UTF16", text/html, TEXT/HTML', charset, hadCharset); check("text/html", "ISO-8859-1", true); + type = netutil.parseRequestContentType('text/plain, TEXT/HTML; param=charset=UTF8; charset="ISO-8859-1"; param2=charset=UTF16, text/html, TEXT/HTML', charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType('text/plain, TEXT/HTML; param=charset=UTF8; charset="ISO-8859-1"; param2=charset=UTF16, text/html, TEXT/HTML', charset, hadCharset); check("text/html", "ISO-8859-1", true); + type = netutil.parseRequestContentType('text/plain, TEXT/HTML; param=charset=UTF8; charset="ISO-8859-1"; param2=charset=UTF16, text/html, TEXT/HTML', charset, hadCharset); + check("", "", false); + + type = netutil.parseRequestContentType("text/plain; param= , text/html", charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType("text/plain; param= , text/html", charset, hadCharset); check("text/html", "", false); + type = netutil.parseRequestContentType('text/plain; param=", text/html"', charset, hadCharset); + check("text/plain", "", false); + type = netutil.parseResponseContentType('text/plain; param=", text/html"', charset, hadCharset); check("text/plain", "", false); + type = netutil.parseRequestContentType('text/plain; param=", \\" , text/html"', charset, hadCharset); + check("text/plain", "", false); + type = netutil.parseResponseContentType('text/plain; param=", \\" , text/html"', charset, hadCharset); check("text/plain", "", false); + type = netutil.parseRequestContentType('text/plain; param=", \\" , text/html , "', charset, hadCharset); + check("text/plain", "", false); + type = netutil.parseResponseContentType('text/plain; param=", \\" , text/html , "', charset, hadCharset); check("text/plain", "", false); + type = netutil.parseRequestContentType('text/plain param=", \\" , text/html , "', charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType('text/plain param=", \\" , text/html , "', charset, hadCharset); check("text/plain", "", false); + type = netutil.parseRequestContentType('text/plain charset=UTF8', charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType('text/plain charset=UTF8', charset, hadCharset); check("text/plain", "", false); + type = netutil.parseRequestContentType('text/plain, TEXT/HTML; param="charset=UTF8"; ; param2="charset=UTF16", text/html, TEXT/HTML', charset, hadCharset); + check("", "", false); + type = netutil.parseResponseContentType('text/plain, TEXT/HTML; param="charset=UTF8"; ; param2="charset=UTF16", text/html, TEXT/HTML', charset, hadCharset); check("text/html", "", false);