summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-scroll-snap-2/snapchanged/snapchanged-with-proximity-strictness.tentative.html
blob: 6a874e82f22dd8fe4239517bec561d559543d3bd (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
<!DOCTYPE html>
<html>
<head>
<title>
  <title> CSS Scroll Snap 2 Test: snapchanged events on proximity strictness container</title>
  <link rel="help" href="https://drafts.csswg.org/css-scroll-snap-2/#snap-events"/>
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/dom/events/scrolling/scroll_support.js"></script>
<script src="/css/css-scroll-snap-2/resources/common.js"></script>
<style>
  div {
    position: absolute;
    margin: 0;
  }

  #scroller {
    height: 600px;
    width: 600px;
    overflow: hidden;
    scroll-snap-type: y proximity;
  }

  .snap {
    width: 300px;
    height: 300px;
    background-color: green;
    scroll-snap-align: start;
  }

  .area {
    width: 2000px;
    height: 2000px;
  }
  </style>
</head>
<body>
<div id="scroller">
  <div class="area"></div>
  <div id="target" class="snap" style="top: 0px;"></div>
</div>

<script>
  const target = document.getElementById("target");
  let resolve_func = null;

  promise_test(async (test) => {
    checkSnapEventSupport("snapchanged");
    await waitForCompositorCommit();
    // The initial snap position is at (0, 0).
    assert_equals(scroller.scrollTop, 0);
    assert_equals(scroller.scrollLeft, 0);

    let snapchanged_promise = waitForSnapChangedEvent(scroller);
    // Scroll to a position where it's outside of the scroll-snap proximity
    // threshold, so that it won't trigger snapping.
    scroller.scrollTo(0, 250);

    // snapchanged should fire as we've moved from within the proximity range
    // to outside the proximity range and are no longer snapped.
    let evt = await snapchanged_promise;
    assert_equals(scroller.scrollTop, 250);
    assertSnapEventDeprecated(evt, []);
    evt = null;

    snapchanged_promise = waitForSnapChangedEvent(scroller);
    // Scroll to a position within the scroll-snap proximity
    // threshold, so that it triggers snapping.
    scroller.scrollTo(0, 190);

    evt = await snapchanged_promise;
    assert_equals(scroller.scrollTop, 0);
    // snapchanged should fire as we've moved from outside the proximity range
    // to inside the proximity range and are once again snapped.
    assertSnapEventDeprecated(evt, [target.id]);
  }, "Snapchanged fires when scrolling outside proximity range.");
  </script>
</body>
</html>