summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/selectors/nth-of-type-namespace.html
blob: f5d81a5df3ac1380749a075cb5588897d6816c58 (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
<!DOCTYPE html>
<title>CSS Selectors Test: :*-of-type with namespace</title>
<link rel="help" href="https://drafts.csswg.org/selectors/#typed-child-index">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
  [test-span]:nth-of-type(100) {
    color: green;
  }
</style>
<div id="container"></div>
<script>

  setup(() => {
    function appendSpans(parent) {
      for (let i = 0; i < 99; i++) {
        parent.appendChild(document.createElement("span"));
      }
      const test_span = document.createElement("span");
      test_span.setAttribute("test-span", "");
      parent.appendChild(test_span);
    }

    function appendSpansNS(parent, namespace) {
      for (let i = 0; i < 99; i++) {
        parent.appendChild(document.createElementNS(namespace, "span"));
      }
      const test_span = document.createElementNS(namespace, "span");
      test_span.setAttribute("test-span", "");
      parent.appendChild(test_span);
    }

    appendSpans(container);
    appendSpansNS(container, "http://dummy1/");
    appendSpansNS(container, "http://dummy2/");
  });

  const green = "rgb(0, 128, 0)";

  for (let span of container.querySelectorAll("[test-span]")) {
    test(() => {
      assert_equals(getComputedStyle(span).color, green,
                    "span with namespace: " + span.namespaceURI
                    + " should have a green color");
    }, ":nth-of-type selectors matching takes element namespace into account ("
       + span.namespaceURI + ")");
  }
</script>