85 lines
3.9 KiB
HTML
85 lines
3.9 KiB
HTML
<!DOCTYPE html>
|
|
<head>
|
|
<title>document.contentType</title>
|
|
<link rel="help" href="http://dom.spec.whatwg.org/#dom-document-contenttype">
|
|
<script src="../../resources/js-test-pre.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
|
|
var htmlContent =
|
|
"<html>" +
|
|
"<head>" +
|
|
"<noscript>" +
|
|
"Scripts must be disabled for the document created using DOMParser.parseFromString()" +
|
|
"</noscript>" +
|
|
"</head>" +
|
|
"<body>" +
|
|
"<div id='text'>Sample text content</div>" +
|
|
"<script>document.getElementById('text').textContent = 'Modified text content';<\/script>" +
|
|
"</body>" +
|
|
"</html>";
|
|
|
|
var xmlContent =
|
|
"<root>" +
|
|
"</root>";
|
|
|
|
|
|
var xhtmlContent =
|
|
"<!DOCTYPE html>" +
|
|
"<html xmlns=\"http://www.w3.org/1999/xhtml\">" +
|
|
"<head>" +
|
|
"<title>Title of document</title>" +
|
|
"<noscript>" +
|
|
"Scripts must be disabled for the document created using DOMParser.parseFromString()" +
|
|
"</noscript>" +
|
|
"</head>" +
|
|
"<body>" +
|
|
"<div id='text'></div>" +
|
|
"<script>document.getElementById('text').textContent = 'Newly added text';<\/script>" +
|
|
"</body>" +
|
|
"</html>";
|
|
|
|
var svgImageContent =
|
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">" +
|
|
"<circle cx=\"100\" cy=\"50\" r=\"40\" stroke=\"black\" stroke-width=\"2\" fill=\"red\"/>" +
|
|
"</svg>";
|
|
|
|
var xslContent =
|
|
"<?xml version=\"1.0\"?>" +
|
|
"<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" +
|
|
"<xsl:template match=\"/\">" +
|
|
"<html>" +
|
|
"<head>" +
|
|
"<title>XML XSL Example</title>" +
|
|
"<style type=\"text/css\">" +
|
|
"body" +
|
|
"{" +
|
|
"background-color:red;" +
|
|
"}" +
|
|
"</style>" +
|
|
"</head>" +
|
|
"<body>" +
|
|
"<xsl:apply-templates/>" +
|
|
"</body>" +
|
|
"</html>" +
|
|
"</xsl:template>" +
|
|
"" +
|
|
"<xsl:template match=\"tutorial\">" +
|
|
"<span><xsl:value-of select=\"name\"/></span>" +
|
|
"<span><xsl:value-of select=\"url\"/></span>" +
|
|
"</xsl:template>" +
|
|
"</xsl:stylesheet>";
|
|
|
|
shouldBeEqualToString('new DOMParser().parseFromString(htmlContent, "text/html").contentType', 'text/html');
|
|
shouldBeEqualToString('new DOMParser().parseFromString(xmlContent, "application/xml").contentType', 'application/xml');
|
|
shouldBeEqualToString('new DOMParser().parseFromString(xhtmlContent, "application/xhtml+xml").contentType', 'application/xhtml+xml');
|
|
shouldBeEqualToString('new DOMParser().parseFromString(svgImageContent, "image/svg+xml").contentType', 'image/svg+xml');
|
|
shouldThrow('new DOMParser().parseFromString(xslContent, "text/xsl").contentType', "'TypeError: Type error'");
|
|
shouldThrow('new DOMParser().parseFromString(xmlContent, "text/dummy+xml").contentType', "'TypeError: Type error'");
|
|
shouldThrow('new DOMParser().parseFromString(xmlContent, "text/XML").contentType', "'TypeError: Type error'");
|
|
shouldThrow('new DOMParser().parseFromString(htmlContent, "TEXT/html").contentType', "'TypeError: Type error'");
|
|
|
|
</script>
|
|
<script src="../../resources/js-test-post.js"></script>
|
|
</body> |