OLD | NEW |
(Empty) | |
| 1 function test_getElementsByTagNameNS(context, element) { |
| 2 test(function() { |
| 3 assert_false(context.getElementsByTagNameNS("http://www.w3.org/1999/xhtml",
"html") instanceof NodeList, "NodeList") |
| 4 assert_true(context.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "
html") instanceof HTMLCollection, "HTMLCollection") |
| 5 var firstCollection = context.getElementsByTagNameNS("http://www.w3.org/1999
/xhtml", "html"), |
| 6 secondCollection = context.getElementsByTagNameNS("http://www.w3.org/199
9/xhtml", "html") |
| 7 assert_true(firstCollection !== secondCollection || firstCollection === seco
ndCollection, |
| 8 "Caching is allowed.") |
| 9 }) |
| 10 |
| 11 test(function() { |
| 12 var t = element.appendChild(document.createElementNS("test", "body")) |
| 13 this.add_cleanup(function() {element.removeChild(t)}) |
| 14 var actual = context.getElementsByTagNameNS("*", "body"); |
| 15 var expected = []; |
| 16 var get_elements = function(node) { |
| 17 for (var i = 0; i < node.childNodes.length; i++) { |
| 18 var child = node.childNodes[i]; |
| 19 if (child.nodeType === child.ELEMENT_NODE) { |
| 20 if (child.localName == "body") { |
| 21 expected.push(child); |
| 22 } |
| 23 get_elements(child); |
| 24 } |
| 25 } |
| 26 } |
| 27 get_elements(context); |
| 28 assert_array_equals(actual, expected); |
| 29 }, "getElementsByTagNameNS('*', 'body')") |
| 30 |
| 31 test(function() { |
| 32 assert_array_equals(context.getElementsByTagNameNS("", "*"), []); |
| 33 var t = element.appendChild(document.createElementNS("", "body")) |
| 34 this.add_cleanup(function() {element.removeChild(t)}) |
| 35 assert_array_equals(context.getElementsByTagNameNS("", "*"), [t]); |
| 36 }, "Empty string namespace") |
| 37 |
| 38 test(function() { |
| 39 var t = element.appendChild(document.createElementNS("test", "body")) |
| 40 this.add_cleanup(function() {element.removeChild(t)}) |
| 41 assert_array_equals(context.getElementsByTagNameNS("test", "body"), [t]); |
| 42 }, "body element in test namespace, no prefix") |
| 43 |
| 44 test(function() { |
| 45 var t = element.appendChild(document.createElementNS("test", "test:body")) |
| 46 this.add_cleanup(function() {element.removeChild(t)}) |
| 47 assert_array_equals(context.getElementsByTagNameNS("test", "body"), [t]); |
| 48 }, "body element in test namespace, prefix") |
| 49 |
| 50 test(function() { |
| 51 var t = element.appendChild(document.createElementNS("test", "BODY")) |
| 52 this.add_cleanup(function() {element.removeChild(t)}) |
| 53 assert_array_equals(context.getElementsByTagNameNS("test", "BODY"), [t]); |
| 54 assert_array_equals(context.getElementsByTagNameNS("test", "body"), []); |
| 55 }, "BODY element in test namespace, no prefix") |
| 56 |
| 57 test(function() { |
| 58 var t = element.appendChild(document.createElementNS("http://www.w3.org/1999
/xhtml", "abc")) |
| 59 this.add_cleanup(function() {element.removeChild(t)}) |
| 60 assert_array_equals(context.getElementsByTagNameNS("http://www.w3.org/1999/x
html", "abc"), [t]); |
| 61 assert_array_equals(context.getElementsByTagNameNS("http://www.w3.org/1999/x
html", "ABC"), []); |
| 62 assert_array_equals(context.getElementsByTagNameNS("test", "ABC"), []); |
| 63 }, "abc element in html namespace") |
| 64 |
| 65 test(function() { |
| 66 var t = element.appendChild(document.createElementNS("http://www.w3.org/1999
/xhtml", "ABC")) |
| 67 this.add_cleanup(function() {element.removeChild(t)}) |
| 68 assert_array_equals(context.getElementsByTagNameNS("http://www.w3.org/1999/x
html", "abc"), []); |
| 69 assert_array_equals(context.getElementsByTagNameNS("http://www.w3.org/1999/x
html", "ABC"), [t]); |
| 70 }, "ABC element in html namespace") |
| 71 |
| 72 test(function() { |
| 73 var t = element.appendChild(document.createElementNS("http://www.w3.org/1999
/xhtml", "AÇ")) |
| 74 this.add_cleanup(function() {element.removeChild(t)}) |
| 75 assert_array_equals(context.getElementsByTagNameNS("http://www.w3.org/1999/x
html", "AÇ"), [t]); |
| 76 assert_array_equals(context.getElementsByTagNameNS("test", "aÇ"), []); |
| 77 assert_array_equals(context.getElementsByTagNameNS("test", "aç"), []); |
| 78 }, "AÇ, case sensitivity") |
| 79 |
| 80 test(function() { |
| 81 var t = element.appendChild(document.createElementNS("test", "test:BODY")) |
| 82 this.add_cleanup(function() {element.removeChild(t)}) |
| 83 assert_array_equals(context.getElementsByTagNameNS("test", "BODY"), [t]); |
| 84 assert_array_equals(context.getElementsByTagNameNS("test", "body"), []); |
| 85 }, "BODY element in test namespace, prefix") |
| 86 |
| 87 test(function() { |
| 88 var t = element.appendChild(document.createElementNS("test", "test:test")) |
| 89 this.add_cleanup(function() {element.removeChild(t)}) |
| 90 var actual = context.getElementsByTagNameNS("http://www.w3.org/1999/xhtml",
"*"); |
| 91 var expected = []; |
| 92 var get_elements = function(node) { |
| 93 for (var i = 0; i < node.childNodes.length; i++) { |
| 94 var child = node.childNodes[i]; |
| 95 if (child.nodeType === child.ELEMENT_NODE) { |
| 96 if (child !== t) { |
| 97 expected.push(child); |
| 98 } |
| 99 get_elements(child); |
| 100 } |
| 101 } |
| 102 } |
| 103 get_elements(context); |
| 104 assert_array_equals(actual, expected); |
| 105 }, "getElementsByTagNameNS('http://www.w3.org/1999/xhtml', '*')") |
| 106 |
| 107 test(function() { |
| 108 var actual = context.getElementsByTagNameNS("*", "*"); |
| 109 var expected = []; |
| 110 var get_elements = function(node) { |
| 111 for (var i = 0; i < node.childNodes.length; i++) { |
| 112 var child = node.childNodes[i]; |
| 113 if (child.nodeType === child.ELEMENT_NODE) { |
| 114 expected.push(child); |
| 115 get_elements(child); |
| 116 } |
| 117 } |
| 118 } |
| 119 get_elements(context); |
| 120 assert_array_equals(actual, expected); |
| 121 }, "getElementsByTagNameNS('*', '*')") |
| 122 |
| 123 test(function() { |
| 124 assert_array_equals(context.getElementsByTagNameNS("**", "*"), []); |
| 125 assert_array_equals(context.getElementsByTagNameNS(null, "0"), []); |
| 126 assert_array_equals(context.getElementsByTagNameNS(null, "div"), []); |
| 127 }, "Empty lists") |
| 128 } |
OLD | NEW |