OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset="utf-8"> |
| 3 <title>Node.prototype.isEqualNode</title> |
| 4 <link rel=help href="https://dom.spec.whatwg.org/#dom-node-isequalnode"> |
| 5 <script src="../../../../resources/testharness.js"></script> |
| 6 <script src="../../../../resources/testharnessreport.js"></script> |
| 7 |
| 8 <script> |
| 9 "use strict"; |
| 10 |
| 11 test(function() { |
| 12 |
| 13 var doctype1 = document.implementation.createDocumentType("qualifiedName", "pu
blicId", "systemId"); |
| 14 var doctype2 = document.implementation.createDocumentType("qualifiedName", "pu
blicId", "systemId"); |
| 15 var doctype3 = document.implementation.createDocumentType("qualifiedName2", "p
ublicId", "systemId"); |
| 16 var doctype4 = document.implementation.createDocumentType("qualifiedName", "pu
blicId2", "systemId"); |
| 17 var doctype5 = document.implementation.createDocumentType("qualifiedName", "pu
blicId", "systemId3"); |
| 18 |
| 19 assert_true(doctype1.isEqualNode(doctype1), "self-comparison"); |
| 20 assert_true(doctype1.isEqualNode(doctype2), "same properties"); |
| 21 assert_false(doctype1.isEqualNode(doctype3), "different name"); |
| 22 assert_false(doctype1.isEqualNode(doctype4), "different public ID"); |
| 23 assert_false(doctype1.isEqualNode(doctype5), "different system ID"); |
| 24 |
| 25 }, "doctypes should be compared on name, public ID, and system ID"); |
| 26 |
| 27 test(function() { |
| 28 |
| 29 var element1 = document.createElementNS("namespace", "prefix:localName"); |
| 30 var element2 = document.createElementNS("namespace", "prefix:localName"); |
| 31 var element3 = document.createElementNS("namespace2", "prefix:localName"); |
| 32 var element4 = document.createElementNS("namespace", "prefix2:localName"); |
| 33 var element5 = document.createElementNS("namespace", "prefix:localName2"); |
| 34 |
| 35 var element6 = document.createElementNS("namespace", "prefix:localName"); |
| 36 element6.setAttribute("foo", "bar"); |
| 37 |
| 38 assert_true(element1.isEqualNode(element1), "self-comparison"); |
| 39 assert_true(element1.isEqualNode(element2), "same properties"); |
| 40 assert_false(element1.isEqualNode(element3), "different namespace"); |
| 41 assert_false(element1.isEqualNode(element4), "different prefix"); |
| 42 assert_false(element1.isEqualNode(element5), "different local name"); |
| 43 assert_false(element1.isEqualNode(element6), "different number of attributes")
; |
| 44 |
| 45 }, "elements should be compared on namespace, namespace prefix, local name, and
number of attributes"); |
| 46 |
| 47 test(function() { |
| 48 |
| 49 var element1 = document.createElement("element"); |
| 50 element1.setAttributeNS("namespace", "prefix:localName", "value"); |
| 51 |
| 52 var element2 = document.createElement("element"); |
| 53 element2.setAttributeNS("namespace", "prefix:localName", "value"); |
| 54 |
| 55 var element3 = document.createElement("element"); |
| 56 element3.setAttributeNS("namespace2", "prefix:localName", "value"); |
| 57 |
| 58 var element4 = document.createElement("element"); |
| 59 element4.setAttributeNS("namespace", "prefix2:localName", "value"); |
| 60 |
| 61 var element5 = document.createElement("element"); |
| 62 element5.setAttributeNS("namespace", "prefix:localName2", "value"); |
| 63 |
| 64 var element6 = document.createElement("element"); |
| 65 element6.setAttributeNS("namespace", "prefix:localName", "value2"); |
| 66 |
| 67 assert_true(element1.isEqualNode(element1), "self-comparison"); |
| 68 assert_true(element1.isEqualNode(element2), "attribute with same properties"); |
| 69 assert_false(element1.isEqualNode(element3), "attribute with different namespa
ce"); |
| 70 assert_true(element1.isEqualNode(element4), "attribute with different prefix")
; |
| 71 assert_false(element1.isEqualNode(element5), "attribute with different local n
ame"); |
| 72 assert_false(element1.isEqualNode(element6), "attribute with different value")
; |
| 73 |
| 74 }, "elements should be compared on attribute namespace, local name, and value"); |
| 75 |
| 76 test(function() { |
| 77 |
| 78 var pi1 = document.createProcessingInstruction("target", "data"); |
| 79 var pi2 = document.createProcessingInstruction("target", "data"); |
| 80 var pi3 = document.createProcessingInstruction("target2", "data"); |
| 81 var pi4 = document.createProcessingInstruction("target", "data2"); |
| 82 |
| 83 assert_true(pi1.isEqualNode(pi1), "self-comparison"); |
| 84 assert_true(pi1.isEqualNode(pi2), "same properties"); |
| 85 assert_false(pi1.isEqualNode(pi3), "different target"); |
| 86 assert_false(pi1.isEqualNode(pi4), "different data"); |
| 87 |
| 88 }, "processing instructions should be compared on target and data"); |
| 89 |
| 90 test(function() { |
| 91 |
| 92 var text1 = document.createTextNode("data"); |
| 93 var text2 = document.createTextNode("data"); |
| 94 var text3 = document.createTextNode("data2"); |
| 95 |
| 96 assert_true(text1.isEqualNode(text1), "self-comparison"); |
| 97 assert_true(text1.isEqualNode(text2), "same properties"); |
| 98 assert_false(text1.isEqualNode(text3), "different data"); |
| 99 |
| 100 }, "text nodes should be compared on data"); |
| 101 |
| 102 test(function() { |
| 103 |
| 104 var comment1 = document.createComment("data"); |
| 105 var comment2 = document.createComment("data"); |
| 106 var comment3 = document.createComment("data2"); |
| 107 |
| 108 assert_true(comment1.isEqualNode(comment1), "self-comparison"); |
| 109 assert_true(comment1.isEqualNode(comment2), "same properties"); |
| 110 assert_false(comment1.isEqualNode(comment3), "different data"); |
| 111 |
| 112 }, "comments should be compared on data"); |
| 113 |
| 114 test(function() { |
| 115 |
| 116 var documentFragment1 = document.createDocumentFragment(); |
| 117 var documentFragment2 = document.createDocumentFragment(); |
| 118 |
| 119 assert_true(documentFragment1.isEqualNode(documentFragment1), "self-comparison
"); |
| 120 assert_true(documentFragment1.isEqualNode(documentFragment2), "same properties
"); |
| 121 |
| 122 }, "document fragments should not be compared based on properties"); |
| 123 |
| 124 test(function() { |
| 125 |
| 126 var document1 = document.implementation.createDocument("", ""); |
| 127 var document2 = document.implementation.createDocument("", ""); |
| 128 |
| 129 assert_true(document1.isEqualNode(document1), "self-comparison"); |
| 130 assert_true(document1.isEqualNode(document2), "another empty XML document"); |
| 131 |
| 132 var htmlDoctype = document.implementation.createDocumentType("html", "", ""); |
| 133 var document3 = document.implementation.createDocument("http://www.w3.org/1999
/xhtml", "html", htmlDoctype); |
| 134 document3.documentElement.appendChild(document3.createElement("head")); |
| 135 document3.documentElement.appendChild(document3.createElement("body")); |
| 136 var document4 = document.implementation.createHTMLDocument(); |
| 137 assert_true(document3.isEqualNode(document4), "default HTML documents, created
different ways"); |
| 138 |
| 139 }, "documents should not be compared based on properties"); |
| 140 |
| 141 test(function() { |
| 142 |
| 143 testDeepEquality(function() { return document.createElement("foo") }); |
| 144 testDeepEquality(function() { return document.createDocumentFragment() }); |
| 145 testDeepEquality(function() { return document.implementation.createDocument(""
, "") }); |
| 146 testDeepEquality(function() { return document.implementation.createHTMLDocumen
t() }); |
| 147 |
| 148 function testDeepEquality(parentFactory) { |
| 149 // Some ad-hoc tests of deep equality |
| 150 |
| 151 var parentA = parentFactory(); |
| 152 var parentB = parentFactory(); |
| 153 |
| 154 parentA.appendChild(document.createComment("data")); |
| 155 assert_false(parentA.isEqualNode(parentB)); |
| 156 parentB.appendChild(document.createComment("data")); |
| 157 assert_true(parentA.isEqualNode(parentB)); |
| 158 } |
| 159 |
| 160 }, "node equality testing should test descendant equality too"); |
| 161 </script> |
OLD | NEW |