• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1description("Test creation of each type of Node and check intial values")
2
3var xmlDoc = document.implementation.createDocument("http://www.w3.org/1999/xhtml", "html", null);
4
5debug("Attribute creation using createElement on an HTML doc:")
6var attr = document.createAttribute("foo");
7shouldBe("attr.nodeName", "'foo'");
8shouldBe("attr.name", "'foo'");
9// Spec: http://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createAttribute
10// Both FF and WebKit return "foo" for Attribute.localName, even though the spec says null
11shouldBe("attr.localName", "null");
12shouldBe("attr.namespaceURI", "null");
13shouldBe("attr.prefix", "null");
14shouldBe("attr.nodeValue", "''");
15shouldBe("attr.value", "''");
16shouldBe("attr.attributes", "null");
17
18debug("Attribute creation using createElementNS on an HTML doc:")
19attr = document.createAttributeNS("http://www.example.com", "example:foo");
20shouldBe("attr.nodeName", "'example:foo'");
21shouldBe("attr.name", "'example:foo'");
22shouldBe("attr.localName", "'foo'");
23shouldBe("attr.namespaceURI", "'http://www.example.com'");
24shouldBe("attr.prefix", "'example'");
25shouldBe("attr.nodeValue", "''");
26shouldBe("attr.value", "''");
27shouldBe("attr.attributes", "null");
28
29debug("Attribute creation using createElement on an XHTML doc:")
30attr = xmlDoc.createAttribute("foo");
31shouldBe("attr.nodeName", "'foo'");
32shouldBe("attr.name", "'foo'");
33// Spec: http://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createAttribute
34// Both FF and WebKit return "foo" for Attribute.localName, even though the spec says null
35shouldBe("attr.localName", "null");
36shouldBe("attr.namespaceURI", "null");
37shouldBe("attr.prefix", "null");
38shouldBe("attr.nodeValue", "''");
39shouldBe("attr.value", "''");
40shouldBe("attr.attributes", "null");
41
42debug("Attribute creation using createElementNS on an XHTML doc:")
43attr = xmlDoc.createAttributeNS("http://www.example.com", "example:foo");
44shouldBe("attr.nodeName", "'example:foo'");
45shouldBe("attr.name", "'example:foo'");
46shouldBe("attr.localName", "'foo'");
47shouldBe("attr.namespaceURI", "'http://www.example.com'");
48shouldBe("attr.prefix", "'example'");
49shouldBe("attr.nodeValue", "''");
50shouldBe("attr.value", "''");
51shouldBe("attr.attributes", "null");
52
53var comment = document.createComment("foo");
54shouldBe("comment.nodeName", "'#comment'");
55shouldBe("comment.localName", "null");
56shouldBe("comment.namespaceURI", "null");
57shouldBe("comment.prefix", "null");
58shouldBe("comment.nodeValue", "'foo'");
59shouldBe("comment.data", "'foo'");
60shouldBe("comment.attributes", "null");
61
62shouldThrow("document.createCDATASection('foo')");
63var cdata = xmlDoc.createCDATASection("foo");
64shouldBe("cdata.nodeName", "'#cdata-section'");
65shouldBe("cdata.localName", "null");
66shouldBe("cdata.namespaceURI", "null");
67shouldBe("cdata.prefix", "null");
68shouldBe("cdata.nodeValue", "'foo'");
69shouldBe("cdata.data", "'foo'");
70shouldBe("cdata.attributes", "null");
71
72var fragment = document.createDocumentFragment();
73shouldBe("fragment.nodeName", "'#document-fragment'");
74shouldBe("fragment.localName", "null");
75shouldBe("fragment.namespaceURI", "null");
76shouldBe("fragment.prefix", "null");
77shouldBe("fragment.nodeValue", "null");
78shouldBe("fragment.attributes", "null");
79
80var doc = document.implementation.createDocument("http://www.w3.org/1999/xhtml", "html", null);
81shouldBe("doc.nodeName", "'#document'");
82shouldBe("doc.localName", "null");
83// Spec: http://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createDocument
84// Currently both FF and WebKit return null here, disagreeing with the spec
85shouldBe("doc.namespaceURI", "'http://www.w3.org/1999/xhtml'");
86shouldBe("doc.prefix", "null");
87shouldBe("doc.nodeValue", "null");
88shouldBe("doc.attributes", "null");
89
90var doctype = document.implementation.createDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd");
91shouldBe("doctype.nodeName", "'svg'");
92shouldBe("doctype.name", "'svg'");
93shouldBe("doctype.localName", "null");
94shouldBe("doctype.namespaceURI", "null");
95shouldBe("doctype.prefix", "null");
96shouldBe("doctype.nodeValue", "null");
97shouldBe("doctype.attributes", "null");
98
99debug("Element creation using createElement on an HTML doc:")
100var element = document.createElement("pre");
101shouldBe("element.nodeName", "'PRE'");
102// Spec: http://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createElement
103// FF returns "PRE" for localName, WebKit returns "pre", the spec says we should return null
104shouldBe("element.localName", "null");
105// FF returns null for namespaceURI, WebKit returns http://www.w3.org/1999/xhtml, the spec says we should return null
106shouldBe("element.namespaceURI", "null");
107shouldBe("element.prefix", "null");
108shouldBe("element.nodeValue", "null");
109shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
110
111debug("Prefixed element creation using createElementNS on an HTML doc:")
112element = document.createElementNS("http://www.w3.org/1999/xhtml", "html:pre");
113shouldBe("element.nodeName", "'html:pre'");
114shouldBe("element.localName", "'pre'");
115shouldBe("element.namespaceURI", "'http://www.w3.org/1999/xhtml'");
116shouldBe("element.prefix", "'html'");
117shouldBe("element.nodeValue", "null");
118shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
119
120debug("SVG Element creation using createElementNS on an HTML doc:")
121element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
122shouldBe("element.nodeName", "'svg'");
123shouldBe("element.localName", "'svg'");
124shouldBe("element.namespaceURI", "'http://www.w3.org/2000/svg'");
125shouldBe("element.prefix", "null");
126shouldBe("element.nodeValue", "null");
127shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
128
129debug("Unknown Element creation using createElementNS on an HTML doc:")
130element = document.createElementNS("http://www.webkit.org", "foo:svg");
131shouldBe("element.nodeName", "'foo:svg'");
132shouldBe("element.localName", "'svg'");
133shouldBe("element.namespaceURI", "'http://www.webkit.org'");
134shouldBe("element.prefix", "'foo'");
135shouldBe("element.nodeValue", "null");
136shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
137
138debug("Element creation using createElementNS on an HTML doc:")
139element = document.createElementNS("http://www.w3.org/1999/xhtml", "pre");
140// Spec: http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-104682815 (element.tagName)
141// FF and Opera returns "pre" for nodeName as it is an XHTML element, WebKit returns "PRE".
142shouldBe("element.nodeName", "'pre'");
143shouldBe("element.localName", "'pre'");
144shouldBe("element.namespaceURI", "'http://www.w3.org/1999/xhtml'");
145shouldBe("element.prefix", "null");
146shouldBe("element.nodeValue", "null");
147shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
148
149debug("Element creation using createElement on an XHTML doc:")
150element = xmlDoc.createElement("pre");
151shouldBe("element.nodeName", "'pre'");
152shouldBe("element.localName", "null");
153// FF returns null for namespaceURI, WebKit returns http://www.w3.org/1999/xhtml, the spec says we should return null
154shouldBe("element.namespaceURI", "null");
155shouldBe("element.prefix", "null");
156shouldBe("element.nodeValue", "null");
157shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
158
159debug("Element creation using createElementNS on an XHTML doc:")
160element = xmlDoc.createElementNS("http://www.w3.org/1999/xhtml", "html:pre");
161shouldBe("element.nodeName", "'html:pre'");
162shouldBe("element.localName", "'pre'");
163shouldBe("element.namespaceURI", "'http://www.w3.org/1999/xhtml'");
164shouldBe("element.prefix", "'html'");
165shouldBe("element.nodeValue", "null");
166shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
167
168// Not possible to create Entity nodes via the DOM, WebKit doesn't create them from parsing
169
170shouldThrow("document.createEntityReference('gt')");
171var entityReference = xmlDoc.createEntityReference("gt");
172shouldBe("entityReference.nodeName", "'gt'");
173shouldBe("entityReference.localName", "null");
174shouldBe("entityReference.namespaceURI", "null");
175shouldBe("entityReference.prefix", "null");
176shouldBe("entityReference.nodeValue", "null");
177shouldBe("entityReference.attributes", "null");
178
179// Not possible to create Notation nodes via the DOM, WebKit doesn't create them from parsing
180
181shouldThrow("document.createProcessingInstruction('xml-stylesheet', 'type=\"text/xsl\" href=\"missing.xsl\"')");
182var processingInstruction = xmlDoc.createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="missing.xsl"');
183shouldBe("processingInstruction.nodeName", "'xml-stylesheet'");
184shouldBe("processingInstruction.localName", "null");
185shouldBe("processingInstruction.namespaceURI", "null");
186shouldBe("processingInstruction.prefix", "null");
187// DOM Core Level 2 and DOM Core Level 3 disagree on ProcessingInstruction.nodeValue
188// L2: entire content excluding the target
189// L3: same as ProcessingInstruction.data
190// We're following Level 3
191shouldBe("processingInstruction.nodeValue", "'type=\"text/xsl\" href=\"missing.xsl\"'");
192shouldBe("processingInstruction.attributes", "null");
193shouldBe("processingInstruction.target", "'xml-stylesheet'");
194shouldBe("processingInstruction.data", "'type=\"text/xsl\" href=\"missing.xsl\"'");
195
196var text = document.createTextNode("foo");
197shouldBe("text.nodeName", "'#text'");
198shouldBe("text.localName", "null");
199shouldBe("text.namespaceURI", "null");
200shouldBe("text.prefix", "null");
201shouldBe("text.nodeValue", "'foo'");
202shouldBe("text.data", "'foo'");
203shouldBe("text.attributes", "null");
204
205var successfullyParsed = true;
206