summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/rules/test/browser_rules_nested_at_rules.js
blob: e945b9269f6153ddf8d256e1a3f2e0c49bded11b (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
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that the rule-view content is correct when the page defines nested at-rules (@media, @layer, @supports, …)
const TEST_URI = `
  <style type="text/css">
    body {
      container: mycontainer / inline-size;
    }

    @layer mylayer {
      @supports (container-name: mycontainer) {
        @container mycontainer (min-width: 1px) {
          @media screen {
            @container mycontainer (min-width: 2rem) {
              h1, [test-hint="nested"] {
                background: gold;
              }
            }
          }
        }
      }
    }
  </style>
  <h1>Hello nested at-rules!</h1>
`;

add_task(async function () {
  await pushPref("layout.css.container-queries.enabled", true);

  await addTab(
    "https://example.com/document-builder.sjs?html=" +
      encodeURIComponent(TEST_URI)
  );
  const { inspector, view } = await openRuleView();

  await selectNode("h1", inspector);

  const expectedRules = [
    { selector: "element", ancestorRulesData: null },
    {
      selector: `h1, [test-hint="nested"]`,
      ancestorRulesData: [
        `@layer mylayer {`,
        `  @supports (container-name: mycontainer) {`,
        `    @container mycontainer (min-width: 1px) {`,
        `      @media screen {`,
        `        @container mycontainer (min-width: 2rem) {`,
      ],
    },
  ];

  const rulesInView = Array.from(view.element.children);
  is(
    rulesInView.length,
    expectedRules.length,
    "All expected rules are displayed"
  );

  for (let i = 0; i < expectedRules.length; i++) {
    const expectedRule = expectedRules[i];
    info(`Checking rule #${i}: ${expectedRule.selector}`);

    const selector = rulesInView[i].querySelector(
      ".ruleview-selectors-container"
    ).innerText;
    is(selector, expectedRule.selector, `Expected selector for ${selector}`);

    if (expectedRule.ancestorRulesData == null) {
      is(
        getRuleViewAncestorRulesDataElementByIndex(view, i),
        null,
        `No ancestor rules data displayed for ${selector}`
      );
    } else {
      is(
        getRuleViewAncestorRulesDataTextByIndex(view, i),
        expectedRule.ancestorRulesData.join("\n"),
        `Expected ancestor rules data displayed for ${selector}`
      );
    }
  }
});