2007-02-06 00:20:25 +00:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=352728
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 352728</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=352728">Mozilla Bug 352728</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
/** Test for Bug 352728 **/
|
|
|
|
|
|
|
|
function checkTypes(aNode, aNodeType, aTypeArray)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < aTypeArray.length; ++i) {
|
|
|
|
ok(aNode instanceof aTypeArray[i], aNodeType + " type test " + i,
|
|
|
|
aNodeType + " should be a " + aTypeArray[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkInterfaces(aNode, aNodeType, aInterfaceArray)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < aInterfaceArray.length; ++i) {
|
2012-09-24 12:46:29 +00:00
|
|
|
ok(aNode instanceof SpecialPowers.Ci[aInterfaceArray[i]],
|
2007-02-06 00:20:25 +00:00
|
|
|
aNodeType + " interface test " + i,
|
|
|
|
aNodeType + " should be a " + aInterfaceArray[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCharacterData(aNode, aText)
|
|
|
|
{
|
|
|
|
is(aNode.length, aText.length, "Text length should match");
|
|
|
|
is(aNode.data, aText, "Text content should match");
|
|
|
|
is(aNode.nodeValue, aText, "Check nodeValue");
|
|
|
|
is(aNode.localName, null, "Check localName")
|
|
|
|
is(aNode.namespaceURI, null, "Check namespaceURI");
|
|
|
|
}
|
|
|
|
|
2012-06-15 12:13:14 +00:00
|
|
|
function testComment(aText)
|
2007-02-06 00:20:25 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
var comment = document.createComment(aText);
|
|
|
|
var types = [ Comment, CharacterData, Node ];
|
|
|
|
checkTypes(comment, "comment", types);
|
|
|
|
|
|
|
|
var interfaces = [ "nsIDOMComment", "nsIDOMCharacterData", "nsIDOMNode",
|
2011-06-14 07:56:48 +00:00
|
|
|
"nsIDOMEventTarget" ];
|
2007-02-06 00:20:25 +00:00
|
|
|
checkInterfaces(comment, "comment", interfaces);
|
|
|
|
|
|
|
|
testCharacterData(comment, aText);
|
|
|
|
is(comment.nodeName, "#comment", "Check nodeName");
|
|
|
|
is(comment.nodeType, Node.COMMENT_NODE, "Check nodeType");
|
|
|
|
} catch (e) {
|
2012-06-15 12:13:14 +00:00
|
|
|
ok(0, "Correct functioning of comment stuff", "something broke: " + e);
|
2007-02-06 00:20:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCDATASection(aText, aShouldSucceed)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
var cdataSection = document.createCDATASection(aText);
|
|
|
|
ok(0, "Invalid CDATA section creation",
|
|
|
|
"Shouldn't create CDATA sections in HTML");
|
|
|
|
} catch (e) {
|
2012-04-26 16:42:26 +00:00
|
|
|
is(e.name, "NotSupportedError", "Check exception");
|
2007-02-06 00:20:25 +00:00
|
|
|
is(e.code, DOMException.NOT_SUPPORTED_ERR, "Check exception code");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPI(aTarget, aData, aShouldSucceed, aReason)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
var pi = document.createProcessingInstruction(aTarget, aData);
|
2011-10-01 16:14:40 +00:00
|
|
|
var types = [ ProcessingInstruction, Node ];
|
|
|
|
checkTypes(pi, "processing instruction", types);
|
|
|
|
|
|
|
|
var interfaces = [ "nsIDOMProcessingInstruction", "nsIDOMNode",
|
|
|
|
"nsIDOMEventTarget" ];
|
|
|
|
checkInterfaces(pi, "processing instruction", interfaces);
|
|
|
|
|
|
|
|
is(pi.target, aTarget, "Check target");
|
|
|
|
is(pi.data, aData, "Check data");
|
|
|
|
is(pi.nodeName, aTarget, "Check nodeName");
|
|
|
|
is(pi.nodeValue, aData, "Check nodeValue");
|
|
|
|
is(pi.localName, null, "Check localName")
|
|
|
|
is(pi.namespaceURI, null, "Check namespaceURI");
|
|
|
|
|
|
|
|
is(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE, "Check nodeType");
|
|
|
|
|
|
|
|
if (!aShouldSucceed) {
|
|
|
|
ok(false, "Invalid processing instruction creation", aReason);
|
|
|
|
}
|
2007-02-06 00:20:25 +00:00
|
|
|
} catch (e) {
|
2011-10-01 16:14:40 +00:00
|
|
|
if (aShouldSucceed) {
|
|
|
|
ok(false, "Correct functioning of processing instruction stuff",
|
|
|
|
"something broke: " + e);
|
|
|
|
} else {
|
2012-04-26 16:42:26 +00:00
|
|
|
is(e.name, "InvalidCharacterError", "Check exception");
|
2011-10-01 16:14:40 +00:00
|
|
|
is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
|
|
|
|
}
|
2007-02-06 00:20:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-15 12:13:14 +00:00
|
|
|
testComment("Some text");
|
|
|
|
testComment("Some text with a '-' in it");
|
|
|
|
testComment("Some text with a '-' and a '-' and another '-'");
|
2012-06-17 09:35:42 +00:00
|
|
|
testComment("Some text -- this should create a node!");
|
2012-06-15 12:13:14 +00:00
|
|
|
testComment("<!-- This is an HTML comment -->");
|
2007-02-06 00:20:25 +00:00
|
|
|
|
|
|
|
testCDATASection("Some text", true);
|
|
|
|
testCDATASection("Some text with a '?' in it", true);
|
|
|
|
testCDATASection("Some text with a '>' in it", true);
|
|
|
|
testCDATASection("Some text with a '?' and a '>' in it", true);
|
|
|
|
testCDATASection("Some text with a '? >' in it", true);
|
|
|
|
testCDATASection("Some text -- ?> this should be ok", true);
|
|
|
|
testCDATASection("Some text ]]> this should not create a node!", false);
|
|
|
|
|
|
|
|
testPI("foo", "bar", true);
|
|
|
|
testPI("foo:bar", "baz", true);
|
|
|
|
testPI("foo", "bar?", true);
|
|
|
|
testPI("foo", "bar>", true);
|
|
|
|
testPI("foo", "bar? >", true);
|
|
|
|
testPI("<aaa", "bar", false, "Target should not contain '<'");
|
|
|
|
testPI("aaa>", "bar", false, "Target should not contain '>'");
|
|
|
|
testPI("aa?", "bar", false, "Target should not contain '?'");
|
|
|
|
testPI("foo", "bar?>", false, "Data should not contain '?>'");
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|