summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-anchor-position/anchor-scroll-006.html
blob: 9c8a8c0ac2fe3cdb8942cbe08dc6a97591a5dc30 (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
<!DOCTYPE html>
<title>Tests that scroll adjustment is applied per-axis</title>
<link rel="help" href="https://drafts.csswg.org/css-anchor-position-1/#needs-scroll-adjustment">
<link rel="author" href="mailto:xiaochengh@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/test-common.js"></script>

<style>
body {
  margin: 0;
}

.scroller {
  width: 150px;
  height: 150px;
  margin-bottom: 50px;
  overflow: scroll;
  position: relative;
}

.spacer {
  width: 400px;
  height: 400px;
}

.anchor {
  position: absolute;
  width: 50px;
  height: 50px;
  top: 50px;
  left: 50px;
  background: orange;
}

.target {
  position: fixed;
  width: 50px;
  height: 50px;
  background: lime;
}

#scroller1 { anchor-name: --scroller1; }
#scroller2 { anchor-name: --scroller2; }
#scroller3 { anchor-name: --scroller3; }

#anchor1 { anchor-name: --a1; }
#anchor2 { anchor-name: --a2; }
#anchor3 { anchor-name: --a3; }

/* Needs scroll adjustment in x axis only */
#target1 {
  position-anchor: --a1;
  left: anchor(left);
  top: anchor(--scroller1 bottom);
}

/* Needs scroll adjustment in y axis only */
#target2 {
  position-anchor: --a2;
  top: anchor(top);
  left: anchor(--scroller2 right);
}

/* No scroll adjustment needed */
#target3 {
  position-anchor: --a3;
  top: anchor(--scroller3 bottom);
  left: anchor(--scroller3 right);
}
</style>

<div class="scroller" id="scroller1">
  <div class="spacer"></div>
  <div class="anchor" id="anchor1"></div>
</div>
<div class="target" id="target1"></div>

<script>
promise_test(async () => {
  await waitUntilNextAnimationFrame();
  assert_equals(target1.getBoundingClientRect().left, 50);
  assert_equals(target1.getBoundingClientRect().top, 150);

  scroller1.scrollLeft = 50;
  await waitUntilNextAnimationFrame();
  assert_equals(target1.getBoundingClientRect().left, 0);

  scroller1.scrollTop = 50;
  await waitUntilNextAnimationFrame();
  assert_equals(target1.getBoundingClientRect().top, 150);
}, '#target1 is scroll-adjusted in x axis only');
</script>

<div class="scroller" id="scroller2">
  <div class="spacer"></div>
  <div class="anchor" id="anchor2"></div>
</div>
<div class="target" id="target2"></div>

<script>
promise_test(async () => {
  await waitUntilNextAnimationFrame();
  assert_equals(target2.getBoundingClientRect().left, 150);
  assert_equals(target2.getBoundingClientRect().top, 250);

  scroller2.scrollLeft = 50;
  await waitUntilNextAnimationFrame();
  assert_equals(target2.getBoundingClientRect().left, 150);

  scroller2.scrollTop = 50;
  await waitUntilNextAnimationFrame();
  assert_equals(target2.getBoundingClientRect().top, 200);
}, '#target2 is scroll-adjusted in y axis only');
</script>

<div class="scroller" id="scroller3">
  <div class="spacer"></div>
  <div class="anchor" id="anchor3"></div>
</div>
<div class="target" id="target3"></div>

<script>
promise_test(async () => {
  await waitUntilNextAnimationFrame();
  assert_equals(target3.getBoundingClientRect().left, 150);
  assert_equals(target3.getBoundingClientRect().top, 550);

  scroller3.scrollLeft = 50;
  await waitUntilNextAnimationFrame();
  assert_equals(target3.getBoundingClientRect().left, 150);

  scroller3.scrollTop = 50;
  await waitUntilNextAnimationFrame();
  assert_equals(target3.getBoundingClientRect().top, 550);
}, '#target3 is scroll-adjusted in neither axis');
</script>