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 shouldBe("attr.attributes", "null"); 17 18 debug("Attribute creation using createElementNS on an HTML doc:") 19 attr = document.createAttributeNS("http://www.example.com", "example:foo"); 20 shouldBe("attr.nodeName", "'example:foo'"); 21 shouldBe("attr.name", "'example:foo'"); 22 shouldBe("attr.localName", "'foo'"); 23 shouldBe("attr.namespaceURI", "'http://www.example.com'"); 24 shouldBe("attr.prefix", "'example'"); 25 shouldBe("attr.nodeValue", "''"); 26 shouldBe("attr.value", "''"); 27 shouldBe("attr.attributes", "null"); 28 29 debug("Attribute creation using createElement on an XHTML doc:") 30 attr = xmlDoc.createAttribute("foo"); 31 shouldBe("attr.nodeName", "'foo'"); 32 shouldBe("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 35 shouldBe("attr.localName", "null"); 36 shouldBe("attr.namespaceURI", "null"); 37 shouldBe("attr.prefix", "null"); 38 shouldBe("attr.nodeValue", "''"); 39 shouldBe("attr.value", "''"); 40 shouldBe("attr.attributes", "null"); 41 42 debug("Attribute creation using createElementNS on an XHTML doc:") 43 attr = xmlDoc.createAttributeNS("http://www.example.com", "example:foo"); 44 shouldBe("attr.nodeName", "'example:foo'"); 45 shouldBe("attr.name", "'example:foo'"); 46 shouldBe("attr.localName", "'foo'"); 47 shouldBe("attr.namespaceURI", "'http://www.example.com'"); 48 shouldBe("attr.prefix", "'example'"); 49 shouldBe("attr.nodeValue", "''"); 50 shouldBe("attr.value", "''"); 51 shouldBe("attr.attributes", "null"); 52 53 var comment = document.createComment("foo"); 54 shouldBe("comment.nodeName", "'#comment'"); 55 shouldBe("comment.localName", "null"); 56 shouldBe("comment.namespaceURI", "null"); 57 shouldBe("comment.prefix", "null"); 58 shouldBe("comment.nodeValue", "'foo'"); 59 shouldBe("comment.data", "'foo'"); 60 shouldBe("comment.attributes", "null"); 61 62 shouldThrow("document.createCDATASection('foo')"); 63 var cdata = xmlDoc.createCDATASection("foo"); 64 shouldBe("cdata.nodeName", "'#cdata-section'"); 65 shouldBe("cdata.localName", "null"); 66 shouldBe("cdata.namespaceURI", "null"); 67 shouldBe("cdata.prefix", "null"); 68 shouldBe("cdata.nodeValue", "'foo'"); 69 shouldBe("cdata.data", "'foo'"); 70 shouldBe("cdata.attributes", "null"); 71 72 var fragment = document.createDocumentFragment(); 73 shouldBe("fragment.nodeName", "'#document-fragment'"); 74 shouldBe("fragment.localName", "null"); 75 shouldBe("fragment.namespaceURI", "null"); 76 shouldBe("fragment.prefix", "null"); 77 shouldBe("fragment.nodeValue", "null"); 78 shouldBe("fragment.attributes", "null"); 79 80 var doc = document.implementation.createDocument("http://www.w3.org/1999/xhtml", "html", null); 81 shouldBe("doc.nodeName", "'#document'"); 82 shouldBe("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 85 shouldBe("doc.namespaceURI", "'http://www.w3.org/1999/xhtml'"); 86 shouldBe("doc.prefix", "null"); 87 shouldBe("doc.nodeValue", "null"); 88 shouldBe("doc.attributes", "null"); 89 90 var doctype = document.implementation.createDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"); 91 shouldBe("doctype.nodeName", "'svg'"); 92 shouldBe("doctype.name", "'svg'"); 93 shouldBe("doctype.localName", "null"); 94 shouldBe("doctype.namespaceURI", "null"); 95 shouldBe("doctype.prefix", "null"); 96 shouldBe("doctype.nodeValue", "null"); 97 shouldBe("doctype.attributes", "null"); 98 99 debug("Element creation using createElement on an HTML doc:") 100 var element = document.createElement("pre"); 101 shouldBe("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 104 shouldBe("element.localName", "null"); 105 // FF returns null for namespaceURI, WebKit returns http://www.w3.org/1999/xhtml, the spec says we should return null 106 shouldBe("element.namespaceURI", "null"); 107 shouldBe("element.prefix", "null"); 108 shouldBe("element.nodeValue", "null"); 109 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); 110 111 debug("Prefixed element creation using createElementNS on an HTML doc:") 112 element = document.createElementNS("http://www.w3.org/1999/xhtml", "html:pre"); 113 shouldBe("element.nodeName", "'html:pre'"); 114 shouldBe("element.localName", "'pre'"); 115 shouldBe("element.namespaceURI", "'http://www.w3.org/1999/xhtml'"); 116 shouldBe("element.prefix", "'html'"); 117 shouldBe("element.nodeValue", "null"); 118 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); 119 120 debug("SVG Element creation using createElementNS on an HTML doc:") 121 element = document.createElementNS("http://www.w3.org/2000/svg", "svg"); 122 shouldBe("element.nodeName", "'svg'"); 123 shouldBe("element.localName", "'svg'"); 124 shouldBe("element.namespaceURI", "'http://www.w3.org/2000/svg'"); 125 shouldBe("element.prefix", "null"); 126 shouldBe("element.nodeValue", "null"); 127 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); 128 129 debug("Unknown Element creation using createElementNS on an HTML doc:") 130 element = document.createElementNS("http://www.webkit.org", "foo:svg"); 131 shouldBe("element.nodeName", "'foo:svg'"); 132 shouldBe("element.localName", "'svg'"); 133 shouldBe("element.namespaceURI", "'http://www.webkit.org'"); 134 shouldBe("element.prefix", "'foo'"); 135 shouldBe("element.nodeValue", "null"); 136 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); 137 138 debug("Element creation using createElementNS on an HTML doc:") 139 element = 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". 142 shouldBe("element.nodeName", "'pre'"); 143 shouldBe("element.localName", "'pre'"); 144 shouldBe("element.namespaceURI", "'http://www.w3.org/1999/xhtml'"); 145 shouldBe("element.prefix", "null"); 146 shouldBe("element.nodeValue", "null"); 147 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); 148 149 debug("Element creation using createElement on an XHTML doc:") 150 element = xmlDoc.createElement("pre"); 151 shouldBe("element.nodeName", "'pre'"); 152 shouldBe("element.localName", "null"); 153 // FF returns null for namespaceURI, WebKit returns http://www.w3.org/1999/xhtml, the spec says we should return null 154 shouldBe("element.namespaceURI", "null"); 155 shouldBe("element.prefix", "null"); 156 shouldBe("element.nodeValue", "null"); 157 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); 158 159 debug("Element creation using createElementNS on an XHTML doc:") 160 element = xmlDoc.createElementNS("http://www.w3.org/1999/xhtml", "html:pre"); 161 shouldBe("element.nodeName", "'html:pre'"); 162 shouldBe("element.localName", "'pre'"); 163 shouldBe("element.namespaceURI", "'http://www.w3.org/1999/xhtml'"); 164 shouldBe("element.prefix", "'html'"); 165 shouldBe("element.nodeValue", "null"); 166 shouldBe("element.attributes.toString()", "'[object NamedNodeMap]'"); 167 168 // Not possible to create Entity nodes via the DOM, WebKit doesn't create them from parsing 169 170 shouldThrow("document.createEntityReference('gt')"); 171 var entityReference = xmlDoc.createEntityReference("gt"); 172 shouldBe("entityReference.nodeName", "'gt'"); 173 shouldBe("entityReference.localName", "null"); 174 shouldBe("entityReference.namespaceURI", "null"); 175 shouldBe("entityReference.prefix", "null"); 176 shouldBe("entityReference.nodeValue", "null"); 177 shouldBe("entityReference.attributes", "null"); 178 179 // Not possible to create Notation nodes via the DOM, WebKit doesn't create them from parsing 180 181 shouldThrow("document.createProcessingInstruction('xml-stylesheet', 'type=\"text/xsl\" href=\"missing.xsl\"')"); 182 var processingInstruction = xmlDoc.createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="missing.xsl"'); 183 shouldBe("processingInstruction.nodeName", "'xml-stylesheet'"); 184 shouldBe("processingInstruction.localName", "null"); 185 shouldBe("processingInstruction.namespaceURI", "null"); 186 shouldBe("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 191 shouldBe("processingInstruction.nodeValue", "'type=\"text/xsl\" href=\"missing.xsl\"'"); 192 shouldBe("processingInstruction.attributes", "null"); 193 shouldBe("processingInstruction.target", "'xml-stylesheet'"); 194 shouldBe("processingInstruction.data", "'type=\"text/xsl\" href=\"missing.xsl\"'"); 195 196 var text = document.createTextNode("foo"); 197 shouldBe("text.nodeName", "'#text'"); 198 shouldBe("text.localName", "null"); 199 shouldBe("text.namespaceURI", "null"); 200 shouldBe("text.prefix", "null"); 201 shouldBe("text.nodeValue", "'foo'"); 202 shouldBe("text.data", "'foo'"); 203 shouldBe("text.attributes", "null"); 204 205 var successfullyParsed = true; 206