File: test_CSSStyleRule_querySelectorAll.html

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (121 lines) | stat: -rw-r--r-- 3,866 bytes parent folder | download | duplicates (13)
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
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Test CSSStyleRule::QuerySelectorAll</title>
    <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
    <style>
      .test-simple {
      }
      .test-nested-parent {
        .test-nested-child {
          .test-nested-and-non-nested {
          }
        }
      }
      .test-nested-and-non-nested {
      }
      .test-no-match {
      }
    </style>
    <script>
      SimpleTest.waitForExplicitFinish();
      addLoadEvent(doTest);

      function doTest() {
        let { cssRules } = document.styleSheets[1];

        info("Testing simple case");
        let rule = cssRules[0];
        let result = rule.querySelectorAll(document);
        is(result.length, 2, `2 elements are matching "${rule.selectorText}"`);
        is(
          result[0].id,
          "a",
          `Got expected id for first element matching "${rule.selectorText}"`
        );
        is(
          result[1].id,
          "b",
          `Got expected id for second element matching "${rule.selectorText}"`
        );

        info("Testing nested rule");
        rule = cssRules[1].cssRules[0];
        result = rule.querySelectorAll(document);
        is(result.length, 1, `1 element is matching "${rule.selectorText}"`);
        is(
          result[0].id,
          "d",
          `Got expected id for element matching "${rule.selectorText}"`
        );

        info("Testing multi-level deep nested rule");
        rule = cssRules[1].cssRules[0].cssRules[0];
        result = rule.querySelectorAll(document);
        // Check that we're not retrieving `f`, as the rule selectorText is `.test-nested-and-non-nested`,
        // but it is nested inside `.test-nested-child`.
        is(result.length, 1, `1 element is matching "${rule.selectorText}"`);
        is(
          result[0].id,
          "e",
          `Got expected id for element matching "${rule.selectorText}"`
        );

        info(
          "Testing rule matching multiple elements with the same class, some nested, some not"
        );
        rule = cssRules[2];
        result = rule.querySelectorAll(document);
        is(result.length, 2, `2 elements are matching "${rule.selectorText}"`);
        is(
          result[0].id,
          "e",
          `Got expected id for first element matching "${rule.selectorText}"`
        );
        is(
          result[1].id,
          "f",
          `Got expected id for second element matching "${rule.selectorText}"`
        );

        info("Testing that search results are limited by the passed root node");
        rule = cssRules[2];
        result = rule.querySelectorAll(document.querySelector("#c"));
        is(
          result.length,
          1,
          `An element is matching "${rule.selectorText}" in #c`
        );
        is(
          result[0].id,
          "e",
          `Got expected id for element matching "${rule.selectorText}"`
        );

        info("Testing rule with no matching elements");
        rule = cssRules[3];
        result = rule.querySelectorAll(document);
        is(result.length, 0, `No elements matching "${rule.selectorText}"`);

        SimpleTest.finish();
      }
    </script>
  </head>
  <body>
    <h1>Test CSSStyleRule::QuerySelectorAll</h1>
    <p id="display"></p>
    <div id="content" style="display: none">
      <div id="a" class="test-simple"></div>
      <div id="b" class="test-simple"></div>
      <div id="c" class="test-nested-parent">
        <span id="d" class="test-nested-child">
          <b id="e" class="test-nested-and-non-nested"></b>
        </span>
      </div>
      <b id="f" class="test-nested-and-non-nested"></b>
    </div>
    <pre id="test"></pre>
  </body>
</html>