File: serialize-group-rules-with-decls.tentative.html

package info (click to toggle)
thunderbird 1%3A115.12.0-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,463,904 kB
  • sloc: cpp: 6,971,272; javascript: 5,208,988; ansic: 3,507,245; python: 1,137,377; asm: 432,531; xml: 205,149; java: 175,761; sh: 116,483; makefile: 22,157; perl: 13,971; objc: 12,561; yacc: 4,583; pascal: 2,840; lex: 1,720; ruby: 1,075; exp: 762; sql: 666; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (69 lines) | stat: -rw-r--r-- 2,970 bytes parent folder | download | duplicates (4)
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
<!doctype html>
<title>Serialization of declarations in group rules</title>
<link rel="author" title="Steinar H. Gunderson" href="mailto:sesse@chromium.org">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/7850">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<style id="test-sheet"></style>
<script>
  function serialize(cssText) {
    let [ss] = document.styleSheets;
    while (ss.rules.length) {
      ss.removeRule(0)
    }
    ss.insertRule(cssText);
    return ss.rules[0].cssText;
  }

  function assert_unchanged(cssText) {
    assert_equals(serialize(cssText), cssText);
  }

  function assert_becomes(cssText, serializedCssText) {
    assert_equals(serialize(cssText), serializedCssText);
  }

  // Declarations are serialized on one line, rules on two.
  test(() => {
    assert_unchanged("@media screen {\n  div { color: red; background-color: green; }\n}");
    assert_unchanged("div {\n  @media screen { color: red; background-color: green; }\n}");
  });

  // Mixed declarations/rules are on two lines.
  test(() => {
    assert_unchanged("div {\n  @supports selector(&) {\n  color: red; background-color: green;\n  &:hover { color: navy; }\n}\n}");
  });

  // & {} rules are removed if and only if they are first, and they have no children.
  test(() => {
    assert_becomes("div { @media screen { & { color: red; } }",
                   "div {\n  @media screen { color: red; }\n}");
    assert_becomes("div { @media screen { & { color: red; &:hover { } } }",
                   "div {\n  @media screen {\n  & {\n  color: red;\n  &:hover { }\n}\n}\n}");
    assert_becomes("div { @media screen { &.cls { color: red; } & { color: red; }",
                   "div {\n  @media screen {\n  &.cls { color: red; }\n  & { color: red; }\n}\n}");
    assert_becomes("div { @media screen { & { color: red; } & { color: red; }",
                   "div {\n  @media screen {\n  color: red;\n  & { color: red; }\n}\n}");
    assert_becomes("div { @media screen { color: red; & { color: red; }",
                   "div {\n  @media screen {\n  color: red;\n  & { color: red; }\n}\n}");
    assert_becomes("div { @media screen { color: red; & { color: blue; }",
                   "div {\n  @media screen {\n  color: red;\n  & { color: blue; }\n}\n}");
    assert_becomes("div { @media screen { &, p > & { color: blue; }",
                   "div {\n  @media screen {\n  &, p > & { color: blue; }\n}\n}");
  });

  // They are not removed from regular rules.
  test(() => {
    assert_becomes("div { & { color: red; } }", "div {\n  & { color: red; }\n}");
  });

  // Empty rules (confusingly?) serialize different between style rules
  // and conditional group rules.
  test(() => {
    assert_unchanged("@media screen {\n}");
    assert_unchanged("div { }");
    assert_unchanged("div {\n  @media screen {\n}\n}");
    assert_unchanged("@media screen {\n  div { }\n}");
  });
</script>