summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/cssom-view/checkVisibility.html
blob: e77be7e9286be2f1cef1f11f2ea5129e0b1311be (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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<link rel=help href="https://github.com/w3c/csswg-drafts/issues/6850">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<div id=visibilityhidden style="visibility:hidden">hello</div>

<div style="content-visibility:hidden">
  <div id=cvhidden>hello</div>
</div>

<div style="content-visibility:auto">
  <div id=cvauto>hello</div>
</div>

<div id=displaynone style="display:none">hello</div>

<div style="display:none" class="shadow-host-with-slot">
  <div id="slottedindisplaynone" slot="slot">slotted</div>
</div>

<div id=displaycontents style="display:contents">
  <div id=displaycontentschild>hello</div>
</div>

<div id=opacityzero style="opacity:0">hello</div>

<div style="opacity:0" class="shadow-host-with-slot">
  <div id="slottedinopacityzero" slot="slot">slotted</div>
</div>

<div style="content-visibility:hidden">
  <div id=cvhiddenchildwithupdate></div>
</div>

<div style="content-visibility:hidden" id=cvhiddenwithupdate></div>

<div style="content-visibility:hidden" class="shadow-host-with-slot">
  <div id="slottedincvhidden" slot="slot">slotted</div>
</div>

<div style="height:10000px">spacer</div>

<div style="content-visibility:auto">
  <div id=cvautooffscreen>hello</div>
</div>

<div id=cvautocontainer>
  <div id=cvautochild></div>
</div>

<div style="content-visibility:auto">
  <div style="content-visibility:auto">
    <div id=nestedcvautochild></div>
  </div>
</div>

<script>
for (const host of document.querySelectorAll(".shadow-host-with-slot")) {
  const shadowRoot = host.attachShadow({ mode: "open" });
  const slot = document.createElement("slot");
  slot.name = "slot";
  shadowRoot.appendChild(slot);
}

test(() => {
  assert_false(visibilityhidden.checkVisibility({
    checkVisibilityCSS: true
  }), 'checkVisibilityCSS:true');
  assert_false(visibilityhidden.checkVisibility({
    visibilityProperty: true
  }), 'visibilityProperty:true');
  assert_true(visibilityhidden.checkVisibility({
    checkVisibilityCSS: false
  }), 'checkVisibilityCSS:false');
}, 'checkVisibility on visibility:hidden element.');

test(() => {
  assert_false(cvhidden.checkVisibility());
}, 'checkVisibility on content-visibility:hidden element.');

test(() => {
  assert_false(slottedincvhidden.checkVisibility());
}, 'checkVisibility on element slotted in content-visibility: hidden shadow host.');

promise_test(async () => {
  await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)));
  assert_true(cvauto.checkVisibility({
    contentVisibilityAuto: false
  }), 'contentVisibilityAuto: false');
  assert_true(cvauto.checkVisibility({
    contentVisibilityAuto: true
  }), 'contentVisibilityAuto: true');
}, 'checkVisibility on content-visibility:auto element.');

test(() => {
  assert_true(cvautooffscreen.checkVisibility({
    contentVisibilityAuto: false
  }), 'contentVisibilityAuto: false');
  assert_false(cvautooffscreen.checkVisibility({
    contentVisibilityAuto: true
  }), 'contentVisibilityAuto: true');
}, 'checkVisibility on content-visibility:auto element which is outside the viewport.');

test(() => {
  assert_false(displaynone.checkVisibility());
}, 'checkVisibility on display:none element.');

test(() => {
  assert_false(slottedindisplaynone.checkVisibility());
}, 'checkVisibility on element slotted in display:none shadow host.');

test(() => {
  assert_false(displaycontents.checkVisibility());
  assert_true(displaycontentschild.checkVisibility());
}, 'checkVisibility on display:contents element.');

test(() => {
  assert_false(opacityzero.checkVisibility({
    checkOpacity: true
  }), 'checkOpacity:true');
  assert_false(opacityzero.checkVisibility({
    opacityProperty: true
  }), 'opacityProperty:true');
  assert_true(opacityzero.checkVisibility({
    checkOpacity: false
  }), 'checkOpacity:false');
}, 'checkVisibility on opacity:0 element.');

test(() => {
  assert_false(slottedinopacityzero.checkVisibility({
    checkOpacity: true
  }), 'checkOpacity: true');
  assert_true(slottedinopacityzero.checkVisibility({
    checkOpacity: false
  }), 'checkOpacity: true');
}, 'checkVisibility on element slotted in opacity: 0; shadow host.');

test(() => {
  cvautocontainer.style.contentVisibility = 'auto';
  cvautochild.style.visibility = 'hidden';
  assert_false(cvautochild.checkVisibility({checkVisibilityCSS: true}));
  assert_false(cvautochild.checkVisibility({contentVisibilityAuto: true}));
  assert_true(cvautochild.checkVisibility());
  cvautochild.style.visibility = 'visible';
  assert_true(cvautochild.checkVisibility({checkVisibilityCSS: true}));
  assert_false(cvautochild.checkVisibility({contentVisibilityAuto: true}));
  assert_true(cvautochild.checkVisibility());
}, 'checkVisibility on content-visibility:auto with visibility:hidden inside.');

test(() => {
  assert_true(nestedcvautochild.checkVisibility());
}, 'checkVisibility on nested content-visibility:auto containers reports that the content is visible.');

test(() => {
  cvhiddenchildwithupdate.getBoundingClientRect();
  assert_false(cvhiddenchildwithupdate.checkVisibility());
}, 'checkVisibility on content-visibility:hidden child after forced layout update.');

test(() => {
  cvhiddenwithupdate.getBoundingClientRect();
  assert_true(cvhiddenwithupdate.checkVisibility());
}, 'checkVisibility on content-visibility:hidden element after forced layout update.');

test(() => {
  document.documentElement.style.contentVisibility = "hidden";
  assert_true(document.documentElement.checkVisibility());
  document.documentElement.style.removeProperty("content-visibility");
}, 'checkVisibility on root element with content-visibility: hidden returns true.');
</script>