Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / base / test / test_bug352728.xhtml
blobb868deb46391e1f1680aa3a96e7a0d32b7b7adb8
1 <html xmlns="http://www.w3.org/1999/xhtml">
2 <!--
3 https://bugzilla.mozilla.org/show_bug.cgi?id=352728
4 -->
5 <head>
6 <title>Test for Bug 352728</title>
7 <script src="/tests/SimpleTest/SimpleTest.js"></script>
8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
9 </head>
10 <body>
11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=352728">Mozilla Bug 352728</a>
12 <p id="display"></p>
13 <div id="content" style="display: none">
15 </div>
16 <pre id="test">
17 <!-- First make sure that a script consisting of multiple CDATA sections is
18 even supported -->
19 <script class="testbody" type="text/javascript">
20 var cdataTest1 = false;
21 var cdataTest2 = false;
22 var cdataTest3 = false;
23 </script>
25 <script class="testbody" type="text/javascript">
26 <![CDATA[
27 cdataTest1 = true;
28 ]]>
29 cdataTest2 = true;
30 <![CDATA[
31 cdataTest3 = true;
32 ]]>
33 </script>
35 <script class="testbody" type="text/javascript">
36 is(cdataTest1, true, "Check first CDATA section");
37 is(cdataTest2, true, "Check in between CDATA sections");
38 is(cdataTest3, true, "Check second CDATA section");
39 </script>
41 <script class="testbody" type="text/javascript">
42 <![CDATA[
44 /** Test for Bug 352728 **/
45 function checkTypes(aNode, aNodeType, aTypeArray)
47 for (var i = 0; i < aTypeArray.length; ++i) {
48 ok(
49 aNode instanceof aTypeArray[i],
50 aNodeType + " type test " + i + " - " +
51 aNodeType + " should be a " + aTypeArray[i]
56 function checkInterfaces(aNode, aNodeType, aInterfaceArray)
58 for (var i = 0; i < aInterfaceArray.length; ++i) {
59 ok(aNode instanceof SpecialPowers.Ci[aInterfaceArray[i]],
60 aNodeType + " interface test " + i + " - " +
61 aNodeType + " should be a " + aInterfaceArray[i]);
65 function testCharacterData(aNode, aText)
67 is(aNode.length, aText.length, "Text length should match");
68 is(aNode.data, aText, "Text content should match");
69 is(aNode.nodeValue, aText, "Check nodeValue");
70 is(aNode.localName, undefined, "Check localName")
71 is(aNode.namespaceURI, undefined, "Check namespaceURI");
74 function testComment(aText)
76 try {
77 var comment = document.createComment(aText);
78 var types = [ Comment, CharacterData, Node ];
79 checkTypes(comment, "comment", types);
81 var interfaces = [];
82 checkInterfaces(comment, "comment", interfaces);
84 testCharacterData(comment, aText);
85 is(comment.nodeName, "#comment", "Check nodeName");
86 is(comment.nodeType, Node.COMMENT_NODE, "Check nodeType");
87 } catch (e) {
88 ok(false, "Correct functioning of comment stuff - something broke: " + e);
92 function testCDATASection(aText, aShouldSucceed)
94 try {
95 var cdataSection = document.createCDATASection(aText);
96 var types = [ CDATASection, CharacterData, Node ];
97 checkTypes(cdataSection, "CDATA section", types);
99 var interfaces = [];
100 checkInterfaces(cdataSection, "CDATA section", interfaces);
102 testCharacterData(cdataSection, aText);
103 is(cdataSection.nodeName, "#cdata-section", "Check nodeName");
104 is(cdataSection.nodeType, Node.CDATA_SECTION_NODE, "Check nodeType");
106 if (!aShouldSucceed) {
107 ok(0, "Invalid CDATA section creation - " +
109 "Shouldn't create CDATA section with embedded \"]]&gt;\"");
110 <![CDATA[
112 } catch (e) {
113 if (aShouldSucceed) {
114 ok(false,
115 "Correct functioning of CDATA section stuff - something broke: " + e);
116 } else {
117 is(e.name, "InvalidCharacterError", "Check exception");
118 is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
123 function testPI(aTarget, aData, aShouldSucceed, aReason)
125 try {
126 var pi = document.createProcessingInstruction(aTarget, aData);
127 var types = [ ProcessingInstruction, Node ];
128 checkTypes(pi, "processing instruction", types);
130 var interfaces = [];
131 checkInterfaces(pi, "processing instruction", interfaces);
133 is(pi.target, aTarget, "Check target");
134 is(pi.data, aData, "Check data");
135 is(pi.nodeName, aTarget, "Check nodeName");
136 is(pi.nodeValue, aData, "Check nodeValue");
137 is(pi.localName, undefined, "Check localName")
138 is(pi.namespaceURI, undefined, "Check namespaceURI");
140 is(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE, "Check nodeType");
142 if (!aShouldSucceed) {
143 ok(false, "Invalid processing instruction creation - " + aReason);
145 } catch (e) {
146 if (aShouldSucceed) {
147 ok(false,
148 "Correct functioning of processing instruction stuff - " +
149 "something broke: " + e);
150 } else {
151 is(e.name, "InvalidCharacterError", "Check exception");
152 is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
157 testComment("Some text");
158 testComment("Some text with a '-' in it");
159 testComment("Some text with a '-' and a '-' and another '-'");
160 testComment("Some text -- this should create a node!");
161 testComment("<!-- This is an HTML comment -->");
163 testCDATASection("Some text", true);
164 testCDATASection("Some text with a '?' in it", true);
165 testCDATASection("Some text with a '>' in it", true);
166 testCDATASection("Some text with a '?' and a '>' in it", true);
167 testCDATASection("Some text with a '? >' in it", true);
168 testCDATASection("Some text -- ?> this should be ok", true);
170 testCDATASection("Some text ]]&gt; this should not create a node!", false);
172 <![CDATA[
174 testPI("foo", "bar", true);
175 testPI("foo:bar", "baz", true);
176 testPI("foo", "bar?", true);
177 testPI("foo", "bar>", true);
178 testPI("foo", "bar? >", true);
179 testPI("<aaa", "bar", false, "Target should not contain '<'");
180 testPI("aaa>", "bar", false, "Target should not contain '>'");
181 testPI("aa?", "bar", false, "Target should not contain '?'");
182 testPI("foo", "bar?>", false, "Data should not contain '?>'");
184 </script>
185 </pre>
186 </body>
187 </html>