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