| OLD | NEW |
| (Empty) | |
| 1 <!doctype html> |
| 2 <title>document.createElement() namespace tests</title> |
| 3 <link rel=author title="Aryeh Gregor" href=ayg@aryeh.name> |
| 4 <div id=log></div> |
| 5 <script src=/resources/testharness.js></script> |
| 6 <script src=/resources/testharnessreport.js></script> |
| 7 <script> |
| 8 "use strict"; |
| 9 /** |
| 10 * This tests the namespace of elements created by the Document interface's |
| 11 * createElement() method. See bug: |
| 12 * https://www.w3.org/Bugs/Public/show_bug.cgi?id=19431 |
| 13 */ |
| 14 |
| 15 /** |
| 16 * Test that an element created using the Document object doc has the namespace |
| 17 * that would be expected for the given contentType. |
| 18 */ |
| 19 function testDoc(doc, contentType) { |
| 20 if (doc.contentType !== undefined) { |
| 21 // Sanity check |
| 22 assert_equals(doc.contentType, contentType, |
| 23 "Wrong MIME type returned from doc.contentType"); |
| 24 } |
| 25 |
| 26 var expectedNamespace = contentType == "text/html" || |
| 27 contentType == "application/xhtml+xml" |
| 28 ? "http://www.w3.org/1999/xhtml" : null; |
| 29 |
| 30 assert_equals(doc.createElement("x").namespaceURI, expectedNamespace); |
| 31 } |
| 32 |
| 33 // First test various objects we create in JS |
| 34 test(function() { |
| 35 testDoc(document, "text/html") |
| 36 }, "Created element's namespace in current document"); |
| 37 test(function() { |
| 38 testDoc(document.implementation.createHTMLDocument(""), "text/html"); |
| 39 }, "Created element's namespace in created HTML document"); |
| 40 test(function() { |
| 41 testDoc(document.implementation.createDocument(null, "", null), |
| 42 "application/xml"); |
| 43 }, "Created element's namespace in created XML document"); |
| 44 test(function() { |
| 45 testDoc(document.implementation.createDocument("http://www.w3.org/1999/xhtml",
"html", null), |
| 46 "application/xhtml+xml"); |
| 47 }, "Created element's namespace in created XHTML document"); |
| 48 test(function() { |
| 49 testDoc(document.implementation.createDocument("http://www.w3.org/2000/svg", "
svg", null), |
| 50 "image/svg+xml"); |
| 51 }, "Created element's namespace in created SVG document"); |
| 52 test(function() { |
| 53 testDoc(document.implementation.createDocument("http://www.w3.org/1998/Math/Ma
thML", "math", null), |
| 54 "application/xml"); |
| 55 }, "Created element's namespace in created MathML document"); |
| 56 |
| 57 // Second also test document created by DOMParser |
| 58 test(function() { |
| 59 testDoc(new DOMParser().parseFromString("", "text/html"), "text/html"); |
| 60 }, "Created element's namespace in created HTML document by DOMParser ('text/htm
l')"); |
| 61 test(function() { |
| 62 testDoc(new DOMParser().parseFromString("<root/>", "text/xml"), "text/xml"); |
| 63 }, "Created element's namespace in created XML document by DOMParser ('text/xml'
)"); |
| 64 test(function() { |
| 65 testDoc(new DOMParser().parseFromString("<root/>", "application/xml"), "applic
ation/xml"); |
| 66 }, "Created element's namespace in created XML document by DOMParser ('applicati
on/xml')"); |
| 67 test(function() { |
| 68 testDoc(new DOMParser().parseFromString("<html/>", "application/xhtml+xml"), "
application/xhtml+xml"); |
| 69 }, "Created element's namespace in created XHTML document by DOMParser ('applica
tion/xhtml+xml')"); |
| 70 test(function() { |
| 71 testDoc(new DOMParser().parseFromString("<math/>", "image/svg+xml"), "image/sv
g+xml"); |
| 72 }, "Created element's namespace in created SVG document by DOMParser ('image/svg
+xml')"); |
| 73 |
| 74 // Now for various externally-loaded files. Note: these lists must be kept |
| 75 // synced with the lists in generate.py in the subdirectory, and that script |
| 76 // must be run whenever the lists are updated. (We could keep the lists in a |
| 77 // shared JSON file, but it seems like too much effort.) |
| 78 var testExtensions = { |
| 79 html: "text/html", |
| 80 xhtml: "application/xhtml+xml", |
| 81 xml: "application/xml", |
| 82 svg: "image/svg+xml", |
| 83 // Was not able to get server MIME type working properly :( |
| 84 //mml: "application/mathml+xml", |
| 85 }; |
| 86 |
| 87 var tests = [ |
| 88 "empty", |
| 89 "minimal_html", |
| 90 |
| 91 "xhtml", |
| 92 "svg", |
| 93 "mathml", |
| 94 |
| 95 "bare_xhtml", |
| 96 "bare_svg", |
| 97 "bare_mathml", |
| 98 |
| 99 "xhtml_ns_removed", |
| 100 "xhtml_ns_changed", |
| 101 ]; |
| 102 |
| 103 tests.forEach(function(testName) { |
| 104 Object.keys(testExtensions).forEach(function(ext) { |
| 105 var iframe = document.createElement("iframe"); |
| 106 iframe.src = "Document-createElement-namespace-tests/" + |
| 107 testName + "." + ext; |
| 108 var t = async_test("Created element's namespace in " + testName + "." + ext)
; |
| 109 iframe.onload = function() { |
| 110 t.step(function() { |
| 111 testDoc(iframe.contentDocument, testExtensions[ext]); |
| 112 }); |
| 113 document.body.removeChild(iframe); |
| 114 t.done(); |
| 115 }; |
| 116 document.body.appendChild(iframe); |
| 117 }); |
| 118 }); |
| 119 </script> |
| OLD | NEW |