|
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 type="text/javascript" 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"> |
|
14 |
|
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> |
|
24 |
|
25 <script class="testbody" type="text/javascript"> |
|
26 <![CDATA[ |
|
27 cdataTest1 = true; |
|
28 ]]> |
|
29 cdataTest2 = true; |
|
30 <![CDATA[ |
|
31 cdataTest3 = true; |
|
32 ]]> |
|
33 </script> |
|
34 |
|
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> |
|
40 |
|
41 <script class="testbody" type="text/javascript"> |
|
42 <![CDATA[ |
|
43 |
|
44 /** Test for Bug 352728 **/ |
|
45 function checkTypes(aNode, aNodeType, aTypeArray) |
|
46 { |
|
47 for (var i = 0; i < aTypeArray.length; ++i) { |
|
48 ok(aNode instanceof aTypeArray[i], aNodeType + " type test " + i, |
|
49 aNodeType + " should be a " + aTypeArray[i]); |
|
50 } |
|
51 } |
|
52 |
|
53 function checkInterfaces(aNode, aNodeType, aInterfaceArray) |
|
54 { |
|
55 for (var i = 0; i < aInterfaceArray.length; ++i) { |
|
56 ok(aNode instanceof SpecialPowers.Ci[aInterfaceArray[i]], |
|
57 aNodeType + " interface test " + i, |
|
58 aNodeType + " should be a " + aInterfaceArray[i]); |
|
59 } |
|
60 } |
|
61 |
|
62 function testCharacterData(aNode, aText) |
|
63 { |
|
64 is(aNode.length, aText.length, "Text length should match"); |
|
65 is(aNode.data, aText, "Text content should match"); |
|
66 is(aNode.nodeValue, aText, "Check nodeValue"); |
|
67 is(aNode.localName, null, "Check localName") |
|
68 is(aNode.namespaceURI, null, "Check namespaceURI"); |
|
69 } |
|
70 |
|
71 function testComment(aText) |
|
72 { |
|
73 try { |
|
74 var comment = document.createComment(aText); |
|
75 var types = [ Comment, CharacterData, Node ]; |
|
76 checkTypes(comment, "comment", types); |
|
77 |
|
78 var interfaces = [ "nsIDOMComment", "nsIDOMCharacterData", "nsIDOMNode", |
|
79 "nsIDOMEventTarget" ]; |
|
80 checkInterfaces(comment, "comment", interfaces); |
|
81 |
|
82 testCharacterData(comment, aText); |
|
83 is(comment.nodeName, "#comment", "Check nodeName"); |
|
84 is(comment.nodeType, Node.COMMENT_NODE, "Check nodeType"); |
|
85 } catch (e) { |
|
86 ok(0, "Correct functioning of comment stuff", "something broke: " + e); |
|
87 } |
|
88 } |
|
89 |
|
90 function testCDATASection(aText, aShouldSucceed) |
|
91 { |
|
92 try { |
|
93 var cdataSection = document.createCDATASection(aText); |
|
94 var types = [ CDATASection, CharacterData, Node ]; |
|
95 checkTypes(cdataSection, "CDATA section", types); |
|
96 |
|
97 var interfaces = [ "nsIDOMCDATASection", "nsIDOMCharacterData", |
|
98 "nsIDOMNode", "nsIDOMEventTarget" ]; |
|
99 checkInterfaces(cdataSection, "CDATA section", interfaces); |
|
100 |
|
101 testCharacterData(cdataSection, aText); |
|
102 is(cdataSection.nodeName, "#cdata-section", "Check nodeName"); |
|
103 is(cdataSection.nodeType, Node.CDATA_SECTION_NODE, "Check nodeType"); |
|
104 |
|
105 if (!aShouldSucceed) { |
|
106 ok(0, "Invalid CDATA section creation", |
|
107 ]]> |
|
108 "Shouldn't create CDATA section with embedded \"]]>\""); |
|
109 <![CDATA[ |
|
110 } |
|
111 } catch (e) { |
|
112 if (aShouldSucceed) { |
|
113 ok(0, "Correct functioning of CDATA section stuff", |
|
114 "something broke: " + e); |
|
115 } else { |
|
116 is(e.name, "InvalidCharacterError", "Check exception"); |
|
117 is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code"); |
|
118 } |
|
119 } |
|
120 } |
|
121 |
|
122 function testPI(aTarget, aData, aShouldSucceed, aReason) |
|
123 { |
|
124 try { |
|
125 var pi = document.createProcessingInstruction(aTarget, aData); |
|
126 var types = [ ProcessingInstruction, Node ]; |
|
127 checkTypes(pi, "processing instruction", types); |
|
128 |
|
129 var interfaces = [ "nsIDOMProcessingInstruction", "nsIDOMNode", |
|
130 "nsIDOMEventTarget" ]; |
|
131 checkInterfaces(pi, "processing instruction", interfaces); |
|
132 |
|
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, null, "Check localName") |
|
138 is(pi.namespaceURI, null, "Check namespaceURI"); |
|
139 |
|
140 is(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE, "Check nodeType"); |
|
141 |
|
142 if (!aShouldSucceed) { |
|
143 ok(0, "Invalid processing instruction creation", aReason); |
|
144 } |
|
145 } catch (e) { |
|
146 if (aShouldSucceed) { |
|
147 ok(0, "Correct functioning of processing instruction stuff", |
|
148 "something broke: " + e); |
|
149 } else { |
|
150 is(e.name, "InvalidCharacterError", "Check exception"); |
|
151 is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code"); |
|
152 } |
|
153 } |
|
154 } |
|
155 |
|
156 testComment("Some text"); |
|
157 testComment("Some text with a '-' in it"); |
|
158 testComment("Some text with a '-' and a '-' and another '-'"); |
|
159 testComment("Some text -- this should create a node!"); |
|
160 testComment("<!-- This is an HTML comment -->"); |
|
161 |
|
162 testCDATASection("Some text", true); |
|
163 testCDATASection("Some text with a '?' in it", true); |
|
164 testCDATASection("Some text with a '>' in it", true); |
|
165 testCDATASection("Some text with a '?' and a '>' in it", true); |
|
166 testCDATASection("Some text with a '? >' in it", true); |
|
167 testCDATASection("Some text -- ?> this should be ok", true); |
|
168 ]]> |
|
169 testCDATASection("Some text ]]> this should not create a node!", false); |
|
170 |
|
171 <![CDATA[ |
|
172 |
|
173 testPI("foo", "bar", true); |
|
174 testPI("foo:bar", "baz", true); |
|
175 testPI("foo", "bar?", true); |
|
176 testPI("foo", "bar>", true); |
|
177 testPI("foo", "bar? >", true); |
|
178 testPI("<aaa", "bar", false, "Target should not contain '<'"); |
|
179 testPI("aaa>", "bar", false, "Target should not contain '>'"); |
|
180 testPI("aa?", "bar", false, "Target should not contain '?'"); |
|
181 testPI("foo", "bar?>", false, "Data should not contain '?>'"); |
|
182 ]]> |
|
183 </script> |
|
184 </pre> |
|
185 </body> |
|
186 </html> |
|
187 |