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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
<!DOCTYPE html>
<html>
<head>
<title>LookupNamespaceURI and IsDefaultNamespace tests</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
</head>
<body>
<h1>LookupNamespaceURI and IsDefaultNamespace</h1>
<div id="log"/>
<script>
function lookupNamespaceURI(node, prefix, expected, name) {
test(function() {
assert_equals(node.lookupNamespaceURI(prefix), expected);
}, name);
}
function isDefaultNamespace(node, namespace, expected, name) {
test(function() {
assert_equals(node.isDefaultNamespace(namespace), expected);
}, name);
}
var frag = document.createDocumentFragment();
lookupNamespaceURI(frag, null, null, 'DocumentFragment should have null namespace, prefix null');
lookupNamespaceURI(frag, '', null, 'DocumentFragment should have null namespace, prefix ""');
lookupNamespaceURI(frag, 'foo', null, 'DocumentFragment should have null namespace, prefix "foo"');
lookupNamespaceURI(frag, 'xml', null, 'DocumentFragment should have null namespace, prefix "xml"');
lookupNamespaceURI(frag, 'xmlns', null, 'DocumentFragment should have null namespace, prefix "xmlns"');
isDefaultNamespace(frag, null, true, 'DocumentFragment is in default namespace, prefix null');
isDefaultNamespace(frag, '', true, 'DocumentFragment is in default namespace, prefix ""');
isDefaultNamespace(frag, 'foo', false, 'DocumentFragment is in default namespace, prefix "foo"');
isDefaultNamespace(frag, 'xmlns', false, 'DocumentFragment is in default namespace, prefix "xmlns"');
var docType = document.doctype;
lookupNamespaceURI(docType, null, null, 'DocumentType should have null namespace, prefix null');
lookupNamespaceURI(docType, '', null, 'DocumentType should have null namespace, prefix ""');
lookupNamespaceURI(docType, 'foo', null, 'DocumentType should have null namespace, prefix "foo"');
lookupNamespaceURI(docType, 'xml', null, 'DocumentType should have null namespace, prefix "xml"');
lookupNamespaceURI(docType, 'xmlns', null, 'DocumentType should have null namespace, prefix "xmlns"');
isDefaultNamespace(docType, null, true, 'DocumentType is in default namespace, prefix null');
isDefaultNamespace(docType, '', true, 'DocumentType is in default namespace, prefix ""');
isDefaultNamespace(docType, 'foo', false, 'DocumentType is in default namespace, prefix "foo"');
isDefaultNamespace(docType, 'xmlns', false, 'DocumentType is in default namespace, prefix "xmlns"');
var fooElem = document.createElementNS('fooNamespace', 'prefix:elem');
fooElem.setAttribute('bar', 'value');
const XMLNS_NS = 'http://www.w3.org/2000/xmlns/';
const XML_NS = 'http://www.w3.org/XML/1998/namespace';
lookupNamespaceURI(fooElem, null, null, 'Element should have null namespace, prefix null');
lookupNamespaceURI(fooElem, '', null, 'Element should have null namespace, prefix ""');
lookupNamespaceURI(fooElem, 'fooNamespace', null, 'Element should not have namespace matching prefix with namespaceURI value');
lookupNamespaceURI(fooElem, 'xml', XML_NS, 'Element should have XML namespace');
lookupNamespaceURI(fooElem, 'xmlns', XMLNS_NS, 'Element should have XMLNS namespace');
lookupNamespaceURI(fooElem, 'prefix', 'fooNamespace', 'Element has namespace URI matching prefix');
isDefaultNamespace(fooElem, null, true, 'Empty namespace is not default, prefix null');
isDefaultNamespace(fooElem, '', true, 'Empty namespace is not default, prefix ""');
isDefaultNamespace(fooElem, 'fooNamespace', false, 'fooNamespace is not default');
isDefaultNamespace(fooElem, XMLNS_NS, false, 'xmlns namespace is not default');
fooElem.setAttributeNS(XMLNS_NS, 'xmlns:bar', 'barURI');
fooElem.setAttributeNS(XMLNS_NS, 'xmlns', 'bazURI');
lookupNamespaceURI(fooElem, null, 'bazURI', 'Element should have baz namespace, prefix null');
lookupNamespaceURI(fooElem, '', 'bazURI', 'Element should have baz namespace, prefix ""');
lookupNamespaceURI(fooElem, 'xmlns', XMLNS_NS, 'Element should have namespace with xmlns prefix');
lookupNamespaceURI(fooElem, 'bar', 'barURI', 'Element has bar namespace');
isDefaultNamespace(fooElem, null, false, 'Empty namespace is not default on fooElem, prefix null');
isDefaultNamespace(fooElem, '', false, 'Empty namespace is not default on fooElem, prefix ""');
isDefaultNamespace(fooElem, 'barURI', false, 'bar namespace is not default');
isDefaultNamespace(fooElem, 'bazURI', true, 'baz namespace is default');
var comment = document.createComment('comment');
fooElem.appendChild(comment);
lookupNamespaceURI(comment, null, 'bazURI', 'Comment should inherit baz namespace');
lookupNamespaceURI(comment, '', 'bazURI', 'Comment should inherit baz namespace');
lookupNamespaceURI(comment, 'prefix', 'fooNamespace', 'Comment should inherit namespace URI matching prefix');
lookupNamespaceURI(comment, 'bar', 'barURI', 'Comment should inherit bar namespace');
isDefaultNamespace(comment, null, false, 'For comment, empty namespace is not default, prefix null');
isDefaultNamespace(comment, '', false, 'For comment, empty namespace is not default, prefix ""');
isDefaultNamespace(comment, 'fooNamespace', false, 'For comment, fooNamespace is not default');
isDefaultNamespace(comment, XMLNS_NS, false, 'For comment, xmlns namespace is not default');
isDefaultNamespace(comment, 'barURI', false, 'For comment, inherited bar namespace is not default');
isDefaultNamespace(comment, 'bazURI', true, 'For comment, inherited baz namespace is default');
var fooChild = document.createElementNS('childNamespace', 'childElem');
fooElem.appendChild(fooChild);
lookupNamespaceURI(fooChild, null, 'childNamespace', 'Child element should inherit baz namespace');
lookupNamespaceURI(fooChild, '', 'childNamespace', 'Child element should have null namespace');
lookupNamespaceURI(fooChild, 'xmlns', XMLNS_NS, 'Child element should have XMLNS namespace');
lookupNamespaceURI(fooChild, 'prefix', 'fooNamespace', 'Child element has namespace URI matching prefix');
isDefaultNamespace(fooChild, null, false, 'Empty namespace is not default for child, prefix null');
isDefaultNamespace(fooChild, '', false, 'Empty namespace is not default for child, prefix ""');
isDefaultNamespace(fooChild, 'fooNamespace', false, 'fooNamespace is not default for child');
isDefaultNamespace(fooChild, XMLNS_NS, false, 'xmlns namespace is not default for child');
isDefaultNamespace(fooChild, 'barURI', false, 'bar namespace is not default for child');
isDefaultNamespace(fooChild, 'bazURI', false, 'baz namespace is default for child');
isDefaultNamespace(fooChild, 'childNamespace', true, 'childNamespace is default for child');
document.documentElement.setAttributeNS(XMLNS_NS, 'xmlns:bar', 'barURI');
document.documentElement.setAttributeNS(XMLNS_NS, 'xmlns', 'bazURI');
lookupNamespaceURI(document, null, 'http://www.w3.org/1999/xhtml', 'Document should have xhtml namespace, prefix null');
lookupNamespaceURI(document, '', 'http://www.w3.org/1999/xhtml', 'Document should have xhtml namespace, prefix ""');
lookupNamespaceURI(document, 'prefix', null, 'Document has no namespace URI matching prefix');
lookupNamespaceURI(document, 'bar', 'barURI', 'Document has bar namespace');
isDefaultNamespace(document, null, false, 'For document, empty namespace is not default, prefix null');
isDefaultNamespace(document, '', false, 'For document, empty namespace is not default, prefix ""');
isDefaultNamespace(document, 'fooNamespace', false, 'For document, fooNamespace is not default');
isDefaultNamespace(document, XMLNS_NS, false, 'For document, xmlns namespace is not default');
isDefaultNamespace(document, 'barURI', false, 'For document, bar namespace is not default');
isDefaultNamespace(document, 'bazURI', false, 'For document, baz namespace is not default');
isDefaultNamespace(document, 'http://www.w3.org/1999/xhtml', true, 'For document, xhtml namespace is default');
const doc = new Document();
lookupNamespaceURI(doc, 'xml', null, 'Document without documentElement has no namespace URI matching "xml"');
lookupNamespaceURI(doc, 'xmlns', null, 'Document without documentElement has no namespace URI matching "xmlns"');
const attr = document.createAttribute('foo');
lookupNamespaceURI(attr, 'xml', null, 'Disconnected Attr has no namespace URI matching "xml"');
lookupNamespaceURI(attr, 'xmlns', null, 'Disconnected Attr has no namespace URI matching "xmlns"');
document.body.setAttributeNode(attr);
lookupNamespaceURI(attr, 'xml', XML_NS, 'Connected Attr has namespace URI matching "xml"');
lookupNamespaceURI(attr, 'xmlns', XMLNS_NS, 'Connected Attr no namespace URI matching "xmlns"');
var comment = document.createComment('comment');
document.appendChild(comment);
lookupNamespaceURI(comment, 'bar', null, 'Comment does not have bar namespace');
</script>
</body>
</html>
|