summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-position/sticky/position-sticky-nested-right.html
blob: 0f7e43f35ad7e41df0e8624943815ed9701e766e (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
<!DOCTYPE html>
<title>Nested right-constrained position:sticky elements should render correctly</title>

<link rel="help" href="https://www.w3.org/TR/css-position-3/#sticky-pos" />
<meta name="assert" content="This test checks that nested position:sticky elements with a right constraint render correctly" />

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

<script src="../resources/sticky-util.js"></script>

<body></body>

<script>
test(() => {
  const elements = setupNestedStickyTest('right', 25, 35);
  elements.scroller.scrollLeft = 200;
  const nonStickyLeftX = elements.container.offsetLeft +
      elements.filler.clientWidth;
  assert_equals(elements.sticky.offsetLeft, nonStickyLeftX);
  // The inner sticky should not be offset from the outer.
  const nonStickyInnerLeftX = elements.sticky.clientWidth -
      elements.innerSticky.clientWidth;
  assert_equals(elements.innerSticky.offsetLeft, nonStickyInnerLeftX);
}, 'before reaching the sticking point, neither sticky box should be offset');

test(() => {
  const elements = setupNestedStickyTest('right', 25, 50);
  elements.scroller.scrollLeft = 150;
  const nonStickyLeftX = elements.container.offsetLeft +
      elements.filler.clientWidth;
  assert_equals(elements.sticky.offsetLeft, nonStickyLeftX);
  assert_equals(elements.innerSticky.offsetLeft, 50);
}, 'the inner sticky can stick before the outer one if necessary');

test(() => {
  const elements = setupNestedStickyTest('right', 25, 35);
  elements.scroller.scrollLeft = 100;

  const nonStickyLeftX = elements.container.offsetLeft +
      elements.filler.clientWidth;
  const nonStickyBottomX = nonStickyLeftX + elements.sticky.clientWidth;
  const targetBottomX = elements.scroller.clientWidth +
      elements.scroller.scrollLeft - 25;
  const stickyOffset = nonStickyBottomX - targetBottomX;
  assert_equals(elements.sticky.offsetLeft, nonStickyLeftX - stickyOffset);

  // The inner sticky has similar math, but its offsetLeft is relative to the
  // sticky element and in this test is (height - the difference between the
  // top values).
  assert_equals(elements.innerSticky.offsetLeft, 40);
}, 'both sticky boxes can be stuck at the same time');

test(() => {
  const elements = setupNestedStickyTest('right', 25, 100);
  elements.scroller.scrollLeft = 0;
  assert_equals(elements.sticky.offsetLeft, elements.container.offsetLeft);
  assert_equals(elements.innerSticky.offsetLeft, 0);
}, 'neither sticky can escape their containing block');

test(() => {
  const elements = setupNestedStickyTest('right', 25, 500);
  elements.scroller.scrollLeft = 200;
  // It doesn't matter how big the inner sticky offset is, it cannot escape its
  // containing block (the outer sticky).
  assert_equals(elements.innerSticky.offsetLeft, 0);
}, 'the inner sticky cannot be pushed outside the outer sticky');

</script>