summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-contain/container-queries/at-container-serialization.html
blob: 141062a8d4711c69e49b368a9ba88ecee2edaf4b (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
<!doctype html>
<title>CSS Container Queries: @container serialization</title>
<link rel="help" href="https://drafts.csswg.org/css-contain-3/#container-queries">
<link rel="help" href="https://drafts.csswg.org/cssom/#serialize-a-css-rule">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/cq-testcommon.js"></script>
<style id="testSheet">
  @container (width=100px) {
    @container \!-name (inline-size > 200px    ) {
      #id { color: lime }
    }
    #id { color: green }
  }
  @container (  wiDTh  ) { }
  @container (width:100px) { }
  @container (min-width:  100px) { }
  @container (   MAX-WIDTH:100px  ) { }
  @container (width > 100px) { }
  @container (width < 100px) { }
  @container (widTH >= 100px) { }
  @container (width <= 100px) { }
  @container (10px < width < 100px) { }
  @container (10px <=  width  <=  100px) { }
  @container (100px>WIDTH>10px) { }
  @container (  100px >= width >= 10px  ) { }
  @container (calc(1em + 1px) >= width >= max(10em, 10px)) { }
</style>
<script>
  setup(() => assert_implements_container_queries());

  let rules = testSheet.sheet.cssRules;

  test(() => {
    assert_equals(rules.length, 14);
    assert_equals(rules[0].cssRules.length, 2);

    assert_equals(rules[0].conditionText, "(width = 100px)");
    assert_equals(rules[0].cssRules[0].conditionText, "\\!-name (inline-size > 200px)");
  }, "Serialization of conditionText");

  test(() => {
    assert_equals(rules[0].cssRules[0].cssText, "@container \\!-name (inline-size > 200px) {\n  #id { color: lime; }\n}");
  }, "Serialization of inner @container rule");

  test(() => {
    assert_equals(rules[0].cssText, "@container (width = 100px) {\n  @container \\!-name (inline-size > 200px) {\n  #id { color: lime; }\n}\n  #id { color: green; }\n}");
  }, "Serialization of nested @container rule");

  test(() => {
    assert_equals(rules[1].conditionText, "(width)");
  }, "Serialization of boolean condition syntax");

  test(() => {
    assert_equals(rules[2].conditionText, "(width: 100px)");
    assert_equals(rules[3].conditionText, "(min-width: 100px)");
    assert_equals(rules[4].conditionText, "(max-width: 100px)");
  }, "Serialization of colon condition syntax");

  test(() => {
    assert_equals(rules[5].conditionText, "(width > 100px)");
    assert_equals(rules[6].conditionText, "(width < 100px)");
    assert_equals(rules[7].conditionText, "(width >= 100px)");
    assert_equals(rules[8].conditionText, "(width <= 100px)");
    assert_equals(rules[9].conditionText, "(10px < width < 100px)");
    assert_equals(rules[10].conditionText, "(10px <= width <= 100px)");
    assert_equals(rules[11].conditionText, "(100px > width > 10px)");
    assert_equals(rules[12].conditionText, "(100px >= width >= 10px)");
  }, "Serialization of range condition syntax");

  test(() => {
    assert_equals(rules[13].conditionText, "(calc(1em + 1px) >= width >= max(10em, 10px))");
  }, "Serialization of calc()");
</script>