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
|
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Node.isEqualNode</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"/>
<script>
function testNullHandling(node) {
test(function() {
assert_false(node.isEqualNode(null))
assert_false(node.isEqualNode(undefined))
})
}
[
document.createElement("foo"),
document.createTextNode("foo"),
document.createProcessingInstruction("foo", "bar"),
document.createComment("foo"),
document,
document.implementation.createDocumentType("html", "", ""),
document.createDocumentFragment()
].forEach(testNullHandling)
test(function() {
var a = document.createElement("foo")
a.setAttribute("a", "bar")
a.setAttribute("b", "baz")
var b = document.createElement("foo")
b.setAttribute("b", "baz")
b.setAttribute("a", "bar")
assert_true(a.isEqualNode(b))
}, "isEqualNode should return true when the attributes are in a different order")
test(function() {
var a = document.createElementNS("ns", "prefix:foo")
var b = document.createElementNS("ns", "prefix:foo")
assert_true(a.isEqualNode(b))
}, "isEqualNode should return true if elements have same namespace, prefix, and local name")
test(function() {
var a = document.createElementNS("ns1", "prefix:foo")
var b = document.createElementNS("ns2", "prefix:foo")
assert_false(a.isEqualNode(b))
}, "isEqualNode should return false if elements have different namespace")
test(function() {
var a = document.createElementNS("ns", "prefix1:foo")
var b = document.createElementNS("ns", "prefix2:foo")
assert_false(a.isEqualNode(b))
}, "isEqualNode should return false if elements have different prefix")
test(function() {
var a = document.createElementNS("ns", "prefix:foo1")
var b = document.createElementNS("ns", "prefix:foo2")
assert_false(a.isEqualNode(b))
}, "isEqualNode should return false if elements have different local name")
test(function() {
var a = document.createElement("foo")
a.setAttributeNS("ns", "x:a", "bar")
var b = document.createElement("foo")
b.setAttributeNS("ns", "y:a", "bar")
assert_true(a.isEqualNode(b))
}, "isEqualNode should return true when the attributes have different prefixes")
var internalSubset = async_test("isEqualNode should return true when only the internal subsets of DocumentTypes differ.")
var wait = 2;
function iframeLoaded() {
if (!--wait) {
internalSubset.step(function() {
var doc1 = document.getElementById("subset1").contentDocument
var doc2 = document.getElementById("subset2").contentDocument
assert_true(doc1.doctype.isEqualNode(doc2.doctype), "doc1.doctype.isEqualNode(doc2.doctype)")
assert_true(doc1.isEqualNode(doc2), "doc1.isEqualNode(doc2)")
})
internalSubset.done()
}
}
</script>
<iframe id="subset1" onload="iframeLoaded()" src="Node-isEqualNode-iframe1.xml" />
<iframe id="subset2" onload="iframeLoaded()" src="Node-isEqualNode-iframe2.xml" />
</body>
</html>
|