Upstream version 5.34.104.0
[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 createElement on an XHTML doc:")
18 attr = xmlDoc.createAttribute("foo");
19 shouldBe("attr.nodeName", "'foo'");
20 shouldBe("attr.name", "'foo'");
21 // Spec: http://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createAttribute
22 // Both FF and WebKit return "foo" for Attribute.localName, even though the spec says null
23 shouldBe("attr.localName", "null");
24 shouldBe("attr.namespaceURI", "null");
25 shouldBe("attr.prefix", "null");
26 shouldBe("attr.nodeValue", "''");
27 shouldBe("attr.value", "''");
28
29 var comment = document.createComment("foo");
30 shouldBe("comment.nodeName", "'#comment'");
31 shouldBe("comment.localName", "null");
32 shouldBe("comment.namespaceURI", "null");
33 shouldBe("comment.nodeValue", "'foo'");
34 shouldBe("comment.data", "'foo'");
35
36 shouldThrow("document.createCDATASection('foo')");
37 var cdata = xmlDoc.createCDATASection("foo");
38 shouldBe("cdata.nodeName", "'#cdata-section'");
39 shouldBe("cdata.localName", "null");
40 shouldBe("cdata.namespaceURI", "null");
41 shouldBe("cdata.nodeValue", "'foo'");
42 shouldBe("cdata.data", "'foo'");
43
44 var fragment = document.createDocumentFragment();
45 shouldBe("fragment.nodeName", "'#document-fragment'");
46 shouldBe("fragment.localName", "null");
47 shouldBe("fragment.namespaceURI", "null");
48 shouldBe("fragment.nodeValue", "null");
49
50 var doc = document.implementation.createDocument("http://www.w3.org/1999/xhtml", "html", null);
51 shouldBe("doc.nodeName", "'#document'");
52 shouldBe("doc.localName", "null");
53 // Spec: http://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createDocument
54 // Currently both FF and WebKit return null here, disagreeing with the spec
55 shouldBe("doc.namespaceURI", "'http://www.w3.org/1999/xhtml'");
56 shouldBe("doc.nodeValue", "null");
57
58 var doctype = document.implementation.createDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd");
59 shouldBe("doctype.nodeName", "'svg'");
60 shouldBe("doctype.name", "'svg'");
61 shouldBe("doctype.localName", "null");
62 shouldBe("doctype.namespaceURI", "null");
63 shouldBe("doctype.nodeValue", "null");
64
65 debug("Element creation using createElement on an HTML doc:")
66 var element = document.createElement("pre");
67 shouldBe("element.nodeName", "'PRE'");
68 // Spec: http://www.w3.org/TR/DOM-Level-2-Core/core.html#Level-2-Core-DOM-createElement
69 // FF returns "PRE" for localName, WebKit returns "pre", the spec says we should return null
70 shouldBe("element.localName", "null");
71 // FF returns null for namespaceURI, WebKit returns http://www.w3.org/1999/xhtml, the spec says we should return null
72 shouldBe("element.namespaceURI", "null");
73 shouldBe("element.prefix", "null");
74 shouldBe("element.nodeValue", "null");
75 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
76
77 debug("Prefixed element creation using createElementNS on an HTML doc:")
78 element = document.createElementNS("http://www.w3.org/1999/xhtml", "html:pre");
79 shouldBe("element.nodeName", "'html:pre'");
80 shouldBe("element.localName", "'pre'");
81 shouldBe("element.namespaceURI", "'http://www.w3.org/1999/xhtml'");
82 shouldBe("element.prefix", "'html'");
83 shouldBe("element.nodeValue", "null");
84 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
85
86 debug("SVG Element creation using createElementNS on an HTML doc:")
87 element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
88 shouldBe("element.nodeName", "'svg'");
89 shouldBe("element.localName", "'svg'");
90 shouldBe("element.namespaceURI", "'http://www.w3.org/2000/svg'");
91 shouldBe("element.prefix", "null");
92 shouldBe("element.nodeValue", "null");
93 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
94
95 debug("Unknown Element creation using createElementNS on an HTML doc:")
96 element = document.createElementNS("http://www.webkit.org", "foo:svg");
97 shouldBe("element.nodeName", "'foo:svg'");
98 shouldBe("element.localName", "'svg'");
99 shouldBe("element.namespaceURI", "'http://www.webkit.org'");
100 shouldBe("element.prefix", "'foo'");
101 shouldBe("element.nodeValue", "null");
102 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
103
104 debug("Element creation using createElementNS on an HTML doc:")
105 element = document.createElementNS("http://www.w3.org/1999/xhtml", "pre");
106 // Spec: http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-104682815 (element.tagName)
107 // FF and Opera returns "pre" for nodeName as it is an XHTML element, WebKit returns "PRE".
108 shouldBe("element.nodeName", "'pre'");
109 shouldBe("element.localName", "'pre'");
110 shouldBe("element.namespaceURI", "'http://www.w3.org/1999/xhtml'");
111 shouldBe("element.prefix", "null");
112 shouldBe("element.nodeValue", "null");
113 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
114
115 debug("Element creation using createElement on an XHTML doc:")
116 element = xmlDoc.createElement("pre");
117 shouldBe("element.nodeName", "'pre'");
118 shouldBe("element.localName", "null");
119 // FF returns null for namespaceURI, WebKit returns http://www.w3.org/1999/xhtml, the spec says we should return null
120 shouldBe("element.namespaceURI", "null");
121 shouldBe("element.prefix", "null");
122 shouldBe("element.nodeValue", "null");
123 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
124
125 debug("Element creation using createElementNS on an XHTML doc:")
126 element = xmlDoc.createElementNS("http://www.w3.org/1999/xhtml", "html:pre");
127 shouldBe("element.nodeName", "'html:pre'");
128 shouldBe("element.localName", "'pre'");
129 shouldBe("element.namespaceURI", "'http://www.w3.org/1999/xhtml'");
130 shouldBe("element.prefix", "'html'");
131 shouldBe("element.nodeValue", "null");
132 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'");
133
134 debug("Processing instruction creation using createProcessingInstruction on an HTML doc:")
135 var processingInstruction = document.createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="missing.xsl"');
136 shouldBe("processingInstruction.nodeName", "'xml-stylesheet'");
137 shouldBe("processingInstruction.localName", "null");
138 shouldBe("processingInstruction.namespaceURI", "null");
139 // DOM Core Level 2 and DOM Core Level 3 disagree on ProcessingInstruction.nodeValue
140 // L2: entire content excluding the target
141 // L3: same as ProcessingInstruction.data
142 // We're following Level 3
143 shouldBe("processingInstruction.nodeValue", "'type=\"text/xsl\" href=\"missing.xsl\"'");
144 shouldBe("processingInstruction.target", "'xml-stylesheet'");
145 shouldBe("processingInstruction.data", "'type=\"text/xsl\" href=\"missing.xsl\"'");
146
147 debug("Processing instruction creation using createProcessingInstruction on an XHTML doc:")
148 processingInstruction = xmlDoc.createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="missing.xsl"');
149 shouldBe("processingInstruction.nodeName", "'xml-stylesheet'");
150 shouldBe("processingInstruction.localName", "null");
151 shouldBe("processingInstruction.namespaceURI", "null");
152 shouldBe("processingInstruction.nodeValue", "'type=\"text/xsl\" href=\"missing.xsl\"'");
153 shouldBe("processingInstruction.target", "'xml-stylesheet'");
154 shouldBe("processingInstruction.data", "'type=\"text/xsl\" href=\"missing.xsl\"'");
155
156 debug("Text node creation using createTextNode on an HTML doc:")
157 var text = document.createTextNode("foo");
158 shouldBe("text.nodeName", "'#text'");
159 shouldBe("text.localName", "null");
160 shouldBe("text.namespaceURI", "null");
161 shouldBe("text.nodeValue", "'foo'");
162 shouldBe("text.data", "'foo'");