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