diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs index 37b75688c2b..8c0f9bd61ee 100644 --- a/components/script/dom/domimplementation.rs +++ b/components/script/dom/domimplementation.rs @@ -12,7 +12,7 @@ use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root}; use dom::bindings::reflector::{Reflector, reflect_dom_object}; -use dom::bindings::xmlname::validate_qualified_name; +use dom::bindings::xmlname::{validate_qualified_name, namespace_from_domstring}; use dom::document::DocumentSource; use dom::document::{Document, IsHTMLDocument}; use dom::documenttype::DocumentType; @@ -62,19 +62,26 @@ impl DOMImplementationMethods for DOMImplementation { // https://dom.spec.whatwg.org/#dom-domimplementation-createdocument fn CreateDocument(&self, - namespace: Option, + maybe_namespace: Option, qname: DOMString, maybe_doctype: Option<&DocumentType>) -> Fallible> { let win = self.document.window(); let loader = DocumentLoader::new(&self.document.loader()); + let namespace = namespace_from_domstring(maybe_namespace.to_owned()); + + let content_type = match namespace { + ns!(html) => "application/xhtml+xml", + ns!(svg) => "image/svg+xml", + _ => "application/xml" + }; // Step 1. let doc = XMLDocument::new(win, None, None, IsHTMLDocument::NonHTMLDocument, - None, + Some(DOMString::from(content_type)), None, DocumentSource::NotFromParser, loader); @@ -82,7 +89,7 @@ impl DOMImplementationMethods for DOMImplementation { let maybe_elem = if qname.is_empty() { None } else { - match doc.upcast::().CreateElementNS(namespace, qname) { + match doc.upcast::().CreateElementNS(maybe_namespace, qname) { Err(error) => return Err(error), Ok(elem) => Some(elem), } diff --git a/tests/wpt/metadata/dom/nodes/DOMImplementation-createDocument.html.ini b/tests/wpt/metadata/dom/nodes/DOMImplementation-createDocument.html.ini deleted file mode 100644 index 6ee786f53be..00000000000 --- a/tests/wpt/metadata/dom/nodes/DOMImplementation-createDocument.html.ini +++ /dev/null @@ -1,9 +0,0 @@ -[DOMImplementation-createDocument.html] - type: testharness - bug: https://github.com/servo/servo/issues/10743 - [createDocument test 179: metadata for "http://www.w3.org/1999/xhtml","",null] - expected: FAIL - - [createDocument test 180: metadata for "http://www.w3.org/2000/svg","",null] - expected: FAIL - diff --git a/tests/wpt/web-platform-tests/dom/nodes/DOMImplementation-createDocument.html b/tests/wpt/web-platform-tests/dom/nodes/DOMImplementation-createDocument.html index a982f23d861..d64bf3640d7 100644 --- a/tests/wpt/web-platform-tests/dom/nodes/DOMImplementation-createDocument.html +++ b/tests/wpt/web-platform-tests/dom/nodes/DOMImplementation-createDocument.html @@ -123,7 +123,7 @@ test(function() { var doc = document.implementation.createDocument(namespace, qualifiedName, doctype) assert_equals(doc.compatMode, "CSS1Compat") assert_equals(doc.characterSet, "UTF-8") - assert_equals(doc.contentType, namespace == htmlNamespace ? "text/html" + assert_equals(doc.contentType, namespace == htmlNamespace ? "application/xhtml+xml" : namespace == svgNamespace ? "image/svg+xml" : "application/xml") assert_equals(doc.URL, "about:blank") diff --git a/tests/wpt/web-platform-tests/dom/nodes/Document-contentType/contentType/createDocument.html b/tests/wpt/web-platform-tests/dom/nodes/Document-contentType/contentType/createDocument.html index 1e4a22d712a..78a952de4a2 100644 --- a/tests/wpt/web-platform-tests/dom/nodes/Document-contentType/contentType/createDocument.html +++ b/tests/wpt/web-platform-tests/dom/nodes/Document-contentType/contentType/createDocument.html @@ -1,11 +1,11 @@ -document.implementation.createDocument: document.contentType === 'application/xml' +document.implementation.createDocument: document.contentType === 'application/xhtml+xml'