|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=352728 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 352728</title> |
|
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
10 </head> |
|
11 <body> |
|
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=352728">Mozilla Bug 352728</a> |
|
13 <p id="display"></p> |
|
14 <div id="content" style="display: none"> |
|
15 |
|
16 </div> |
|
17 <pre id="test"> |
|
18 <script class="testbody" type="text/javascript"> |
|
19 /** Test for Bug 352728 **/ |
|
20 |
|
21 function checkTypes(aNode, aNodeType, aTypeArray) |
|
22 { |
|
23 for (var i = 0; i < aTypeArray.length; ++i) { |
|
24 ok(aNode instanceof aTypeArray[i], aNodeType + " type test " + i, |
|
25 aNodeType + " should be a " + aTypeArray[i]); |
|
26 } |
|
27 } |
|
28 |
|
29 function checkInterfaces(aNode, aNodeType, aInterfaceArray) |
|
30 { |
|
31 for (var i = 0; i < aInterfaceArray.length; ++i) { |
|
32 ok(aNode instanceof SpecialPowers.Ci[aInterfaceArray[i]], |
|
33 aNodeType + " interface test " + i, |
|
34 aNodeType + " should be a " + aInterfaceArray[i]); |
|
35 } |
|
36 } |
|
37 |
|
38 function testCharacterData(aNode, aText) |
|
39 { |
|
40 is(aNode.length, aText.length, "Text length should match"); |
|
41 is(aNode.data, aText, "Text content should match"); |
|
42 is(aNode.nodeValue, aText, "Check nodeValue"); |
|
43 is(aNode.localName, null, "Check localName") |
|
44 is(aNode.namespaceURI, null, "Check namespaceURI"); |
|
45 } |
|
46 |
|
47 function testComment(aText) |
|
48 { |
|
49 try { |
|
50 var comment = document.createComment(aText); |
|
51 var types = [ Comment, CharacterData, Node ]; |
|
52 checkTypes(comment, "comment", types); |
|
53 |
|
54 var interfaces = [ "nsIDOMComment", "nsIDOMCharacterData", "nsIDOMNode", |
|
55 "nsIDOMEventTarget" ]; |
|
56 checkInterfaces(comment, "comment", interfaces); |
|
57 |
|
58 testCharacterData(comment, aText); |
|
59 is(comment.nodeName, "#comment", "Check nodeName"); |
|
60 is(comment.nodeType, Node.COMMENT_NODE, "Check nodeType"); |
|
61 } catch (e) { |
|
62 ok(0, "Correct functioning of comment stuff", "something broke: " + e); |
|
63 } |
|
64 } |
|
65 |
|
66 function testCDATASection(aText, aShouldSucceed) |
|
67 { |
|
68 try { |
|
69 var cdataSection = document.createCDATASection(aText); |
|
70 ok(0, "Invalid CDATA section creation", |
|
71 "Shouldn't create CDATA sections in HTML"); |
|
72 } catch (e) { |
|
73 is(e.name, "NotSupportedError", "Check exception"); |
|
74 is(e.code, DOMException.NOT_SUPPORTED_ERR, "Check exception code"); |
|
75 } |
|
76 } |
|
77 |
|
78 function testPI(aTarget, aData, aShouldSucceed, aReason) |
|
79 { |
|
80 try { |
|
81 var pi = document.createProcessingInstruction(aTarget, aData); |
|
82 var types = [ ProcessingInstruction, Node ]; |
|
83 checkTypes(pi, "processing instruction", types); |
|
84 |
|
85 var interfaces = [ "nsIDOMProcessingInstruction", "nsIDOMNode", |
|
86 "nsIDOMEventTarget" ]; |
|
87 checkInterfaces(pi, "processing instruction", interfaces); |
|
88 |
|
89 is(pi.target, aTarget, "Check target"); |
|
90 is(pi.data, aData, "Check data"); |
|
91 is(pi.nodeName, aTarget, "Check nodeName"); |
|
92 is(pi.nodeValue, aData, "Check nodeValue"); |
|
93 is(pi.localName, null, "Check localName") |
|
94 is(pi.namespaceURI, null, "Check namespaceURI"); |
|
95 |
|
96 is(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE, "Check nodeType"); |
|
97 |
|
98 if (!aShouldSucceed) { |
|
99 ok(false, "Invalid processing instruction creation", aReason); |
|
100 } |
|
101 } catch (e) { |
|
102 if (aShouldSucceed) { |
|
103 ok(false, "Correct functioning of processing instruction stuff", |
|
104 "something broke: " + e); |
|
105 } else { |
|
106 is(e.name, "InvalidCharacterError", "Check exception"); |
|
107 is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code"); |
|
108 } |
|
109 } |
|
110 } |
|
111 |
|
112 testComment("Some text"); |
|
113 testComment("Some text with a '-' in it"); |
|
114 testComment("Some text with a '-' and a '-' and another '-'"); |
|
115 testComment("Some text -- this should create a node!"); |
|
116 testComment("<!-- This is an HTML comment -->"); |
|
117 |
|
118 testCDATASection("Some text", true); |
|
119 testCDATASection("Some text with a '?' in it", true); |
|
120 testCDATASection("Some text with a '>' in it", true); |
|
121 testCDATASection("Some text with a '?' and a '>' in it", true); |
|
122 testCDATASection("Some text with a '? >' in it", true); |
|
123 testCDATASection("Some text -- ?> this should be ok", true); |
|
124 testCDATASection("Some text ]]> this should not create a node!", false); |
|
125 |
|
126 testPI("foo", "bar", true); |
|
127 testPI("foo:bar", "baz", true); |
|
128 testPI("foo", "bar?", true); |
|
129 testPI("foo", "bar>", true); |
|
130 testPI("foo", "bar? >", true); |
|
131 testPI("<aaa", "bar", false, "Target should not contain '<'"); |
|
132 testPI("aaa>", "bar", false, "Target should not contain '>'"); |
|
133 testPI("aa?", "bar", false, "Target should not contain '?'"); |
|
134 testPI("foo", "bar?>", false, "Data should not contain '?>'"); |
|
135 </script> |
|
136 </pre> |
|
137 </body> |
|
138 </html> |
|
139 |