4 https://bugzilla.mozilla.org/show_bug.cgi?id=352728
7 <title>Test for Bug
352728</title>
8 <script type=
"text/javascript" src=
"/MochiKit/MochiKit.js"></script>
9 <script type=
"text/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=352728">Mozilla Bug
352728</a>
15 <div id=
"content" style=
"display: none">
19 <script class=
"testbody" type=
"text/javascript">
20 /** Test for Bug
352728 **/
22 function checkTypes(aNode, aNodeType, aTypeArray)
24 for (var i =
0; i < aTypeArray.length; ++i) {
25 ok(aNode instanceof aTypeArray[i], aNodeType +
" type test " + i,
26 aNodeType +
" should be a " + aTypeArray[i]);
30 function checkInterfaces(aNode, aNodeType, aInterfaceArray)
32 for (var i =
0; i < aInterfaceArray.length; ++i) {
33 ok(aNode instanceof Components.interfaces[aInterfaceArray[i]],
34 aNodeType +
" interface test " + i,
35 aNodeType +
" should be a " + aInterfaceArray[i]);
39 function testCharacterData(aNode, aText)
41 is(aNode.length, aText.length,
"Text length should match");
42 is(aNode.data, aText,
"Text content should match");
43 is(aNode.nodeValue, aText,
"Check nodeValue");
44 is(aNode.localName, null,
"Check localName")
45 is(aNode.namespaceURI, null,
"Check namespaceURI");
48 function testComment(aText, aShouldSucceed)
51 var comment = document.createComment(aText);
52 var types = [ Comment, CharacterData, Node ];
53 checkTypes(comment,
"comment", types);
55 var interfaces = [
"nsIDOMComment",
"nsIDOMCharacterData",
"nsIDOMNode",
56 "nsIDOM3Node",
"nsIDOMEventTarget" ];
57 checkInterfaces(comment,
"comment", interfaces);
59 testCharacterData(comment, aText);
60 is(comment.nodeName,
"#comment",
"Check nodeName");
61 is(comment.nodeType, Node.COMMENT_NODE,
"Check nodeType");
63 if (!aShouldSucceed) {
64 ok(
0,
"Invalid comment creation",
65 "Shouldn't create comment with embedded \"--\
"");
69 ok(
0,
"Correct functioning of comment stuff",
"something broke: " + e);
71 is(e.code, DOMException.INVALID_CHARACTER_ERR,
"Check exception code");
76 function testCDATASection(aText, aShouldSucceed)
79 var cdataSection = document.createCDATASection(aText);
80 ok(
0,
"Invalid CDATA section creation",
81 "Shouldn't create CDATA sections in HTML");
83 is(e.code, DOMException.NOT_SUPPORTED_ERR,
"Check exception code");
87 function testPI(aTarget, aData, aShouldSucceed, aReason)
90 var pi = document.createProcessingInstruction(aTarget, aData);
91 ok(
0,
"Invalid processing instruction creation",
92 "Shouldn't create processing instructions in HTML");
94 is(e.code, DOMException.NOT_SUPPORTED_ERR,
"Check exception code");
98 testComment(
"Some text", true);
99 testComment(
"Some text with a '-' in it", true);
100 testComment(
"Some text with a '-' and a '-' and another '-'", true);
101 testComment(
"Some text -- this shouldn't create a node!", false);
102 testComment(
"<!-- This is an HTML comment -->", false);
104 testCDATASection(
"Some text", true);
105 testCDATASection(
"Some text with a '?' in it", true);
106 testCDATASection(
"Some text with a '>' in it", true);
107 testCDATASection(
"Some text with a '?' and a '>' in it", true);
108 testCDATASection(
"Some text with a '? >' in it", true);
109 testCDATASection(
"Some text -- ?> this should be ok", true);
110 testCDATASection(
"Some text ]]> this should not create a node!", false);
112 testPI(
"foo",
"bar", true);
113 testPI(
"foo:bar",
"baz", true);
114 testPI(
"foo",
"bar?", true);
115 testPI(
"foo",
"bar>", true);
116 testPI(
"foo",
"bar? >", true);
117 testPI(
"<aaa",
"bar", false,
"Target should not contain '<'");
118 testPI(
"aaa>",
"bar", false,
"Target should not contain '>'");
119 testPI(
"aa?",
"bar", false,
"Target should not contain '?'");
120 testPI(
"foo",
"bar?>", false,
"Data should not contain '?>'");