summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-contain/contain-size-dynamic-001.html
blob: f670d301c563e9317a0558a66609159c65b474eb (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
86
87
88
89
90
<!DOCTYPE html>
<meta charset="utf-8">
<title>Dynamic change to size containment</title>
<link rel="help" href="https://drafts.csswg.org/css-contain/#contain-property">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1765615">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
<meta name="assert" content="Verify size containment is properly updated after dynamic change to the contain property.">
<style>
  /* Selectors for contain */
  #none .wrapper {
      containt: none;
  }
  #size .wrapper {
      contain: size;
  }
  #none_to_size .wrapper {
      containt: none;
  }
  #size_to_none .wrapper {
      contain: size;
  }

  /* Selectors for testing sizing as empty */
  .wrapper {
      display: inline-block;
  }
  .box {
      display: inline-block;
      width: 50px;
      height: 5px;
      background: black;
  }
</style>
<body>
  <div id="log"></div>

  <div id="none">
    <div class="wrapper"><div class="box"></div></div>
  </div>

  <div id="size">
    <div class="wrapper"><div class="box"></div></div>
  </div>

  <div id="none_to_size">
    <div class="wrapper"><div class="box"></div></div>
  </div>

  <div id="size_to_none">
    <div class="wrapper"><div class="box"></div></div>
  </div>

  <script>
    function verifySizeContainment(id, applied) {
        // To verify size containment applies, we test whether it is sized as
        // if empty i.e. the size of its inner box is ignored.
        let container = document.getElementById(id);
        let wrapper = container.getElementsByClassName("wrapper")[0];
        let wrapperBox = wrapper.getBoundingClientRect();
        assert_equals(wrapperBox.width == 0, applied, "width is zero");
        assert_equals(wrapperBox.height == 0, applied, "height is zero");
    }

    function setContain(id, value) {
        let container = document.getElementById(id);
        let wrapper = container.getElementsByClassName("wrapper")[0];
        wrapper.style.contain = value;
    }

    promise_test(async () => {
        verifySizeContainment("none", /*applied=*/false);
    }, "contain: none");

    promise_test(async () => {
        verifySizeContainment("size", /*applied=*/true);
    }, "contain: size");

    promise_test(async () => {
        setContain("none_to_size", "size");
        verifySizeContainment("none_to_size", /*applied=*/true);
    }, "switching contain from none to size");

    promise_test(async () => {
        setContain("size_to_none", "none");
        verifySizeContainment("size_to_none", /*applied=*/false);
    }, "switching contain from size to none");
  </script>
</body>