summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/nodes/Document-Element-getElementsByTagNameNS.js
blob: a1bb3158745d6950d3dd332a1ad382a471cccf1f (plain)
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
function test_getElementsByTagNameNS(context, element) {
  test(function() {
    assert_false(context.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "html") instanceof NodeList, "NodeList")
    assert_true(context.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "html") instanceof HTMLCollection, "HTMLCollection")
    var firstCollection = context.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "html"),
        secondCollection = context.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "html")
    assert_true(firstCollection !== secondCollection || firstCollection === secondCollection,
                "Caching is allowed.")
  })

  test(function() {
    var t = element.appendChild(document.createElementNS("test", "body"))
    this.add_cleanup(function() {element.removeChild(t)})
    var actual = context.getElementsByTagNameNS("*", "body");
    var expected = [];
    var get_elements = function(node) {
      for (var i = 0; i < node.childNodes.length; i++) {
        var child = node.childNodes[i];
        if (child.nodeType === child.ELEMENT_NODE) {
          if (child.localName == "body") {
            expected.push(child);
          }
          get_elements(child);
        }
      }
    }
    get_elements(context);
    assert_array_equals(actual, expected);
  }, "getElementsByTagNameNS('*', 'body')")

  test(function() {
    assert_array_equals(context.getElementsByTagNameNS("", "*"), []);
    var t = element.appendChild(document.createElementNS("", "body"))
    this.add_cleanup(function() {element.removeChild(t)})
    assert_array_equals(context.getElementsByTagNameNS("", "*"), [t]);
  }, "Empty string namespace")

  test(function() {
    var t = element.appendChild(document.createElementNS("test", "body"))
    this.add_cleanup(function() {element.removeChild(t)})
    assert_array_equals(context.getElementsByTagNameNS("test", "body"), [t]);
  }, "body element in test namespace, no prefix")

  test(function() {
    var t = element.appendChild(document.createElementNS("test", "test:body"))
    this.add_cleanup(function() {element.removeChild(t)})
    assert_array_equals(context.getElementsByTagNameNS("test", "body"), [t]);
  }, "body element in test namespace, prefix")

  test(function() {
    var t = element.appendChild(document.createElementNS("test", "BODY"))
    this.add_cleanup(function() {element.removeChild(t)})
    assert_array_equals(context.getElementsByTagNameNS("test", "BODY"), [t]);
    assert_array_equals(context.getElementsByTagNameNS("test", "body"), []);
  }, "BODY element in test namespace, no prefix")

  test(function() {
    var t = element.appendChild(document.createElementNS("http://www.w3.org/1999/xhtml", "abc"))
    this.add_cleanup(function() {element.removeChild(t)})
    assert_array_equals(context.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "abc"), [t]);
    assert_array_equals(context.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "ABC"), []);
    assert_array_equals(context.getElementsByTagNameNS("test", "ABC"), []);
  }, "abc element in html namespace")

  test(function() {
    var t = element.appendChild(document.createElementNS("http://www.w3.org/1999/xhtml", "ABC"))
    this.add_cleanup(function() {element.removeChild(t)})
    assert_array_equals(context.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "abc"), []);
    assert_array_equals(context.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "ABC"), [t]);
  }, "ABC element in html namespace")

  test(function() {
    var t = element.appendChild(document.createElementNS("http://www.w3.org/1999/xhtml", "AÇ"))
    this.add_cleanup(function() {element.removeChild(t)})
    assert_array_equals(context.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "AÇ"), [t]);
    assert_array_equals(context.getElementsByTagNameNS("test", "aÇ"), []);
    assert_array_equals(context.getElementsByTagNameNS("test", "aç"), []);
  }, "AÇ, case sensitivity")

  test(function() {
    var t = element.appendChild(document.createElementNS("test", "test:BODY"))
    this.add_cleanup(function() {element.removeChild(t)})
    assert_array_equals(context.getElementsByTagNameNS("test", "BODY"), [t]);
    assert_array_equals(context.getElementsByTagNameNS("test", "body"), []);
  }, "BODY element in test namespace, prefix")

  test(function() {
    var t = element.appendChild(document.createElementNS("test", "test:test"))
    this.add_cleanup(function() {element.removeChild(t)})
    var actual = context.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "*");
    var expected = [];
    var get_elements = function(node) {
      for (var i = 0; i < node.childNodes.length; i++) {
        var child = node.childNodes[i];
        if (child.nodeType === child.ELEMENT_NODE) {
          if (child !== t) {
            expected.push(child);
          }
          get_elements(child);
        }
      }
    }
    get_elements(context);
    assert_array_equals(actual, expected);
  }, "getElementsByTagNameNS('http://www.w3.org/1999/xhtml', '*')")

  test(function() {
    var actual = context.getElementsByTagNameNS("*", "*");
    var expected = [];
    var get_elements = function(node) {
      for (var i = 0; i < node.childNodes.length; i++) {
        var child = node.childNodes[i];
        if (child.nodeType === child.ELEMENT_NODE) {
          expected.push(child);
          get_elements(child);
        }
      }
    }
    get_elements(context);
    assert_array_equals(actual, expected);
  }, "getElementsByTagNameNS('*', '*')")

  test(function() {
    assert_array_equals(context.getElementsByTagNameNS("**", "*"), []);
    assert_array_equals(context.getElementsByTagNameNS(null, "0"), []);
    assert_array_equals(context.getElementsByTagNameNS(null, "div"), []);
  }, "Empty lists")
}