File: content-visibility-auto-relevancy-updates.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (109 lines) | stat: -rw-r--r-- 3,552 bytes parent folder | download | duplicates (13)
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
<!doctype html>
<meta charset="utf-8">
<title>Content Visibility: relevancy updates</title>
<link rel="author" title="Frédéric Wang" href="mailto:fwang@igalia.com">
<link rel="help" href="https://drafts.csswg.org/css-contain/#content-visibility">
<link rel="help" href="https://drafts.csswg.org/css-contain/#relevant-to-the-user">
<link rel="help" href="https://drafts.csswg.org/css-contain/#cv-notes">
<meta name="assert" content="Verify relevancy is properly updated for content-visibility: auto elements.">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<style>
  #spacer {
    height: 300vh;
  }
  #contentVisibilityAuto {
    content-visibility: auto;
    border: solid;
  }
</style>
<div>
  <div id="log"></div>
  <div tabindex="1" id="spacer"></div>
  <div tabindex="2" id="contentVisibilityAuto">
    <span>Hello, World!</span>
  </div>
</div>

<script>
function tick() {
  return new Promise(r => {
    requestAnimationFrame(() => requestAnimationFrame(r));
  });
}

function contentVisibilityAutoElementIsRelevant() {
  // A content-visibility: auto element that is not relevant skips its contents,
  // which do not contribute to the result of innerText.
  return contentVisibilityAuto.innerText.length > 0;
}

function clearRelevancyReasons() {
  window.scrollTo(0, 0);
  spacer.focus({preventScroll: true});
  window.getSelection().empty();
}

promise_test(async function(t) {
  // Wait for page load.
  await new Promise(resolve => { window.addEventListener("load", resolve); });

  // Register cleanup method to reset relevancy.
  t.add_cleanup(clearRelevancyReasons);

  // Element should initially not be relevant.
  await tick();
  assert_false(contentVisibilityAutoElementIsRelevant(), "initial relevancy");

  // Make element close to the viewport.
  contentVisibilityAuto.firstElementChild.scrollIntoView();
  await tick();
  assert_true(contentVisibilityAutoElementIsRelevant(), "close to viewport");

  // Scroll away from the element again.
  window.scrollTo(0, 0);
  await tick();
  assert_false(contentVisibilityAutoElementIsRelevant(), "far from viewport");
}, "Relevancy updated after changing proximity to the viewport.");

promise_test(async function(t) {
  // Register cleanup method to reset relevancy.
  t.add_cleanup(clearRelevancyReasons);

  // Element should initially not be relevant.
  await tick();
  assert_false(contentVisibilityAutoElementIsRelevant(), "initial relevancy");

  // Focus the element.
  contentVisibilityAuto.focus({preventScroll: true});
  await tick();
  assert_true(contentVisibilityAutoElementIsRelevant(), "focused");

  // Unfocus the element again.
  spacer.focus({preventScroll: true});
  await tick();
  assert_false(contentVisibilityAutoElementIsRelevant(), "unfocused");
}, "Relevancy updated after being focused/unfocused.");

promise_test(async function(t) {
  // Register cleanup method to reset relevancy.
  t.add_cleanup(clearRelevancyReasons);

  // Element should initially not be relevant.
  await tick();
  assert_false(contentVisibilityAutoElementIsRelevant(), "initial relevancy");

  // Select the contents of the element.
  window.getSelection().selectAllChildren(contentVisibilityAuto);
  await tick();
  assert_true(contentVisibilityAutoElementIsRelevant(), "selected");

  // Unselect the contents of the element.
  window.getSelection().empty();
  await tick();
  assert_false(contentVisibilityAutoElementIsRelevant(), "unselected");
}, "Relevancy updated after being selected/unselected.");

</script>